Skip to content

Commit 40ada94

Browse files
Merge pull request #1335 from OneCommunityGlobal/development
Backend Release to Main [2.28]
2 parents b1a55f3 + fbba694 commit 40ada94

9 files changed

Lines changed: 534 additions & 173 deletions

File tree

package-lock.json

Lines changed: 51 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controllers/userProfileController.js

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ async function ValidatePassword(req, res) {
4747
});
4848
return;
4949
}
50+
51+
const canUpdate = await hasPermission(req.body.requestor, 'updatePassword');
52+
5053
// Verify request is authorized by self or adminsitrator
5154
if (
5255
userId !== requestor.requestorId &&
53-
!(await hasPermission(req.body.requestor, 'updatePassword'))
56+
!canUpdate
5457
) {
5558
res.status(403).send({
5659
error: "You are unauthorized to update this user's password",
@@ -60,8 +63,7 @@ async function ValidatePassword(req, res) {
6063

6164
// Verify request is authorized by self or adminsitrator
6265
if (
63-
userId === requestor.requestorId ||
64-
!(await hasPermission(req.body.requestor, 'updatePassword'))
66+
userId === requestor.requestorId && !canUpdate
6567
) {
6668
res.status(403).send({
6769
error: "You are unauthorized to update this user's password",
@@ -523,14 +525,14 @@ const userProfileController = function (UserProfile, Project) {
523525
}
524526
// validate userprofile pic
525527

526-
if (req.body.profilePic) {
527-
const results = userHelper.validateProfilePic(req.body.profilePic);
528+
// if (req.body.profilePic) {
529+
// const results = userHelper.validateProfilePic(req.body.profilePic);
528530

529-
if (!results.result) {
530-
res.status(400).json(results.errors);
531-
return;
532-
}
533-
}
531+
// if (!results.result) {
532+
// res.status(400).json(results.errors);
533+
// return;
534+
// }
535+
// }
534536

535537
const canEditTeamCode =
536538
req.body.requestor.role === 'Owner' ||
@@ -1412,7 +1414,7 @@ const userProfileController = function (UserProfile, Project) {
14121414

14131415
const resetPassword = async function (req, res) {
14141416
try {
1415-
ValidatePassword(req);
1417+
await ValidatePassword(req);
14161418

14171419
const requestor = await UserProfile.findById(req.body.requestor.requestorId)
14181420
.select('firstName lastName email role')
@@ -1433,11 +1435,6 @@ const userProfileController = function (UserProfile, Project) {
14331435
return;
14341436
}
14351437

1436-
if (!(await hasPermission(requestor, 'putUserProfileImportantInfo'))) {
1437-
res.status(403).send('You are not authorized to reset this users password');
1438-
return;
1439-
}
1440-
14411438
if (user.role === 'Owner' && !(await hasPermission(requestor, 'addDeleteEditOwners'))) {
14421439
res.status(403).send('You are not authorized to reset this user password');
14431440
return;
@@ -1957,6 +1954,41 @@ const userProfileController = function (UserProfile, Project) {
19571954
}
19581955
};
19591956

1957+
const replaceTeamCodeForUsers = async (req, res) => {
1958+
const { oldTeamCodes, newTeamCode } = req.body;
1959+
1960+
// Validate input
1961+
if (!Array.isArray(oldTeamCodes) || oldTeamCodes.length === 0 || !newTeamCode) {
1962+
console.error('Validation Failed:', { oldTeamCodes, newTeamCode });
1963+
return res.status(400).send({ error: 'Invalid input. Provide oldTeamCodes as an array and a valid newTeamCode.' });
1964+
}
1965+
1966+
try {
1967+
// Sanitize input
1968+
const sanitizedOldTeamCodes = oldTeamCodes.map(code => String(code).trim());
1969+
1970+
// Find and update users
1971+
const usersToUpdate = await UserProfile.find({ teamCode: { $in: sanitizedOldTeamCodes } });
1972+
1973+
if (usersToUpdate.length === 0) {
1974+
return res.status(404).send({ error: 'No users found with the specified team codes.' });
1975+
}
1976+
1977+
const updateResult = await UserProfile.updateMany(
1978+
{ teamCode: { $in: sanitizedOldTeamCodes } },
1979+
{ $set: { teamCode: newTeamCode } }
1980+
);
1981+
1982+
return res.status(200).send({
1983+
message: 'Team codes updated successfully.',
1984+
updatedCount: updateResult.nModified,
1985+
});
1986+
} catch (error) {
1987+
console.error('Error updating team codes:', error);
1988+
return res.status(500).send({ error: 'An error occurred while updating team codes.' });
1989+
}
1990+
};
1991+
19601992
return {
19611993
postUserProfile,
19621994
getUserProfiles,
@@ -1992,6 +2024,7 @@ const userProfileController = function (UserProfile, Project) {
19922024
getUserByAutocomplete,
19932025
getUserProfileBasicInfo,
19942026
updateUserInformation,
2027+
replaceTeamCodeForUsers,
19952028
};
19962029
};
19972030

src/cronjobs/userProfileJobs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const userProfileJobs = () => {
3030
const SUNDAY = 0;
3131
if (moment().tz('America/Los_Angeles').day() === SUNDAY) {
3232
await userhelper.completeHoursAndMissedSummary();
33+
await userhelper.weeklyBlueSquareReminderFunction();
34+
await userhelper.inCompleteHoursEmailFunction();
3335
}
3436
},
3537
null,

src/helpers/helperModels/myTeam.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ const myTeamSchema = new Schema({
1313
}],
1414

1515
});
16-
16+
// Add index on the 'myteam._id' field to optimize lookups on team members
17+
myTeamSchema.index({ 'myteam._id': 1 });
18+
myTeamSchema.index({ 'myteam.role': 1 });
1719
module.exports = mongoose.model('myTeam', myTeamSchema, 'myTeam');

0 commit comments

Comments
 (0)