mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	fix: #9973, ignore if assigning to same parent
This commit is contained in:
		| @@ -71,6 +71,9 @@ module.exports = function (Categories) { | ||||
| 		} | ||||
| 		const categoryData = await Categories.getCategoryFields(cid, ['parentCid', 'order']); | ||||
| 		const oldParent = categoryData.parentCid; | ||||
| 		if (oldParent === newParent) { | ||||
| 			return; | ||||
| 		} | ||||
| 		await Promise.all([ | ||||
| 			db.sortedSetRemove(`cid:${oldParent}:children`, cid), | ||||
| 			db.sortedSetAdd(`cid:${newParent}:children`, categoryData.order, cid), | ||||
|   | ||||
| @@ -432,6 +432,26 @@ describe('Categories', () => { | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		it('should not remove category from parent if parent is set again to same category', async () => { | ||||
| 			const parentCat = await Categories.create({ name: 'parent', description: 'poor parent' }); | ||||
| 			const updateData = {}; | ||||
| 			updateData[cid] = { | ||||
| 				parentCid: parentCat.cid, | ||||
| 			}; | ||||
| 			await Categories.update(updateData); | ||||
| 			let data = await Categories.getCategoryData(cid); | ||||
| 			assert.equal(data.parentCid, updateData[cid].parentCid); | ||||
| 			let childrenCids = await db.getSortedSetRange(`cid:${parentCat.cid}:children`, 0, -1); | ||||
| 			assert(childrenCids.includes(String(cid))); | ||||
|  | ||||
| 			// update again to same parent | ||||
| 			await Categories.update(updateData); | ||||
| 			data = await Categories.getCategoryData(cid); | ||||
| 			assert.equal(data.parentCid, updateData[cid].parentCid); | ||||
| 			childrenCids = await db.getSortedSetRange(`cid:${parentCat.cid}:children`, 0, -1); | ||||
| 			assert(childrenCids.includes(String(cid))); | ||||
| 		}); | ||||
|  | ||||
| 		it('should purge category', (done) => { | ||||
| 			Categories.create({ | ||||
| 				name: 'purge me', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user