mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	breaking: remove deprecated methods
socket.emit('topics.delete') removed use `DELETE /api/v3/topics/state`
socket.emit('topics.restore') removed use `PUT /api/v3/topics/state`
socket.emit('topics.purge') removed use `DELETE /api/v3/topics`
socket.emit('topics.lock') removed use `PUT /api/v3/topics/lock`
socket.emit('topics.unlock') removed use `DELETE /api/v3/topics/lock`
socket.emit('topics.pin') removed use `PUT /api/v3/topics/pin`
socket.emit('topics.unpin') removed use `DELETE /api/v3/topics/pin`
			
			
This commit is contained in:
		| @@ -1,10 +1,8 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| const api = require('../../api'); |  | ||||||
| const topics = require('../../topics'); | const topics = require('../../topics'); | ||||||
| const privileges = require('../../privileges'); | const privileges = require('../../privileges'); | ||||||
| const plugins = require('../../plugins'); | const plugins = require('../../plugins'); | ||||||
| const sockets = require('..'); |  | ||||||
|  |  | ||||||
| module.exports = function (SocketTopics) { | module.exports = function (SocketTopics) { | ||||||
| 	SocketTopics.loadTopicTools = async function (socket, data) { | 	SocketTopics.loadTopicTools = async function (socket, data) { | ||||||
| @@ -32,41 +30,6 @@ module.exports = function (SocketTopics) { | |||||||
| 		return result.topic; | 		return result.topic; | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	SocketTopics.delete = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'DELETE /api/v3/topics/state'); |  | ||||||
| 		await api.topics.delete(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.restore = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'PUT /api/v3/topics/state'); |  | ||||||
| 		await api.topics.restore(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.purge = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'DELETE /api/v3/topics'); |  | ||||||
| 		await api.topics.purge(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.lock = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'PUT /api/v3/topics/lock'); |  | ||||||
| 		await api.topics.lock(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.unlock = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'DELETE /api/v3/topics/lock'); |  | ||||||
| 		await api.topics.unlock(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.pin = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'PUT /api/v3/topics/pin'); |  | ||||||
| 		await api.topics.pin(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.unpin = async function (socket, data) { |  | ||||||
| 		sockets.warnDeprecated(socket, 'DELETE /api/v3/topics/pin'); |  | ||||||
| 		await api.topics.unpin(socket, data); |  | ||||||
| 	}; |  | ||||||
|  |  | ||||||
| 	SocketTopics.orderPinnedTopics = async function (socket, data) { | 	SocketTopics.orderPinnedTopics = async function (socket, data) { | ||||||
| 		if (!data || !data.tid) { | 		if (!data || !data.tid) { | ||||||
| 			throw new Error('[[error:invalid-data]]'); | 			throw new Error('[[error:invalid-data]]'); | ||||||
|   | |||||||
							
								
								
									
										120
									
								
								test/topics.js
									
									
									
									
									
								
							
							
						
						
									
										120
									
								
								test/topics.js
									
									
									
									
									
								
							| @@ -21,6 +21,7 @@ const groups = require('../src/groups'); | |||||||
| const helpers = require('./helpers'); | const helpers = require('./helpers'); | ||||||
| const socketPosts = require('../src/socket.io/posts'); | const socketPosts = require('../src/socket.io/posts'); | ||||||
| const socketTopics = require('../src/socket.io/topics'); | const socketTopics = require('../src/socket.io/topics'); | ||||||
|  | const apiTopics = require('../src/api/topics'); | ||||||
|  |  | ||||||
| const requestType = util.promisify((type, url, opts, cb) => { | const requestType = util.promisify((type, url, opts, cb) => { | ||||||
| 	request[type](url, opts, (err, res, body) => cb(err, { res: res, body: body })); | 	request[type](url, opts, (err, res, body) => cb(err, { res: res, body: body })); | ||||||
| @@ -621,62 +622,40 @@ describe('Topic\'s', () => { | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should delete the topic', (done) => { | 		it('should delete the topic', async () => { | ||||||
| 			socketTopics.delete({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.delete({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }) | ||||||
| 				assert.ifError(err); | 			const deleted = await topics.getTopicField(newTopic.tid, 'deleted'); | ||||||
| 				done(); | 			assert.strictEqual(deleted, 1); | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should restore the topic', (done) => { | 		it('should restore the topic', async () => { | ||||||
| 			socketTopics.restore({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.restore({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }); | ||||||
| 				assert.ifError(err); | 			const deleted = await topics.getTopicField(newTopic.tid, 'deleted'); | ||||||
| 				done(); | 			assert.strictEqual(deleted, 0); | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should lock topic', (done) => { | 		it('should lock topic', async () => { | ||||||
| 			socketTopics.lock({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.lock({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }); | ||||||
| 				assert.ifError(err); | 			const isLocked = await topics.isLocked(newTopic.tid); | ||||||
| 				topics.isLocked(newTopic.tid, (err, isLocked) => { |  | ||||||
| 					assert.ifError(err); |  | ||||||
| 			assert(isLocked); | 			assert(isLocked); | ||||||
| 					done(); |  | ||||||
| 				}); |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should unlock topic', (done) => { | 		it('should unlock topic', async () => { | ||||||
| 			socketTopics.unlock({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.unlock({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }); | ||||||
| 				assert.ifError(err); | 			const isLocked = await topics.isLocked(newTopic.tid); | ||||||
| 				topics.isLocked(newTopic.tid, (err, isLocked) => { |  | ||||||
| 					assert.ifError(err); |  | ||||||
| 			assert(!isLocked); | 			assert(!isLocked); | ||||||
| 					done(); |  | ||||||
| 				}); |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should pin topic', (done) => { | 		it('should pin topic', async () => { | ||||||
| 			socketTopics.pin({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.pin({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }); | ||||||
| 				assert.ifError(err); | 			const pinned = await topics.getTopicField(newTopic.tid, 'pinned'); | ||||||
| 				topics.getTopicField(newTopic.tid, 'pinned', (err, pinned) => { |  | ||||||
| 					assert.ifError(err); |  | ||||||
| 			assert.strictEqual(pinned, 1); | 			assert.strictEqual(pinned, 1); | ||||||
| 					done(); |  | ||||||
| 				}); |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should unpin topic', (done) => { | 		it('should unpin topic', async () => { | ||||||
| 			socketTopics.unpin({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.unpin({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }); | ||||||
| 				assert.ifError(err); | 			const pinned = await topics.getTopicField(newTopic.tid, 'pinned'); | ||||||
| 				topics.getTopicField(newTopic.tid, 'pinned', (err, pinned) => { |  | ||||||
| 					assert.ifError(err); |  | ||||||
| 			assert.strictEqual(pinned, 0); | 			assert.strictEqual(pinned, 0); | ||||||
| 					done(); |  | ||||||
| 				}); |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should move all topics', (done) => { | 		it('should move all topics', (done) => { | ||||||
| @@ -815,47 +794,31 @@ describe('Topic\'s', () => { | |||||||
| 			], done); | 			], done); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should fail to purge topic if user does not have privilege', (done) => { | 		it('should fail to purge topic if user does not have privilege', async () => { | ||||||
| 			let globalModUid; | 			const topic1 = await topics.post({ | ||||||
| 			let tid; |  | ||||||
| 			async.waterfall([ |  | ||||||
| 				function (next) { |  | ||||||
| 					topics.post({ |  | ||||||
| 				uid: adminUid, | 				uid: adminUid, | ||||||
| 				title: 'topic for purge test', | 				title: 'topic for purge test', | ||||||
| 				content: 'topic content', | 				content: 'topic content', | ||||||
| 				cid: categoryObj.cid, | 				cid: categoryObj.cid, | ||||||
| 					}, next); |  | ||||||
| 				}, |  | ||||||
| 				function (result, next) { |  | ||||||
| 					tid = result.topicData.tid; |  | ||||||
| 					User.create({ username: 'global mod' }, next); |  | ||||||
| 				}, |  | ||||||
| 				function (uid, next) { |  | ||||||
| 					globalModUid = uid; |  | ||||||
| 					groups.join('Global Moderators', uid, next); |  | ||||||
| 				}, |  | ||||||
| 				function (next) { |  | ||||||
| 					privileges.categories.rescind(['groups:purge'], categoryObj.cid, 'Global Moderators', next); |  | ||||||
| 				}, |  | ||||||
| 				function (next) { |  | ||||||
| 					socketTopics.purge({ uid: globalModUid }, { tids: [tid], cid: categoryObj.cid }, (err) => { |  | ||||||
| 						assert.equal(err.message, '[[error:no-privileges]]'); |  | ||||||
| 						privileges.categories.give(['groups:purge'], categoryObj.cid, 'Global Moderators', next); |  | ||||||
| 			}); | 			}); | ||||||
| 				}, | 			const tid1 = topic1.topicData.tid; | ||||||
| 			], done); | 			const globalModUid = await User.create({ username: 'global mod' }); | ||||||
|  | 			await groups.join('Global Moderators', globalModUid); | ||||||
|  | 			await privileges.categories.rescind(['groups:purge'], categoryObj.cid, 'Global Moderators'); | ||||||
|  | 			try { | ||||||
|  | 				await apiTopics.purge({ uid: globalModUid }, { tids: [tid1], cid: categoryObj.cid }); | ||||||
|  | 			} catch (err) { | ||||||
|  | 				assert.equal(err.message, '[[error:no-privileges]]'); | ||||||
|  | 				await privileges.categories.give(['groups:purge'], categoryObj.cid, 'Global Moderators'); | ||||||
|  | 				return; | ||||||
|  | 			} | ||||||
|  | 			assert(false); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should purge the topic', (done) => { | 		it('should purge the topic', async () => { | ||||||
| 			socketTopics.purge({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }, (err) => { | 			await apiTopics.purge({ uid: adminUid }, { tids: [newTopic.tid], cid: categoryObj.cid }); | ||||||
| 				assert.ifError(err); | 			const isMember = await db.isSortedSetMember(`uid:${followerUid}:followed_tids`, newTopic.tid); | ||||||
| 				db.isSortedSetMember(`uid:${followerUid}:followed_tids`, newTopic.tid, (err, isMember) => { |  | ||||||
| 					assert.ifError(err); |  | ||||||
| 			assert.strictEqual(false, isMember); | 			assert.strictEqual(false, isMember); | ||||||
| 					done(); |  | ||||||
| 				}); |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should not allow user to restore their topic if it was deleted by an admin', async () => { | 		it('should not allow user to restore their topic if it was deleted by an admin', async () => { | ||||||
| @@ -865,12 +828,13 @@ describe('Topic\'s', () => { | |||||||
| 				content: 'topic content', | 				content: 'topic content', | ||||||
| 				cid: categoryObj.cid, | 				cid: categoryObj.cid, | ||||||
| 			}); | 			}); | ||||||
| 			await socketTopics.delete({ uid: adminUid }, { tids: [result.topicData.tid], cid: categoryObj.cid }); | 			await apiTopics.delete({ uid: adminUid }, { tids: [result.topicData.tid], cid: categoryObj.cid }); | ||||||
| 			try { | 			try { | ||||||
| 				await socketTopics.restore({ uid: fooUid }, { tids: [result.topicData.tid], cid: categoryObj.cid }); | 				await apiTopics.restore({ uid: fooUid }, { tids: [result.topicData.tid], cid: categoryObj.cid }); | ||||||
| 			} catch (err) { | 			} catch (err) { | ||||||
| 				assert.strictEqual(err.message, '[[error:no-privileges]]'); | 				return assert.strictEqual(err.message, '[[error:no-privileges]]'); | ||||||
| 			} | 			} | ||||||
|  | 			assert(false); | ||||||
| 		}); | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user