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

Installing & Running StandardJS static analysis tool #101

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
576fb84
add deadline
github-classroom[bot] Sep 9, 2024
7e47494
Refactored rooms.io code from complexity 16 to 15
alicekang1 Sep 18, 2024
f5f5500
Refactoring code in src/groups/update.js
JasmineRocket Sep 20, 2024
be7d2cb
fix "no-trailing-space" error
mhli1260 Sep 21, 2024
03aed02
fixing "trailing space not allowed" error
mhli1260 Sep 21, 2024
fd2bda9
fixing grammar errors in update.js
JasmineRocket Sep 23, 2024
b6c3308
Update update.js
JasmineRocket Sep 23, 2024
f46f43b
Add "Homework" and "Assignment" categories to the tags
JasmineRocket Sep 23, 2024
b097dd5
fixing grammar
JasmineRocket Sep 24, 2024
7c4b225
Adding 'Homework' and 'Assignment' Tags for default NodeBB Post
JasmineRocket Sep 24, 2024
314b43b
fixing grammar
JasmineRocket Sep 24, 2024
99d68dd
adjusted require statement and fixing grammar
JasmineRocket Sep 24, 2024
4c14ce8
Added project 1 refactored code - Jullia. (#21)
jullia02 Sep 24, 2024
c5703d7
Added check for admin replies and handled notification bundling.
Sep 24, 2024
0594f86
Changed notification message for admin replies.
Sep 24, 2024
f63f393
Changed notification message to course-faculty role.
Sep 24, 2024
a471b87
disabling call in start.start
JasmineRocket Sep 24, 2024
75ac75d
Merge pull request #25 from CMU-313/jullia/instructor-notif-ft
mhli1260 Sep 25, 2024
1eb5ecc
deleting unnecessary comments
JasmineRocket Sep 25, 2024
0f8b99b
recovered start.js
JasmineRocket Sep 25, 2024
4bf4e15
Fixing parsing errors
JasmineRocket Sep 25, 2024
94fca54
Fixing line syntax and definition issues
JasmineRocket Sep 25, 2024
1742f8a
Merge pull request #26 from CMU-313/jasmine/default-topic-tags
JasmineRocket Sep 25, 2024
ab4037b
refactor digest.js to reduce nested functions
mhli1260 Sep 25, 2024
7d96899
Merge pull request #16 from CMU-313/JasmineRocket-patch-3
JasmineRocket Sep 25, 2024
3dd828d
removed trailing space, but sitll getting file erorrs
alicekang1 Sep 25, 2024
7bed986
Merge pull request #27 from CMU-313/mia/refactor-digest
mhli1260 Sep 25, 2024
98f6e71
Merge pull request #28 from CMU-313/alice/refactor
alicekang1 Sep 25, 2024
c030b92
refactor Flags.validate()
tu2463 Sep 25, 2024
e90b966
Merge pull request #29 from CMU-313/cheyut/refactor-Flags-Validate
tu2463 Sep 25, 2024
e332479
Added team member names to readme.
Sep 25, 2024
159feac
adding install and run StandardJS into test workflow
mhli1260 Oct 24, 2024
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
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "nodebb"
"extends": "nodebb",
"parserOptions": {
"ecmaVersion": 2020 // This change in configuration is suggested by Copilot
}
}
6 changes: 6 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ jobs:

- name: Test coverage
uses: coverallsapp/github-action@v2

- name: Install StandardJS
run: npm install standard --save-dev

- name: Run StandardJS
run: npx standard
2 changes: 1 addition & 1 deletion .mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
reporter: dot
timeout: 25000
exit: true
bail: true
bail: false
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/ithVU1OO)

## Team Members
- Mia Li
- Alice Kang
- Cheyu Tu
- Jasmine Shi
- Jullia Andrei Montejo

# ![NodeBB](public/images/sm-card.png)

