Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor/implement the required user management capabilities for administrators #88

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

@fulleni
Copy link
Member

@fulleni fulleni commented Oct 31, 2025
edited
Loading

Status

READY

Description

This pull request significantly enhances the administrative user management capabilities within the system. It introduces dedicated permissions for creating, updating, and deleting user accounts, assigning these to dashboard administrators. Concurrently, it refactors the user update mechanism to securely handle both administrative role changes and user-initiated profile updates, preventing mass assignment vulnerabilities. The changes also activate a data API endpoint for admin-driven user creation and enforce essential validation for new user entries.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

- Add 'user.create' permission for creating new users (admin-only)
- Add 'user.update' permission for updating any user's profile (admin-only)
- Add 'user.delete' permission for deleting any user's account (admin-only)
- Add user management permissions (create, update, delete) to dashboard admins
- Update comment for userRead permission to clarify its purpose
- Add create user permission for admins
- Implement update and delete permissions for both admins and regular users
- Add detailed comments explaining the permission logic
Adds and refactors data operations for the user model.
- Create: A new entry in _itemCreators is added for 'user', enabling user creation through the generic data endpoint.
- Update: The updater for 'user' is refactored to be more secure and flexible. It now accepts a raw Map<String, dynamic> from the request body and selectively applies changes for appRole, dashboardRole, and feedDecoratorStatus.
This approach prevents mass assignment vulnerabilities while allowing both admins and users to perform their permitted updates.
Updates the _handlePost function in the generic data endpoint to include a specific validation check for modelName == 'user'. This ensures that any request to create a user includes a non-empty email field, preventing the creation of invalid user records.
Modifies the _handlePut function to introduce special handling for the 'user' model. When updating a user, the raw request body map is now passed directly to the _updateItem function, bypassing the standard fromJson deserialization.
This change enables the custom user updater in the DataOperationRegistry to perform a secure, selective merge of updatable fields (like roles), preventing mass assignment vulnerabilities. For all other models, the behavior remains unchanged.
@fulleni fulleni linked an issue Oct 31, 2025 that may be closed by this pull request
Copy link

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 enhances the administrative user management capabilities within the system. It introduces dedicated permissions for creating, updating, and deleting user accounts, assigning these to dashboard administrators. Concurrently, it refactors the user update mechanism to securely handle both administrative role changes and user-initiated profile updates, preventing mass assignment vulnerabilities. The changes also activate a data API endpoint for admin-driven user creation and enforce essential validation for new user entries.

Highlights

  • New Admin User Permissions: Introduced user.create, user.update, and user.delete permissions to enable comprehensive user management capabilities for administrators.
  • Admin Role Assignment: Assigned the newly created user management permissions (user.create, user.update, user.delete) to the _dashboardAdminPermissions set, granting administrators the ability to create, update, and delete user accounts.
  • Refactored User Update Logic: Enhanced the user update handler in DataOperationRegistry to securely support both administrator-driven role updates (e.g., appRole, dashboardRole) and user-owned feedDecoratorStatus updates, by processing a raw request body map to prevent mass assignment vulnerabilities.
  • User Creation Endpoint Activation: Configured the 'user' model's postPermission to require Permissions.userCreate, enabling administrators to create new users via the data API, distinct from authentication-based sign-up flows.
  • Dynamic User Update Handling in API Route: Modified the _handlePut route to specifically handle 'user' model updates by passing the raw request body to the updater, allowing for granular, secure field updates (like roles) without requiring a full model deserialization and bypassing ID validation for role updates.
  • User Creation Email Validation: Added a check in the _handlePost route to ensure that a new 'user' creation request includes a non-empty 'email' field, enforcing a critical validation step.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 effectively refactors and implements administrator capabilities for user management. The changes are well-structured, introducing new permissions and updating the data registries and route handlers accordingly. The use of a raw map for user updates is a good security measure to prevent mass assignment vulnerabilities.

My review includes two main suggestions for improvement in lib/src/registry/data_operation_registry.dart: one to add robust error handling for parsing user roles to prevent server errors from invalid input, and another to refactor the parsing of feedDecoratorStatus for better efficiency and code clarity. Overall, this is a solid contribution.

Adds try-catch blocks around the byName() enum parsing for appRole and dashboardRole in the user updater logic. This prevents unhandled ArgumentError exceptions when a client provides an invalid role string.
Instead of causing a 500 Internal Server Error, the API will now correctly return a 400 Bad Request with a clear error message, improving client-side error handling and API robustness.
@fulleni fulleni merged commit c1ec019 into main Oct 31, 2025
1 check failed
@fulleni fulleni deleted the refactor/implement-the-required-user-management-capabilities-for-administrators branch October 31, 2025 06:14
@fulleni fulleni added this to the Foundation Edition milestone Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Expose Secure User Management Endpoints

2 participants

AltStyle によって変換されたページ (->オリジナル) /