-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/user management capabilities within the generic data api #89
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
Refactor/user management capabilities within the generic data api #89
Conversation
Updated the documentation for the `user.update` permission to explicitly state it is an administrator-level permission, distinguishing it from `user.update_owned`.
Removed `Permissions.userCreate` and `Permissions.userDelete` from the `_dashboardAdminPermissions` set. This change enforces the rule that administrators can only update users through the generic data API, while creation and deletion are handled exclusively by the authentication service.
Updated the `ModelConfig` for the `user` model to mark `POST` (create) and `DELETE` operations as `RequiredPermissionType.unsupported`. This change enforces that user lifecycle management is handled exclusively by the authentication service, not the generic data endpoint. Added comments to clarify the update logic flow.
Removed the 'user' model from the item creators and deleters maps, enforcing that user creation and deletion are handled exclusively by the authentication service. Completely rewrote the custom updater for the 'user' model to be secure and architecturally sound. The new logic: - Enforces that administrators can only update `appRole` and `dashboardRole`. - Enforces that regular users can only update their own `feedDecoratorStatus`. - Rejects attempts to update any other fields via this endpoint. - Reads the pre-fetched user object and uses `copyWith` to apply only the allowed changes, creating a full, valid `User` object for the repository's `update` method. This resolves the previous partial update issue and aligns with the `DataRepository<T>` contract.
Added two new methods to `AuthService` to handle user email changes securely: - `initiateEmailUpdate`: Checks if the new email is available, then generates and sends a verification code to the new address. - `completeEmailUpdate`: Verifies the provided code and, upon success, updates the user's email in the database. This ensures that a user must prove ownership of the new email address before the change is finalized, enhancing account security.
Refactored the custom user updater to correctly handle a full `User` object in the request body, aligning with the `DataRepository` contract and fixing the `500` error seen by the client. The new logic performs a state comparison: - It deserializes the incoming request body into a `User` object. - It compares this object against the pre-fetched user from the database to identify which fields have changed. - It verifies that only permitted fields (`appRole`/`dashboardRole` for admins, `feedDecoratorStatus` for users) have been modified. - If validation passes, it proceeds with the update using the full `User` object from the request. This fixes the bug while maintaining security and architectural consistency.
Summary of ChangesHello @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 refactors the user management capabilities within the generic data API to improve security, clarify service responsibilities, and enhance the user update experience. It centralizes user creation and deletion to the authentication service and implements a robust, permission-aware update handler for user profiles, ensuring that only authorized fields can be modified by specific roles. Additionally, a secure, multi-step email update process has been added to the authentication service. Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
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 is a significant and well-executed refactoring of user management capabilities. Moving user creation and deletion out of the generic data API and into the AuthService clarifies the separation of concerns. The new implementation for updating user data is much more secure and robust, effectively preventing mass assignment vulnerabilities by comparing object states. The addition of a secure, two-step email update process is also a great enhancement. I've found a couple of areas for improvement: one is a misleading comment, and the other is a potential race condition in the new email update logic. Overall, these are excellent changes that improve the security and maintainability of the codebase.
Uh oh!
There was an error while loading. Please reload this page.
Status
READY
Description
This pull request refactors the user management capabilities within the generic data API to improve security, clarify service responsibilities, and enhance the user update experience. It centralizes user creation and deletion to the authentication service and implements a robust, permission-aware update handler for user profiles, ensuring that only authorized fields can be modified by specific roles. Additionally, a secure, multi-step email update process has been added to the authentication service.
Type of Change