[![Workflow](https://github.com/CMU-313/NodeBB/actions/workflows/test.yaml/badge.svg)](https://github.com/CMU-313/NodeBB/actions/workflows/test.yaml)
Expand Down
Binary file added dump.rdb
Binary file not shown.
1 change: 1 addition & 0 deletions public/language/ar/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"user-flagged-user-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to": "<strong>[COURSE FACULTY] %1</strong> أضاف ردًا إلى: <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> أضاف ردا إلى: <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand Down
1 change: 1 addition & 0 deletions public/language/en-GB/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"user-flagged-user-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to" : "<strong>%1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to-dual" : "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
"user-posted-to-triple" : "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand Down
1 change: 1 addition & 0 deletions public/language/en-US/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"user-flagged-user-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand Down
1 change: 1 addition & 0 deletions public/language/es/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"user-flagged-user-dual": "<strong>%1</strong> y <strong>%2</strong> reportaron el perfil (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to" : "<strong>[COURSE FACULTY] %1</strong> ha respondido a: <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> ha respondido a: <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> y <strong>%2</strong> han respondido a <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand Down
1 change: 1 addition & 0 deletions public/language/fr/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"user-flagged-user-dual": "<strong>%1</strong> et <strong>%2</strong> ont signalé un profil utilisateur (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> et <strong>%3</strong> ont signalé un profil utilisateur (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> et %3 autres ont signalé un profil utilisateur (%4)",
"admin-posted-to": "<strong>[COURSE FACULTY] %1</strong> a répondu à : <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> a répondu à : <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> et <strong>%2</strong> ont posté une réponse à : <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> et <strong>%3</strong> ont publié des réponses à : <strong>%4</strong>",
Expand Down
44 changes: 24 additions & 20 deletions public/src/admin/manage/digest.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
'use strict';


define('admin/manage/digest', ['bootbox', 'alerts'], function (bootbox, alerts) {
const Digest = {};
console.log('Mia Li');
function interval_resend(action) {
const interval = action.slice(7);
bootbox.confirm('[[admin/manage/digest:resend-all-confirm]]', function (ok) {
if (ok) {
Digest.send(action, undefined, function (err) {
if (err) {
return alerts.error(err);
}
alerts.success('[[admin/manage/digest:resent-' + interval + ']]');
});
}
});
}

function single_resend(action, uid) {
Digest.send(action, uid, function (err) {
if (err) {
return alerts.error(err);
}
alerts.success('[[admin/manage/digest:resent-single]]');
});
}
Digest.init = function () {
$('.digest').on('click', '[data-action]', function () {
const action = this.getAttribute('data-action');
const uid = this.getAttribute('data-uid');

if (action.startsWith('resend-')) {
const interval = action.slice(7);
bootbox.confirm('[[admin/manage/digest:resend-all-confirm]]', function (ok) {
if (ok) {
Digest.send(action, undefined, function (err) {
if (err) {
return alerts.error(err);
}

alerts.success('[[admin/manage/digest:resent-' + interval + ']]');
});
}
});
interval_resend(action);
} else {
Digest.send(action, uid, function (err) {
if (err) {
return alerts.error(err);
}

alerts.success('[[admin/manage/digest:resent-single]]');
});
single_resend(action, uid);
}
});
};
Expand Down
51 changes: 32 additions & 19 deletions public/src/client/account/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,40 @@ define('forum/account/settings', [
}

function saveSettings(settings) {
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then((newSettings) => {
alerts.success('[[success:settings-saved]]');
let languageChanged = false;
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
languageChanged = true;
}
if (key === 'bootswatchSkin') {
savedSkin = newSettings.bootswatchSkin;
config.bootswatchSkin = savedSkin === 'noskin' ? '' : savedSkin;
} else if (config.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}
}
console.log('Logging Jullia Montejo');
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then(handleNewSettings);
}

// Alerts the user that the settings have been saved and updates the configuration.
function handleNewSettings(newSettings) {
alerts.success('[[success:settings-saved]]');
processNewSettings(newSettings);
}

if (languageChanged && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {
window.location.reload();
// Processes the new settings and updates the configuration accordingly.
function processNewSettings(newSettings) {
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
checkAndUpdateConfig(key, newSettings);
}
});
}
}

// Updates the configuration based on the provided key and new settings.
function checkAndUpdateConfig(key, newSettings) {
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
window.location.reload();
} else if (key === 'bootswatchSkin') {
updateSkin(newSettings.bootswatchSkin);
} else if (config.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}

// Updates the saved skin with the new skin.
function updateSkin(skin) {
savedSkin = skin;
config.bootswatchSkin = skin === 'noskin' ? '' : skin;
}

function toggleCustomRoute() {
Expand Down
13 changes: 9 additions & 4 deletions src/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ Flags.sort = async function (flagIds, sort) {
return flagIds;
};

function checkSelfFlagError(payload) {
console.log('CHEYU TU - checkSelfFlagError');
if (parseInt(payload.id, 10) === parseInt(payload.uid, 10)) {
throw new Error('[[error:cant-flag-self]]');
}
}

Flags.validate = async function (payload) {
const [target, reporter] = await Promise.all([
Flags.getTarget(payload.type, payload.id, payload.uid),
Expand All @@ -283,7 +290,7 @@ Flags.validate = async function (payload) {
throw new Error('[[error:invalid-data]]');
} else if (target.deleted) {
throw new Error('[[error:post-deleted]]');
} else if (!reporter || !reporter.userslug) {
} else if (!reporter?.userslug) {
throw new Error('[[error:no-user]]');
} else if (reporter.banned) {
throw new Error('[[error:user-banned]]');
Expand All @@ -304,9 +311,7 @@ Flags.validate = async function (payload) {
throw new Error(`[[error:not-enough-reputation-to-flag, ${meta.config['min:rep:flag']}]]`);
}
} else if (payload.type === 'user') {
if (parseInt(payload.id, 10) === parseInt(payload.uid, 10)) {
throw new Error('[[error:cant-flag-self]]');
}
checkSelfFlagError(payload);
const editable = await privileges.users.canEdit(payload.uid, payload.id);
if (!editable && !meta.config['reputation:disabled'] && reporter.reputation < meta.config['min:rep:flag']) {
throw new Error(`[[error:not-enough-reputation-to-flag, ${meta.config['min:rep:flag']}]]`);
Expand Down
49 changes: 27 additions & 22 deletions src/groups/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,7 @@ module.exports = function (Groups) {
}
});

const payload = {
description: values.description || '',
icon: values.icon || '',
labelColor: values.labelColor || '#000000',
textColor: values.textColor || '#ffffff',
};

if (values.hasOwnProperty('userTitle')) {
payload.userTitle = values.userTitle || '';
}

if (values.hasOwnProperty('userTitleEnabled')) {
payload.userTitleEnabled = values.userTitleEnabled ? '1' : '0';
}

if (values.hasOwnProperty('hidden')) {
payload.hidden = values.hidden ? '1' : '0';
}

if (values.hasOwnProperty('private')) {
payload.private = values.private ? '1' : '0';
}
const payload = payload_helper(values);

if (values.hasOwnProperty('disableJoinRequests')) {
payload.disableJoinRequests = values.disableJoinRequests ? '1' : '0';
Expand Down Expand Up @@ -90,6 +69,32 @@ module.exports = function (Groups) {
});
};

function payload_helper(values) {
const payload = {
description: values.description || '',
icon: values.icon || '',
labelColor: values.labelColor || '#000000',
textColor: values.textColor || '#ffffff',
};

if (values.hasOwnProperty('userTitle')) {
payload.userTitle = values.userTitle || '';
}

if (values.hasOwnProperty('userTitleEnabled')) {
payload.userTitleEnabled = values.userTitleEnabled ? '1' : '0';
}

if (values.hasOwnProperty('hidden')) {
payload.hidden = values.hidden ? '1' : '0';
}

if (values.hasOwnProperty('private')) {
payload.private = values.private ? '1' : '0';
}
return payload;
}

async function updateVisibility(groupName, hidden) {
if (hidden) {
await db.sortedSetRemoveBulk([
Expand Down
48 changes: 28 additions & 20 deletions src/socket.io/admin/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,38 @@ SocketRooms.getAll = async function () {
};
const userRooms = {};
const topicData = {};
function checkTid(key) {
const tid = key.match(/^topic_(\d+)/);
if (tid) {
totals.users.topics += 1;
topicData[tid[1]] = topicData[tid[1]] || { count: 0 };
topicData[tid[1]].count += 1;
}
}
function checkKey(key) {
if (key === 'online_guests') {
totals.onlineGuestCount += 1;
} else if (key === 'categories') {
totals.users.categories += 1;
} else if (key === 'recent_topics') {
totals.users.recent += 1;
} else if (key === 'unread_topics') {
totals.users.unread += 1;
} else if (key.startsWith('uid_')) {
userRooms[key] = 1;
} else if (key.startsWith('category_')) {
totals.users.category += 1;
} else {
checkTid(key);
}
}

for (const s of sockets) {
for (const key of s.rooms) {
if (key === 'online_guests') {
totals.onlineGuestCount += 1;
} else if (key === 'categories') {
totals.users.categories += 1;
} else if (key === 'recent_topics') {
totals.users.recent += 1;
} else if (key === 'unread_topics') {
totals.users.unread += 1;
} else if (key.startsWith('uid_')) {
userRooms[key] = 1;
} else if (key.startsWith('category_')) {
totals.users.category += 1;
} else {
const tid = key.match(/^topic_(\d+)/);
if (tid) {
totals.users.topics += 1;
topicData[tid[1]] = topicData[tid[1]] || { count: 0 };
topicData[tid[1]].count += 1;
}
}
checkKey(key);
}
}

totals.onlineRegisteredCount = Object.keys(userRooms).length;

let topTenTopics = [];
Expand Down
29 changes: 28 additions & 1 deletion src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const winston = require('winston');

const start = module.exports;

const db = require('./database');
const Topics = require('./topics');

start.start = async function () {
printStartupInfo();

addProcessHandlers();

try {
const db = require('./database');
await db.init();
await db.checkCompatibility();

Expand Down Expand Up @@ -149,3 +151,28 @@ async function shutdown(code) {
return process.exit(code || 0);
}
}

/* eslint-disable no-unused-vars */
async function getTopicIdByTitle(title) {
const topic = await db.models.topics.findOne({ title });
return topic ? topic.tid : null;
}

async function addTagsToTopic() {
try {
const tid = await getTopicIdByTitle('Welcome to your NodeBB!');
if (tid) {
console.log(`Topic ID: ${tid}`);

const timestamp = Date.now(); // Get current timestamp
const tagsToAdd = ['Homework', 'Assignment']; // Default tags

await Topics.createTags(tagsToAdd, tid, timestamp); // Add tags to the topic
} else {
console.error('Topic not found');
}
} catch (error) {
console.error('Error adding tags:', error);
}
}
/* eslint-enable no-unused-vars */
Loading
Loading