-
Notifications
You must be signed in to change notification settings - Fork 43
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
Yashwanth individual permission change show #2868
base: development
Are you sure you want to change the base?
Yashwanth individual permission change show #2868
Conversation
✅ Deploy Preview for highestgoodnetwork-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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 @yashwanth170
I have tested this , and it is displaying the text Loading for a long time instead of a table and I hjave also tried using clearing the cache.
Thank you.
Hello, |
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.
Most of this logic should be on the backend. The only frontend changes required should be accommodating the new info in the permissionChangeLogTable
.
@@ -94,6 +135,7 @@ function UserPermissionsPopUp({ | |||
autoClose: 10000, | |||
}); | |||
setToastShown(true); | |||
logPermissionChanges(logPermissionChangesUrl, permissionChangeLog); |
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.
logPermissionChanges(logPermissionChangesUrl, permissionChangeLog); |
This is not atomic. This request could fail after the permission change request succeeds, so it wouldn't show up in the history. If a dev wanted to test updating permissions manually with something like Postman, they could avoid also logging those changes which could cause confusion or potential problems.
Logging permission changes should be part of the same API call as updating the user's permissions.
src/utils/URL.js
Outdated
@@ -5,6 +5,8 @@ const APIEndpoint = | |||
export const ENDPOINTS = { | |||
APIEndpoint: () => APIEndpoint, | |||
USER_PROFILE: userId => `${APIEndpoint}/userprofile/${userId}`, | |||
POST_USER_PERMISSION_CHANGE_LOGS: `${APIEndpoint}/logPermissionChanges`, |
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.
POST_USER_PERMISSION_CHANGE_LOGS: `${APIEndpoint}/logPermissionChanges`, |
let existingPermissions = allUserInfo.permissions?.frontPermissions || []; | ||
const existingPermissionsSet = new Set(existingPermissions || []); | ||
const newPermissionsSet = new Set(userPermissions || []); | ||
const addedPermissions = (userPermissions || []).filter( | ||
permission => !existingPermissionsSet.has(permission), | ||
); | ||
const removedPermissions = (existingPermissions || []).filter( | ||
permission => !newPermissionsSet.has(permission), | ||
); | ||
|
||
existingPermissions = [ | ||
...existingPermissions.filter(permission => !removedPermissions.includes(permission)), | ||
...addedPermissions, | ||
]; | ||
|
||
const permissionChangeLog = { | ||
actualUserProfile: { | ||
firstName: actualUserProfile.firstName, | ||
lastName: actualUserProfile.lastName, | ||
}, | ||
authUser: { | ||
email: authUser.email, | ||
role: authUser.role, | ||
}, | ||
userId, | ||
existingPermissions, // Existing permissions before change | ||
addedPermissions, // New permissions added | ||
removedPermissions, // Permissions removed | ||
}; | ||
|
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.
let existingPermissions = allUserInfo.permissions?.frontPermissions || []; | |
const existingPermissionsSet = new Set(existingPermissions || []); | |
const newPermissionsSet = new Set(userPermissions || []); | |
const addedPermissions = (userPermissions || []).filter( | |
permission => !existingPermissionsSet.has(permission), | |
); | |
const removedPermissions = (existingPermissions || []).filter( | |
permission => !newPermissionsSet.has(permission), | |
); | |
existingPermissions = [ | |
...existingPermissions.filter(permission => !removedPermissions.includes(permission)), | |
...addedPermissions, | |
]; | |
const permissionChangeLog = { | |
actualUserProfile: { | |
firstName: actualUserProfile.firstName, | |
lastName: actualUserProfile.lastName, | |
}, | |
authUser: { | |
email: authUser.email, | |
role: authUser.role, | |
}, | |
userId, | |
existingPermissions, // Existing permissions before change | |
addedPermissions, // New permissions added | |
removedPermissions, // Permissions removed | |
}; |
This logic should be on the backend and part of the same API call as the update itself.
@@ -80,9 +90,40 @@ function UserPermissionsPopUp({ | |||
const userId = actualUserProfile?._id; | |||
|
|||
const url = ENDPOINTS.USER_PROFILE(userId); | |||
const logPermissionChangesUrl = ENDPOINTS.POST_USER_PERMISSION_CHANGE_LOGS; |
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 logPermissionChangesUrl = ENDPOINTS.POST_USER_PERMISSION_CHANGE_LOGS; |
const logPermissionChanges = async (logPermissionChangesUrl, permissionChangeLog) => { | ||
try { | ||
await axios.post(logPermissionChangesUrl, permissionChangeLog); | ||
} catch (error) { | ||
toast.error('Error logging permissions:', { | ||
autoClose: 10000, | ||
}); | ||
} | ||
}; | ||
|
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 logPermissionChanges = async (logPermissionChangesUrl, permissionChangeLog) => { | |
try { | |
await axios.post(logPermissionChangesUrl, permissionChangeLog); | |
} catch (error) { | |
toast.error('Error logging permissions:', { | |
autoClose: 10000, | |
}); | |
} | |
}; |
@@ -243,7 +244,7 @@ function PermissionsManagement({ roles, auth, getUserRole, userProfile, darkMode | |||
</div> | |||
{loading && <p className="loading-message">Loading...</p>} | |||
{changeLogs?.length > 0 && ( | |||
<PermissionChangeLogTable changeLogs={changeLogs.slice().reverse()} darkMode={darkMode} /> | |||
<PermissionChangeLogTable changeLogs={changeLogs} darkMode={darkMode} /> |
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.
removing reverse? Nvm I see the sort on the backend now.
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.
The table doesn't show, and I have done git checkout for backend PR #1149.
…ighestGoodNetworkApp into Yashwanth_individual_permission_change_show
…ighestGoodNetworkApp into Yashwanth_individual_permission_change_show
Description
The permission change log table only logs changes made to role, so I have added additional features to log permission changes made to individual account. Now the table shows latest logs of changes made to both individual and role
Related PRS (if any):
This frontend PR is related to the #1149 backend PR.
To test this frontend PR you need to checkout the 'Yashwanth_individual_permission_change_show_backend' Backend PR.
…
Main changes explained:
How to test:
npm install
and...
to run this PR locallyScreenshots or videos of changes:
Note:
Test it across different user types, and let me know if I missed any expected conventions or if you have any other suggestions.