-
Notifications
You must be signed in to change notification settings - Fork 48
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
Sai preetham tracking management #3091
base: development
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for highestgoodnetwork-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
the code works for majority of the part. I had issue regarding issuing a blue square or a warning when you make a new title. Also it let me add a blue square when i didn't have the permission to do it. please check the video i did multiple checks to confirm it. other than this everything else works how it is mentioned above. 20250129-1717-21.9006812.1.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a backend PR for this? You'll need backend changes to implement these permissions.
const rolesAllowedToTracking = ['Administrator', 'Owner']; | ||
|
||
const canIssueTrackingWarnings = | ||
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('issueTrackingWarnings')); | ||
const canIssueBlueSquare = | ||
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('issueBlueSquare')); | ||
const canDeleteWarning = | ||
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('deleteWarning')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const rolesAllowedToTracking = ['Administrator', 'Owner']; | |
const canIssueTrackingWarnings = | |
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('issueTrackingWarnings')); | |
const canIssueBlueSquare = | |
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('issueBlueSquare')); | |
const canDeleteWarning = | |
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('deleteWarning')); | |
const canIssueTrackingWarnings = dispatch(hasPermission('issueTrackingWarnings')); | |
const canIssueBlueSquare = dispatch(hasPermission('issueBlueSquare')); | |
const canDeleteWarning = dispatch(hasPermission('deleteWarning')); |
hasPermission()
will check for role permissions too, so you can remove rolesAllowedToTracking
. If you want to guarantee that Admins and Owners have this permission, you can add it to CreateInitialPermissions.js
on the backend and those permissions will be guaranteed for the roles you add it to (they will be re-added to the roles every time the server restarts).
const rolesAllowedToTracking = ['Administrator', 'Owner']; | ||
const isAllowedToTracking = | ||
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('viewTrackingOverview')); | ||
const canViewTrackerButton = | ||
rolesAllowedToTracking.includes(userRole) || | ||
dispatch(hasPermission('addWarningTracker')) || | ||
dispatch(hasPermission('deactivateWarningTracker')) || | ||
dispatch(hasPermission('deleteWarningTracker')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const rolesAllowedToTracking = ['Administrator', 'Owner']; | |
const isAllowedToTracking = | |
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('viewTrackingOverview')); | |
const canViewTrackerButton = | |
rolesAllowedToTracking.includes(userRole) || | |
dispatch(hasPermission('addWarningTracker')) || | |
dispatch(hasPermission('deactivateWarningTracker')) || | |
dispatch(hasPermission('deleteWarningTracker')); | |
const isAllowedToTracking = dispatch(hasPermission('viewTrackingOverview')); | |
const canViewTrackerButton = | |
dispatch(hasPermission('addWarningTracker')) || | |
dispatch(hasPermission('deactivateWarningTracker')) || | |
dispatch(hasPermission('deleteWarningTracker')); |
Same thing here.
@@ -13,7 +14,19 @@ function WarningItem({ | |||
username, | |||
handleDeleteWarning, | |||
submitWarning, | |||
userRole, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userRole, |
Don't need to pass in userRole
if you rely on hasPermission()
.
@@ -94,11 +102,12 @@ export default function Warning({ personId, username, userRole, displayUser }) { | |||
username={username} | |||
submitWarning={handlePostWarningDetails} | |||
handleDeleteWarning={handleDeleteWarning} | |||
userRole={userRole} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userRole={userRole} |
Don't need to pass in userRole
if you rely on hasPermission()
.
@@ -126,6 +135,7 @@ export default function Warning({ personId, username, userRole, displayUser }) { | |||
personId={personId} | |||
setToggleWarningTrackerModal={setToggleWarningTrackerModal} | |||
getUsersWarnings={fetchUsersWarningsById} | |||
userRole={userRole} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userRole={userRole} |
Same here
@@ -34,6 +33,7 @@ function WarningTrackerModal({ | |||
toggleWarningTrackerModal, | |||
getUsersWarnings, | |||
setToggleWarningTrackerModal, | |||
userRole, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userRole, |
Same here.
const rolesAllowedToTracking = ['Administrator', 'Owner']; | ||
const canAddWarningTracker = | ||
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('addWarningTracker')); | ||
const canDeactivateWarningTracker = | ||
rolesAllowedToTracking.includes(userRole) || | ||
dispatch(hasPermission('deactivateWarningTracker')); | ||
const canReactivateWarningTracker = | ||
rolesAllowedToTracking.includes(userRole) || | ||
dispatch(hasPermission('reactivateWarningTracker')); | ||
const canDeleteWarningTracker = | ||
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('deleteWarningTracker')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const rolesAllowedToTracking = ['Administrator', 'Owner']; | |
const canAddWarningTracker = | |
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('addWarningTracker')); | |
const canDeactivateWarningTracker = | |
rolesAllowedToTracking.includes(userRole) || | |
dispatch(hasPermission('deactivateWarningTracker')); | |
const canReactivateWarningTracker = | |
rolesAllowedToTracking.includes(userRole) || | |
dispatch(hasPermission('reactivateWarningTracker')); | |
const canDeleteWarningTracker = | |
rolesAllowedToTracking.includes(userRole) || dispatch(hasPermission('deleteWarningTracker')); | |
const canAddWarningTracker = dispatch(hasPermission('addWarningTracker')); | |
const canDeactivateWarningTracker = dispatch(hasPermission('deactivateWarningTracker')); | |
const canReactivateWarningTracker = dispatch(hasPermission('reactivateWarningTracker')); | |
const canDeleteWarningTracker = dispatch(hasPermission('deleteWarningTracker')); |
Same here.
Thanks for your feedback! I've made the requested changes to ensure permissions are correctly enforced for adding blue squares and warnings. Everything is working as expected now. Could you please review it again and let me know your thoughts? Regards, |
Hi @nathanah, Thank you for the suggestions! Regarding your feedback: UserRole: Backend Changes: Let me know if you have further questions or would like me to clarify anything else! Best regards, |
With this implementation, Admin and Owner will look like they don't have permission when you check in Permission Management, but still have access to the buttons. My suggestion is to, instead of your current implementation of adding an additional check on the front-end, add this permission on the back end (in CreateInitialPermissions.js) so the permission is guaranteed for these roles. This has the same flexibility for adding the permissions to any role and simplifies logic to be in alignment with how we do permission checks throughout the codebase.
I'm not necessarily suggesting adding new endpoints, just adding in permission checks to the existing ones. Without backend checks, someone could circumvent the frontend permission checks by manually sending custom API requests (using something like Postman). I think the backend controller is the const deleteWarningDescription = async (req, res) => {
+ if(!(await hasPermission(req.body.requestor, 'deleteWarning'))){
+ res.status(403).send({error: 'You are not authorized to delete warnings'})
+ }
... Ideally, the permissions should be 1:1 with the APIs IMO since it makes these changes trivial. Reusing APIs makes the checks have to be more complicated so that they only have access to exactly what their permissions allow. Let me know if you have any other questions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @preethamdnr,
I reviewed your PR but I had issues when I tried assigning the permission to my volunteer account.
Since my volunteer account doesn't have the permission to see all the users, I first added that task then the tracking permission, but it fails, and crashes on the backend as well.
I am checked in the development backend branch as well. My previous PR about the tracking might be a cause as well as I see an error related to the enum.
I also agree with @nathanah . You should have a backend route since you are updating the user's permissions. Otherwise anyone can just adjust their account on the frontend and be
displayed information they shouldn't. You probably don't need a new route, as theres probably already a route that can update a user's permission you'll probably need to use that as Nathan suggested too.
Also, the backend displaying a ton of data too, there seems to be a log somewhere in the backend.
Description
This PR implements a new "Tracking Management" section within the permissions module, allowing owners to grant specific tracking-related permissions (Tracking Button, <+/->, etc.) to other users.
Related PRS (if any):
none.
Main changes explained:
How to test:
npm install
and...
to run this PR locallyScreenshots or videos of changes:
video1708959534.mp4