feat: allow modifying default category privileges

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 8672329218
commit 57e46e41e3

@ -50,22 +50,7 @@ module.exports = function (Categories) {
category.backgroundImage = data.backgroundImage; category.backgroundImage = data.backgroundImage;
} }
const result = await plugins.hooks.fire('filter:category.create', { category: category, data: data }); let defaultPrivileges = [
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 = [
'groups:find', 'groups:find',
'groups:read', 'groups:read',
'groups:topics:read', 'groups:topics:read',
@ -79,14 +64,36 @@ module.exports = function (Categories) {
'groups:posts:downvote', 'groups:posts:downvote',
'groups:topics:delete', 'groups:topics:delete',
]; ];
const modPrivileges = defaultPrivileges.concat([ let modPrivileges = defaultPrivileges.concat([
'groups:topics:schedule', 'groups:topics:schedule',
'groups:posts:view_deleted', 'groups:posts:view_deleted',
'groups:purge', 'groups:purge',
]); ]);
await privileges.categories.give(defaultPrivileges, category.cid, 'registered-users'); let guestPrivileges = ['groups:find', 'groups:read', 'groups:topics:read'];
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']); 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([ cache.del([
'categories:cid', 'categories:cid',

Loading…
Cancel
Save