|
|
|
@ -50,22 +50,7 @@ module.exports = function (Categories) {
|
|
|
|
|
category.backgroundImage = data.backgroundImage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await plugins.hooks.fire('filter:category.create', { category: category, data: data });
|
|
|
|
|
category = result.category;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await db.setObject(`category:${category.cid}`, category);
|
|
|
|
|
if (!category.descriptionParsed) {
|
|
|
|
|
await Categories.parseDescription(category.cid, category.description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await db.sortedSetAddBulk([
|
|
|
|
|
['categories:cid', category.order, category.cid],
|
|
|
|
|
[`cid:${parentCid}:children`, category.order, category.cid],
|
|
|
|
|
['categories:name', 0, `${data.name.substr(0, 200).toLowerCase()}:${category.cid}`],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const defaultPrivileges = [
|
|
|
|
|
let defaultPrivileges = [
|
|
|
|
|
'groups:find',
|
|
|
|
|
'groups:read',
|
|
|
|
|
'groups:topics:read',
|
|
|
|
@ -79,14 +64,36 @@ module.exports = function (Categories) {
|
|
|
|
|
'groups:posts:downvote',
|
|
|
|
|
'groups:topics:delete',
|
|
|
|
|
];
|
|
|
|
|
const modPrivileges = defaultPrivileges.concat([
|
|
|
|
|
let modPrivileges = defaultPrivileges.concat([
|
|
|
|
|
'groups:topics:schedule',
|
|
|
|
|
'groups:posts:view_deleted',
|
|
|
|
|
'groups:purge',
|
|
|
|
|
]);
|
|
|
|
|
await privileges.categories.give(defaultPrivileges, category.cid, 'registered-users');
|
|
|
|
|
await privileges.categories.give(modPrivileges, category.cid, ['administrators', 'Global Moderators']);
|
|
|
|
|
await privileges.categories.give(['groups:find', 'groups:read', 'groups:topics:read'], category.cid, ['guests', 'spiders']);
|
|
|
|
|
let guestPrivileges = ['groups:find', 'groups:read', 'groups:topics:read'];
|
|
|
|
|
|
|
|
|
|
const result = await plugins.hooks.fire('filter:category.create', {
|
|
|
|
|
category: category,
|
|
|
|
|
data: data,
|
|
|
|
|
defaultPrivileges: defaultPrivileges,
|
|
|
|
|
modPrivileges: modPrivileges,
|
|
|
|
|
guestPrivileges: guestPrivileges,
|
|
|
|
|
});
|
|
|
|
|
category = result.category;
|
|
|
|
|
|
|
|
|
|
await db.setObject(`category:${category.cid}`, category);
|
|
|
|
|
if (!category.descriptionParsed) {
|
|
|
|
|
await Categories.parseDescription(category.cid, category.description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await db.sortedSetAddBulk([
|
|
|
|
|
['categories:cid', category.order, category.cid],
|
|
|
|
|
[`cid:${parentCid}:children`, category.order, category.cid],
|
|
|
|
|
['categories:name', 0, `${data.name.substr(0, 200).toLowerCase()}:${category.cid}`],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
await privileges.categories.give(result.defaultPrivileges, category.cid, 'registered-users');
|
|
|
|
|
await privileges.categories.give(result.modPrivileges, category.cid, ['administrators', 'Global Moderators']);
|
|
|
|
|
await privileges.categories.give(result.guestPrivileges, category.cid, ['guests', 'spiders']);
|
|
|
|
|
|
|
|
|
|
cache.del([
|
|
|
|
|
'categories:cid',
|
|
|
|
|