Skip to content

Humemah(userProfile): add final day API route#1749

Merged
one-community merged 3 commits intodevelopmentfrom
humemah-set-final-day-api
Nov 20, 2025
Merged

Humemah(userProfile): add final day API route#1749
one-community merged 3 commits intodevelopmentfrom
humemah-set-final-day-api

Conversation

@humemah
Copy link
Copy Markdown
Contributor

@humemah humemah commented Sep 24, 2025

Description

This PR introduces functionality to set the final day (endDate) for a user.

Related PRS (if any):

This backend PR is related to the frontend PR.

Main changes explained:

Implemented permission checks to ensure only authorized users (Owners, Administrators, or those with the appropriate front/back permissions) can set a Final Day
Permission Rules

Users with the setFinalDay permission can set the final day.
This includes Owners and Administrators by default.
Users without the setFinalDay permission (e.g., Volunteers) will receive an access denied response.

How to test:

Checkout this branch.
Run npm install and start the backend with npm run dev.
Send a PATCH request via Postman
2d8cbf69-0d2d-4808-942c-50c1d98772eb
14178fb9-fad4-48c3-9768-fcc9db5112ab
8c06d43a-8169-449b-8c99-55b3bad35b1f
96326a9a-31fd-453d-9f5b-1276b2d402a2

Note:

Include the information the reviewers need to know.

Comment on lines +2368 to +2373
const requestor = req.body.requestor;
const hasPermission =
requestor?.role === 'Owner' ||
requestor?.role === 'Administrator' ||
requestor?.permissions?.frontPermissions?.includes('setUserFinalDay') ||
requestor?.permissions?.backPermissions?.includes('interactWithSetFinalDayButton');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const requestor = req.body.requestor;
const hasPermission =
requestor?.role === 'Owner' ||
requestor?.role === 'Administrator' ||
requestor?.permissions?.frontPermissions?.includes('setUserFinalDay') ||
requestor?.permissions?.backPermissions?.includes('interactWithSetFinalDayButton');
const hasPermission = await hasPermission(req.body.requestor, 'setFinalDay');

Need to use hasPermission() to check role and individual permissions and be consistent with the rest of the codebase. Also, not sure if these permission keys are consistent with the FE now.

'accessHgnSkillsDashboard',
'manageFAQs',
'manageHGNAccessSetup',
'interactWithSetFinalDayButton'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'interactWithSetFinalDayButton'
'setFinalDay'

I believe this was the key we used on the FE.

'editTeamCode',
'accessHgnSkillsDashboard',
'manageFAQs',
'interactWithSetFinalDayButton',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'interactWithSetFinalDayButton',
'setFinalDay',

I believe this was the key we used on the FE.

Comment on lines +2340 to +2357


// if (!req.user.permissions.includes('interactWithSetFinalDayButton')) {
// return res.status(403).json({
// success: false,
// message: 'Access denied. Insufficient permissions.',
// });
// }
// if (!req.user || !req.user.permissions || !req.user.permissions.includes('interactWithSetFinalDayButton')) {
// return res.status(403).json({
// success: false,
// message: 'Access denied. Insufficient permissions.',
// });
// }
console.log('=== DEBUG setFinalDay ===');
console.log('req.body.requestor:', req.body.requestor);
console.log('req.body.requestor.role:', req.body.requestor?.role);
console.log('req.body.requestor.permissions:', req.body.requestor?.permissions);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if (!req.user.permissions.includes('interactWithSetFinalDayButton')) {
// return res.status(403).json({
// success: false,
// message: 'Access denied. Insufficient permissions.',
// });
// }
// if (!req.user || !req.user.permissions || !req.user.permissions.includes('interactWithSetFinalDayButton')) {
// return res.status(403).json({
// success: false,
// message: 'Access denied. Insufficient permissions.',
// });
// }
console.log('=== DEBUG setFinalDay ===');
console.log('req.body.requestor:', req.body.requestor);
console.log('req.body.requestor.role:', req.body.requestor?.role);
console.log('req.body.requestor.permissions:', req.body.requestor?.permissions);

Cleaning up

const { hasPermission, canRequestorUpdateUser } = require('../utilities/permissions');
const helper = require('../utilities/permissions');

// const { hasPermission } = require('../utilities/createInitialPermissions');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// const { hasPermission } = require('../utilities/createInitialPermissions');

more cleaning

Copy link
Copy Markdown
Contributor Author

@humemah humemah Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nathanah
Thanks for the review! I’ve updated the code
4c472bfc-02b1-4e7f-9cf4-573b15ced2d7

a8e302fc-016c-40b1-8755-0f253b167b57
its working with set final day key
Volunter with no permision is denied acesss
6850f6b4-eec4-4159-b8d6-246ba5400ecd

Copy link
Copy Markdown
Contributor

@nathanah nathanah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! LGTM

@one-community
Copy link
Copy Markdown
Member

Thank you all, merging!

@one-community one-community merged commit b29d3ee into development Nov 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants