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

Backend Release to Main [1.99] #1099

Merged
merged 50 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8701e97
added infringements permission check in profile controller
ImzIssa May 10, 2024
4735548
added infringements permission check in profile controller
ImzIssa May 11, 2024
5da634a
add endpoints for each bluesquare modification
ImzIssa Jun 1, 2024
ae99069
edit header message permission
Jun 7, 2024
a59c8b4
Merge remote-tracking branch 'origin' into Jingyi_edit_header_message…
jingyij Jun 11, 2024
9345aaf
logic with delete header message permission
jingyij Jun 11, 2024
dc4ba51
Merge branch 'development' into Imran_Split_Blue_Squares_Permissions
ImzIssa Jun 15, 2024
0942dbd
Update src/controllers/ownerMessageController.js
Jingyii800 Jun 18, 2024
de33c66
Update ownerMessageController.js
Jingyii800 Jun 18, 2024
d636a37
Changes for Blue Squares
DiyaWadhwani Jul 3, 2024
ed81b70
Update profileInitialSetupController.js
Logeshwari-Renu Jul 11, 2024
ccedf07
Update profileInitialSetupController.js
Logeshwari-Renu Jul 11, 2024
21b2887
new route added to update existing quick action functions
JatinAgrawal94 Aug 18, 2024
d0a6e24
update route added
JatinAgrawal94 Aug 18, 2024
0397aa0
chore: update invalid pwd status code
20chen-7 Aug 19, 2024
f2fbe13
Delete src/helpers/userHelper.js
20chen-7 Aug 19, 2024
c6d8ed7
Update userProfileController.js
20chen-7 Aug 19, 2024
e1c413b
Update userProfileController.js
20chen-7 Aug 20, 2024
ea3dadc
Update userProfileController.js
20chen-7 Aug 20, 2024
5c9cf30
update function for editing the quick setup modal working
JatinAgrawal94 Aug 20, 2024
a245b5d
Merge branch 'development' into Imran_Split_Blue_Squares_Permissions
ImzIssa Aug 22, 2024
325ddf9
chore: conflict
20chen-7 Sep 2, 2024
b24baf3
Merge branch 'development' into Ivy-pwd-error-BE
20chen-7 Sep 2, 2024
e341c2a
chore: conflict
20chen-7 Sep 2, 2024
f7d7c07
chore: conflict
20chen-7 Sep 2, 2024
6c33cd1
chore: conflict
20chen-7 Sep 2, 2024
0f177f9
remove infringement duplicate code in userProfile
ImzIssa Sep 3, 2024
6190043
Merge branch 'development' into Logeshwari_fix_for_user_management_fe…
Logeshwari-Renu Sep 3, 2024
32a4774
Merge pull request #943 from OneCommunityGlobal/Imran_Split_Blue_Squa…
one-community Sep 5, 2024
c28e936
Merge pull request #985 from OneCommunityGlobal/Jingyi_edit_header_me…
one-community Sep 5, 2024
97dd0af
Merge pull request #1016 from OneCommunityGlobal/Diya_Blue_Sqaures_Ch…
one-community Sep 5, 2024
3b06327
Merge pull request #1077 from OneCommunityGlobal/Ivy-pwd-error-BE
one-community Sep 5, 2024
a90d8fb
Merge pull request #1026 from OneCommunityGlobal/Logeshwari_fix_for_u…
one-community Sep 6, 2024
4262a04
Merge branch 'development' into jatin_create_quick_setup_function_per…
JatinAgrawal94 Sep 6, 2024
bdba2cd
Merge pull request #1078 from OneCommunityGlobal/jatin_create_quick_s…
one-community Sep 8, 2024
9191e9d
fix: send keep-alive messages at regular intervals
metaphor987 Sep 10, 2024
50e6f19
fix: update interval
metaphor987 Sep 10, 2024
866db56
chore: hotfix-template
20chen-7 Sep 10, 2024
ecb4863
chore: hotfix-template
20chen-7 Sep 10, 2024
e91fd72
chore: pause
20chen-7 Sep 11, 2024
e4d996e
Merge branch 'development' into Ivy-pause-btn-template
20chen-7 Sep 11, 2024
5a532cb
Merge branch 'development' into Ivy-update-deactivate-email-template
20chen-7 Sep 11, 2024
7cc97a3
Update userHelper.js
20chen-7 Sep 12, 2024
e339666
Merge pull request #1097 from OneCommunityGlobal/Ivy-pause-btn-template
one-community Sep 12, 2024
a0396ee
Merge branch 'development' into Ivy-update-deactivate-email-template
20chen-7 Sep 12, 2024
55c67e3
Update userHelper.js
20chen-7 Sep 12, 2024
d43239c
Merge pull request #1094 from OneCommunityGlobal/Ivy-update-deactivat…
one-community Sep 12, 2024
2f0d949
chore: check endDate & inactive
20chen-7 Sep 12, 2024
bdd1940
Merge pull request #1098 from OneCommunityGlobal/Ivy-hotfix-isSet-Ina…
one-community Sep 12, 2024
b5d5536
Merge pull request #1093 from OneCommunityGlobal/huijie-recalculation…
one-community Sep 12, 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
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion src/controllers/logincontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const logincontroller = function () {

res.status(200).send({ token });
} else {
res.status(403).send({
res.status(404).send({
message: 'Invalid password.',
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/logincontroller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('logincontroller module', () => {
expect(findOneSpy).toHaveBeenCalledWith({ email: mockReqModified.body.email });

assertResMock(
403,
404,
{
message: 'Invalid password.',
},
Expand Down
13 changes: 10 additions & 3 deletions src/controllers/ownerMessageController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const helper = require('../utilities/permissions');

const ownerMessageController = function (OwnerMessage) {
const getOwnerMessage = async function (req, res) {
try {
const results = await OwnerMessage.find({});
if (results.length === 0) { // first time initialization
if (results.length === 0) {
// first time initialization
const ownerMessage = new OwnerMessage();
await ownerMessage.save();
res.status(200).send({ ownerMessage });
Expand All @@ -15,7 +18,9 @@ const ownerMessageController = function (OwnerMessage) {
};

const updateOwnerMessage = async function (req, res) {
if (req.body.requestor.role !== 'Owner') {
if (
!(await helper.hasPermission(req.body.requestor, 'editHeaderMessage'))
) {
res.status(403).send('You are not authorized to create messages!');
}
const { isStandard, newMessage } = req.body;
Expand All @@ -40,7 +45,9 @@ const ownerMessageController = function (OwnerMessage) {
};

const deleteOwnerMessage = async function (req, res) {
if (req.body.requestor.role !== 'Owner') {
if (
!(await helper.hasPermission(req.body.requestor, 'editHeaderMessage'))
) {
res.status(403).send('You are not authorized to delete messages!');
}
try {
Expand Down
44 changes: 20 additions & 24 deletions src/controllers/profileInitialSetupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,30 +523,26 @@ const profileInitialSetupController = function (
*/
const getSetupInvitation = (req, res) => {
const { role } = req.body.requestor;
if (role === 'Administrator' || role === 'Owner') {
try {
ProfileInitialSetupToken.find({ isSetupCompleted: false })
.sort({ createdDate: -1 })
.exec((err, result) => {
// Handle the result
if (err) {
LOGGER.logException(err);
return res
.status(500)
.send(
'Internal Error: Please retry. If the problem persists, please contact the administrator',
);
}
return res.status(200).send(result);
});
} catch (error) {
LOGGER.logException(error);
return res
.status(500)
.send(
'Internal Error: Please retry. If the problem persists, please contact the administrator',
);
}

const { permissions } = req.body.requestor;
let user_permissions = ['getUserProfiles','postUserProfile','putUserProfile','changeUserStatus']
if ((role === 'Administrator') || (role === 'Owner') || (role === 'Manager') || (role === 'Mentor') || user_permissions.some(e=>permissions.frontPermissions.includes(e))) {
try{
ProfileInitialSetupToken
.find({ isSetupCompleted: false })
.sort({ createdDate: -1 })
.exec((err, result) => {
// Handle the result
if (err) {
LOGGER.logException(err);
return res.status(500).send('Internal Error: Please retry. If the problem persists, please contact the administrator');
}
return res.status(200).send(result);
});
} catch (error) {
LOGGER.logException(error);
return res.status(500).send('Internal Error: Please retry. If the problem persists, please contact the administrator');
}
} else {
return res.status(403).send('You are not authorized to get setup history.');
}
Expand Down
19 changes: 15 additions & 4 deletions src/controllers/timeEntryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1373,8 +1373,15 @@ const timeEntrycontroller = function (TimeEntry) {
const recalculateHoursByCategoryAllUsers = async function (req, res) {
const session = await mongoose.startSession();
session.startTransaction();
let keepAliveInterval;

try {
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Transfer-Encoding', 'chunked');
keepAliveInterval = setInterval(() => {
res.write('Processing... keep connection alive\n');
}, 150 * 1000); // interval of 150 seconds

const userprofiles = await UserProfile.find({}, '_id').lean();

const recalculationPromises = userprofiles.map(async (userprofile) => {
Expand All @@ -1385,13 +1392,17 @@ const timeEntrycontroller = function (TimeEntry) {
await Promise.all(recalculationPromises);

await session.commitTransaction();
return res.status(200).send({
message: 'finished the recalculation for hoursByCategory for all users',
});
clearInterval(keepAliveInterval);
res.write('finished the recalculation for hoursByCategory for all users\n');
return res.end();
} catch (err) {
await session.abortTransaction();
if (keepAliveInterval) {
clearInterval(keepAliveInterval);
}
logger.logException(err);
return res.status(500).send({ error: err.toString() });
res.write(`error: ${err.toString()}\n`);
return res.end();
} finally {
session.endSession();
}
Expand Down
77 changes: 75 additions & 2 deletions src/controllers/titleController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const Team = require('../models/team');
const Project = require('../models/project');
const cacheClosure = require('../utilities/nodeCache');
const { getAllTeamCodeHelper } = require("./userProfileController");
const userProfileController = require("./userProfileController");
const userProfile = require('../models/userProfile');
const project = require('../models/project');
const controller = userProfileController(userProfile, project);
const getAllTeamCodeHelper = controller.getAllTeamCodeHelper;

const titlecontroller = function (Title) {
const cache = cacheClosure();
Expand All @@ -22,7 +26,6 @@ const titlecontroller = function (Title) {

const postTitle = async function (req, res) {
const title = new Title();

title.titleName = req.body.titleName;
title.teamCode = req.body.teamCode;
title.projectAssigned = req.body.projectAssigned;
Expand Down Expand Up @@ -81,6 +84,72 @@ const titlecontroller = function (Title) {
.catch((error) => res.status(404).send(error));
};

// update title function.
const updateTitle = async function (req, res) {
try{

const filter=req.body.id;

// valid title name
if (!req.body.titleName.trim()) {
res.status(400).send({ message: 'Title cannot be empty.' });
return;
}

// if media is empty
if (!req.body.mediaFolder.trim()) {
res.status(400).send({ message: 'Media folder cannot be empty.' });
return;
}
const shortnames = req.body.titleName.trim().split(' ');
let shortname;
if (shortnames.length > 1) {
shortname = (shortnames[0][0] + shortnames[1][0]).toUpperCase();
} else if (shortnames.length === 1) {
shortname = shortnames[0][0].toUpperCase();
}
req.body.shortName = shortname;

// Validate team code by checking if it exists in the database
if (!req.body.teamCode) {
res.status(400).send({ message: 'Please provide a team code.' });
return;
}

const teamCodeExists = await checkTeamCodeExists(req.body.teamCode);
if (!teamCodeExists) {
res.status(400).send({ message: 'Invalid team code. Please provide a valid team code.' });
return;
}

// validate if project exist
const projectExist = await checkProjectExists(req.body.projectAssigned._id);
if (!projectExist) {
res.status(400).send({ message: 'Project is empty or not exist.' });
return;
}

// validate if team exist
if (req.body.teamAssiged && req.body.teamAssiged._id === 'N/A') {
res.status(400).send({ message: 'Team not exists.' });
return;
}
const result = await Title.findById(filter);
result.titleName = req.body.titleName;
result.teamCode = req.body.teamCode;
result.projectAssigned = req.body.projectAssigned;
result.mediaFolder = req.body.mediaFolder;
result.teamAssiged = req.body.teamAssiged;
const updatedTitle = await result.save();
res.status(200).send({ message: 'Update successful', updatedTitle });

}catch(error){
console.log(error);
res.status(500).send({ message: 'An error occurred', error });
}

};

const deleteTitleById = async function (req, res) {
const { titleId } = req.params;
Title.deleteOne({ _id: titleId })
Expand All @@ -98,6 +167,7 @@ const titlecontroller = function (Title) {
}
})
.catch((error) => {
console.log(error)
res.status(500).send(error);
});
};
Expand Down Expand Up @@ -126,12 +196,15 @@ const titlecontroller = function (Title) {
}
}



return {
getAllTitles,
getTitleById,
postTitle,
deleteTitleById,
deleteAllTitles,
updateTitle
};
};

Expand Down
Loading
Loading