From 346082b365e833b1439b4ce60777ee4417ca5f58 Mon Sep 17 00:00:00 2001 From: AriaYu927 Date: Tue, 29 Aug 2023 12:14:47 +0800 Subject: [PATCH 1/6] solve conflicts --- src/controllers/userProfileController.js | 1 + src/helpers/reporthelper.js | 3 +++ src/models/userProfile.js | 1 + 3 files changed, 5 insertions(+) diff --git a/src/controllers/userProfileController.js b/src/controllers/userProfileController.js index 9d0e7e63a..6b6cee9b1 100644 --- a/src/controllers/userProfileController.js +++ b/src/controllers/userProfileController.js @@ -284,6 +284,7 @@ const userProfileController = function (UserProfile) { record.totalIntangibleHrs = req.body.totalIntangibleHrs; record.bioPosted = req.body.bioPosted || 'default'; record.isFirstTimelog = req.body.isFirstTimelog; + record.teamCode = req.body.teamCode; // find userData in cache const isUserInCache = cache.hasCache('allusers'); diff --git a/src/helpers/reporthelper.js b/src/helpers/reporthelper.js index 4b66c7d65..317605dd4 100644 --- a/src/helpers/reporthelper.js +++ b/src/helpers/reporthelper.js @@ -112,6 +112,9 @@ const reporthelper = function () { }, }, }, + teamCode: { + $ifNull: ['$teamCode', ''], + }, role: 1, weeklySummaries: { $filter: { diff --git a/src/models/userProfile.js b/src/models/userProfile.js index 79223fbe2..aa728f968 100644 --- a/src/models/userProfile.js +++ b/src/models/userProfile.js @@ -154,6 +154,7 @@ const userProfileSchema = new Schema({ weeklySummaryOption: { type: String }, bioPosted: { type: String, default: 'default' }, isFirstTimelog: { type: Boolean, default: true}, + teamCode: { type: String, default: '' }, infoCollections: [ { areaName:{type: String}, areaContent:{type:String}, From 0b63eac581a39838425c7f698cc3758903c4236c Mon Sep 17 00:00:00 2001 From: AriaYu927 Date: Thu, 31 Aug 2023 15:28:57 +0800 Subject: [PATCH 2/6] add Edit Team Code permission to Owner --- src/utilities/createInitialPermissions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utilities/createInitialPermissions.js b/src/utilities/createInitialPermissions.js index 9ac0f12b0..e42ca9a15 100644 --- a/src/utilities/createInitialPermissions.js +++ b/src/utilities/createInitialPermissions.js @@ -209,6 +209,7 @@ const permissionsRoles = [ 'getWeeklySummaries', 'getTimeZoneAPIKey', 'checkLeadTeamOfXplus', + 'editTeamCode', ], }, ]; From 84b3baf05c234f43ba2099f080d855e729490854 Mon Sep 17 00:00:00 2001 From: AriaYu927 Date: Wed, 6 Sep 2023 09:15:41 +0800 Subject: [PATCH 3/6] add teamCode Property to team object --- src/controllers/teamController.js | 1 + src/models/team.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/controllers/teamController.js b/src/controllers/teamController.js index 1072f1fb4..0ff777870 100644 --- a/src/controllers/teamController.js +++ b/src/controllers/teamController.js @@ -71,6 +71,7 @@ const teamcontroller = function (Team) { } record.teamName = req.body.teamName; record.isActive = req.body.isActive; + record.teamCode = req.body.teamCode; record.createdDatetime = Date.now(); record.modifiedDatetime = Date.now(); diff --git a/src/models/team.js b/src/models/team.js index 8d46db283..a57d7bb27 100644 --- a/src/models/team.js +++ b/src/models/team.js @@ -13,6 +13,7 @@ const team = new Schema({ addDateTime: { type: Date, default: Date.now(), ref: 'userProfile' }, }, ], + teamCode: { type: 'String', default: '' }, }); module.exports = mongoose.model('team', team, 'teams'); From 9a7bfb948da6f7b0c2beeb7cf310e3addeaa72b6 Mon Sep 17 00:00:00 2001 From: AriaYu927 Date: Thu, 19 Oct 2023 10:06:48 +0800 Subject: [PATCH 4/6] add validator of regex and authorization --- src/controllers/teamController.js | 11 ++++++++++- src/models/team.js | 13 ++++++++++++- src/models/userProfile.js | 17 ++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/controllers/teamController.js b/src/controllers/teamController.js index 5215b024b..b204875a5 100644 --- a/src/controllers/teamController.js +++ b/src/controllers/teamController.js @@ -70,6 +70,15 @@ const teamcontroller = function (Team) { res.status(400).send('No valid records found'); return; } + + const canEditTeamCode = req.body.requestor.role === 'Owner' + || req.body.requestor.permissions?.frontPermissions.includes('editTeamCode'); + + if (!canEditTeamCode) { + res.status(403).send('You are not authorized to edit team code.'); + return; + } + record.teamName = req.body.teamName; record.isActive = req.body.isActive; record.teamCode = req.body.teamCode; @@ -116,7 +125,7 @@ const teamcontroller = function (Team) { users.forEach((element) => { const { userId, operation } = element; // if user's profile is stored in cache, clear it so when you visit their profile page it will be up to date - if(cache.hasCache(`user-${userId}`)) cache.removeCache(`user-${userId}`); + if (cache.hasCache(`user-${userId}`)) cache.removeCache(`user-${userId}`); if (operation === 'Assign') { assignlist.push(userId); diff --git a/src/models/team.js b/src/models/team.js index a57d7bb27..97f8dc360 100644 --- a/src/models/team.js +++ b/src/models/team.js @@ -13,7 +13,18 @@ const team = new Schema({ addDateTime: { type: Date, default: Date.now(), ref: 'userProfile' }, }, ], - teamCode: { type: 'String', default: '' }, + teamCode: { + type: 'String', + default: '', + validate: { + validator(v) { + const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$/; + return teamCoderegex.test(v); + }, + message: + 'Please enter a code in the format of A-AAA or AAAAA', + }, + }, }); module.exports = mongoose.model('team', team, 'teams'); diff --git a/src/models/userProfile.js b/src/models/userProfile.js index a58d1d293..4739a05e7 100644 --- a/src/models/userProfile.js +++ b/src/models/userProfile.js @@ -7,7 +7,7 @@ const bcrypt = require('bcryptjs'); const SALT_ROUNDS = 10; const nextDay = new Date(); -nextDay.setDate(nextDay.getDate()+1); +nextDay.setDate(nextDay.getDate() + 1); const userProfileSchema = new Schema({ password: { @@ -153,8 +153,19 @@ const userProfileSchema = new Schema({ isVisible: { type: Boolean, default: false }, weeklySummaryOption: { type: String }, bioPosted: { type: String, default: 'default' }, - isFirstTimelog: { type: Boolean, default: true}, - teamCode: { type: String, default: '' }, + isFirstTimelog: { type: Boolean, default: true }, + teamCode: { + type: String, + default: '', + validate: { + validator(v) { + const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$/; + return teamCoderegex.test(v); + }, + message: + 'Please enter a code in the format of A-AAA or AAAAA', + }, + }, infoCollections: [ { areaName: { type: String }, From 64f6c4121012e4e10d01568e847a6172562a2512 Mon Sep 17 00:00:00 2001 From: AriaYu927 Date: Tue, 31 Oct 2023 16:04:22 +0800 Subject: [PATCH 5/6] set default value for createdDatetime --- src/models/team.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/team.js b/src/models/team.js index 97f8dc360..00fbaf8e3 100644 --- a/src/models/team.js +++ b/src/models/team.js @@ -5,7 +5,7 @@ const { Schema } = mongoose; const team = new Schema({ teamName: { type: 'String', required: true }, isActive: { type: 'Boolean', required: true, default: true }, - createdDatetime: { type: Date }, + createdDatetime: { type: Date, default: Date.now() }, modifiedDatetime: { type: Date, default: Date.now() }, members: [ { From 4e318bc4046fb42324a9b12b0adc5c1522208f5c Mon Sep 17 00:00:00 2001 From: wang9hu Date: Sat, 4 Nov 2023 17:01:10 -0700 Subject: [PATCH 6/6] add empty string in teamCode validator for creating new user --- src/models/userProfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/userProfile.js b/src/models/userProfile.js index 4739a05e7..3219fec18 100644 --- a/src/models/userProfile.js +++ b/src/models/userProfile.js @@ -159,7 +159,7 @@ const userProfileSchema = new Schema({ default: '', validate: { validator(v) { - const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$/; + const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$|^$/; return teamCoderegex.test(v); }, message: