mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
breaking: remove deprecated socket.emit('admin.categories.update')
This commit is contained in:
@@ -27,6 +27,9 @@ categoriesAPI.create = async function (caller, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
categoriesAPI.update = async function (caller, data) {
|
categoriesAPI.update = async function (caller, data) {
|
||||||
|
if (!data) {
|
||||||
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
}
|
||||||
await categories.update(data);
|
await categories.update(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ privsAdmin.socketMap = {
|
|||||||
'admin.rooms.getAll': 'admin:dashboard',
|
'admin.rooms.getAll': 'admin:dashboard',
|
||||||
'admin.analytics.get': 'admin:dashboard',
|
'admin.analytics.get': 'admin:dashboard',
|
||||||
|
|
||||||
'admin.categories.update': 'admin:categories',
|
|
||||||
'admin.categories.copySettingsFrom': 'admin:categories',
|
'admin.categories.copySettingsFrom': 'admin:categories',
|
||||||
|
|
||||||
'admin.categories.getPrivilegeSettings': 'admin:privileges',
|
'admin.categories.getPrivilegeSettings': 'admin:privileges',
|
||||||
|
|||||||
@@ -11,15 +11,6 @@ Categories.getNames = async function () {
|
|||||||
return await categories.getAllCategoryFields(['cid', 'name']);
|
return await categories.getAllCategoryFields(['cid', 'name']);
|
||||||
};
|
};
|
||||||
|
|
||||||
Categories.update = async function (socket, data) {
|
|
||||||
sockets.warnDeprecated(socket, 'PUT /api/v3/categories/:cid');
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
throw new Error('[[error:invalid-data]]');
|
|
||||||
}
|
|
||||||
return await api.categories.update(socket, data);
|
|
||||||
};
|
|
||||||
|
|
||||||
Categories.setPrivilege = async function (socket, data) {
|
Categories.setPrivilege = async function (socket, data) {
|
||||||
sockets.warnDeprecated(socket, 'PUT /api/v3/categories/:cid/privileges/:privilege');
|
sockets.warnDeprecated(socket, 'PUT /api/v3/categories/:cid/privileges/:privilege');
|
||||||
|
|
||||||
|
|||||||
@@ -363,50 +363,49 @@ describe('Categories', () => {
|
|||||||
cid = category.cid;
|
cid = category.cid;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error with invalid data', (done) => {
|
it('should return error with invalid data', async () => {
|
||||||
socketCategories.update({ uid: adminUid }, null, (err) => {
|
let err;
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
try {
|
||||||
done();
|
await apiCategories.update({ uid: adminUid }, null);
|
||||||
});
|
} catch (_err) {
|
||||||
|
err = _err;
|
||||||
|
}
|
||||||
|
assert.strictEqual(err.message, '[[error:invalid-data]]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error if you try to set parent as self', (done) => {
|
it('should error if you try to set parent as self', async () => {
|
||||||
const updateData = {};
|
const updateData = {};
|
||||||
updateData[cid] = {
|
updateData[cid] = {
|
||||||
parentCid: cid,
|
parentCid: cid,
|
||||||
};
|
};
|
||||||
socketCategories.update({ uid: adminUid }, updateData, (err) => {
|
let err;
|
||||||
assert.equal(err.message, '[[error:cant-set-self-as-parent]]');
|
try {
|
||||||
done();
|
await apiCategories.update({ uid: adminUid }, updateData);
|
||||||
});
|
} catch (_err) {
|
||||||
|
err = _err;
|
||||||
|
}
|
||||||
|
assert.strictEqual(err.message, '[[error:cant-set-self-as-parent]]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error if you try to set child as parent', (done) => {
|
it('should error if you try to set child as parent', async () => {
|
||||||
let child1Cid;
|
const parentCategory = await Categories.create({ name: 'parent 1', description: 'poor parent' });
|
||||||
let parentCid;
|
const parentCid = parentCategory.cid;
|
||||||
async.waterfall([
|
const childCategory = await Categories.create({ name: 'child1', description: 'wanna be parent', parentCid: parentCid });
|
||||||
function (next) {
|
const child1Cid = childCategory.cid;
|
||||||
Categories.create({ name: 'parent 1', description: 'poor parent' }, next);
|
const updateData = {};
|
||||||
},
|
updateData[parentCid] = {
|
||||||
function (category, next) {
|
parentCid: child1Cid,
|
||||||
parentCid = category.cid;
|
};
|
||||||
Categories.create({ name: 'child1', description: 'wanna be parent', parentCid: parentCid }, next);
|
let err;
|
||||||
},
|
try {
|
||||||
function (category, next) {
|
await apiCategories.update({ uid: adminUid }, updateData);
|
||||||
child1Cid = category.cid;
|
} catch (_err) {
|
||||||
const updateData = {};
|
err = _err;
|
||||||
updateData[parentCid] = {
|
}
|
||||||
parentCid: child1Cid,
|
assert.strictEqual(err.message, '[[error:cant-set-child-as-parent]]');
|
||||||
};
|
|
||||||
socketCategories.update({ uid: adminUid }, updateData, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:cant-set-child-as-parent]]');
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
], done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update category data', (done) => {
|
it('should update category data', async () => {
|
||||||
const updateData = {};
|
const updateData = {};
|
||||||
updateData[cid] = {
|
updateData[cid] = {
|
||||||
name: 'new name',
|
name: 'new name',
|
||||||
@@ -415,18 +414,14 @@ describe('Categories', () => {
|
|||||||
order: 3,
|
order: 3,
|
||||||
icon: 'fa-hammer',
|
icon: 'fa-hammer',
|
||||||
};
|
};
|
||||||
socketCategories.update({ uid: adminUid }, updateData, (err) => {
|
await apiCategories.update({ uid: adminUid }, updateData);
|
||||||
assert.ifError(err);
|
|
||||||
Categories.getCategoryData(cid, (err, data) => {
|
const data = await Categories.getCategoryData(cid);
|
||||||
assert.ifError(err);
|
assert.equal(data.name, updateData[cid].name);
|
||||||
assert.equal(data.name, updateData[cid].name);
|
assert.equal(data.description, updateData[cid].description);
|
||||||
assert.equal(data.description, updateData[cid].description);
|
assert.equal(data.parentCid, updateData[cid].parentCid);
|
||||||
assert.equal(data.parentCid, updateData[cid].parentCid);
|
assert.equal(data.order, updateData[cid].order);
|
||||||
assert.equal(data.order, updateData[cid].order);
|
assert.equal(data.icon, updateData[cid].icon);
|
||||||
assert.equal(data.icon, updateData[cid].icon);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not remove category from parent if parent is set again to same category', async () => {
|
it('should not remove category from parent if parent is set again to same category', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user