- 
  Notifications
 You must be signed in to change notification settings 
- Fork 0
Refactor migrate user role to multi role system #8
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
Conversation
 
 @gemini-code-assist
 
 gemini-code-assist
 bot
 
 
 left a comment
 
 
 
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.
Summary of Changes
Hello @fulleni, I'm Gemini Code Assist1 ! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly refactors the application's user role management system, transitioning from a single-role assignment to a robust multi-role architecture. This change enhances the flexibility and granularity of access control, allowing users to possess multiple roles simultaneously and enabling more sophisticated permission management across various services and features.
Highlights
- Multi-Role System Implementation: The core user role management has been refactored from a single UserRoleenum to a flexible system supporting multiple roles per user. This involves changing user objects to store a list of roles (e.g.,roles: [UserRoles.standardUser, UserRoles.publisher]) instead of a singlerole.
- Enhanced Role-Based Access Control (RBAC): The PermissionServicehas been updated to leverage the new multi-role system. It now checks if a user has a specific permission by iterating through all of their assigned roles, rather than just a single one. A newpublisherrole has also been introduced with specific content creation permissions.
- Dynamic User Provisioning: The AuthServicenow supports conditional role assignment during user creation and account linking. For instance, new users signing up from a 'dashboard' client can automatically be granted bothstandardUserandpublisherroles, enabling more granular initial access.
- JWT Token Structure Update: JSON Web Tokens (JWTs) issued by the JwtAuthTokenServicenow include a list of user roles in their claims, replacing the previous single role string. This ensures that client applications receive comprehensive role information for authorization.
- Adaptive User Preference Limits: The DefaultUserPreferenceLimitServicehas been adapted to the multi-role model. User preference limits (e.g., number of saved headlines) are now determined based on the most permissive role a user holds, ensuring that limits are correctly applied in the new system.
- Documentation Update: The README.mdhas been updated to reflect the new 'Flexible Role-Based Access Control (RBAC)' feature, highlighting the ability to assign multiple roles for precise control over API features and data management.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description | 
|---|---|---|
| Code Review | /gemini review | Performs a code review for the current pull request in its current state. | 
| Pull Request Summary | /gemini summary | Provides a summary of the current pull request in its current state. | 
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. | 
| Help | /gemini help | Displays a list of available commands. | 
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
- 
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. β© 
 
 @gemini-code-assist
 
 gemini-code-assist
 bot
 
 
 left a comment
 
 
 
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.
Code Review
This pull request refactors the user authentication and authorization system to support multiple roles. The changes are well-structured and consistent. I suggested defining constants for client types and refactoring duplicated logic for determining user preference limits into a shared helper method to improve maintainability.
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.
Consider defining constants for the clientType values instead of using a magic string1 . This improves maintainability and reduces the risk of typos.
const String dashboardClient = 'dashboard';
const String mobileAppClient = 'mobile_app';
final roles = (clientType == dashboardClient)
 ? [UserRoles.standardUser, UserRoles.publisher]
 : [UserRoles.standardUser];
Style Guide References
Footnotes
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 logic for determining user limits based on roles is duplicated in checkAddItem and checkUpdatePreferences. Refactor this into a private helper method to reduce redundancy and improve maintainability.1 
 int _getLimitForUser(User user, String itemType, UserPreferenceLimits limits) {
 if (user.roles.contains(UserRoles.premiumUser)) {
 return (itemType == 'headline')
 ? limits.premiumSavedHeadlinesLimit
 : limits.premiumFollowedItemsLimit;
 } else if (user.roles.contains(UserRoles.standardUser)) {
 return (itemType == 'headline')
 ? limits.authenticatedSavedHeadlinesLimit
 : limits.authenticatedFollowedItemsLimit;
 } else if (user.roles.contains(UserRoles.guestUser)) {
 return (itemType == 'headline')
 ? limits.guestSavedHeadlinesLimit
 : limits.guestFollowedItemsLimit;
 } else {
 throw const ForbiddenException(
 'Cannot determine preference limits for this user account.');
 }
 }
Style Guide References
Footnotes
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.
Consider using the accountType variable in the exception message for better clarity.
 'for your account type ($accountType).',
 );
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.
Consider using the accountType variable in the exception message for better clarity.
 'for your account type ($accountType).',
 );
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.
Consider using the accountType variable in the exception message for better clarity.
 'for your account type ($accountType).',
 );
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.
Consider using the accountType variable in the exception message for better clarity.
 'for your account type ($accountType).',
 );
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.
Consider using the accountType variable in the exception message for better clarity.
 'for your account type ($accountType).',
 );
Status
READY/IN DEVELOPMENT/HOLD
Description
Type of Change