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

Updates on the frontends with a questions category and students /instructor default group #10

Closed
wants to merge 6 commits into from
Closed
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
9 changes: 9 additions & 0 deletions install/data/categories.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job getting a new category to show

Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@
"color": "#ffffff",
"icon" : "fa-question",
"order": 3
},
{
"name": "Questions",
"description": "Post any question you have!",
"descriptionParsed": "<p>Post any question you have!</p>\n",
"bgColor": "#e95c5a",
"color": "#ffffff",
"icon" : "fa-question",
"order": 5
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
{./name}
{{{ else }}}
<a class="text-reset" href="{{{ if ./link }}}{./link}{{{ else }}}{config.relative_path}/category/{./slug}{{{ end }}}" itemprop="url">{../name}</a>
{{{ end }}}
{{{ end }}}
38 changes: 38 additions & 0 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,42 @@ async function createGlobalModeratorsGroup() {
await groups.show('Global Moderators');
}

async function createStudents() {
const groups = require('./groups');
const exists = await groups.exists('Students');
if (exists) {
winston.info('Students group found, skipping creation!');
} else {
await groups.create({
name: 'Students',
userTitle: 'Student',
description: 'Cute students here',
hidden: 0,
private: 0,
disableJoinRequests: 0,
});
}
await groups.show('Students');
}

async function createInstructors() {
const groups = require('./groups');
const exists = await groups.exists('Instructors');
if (exists) {
winston.info('Instructors group found, skipping creation!');
} else {
await groups.create({
name: 'Instructors',
userTitle: 'Instructor',
description: 'Cool instructors are here',
hidden: 0,
private: 0,
disableJoinRequests: 0,
});
}
await groups.show('Instructors');
}

async function giveGlobalPrivileges() {
const privileges = require('./privileges');
const defaultPrivileges = [
Expand Down Expand Up @@ -584,6 +620,8 @@ install.setup = async function () {
await createDefaultUserGroups();
const adminInfo = await createAdministrator();
await createGlobalModeratorsGroup();
await createStudents();
await createInstructors();
await giveGlobalPrivileges();
await createMenuItems();
await createWelcomePost();
Expand Down
39 changes: 39 additions & 0 deletions src/posts/create.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just go through this file and fix the small syntax errors that are causing failures

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const categories = require('../categories');
const groups = require('../groups');
const privileges = require('../privileges');
const notifications = require('../notifications');

module.exports = function (Posts) {
Posts.create = async function (data) {
Expand Down Expand Up @@ -64,11 +65,49 @@
addReplyTo(postData, timestamp),
Posts.uploads.sync(postData.pid),
]);

Check failure on line 68 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed

Check failure on line 68 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
// 🔹 Check if the posting user is in a specific group

Check failure on line 69 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 69 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs
const postingGroup = "Students"; // Change this to the correct group name

Check failure on line 70 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 70 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote

Check failure on line 70 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 70 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
const notifyGroup = "Instructors"; // Change this to the target group

Check failure on line 71 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 71 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote

Check failure on line 71 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 71 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
const targetCategoryId = 5; // Change to the category ID you want

Check failure on line 72 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 72 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

const belongsToPostingGroup = await groups.isMember(uid, postingGroup);

Check failure on line 74 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 74 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Mixed spaces and tabs

Check failure on line 75 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed

Check failure on line 75 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed

Check failure on line 76 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed

Check failure on line 76 in src/posts/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed

result = await plugins.hooks.fire('filter:post.get', { post: postData, uid: data.uid });
result.post.isMain = isMain;
plugins.hooks.fire('action:post.save', { post: _.clone(result.post) });

if (belongsToPostingGroup && postData.cid === targetCategoryId) {

console.log(`User in ${postingGroup} posted in category ${targetCategoryId}, notifying ${notifyGroup}`);

// 🔹 Get all members of the notify group using `getMembers`
const notifyUids = await groups.getMembers(notifyGroup, 0, -1);

if (notifyUids.length === 0) {
console.log(`No users found in group ${notifyGroup}, skipping notifications.`);
return;
}

// 🔹 Create the notification
const notification = await notifications.create({
type: 'custom-notification',
bodyShort: `A new post was made in category Question!`,
nid: `post:${postData.pid}`,
path: `/post/${postData.pid}`,
from: postData.uid,
});

// 🔹 Push the notification to all users in notifyGroup

await notifications.push(notification, notifyUids);

}
return result.post;


};

async function addReplyTo(postData, timestamp) {
Expand Down
Loading