Skip to content

Commit

Permalink
Merge pull request #598 from OneCommunityGlobal/development
Browse files Browse the repository at this point in the history
Backend Release to Main [1.16]
  • Loading branch information
one-community authored Nov 7, 2023
2 parents 1a95807 + 5aabaaf commit d45e601
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/controllers/teamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ 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;
record.createdDatetime = Date.now();
record.modifiedDatetime = Date.now();

Expand Down Expand Up @@ -115,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);
Expand Down
1 change: 1 addition & 0 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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;

if(!canEditTeamCode && record.teamCode !== req.body.teamCode){
res.status(403).send("You are not authorized to edit team code.");
Expand Down
14 changes: 13 additions & 1 deletion src/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ 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: [
{
userId: { type: mongoose.SchemaTypes.ObjectId, required: true },
addDateTime: { type: Date, default: Date.now(), ref: 'userProfile' },
},
],
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');
17 changes: 14 additions & 3 deletions src/models/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit d45e601

Please sign in to comment.