Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 1 Changes Anuja #26

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Interested in a sublicense agreement for use of NodeBB in a non-free/restrictive
* [Follow us on Twitter](http://www.twitter.com/NodeBB/ "NodeBB Twitter")
* [Like us on Facebook](http://www.facebook.com/NodeBB/ "NodeBB Facebook")

=======
## Team Members
Kester Tan
Anuja Uppuluri
Expand All @@ -107,4 +108,5 @@ Here is how to set it up:
```
./nodebb stop && ./nodebb reset -t nodebb-theme-slackers && ./nodebb build && ./nodebb start
```
4. Go to http://localhost:4567/ to see the new theme in action!
4. Go to http://localhost:4567/ to see the new theme in action!

83 changes: 41 additions & 42 deletions src/categories/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const cache = require('../cache');

module.exports = function (Categories) {
Categories.create = async function (data) {
const parentCid = data.parentCid ? data.parentCid : 0;
const parentCid = data.parentCid || 0;
const [cid, firstChild] = await Promise.all([
db.incrObjectField('global', 'nextCid'),
db.getSortedSetRangeWithScores(`cid:${parentCid}:children`, 0, 0),
Expand All @@ -24,52 +24,15 @@ module.exports = function (Categories) {
const order = data.order || smallestOrder; // If no order provided, place it at the top
const colours = Categories.assignColours();

let category = {
cid: cid,
name: data.name,
description: data.description ? data.description : '',
descriptionParsed: data.descriptionParsed ? data.descriptionParsed : '',
icon: data.icon ? data.icon : '',
bgColor: data.bgColor || colours[0],
color: data.color || colours[1],
slug: slug,
parentCid: parentCid,
topic_count: 0,
post_count: 0,
disabled: data.disabled ? 1 : 0,
order: order,
link: data.link || '',
numRecentReplies: 1,
class: (data.class ? data.class : 'col-md-3 col-6'),
imageClass: 'cover',
isSection: 0,
subCategoriesPerPage: 10,
};
let category = createCategory(data, cid, colours, slug, parentCid, order);
console.log('Anuja - createCategory');

if (data.backgroundImage) {
category.backgroundImage = data.backgroundImage;
}

const defaultPrivileges = [
'groups:find',
'groups:read',
'groups:topics:read',
'groups:topics:create',
'groups:topics:reply',
'groups:topics:tag',
'groups:posts:edit',
'groups:posts:history',
'groups:posts:delete',
'groups:posts:upvote',
'groups:posts:downvote',
'groups:topics:delete',
];
const modPrivileges = defaultPrivileges.concat([
'groups:topics:schedule',
'groups:posts:view_deleted',
'groups:purge',
]);
const guestPrivileges = ['groups:find', 'groups:read', 'groups:topics:read'];
const { defaultPrivileges, modPrivileges, guestPrivileges } = getCategoryPrivileges();


const result = await plugins.hooks.fire('filter:category.create', {
category: category,
Expand Down Expand Up @@ -259,4 +222,40 @@ module.exports = function (Categories) {
await privileges.categories.give(givePrivs, toCid, group);
await privileges.categories.rescind(rescindPrivs, toCid, group);
}
function getCategoryPrivileges() {
const defaultPrivileges = [
'groups:find', 'groups:read', 'groups:topics:read', 'groups:topics:create',
'groups:topics:reply', 'groups:topics:tag', 'groups:posts:edit',
'groups:posts:history', 'groups:posts:delete', 'groups:posts:upvote',
'groups:posts:downvote', 'groups:topics:delete',
];
const modPrivileges = defaultPrivileges.concat([
'groups:topics:schedule', 'groups:posts:view_deleted', 'groups:purge',
]);
const guestPrivileges = ['groups:find', 'groups:read', 'groups:topics:read'];
return { defaultPrivileges, modPrivileges, guestPrivileges };
}
function createCategory(data, cid, colours, slug, parentCid, order) {
return {
cid: cid,
name: data.name || `Category ${cid}`,
description: data.description || '',
descriptionParsed: data.descriptionParsed || '',
icon: data.icon || '',
bgColor: data.bgColor || colours[0],
color: data.color || colours[1],
slug: slug,
parentCid: parentCid,
topic_count: 0,
post_count: 0,
disabled: data.disabled ? 1 : 0,
order: order,
link: data.link || '',
numRecentReplies: 1,
class: data.class || 'col-md-3 col-6',
imageClass: 'cover',
isSection: 0,
subCategoriesPerPage: 10,
};
}
};