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

Modify Users' Access Types #357

Merged
merged 30 commits into from
Dec 2, 2023
Merged

Modify Users' Access Types #357

merged 30 commits into from
Dec 2, 2023

Conversation

nik-dange
Copy link
Member

@nik-dange nik-dange commented Jul 6, 2023

Closes #342.

Added PATCH route to update user access types.

Finalized GET route to obtain all users and access types.

@github-actions
Copy link

github-actions bot commented Jul 6, 2023

Thanks for contributing! If you've made changes to the API's functionality, please make sure to bump the package version—see this guide to semantic versioning for details—and document those changes as appropriate.

@nik-dange
Copy link
Member Author

Screenshot 2023-07-07 at 10 53 23 PM

@nik-dange
Copy link
Member Author

Screenshot 2023-07-07 at 11 02 17 PM

Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

Put some thoughts down

api/validators/AdminControllerRequests.ts Outdated Show resolved Hide resolved
repositories/UserRepository.ts Outdated Show resolved Hide resolved
repositories/UserRepository.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Show resolved Hide resolved
tests/admin.test.ts Show resolved Hide resolved
tests/admin.test.ts Show resolved Hide resolved
]
}, standard);
}).rejects.toThrow(ForbiddenError);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also add another test making sure the role of the user is not updated

Copy link
Member Author

Choose a reason for hiding this comment

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

The role of the current user making the request?

Copy link
Contributor

Choose a reason for hiding this comment

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

the role of all users in the input of the changes requested

Copy link
Contributor

Choose a reason for hiding this comment

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

the goal is that when an error is thrown, the request should not make changes to the database

Copy link
Contributor

Choose a reason for hiding this comment

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

let me know if there is any questions regarding for what I requested

services/UserAccountService.ts Outdated Show resolved Hide resolved
types/ApiRequests.ts Outdated Show resolved Hide resolved
types/ApiResponses.ts Outdated Show resolved Hide resolved
types/ApiResponses.ts Outdated Show resolved Hide resolved
@nik-dange
Copy link
Member Author

Screenshot 2023-08-04 at 10 57 23 PM Screenshot 2023-08-04 at 11 00 27 PM

api/validators/AdminControllerRequests.ts Outdated Show resolved Hide resolved
repositories/UserRepository.ts Outdated Show resolved Hide resolved
services/UserAccountService.ts Outdated Show resolved Hide resolved
services/UserAccountService.ts Outdated Show resolved Hide resolved
services/UserAccountService.ts Outdated Show resolved Hide resolved
services/UserAccountService.ts Outdated Show resolved Hide resolved
services/UserAccountService.ts Outdated Show resolved Hide resolved
Comment on lines 241 to 244
}
// Prevent anyone from demoting user with current admin status
if (currUser.accessType === UserAccessType.ADMIN && newAccess !== UserAccessType.ADMIN) {
throw new ForbiddenError('You cannot demote an admin.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know there's been some use-case of this e.g. at end of school year where we want to remove ADMIN from users who no longer need admin perms. Do we plan on doing this manually? If so, should we also only grand ADMIN permissions manually as well?

services/UserAccountService.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

a few changes and some ideas needed to be discussed

tests/admin.test.ts Outdated Show resolved Hide resolved
]
}, standard);
}).rejects.toThrow(ForbiddenError);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

the role of all users in the input of the changes requested

tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
]
}, standard);
}).rejects.toThrow(ForbiddenError);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

the goal is that when an error is thrown, the request should not make changes to the database

types/ApiResponses.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

Make sure to make changes that allows promotion to admin

services/UserAccountService.ts Outdated Show resolved Hide resolved
services/UserAccountService.ts Outdated Show resolved Hide resolved
]
}, standard);
}).rejects.toThrow(ForbiddenError);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

let me know if there is any questions regarding for what I requested

tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/admin.test.ts Outdated Show resolved Hide resolved
tests/data/PortalState.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

This looks good for me now. I will run tests in your branch in a bit. Meanwhile, let's also get Shravan to review this since it is moderately size change.

@@ -234,7 +234,6 @@ export default class UserAccountService {

const updatedUser = await userRepository.upsertUser(currUser, { accessType });

// log the activity of changing a user's access type
Copy link
Contributor

Choose a reason for hiding this comment

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

I will be honest this specific comment is fine as it explains a decent size of code

@dowhep
Copy link
Contributor

dowhep commented Oct 21, 2023

Also make sure to fix linting

@dowhep dowhep added the Priority High priority issues label Nov 29, 2023
Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

Everything else looks good - if you fix the two nit I mentioned, I will approve this PR

services/UserAccountService.ts Show resolved Hide resolved
});
}

public async getAllUsersWithAccessLevels(): Promise<PrivateProfile[]> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just double checking, are you thinking that we might have a type for just the user with accesslevels in the future? If that is not the case, we can just change the name of the function to getAllFullUserProfile()

Copy link
Contributor

@dowhep dowhep left a comment

Choose a reason for hiding this comment

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

LGTM 🚀🚀

@nik-dange nik-dange merged commit 81d7ce5 into master Dec 2, 2023
5 checks passed
@nik-dange nik-dange deleted the nikhil/admin-role-management branch February 29, 2024 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority High priority issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Admin Role Management
3 participants