Skip to content

[Core] As a user_admin, I want to create a new user account. #186

Closed

Description

@nielsdrost7
No description provided.

Activity

  1. coderabbitai commented on Dec 28, 2025

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    ✅ Successfully generated implementation plan.

    💡 Use @coderabbitai <feedback> to replan

    Examples

    🔗 Similar Issues

    Related Issues

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. coderabbitai commented on Dec 28, 2025

    @coderabbitai
    Contributor

    Coding Plan

    Approach

    Enable CUSTOMER_ADMIN role users to create new user accounts within their company context, with appropriate restrictions on assignable roles and automatic company association.

    Observations

    The application uses a modular Laravel architecture with Filament admin panels. User management is currently exclusive to the admin panel with resources under Modules/Core/Filament/Admin/Resources/Users/. The system implements role-based access control via Spatie Permission, with five defined roles (SUPER_ADMIN, ADMIN, ASSIST, CUSTOMER_ADMIN, CUSTOMER). Multi-tenancy is supported through company associations using a pivot table. Resources follow a pattern of delegating form and table configuration to dedicated schema classes. Currently, only SUPER_ADMIN, ADMIN, and ASSIST roles have the "create-users" permission.

    Assumptions
    Assumption 1: "user_admin" role interpretation

    Options Considered:

    • Create a new "user_admin" role distinct from CUSTOMER_ADMIN
    • Interpret "user_admin" as referring to the existing CUSTOMER_ADMIN role

    Chosen Option: Treat "user_admin" as referring to CUSTOMER_ADMIN, as this aligns with the existing role structure where CUSTOMER_ADMIN serves as the administrative role for company tenants.

    Rationale: Creating a new role would introduce unnecessary complexity when the semantic intent matches CUSTOMER_ADMIN's purpose.

    Assumption 2: Panel placement for user creation

    Options Considered:

    • Add user creation to company panel as a new resource
    • Grant CUSTOMER_ADMIN access to admin panel's existing UserResource
    • Create a custom action/modal in the company panel

    Chosen Option: Create a dedicated UserResource in the company panel.

    Rationale: This follows the established pattern of separate panel-specific resources, maintains clear separation between administrative and tenant contexts, and makes the functionality easily discoverable through standard navigation.

    Assumption 3: Role assignment restrictions

    Options Considered:

    • Allow CUSTOMER_ADMIN to assign any role
    • Restrict to only CUSTOMER_ADMIN and CUSTOMER roles
    • Restrict to only CUSTOMER role

    Chosen Option: Restrict CUSTOMER_ADMIN to creating users with CUSTOMER_ADMIN or CUSTOMER roles only.

    Rationale: This prevents privilege escalation while allowing flexibility for company administrators to delegate administrative responsibilities within their organization. The restriction aligns with the principle that users should not be able to create accounts with higher privileges than their own.

    💡 User Tips

    Regenerate the plan with different choices with @coderabbitai <feedback>.

    Implementation Steps

    Phase 1: Permission and Authorization Foundation

    Establish the permission structure and role-based access controls needed for CUSTOMER_ADMIN to create users within their tenant context.

    Task 1: Grant User Creation Permission to CUSTOMER_ADMIN

    Update the role-permission matrix to allow CUSTOMER_ADMIN users to create user accounts.

    • Modify Modules/Core/Database/Seeders/RolesSeeder.php to include "create-users" permission in the CUSTOMER_ADMIN role's default permission set
    • Add "edit-users" permission to support updating created users
    • Ensure CUSTOMER_ADMIN retains existing view permissions for users
    Task 2: Create Authorization Service for Role Assignment Validation

    Introduce business logic to enforce role assignment restrictions based on the creator's role.

    • Create new service class in Modules/Core/Services/ to handle user creation authorization
    • Implement method to validate that CUSTOMER_ADMIN can only assign CUSTOMER_ADMIN and CUSTOMER roles
    • Add validation to check that users cannot create accounts with roles exceeding their own privilege level
    • Return clear error messages when role assignment is attempted outside allowed scope
    🤖 Prompt for AI agents
    This phase establishes permissions and authorization for CUSTOMER_ADMIN to
    create users.
    
    Update RolesSeeder to grant "create-users" and "edit-users" permissions to
    CUSTOMER_ADMIN role.
    
    Create an authorization service class in Modules/Core/Services/ that validates
    role assignments, ensuring CUSTOMER_ADMIN can only assign CUSTOMER_ADMIN and
    CUSTOMER roles, and returns clear error messages for invalid role assignments.
    

    Phase 2: Company Panel User Resource

    Create a dedicated user management resource in the company panel with tenant-scoped functionality and appropriate field restrictions.

    Task 1: Create Company Panel UserResource Structure

    Set up the resource infrastructure following the established pattern for company panel resources.

    • Create Modules/Core/Filament/Company/Resources/Users/ directory structure
    • Create UserResource.php extending Filament's Resource class
    • Define resource configuration (model, navigation icon, navigation label)
    • Create Pages/ subdirectory with CreateUser, EditUser, and ListUsers page classes
    • Configure getPages() method to register the three page classes
    Task 2: Create User Form Schema for Company Panel

    Build the form configuration with role selection restricted to appropriate values.

    • Create Modules/Core/Filament/Company/Resources/Users/Schemas/UserForm.php
    • Reuse basic fields from admin panel's UserForm (name, email, password)
    • Add role selection field using Select component with options filtered to CUSTOMER_ADMIN and CUSTOMER roles only
    • Set appropriate validation rules including required fields and email format
    • Configure password field to hash on save and be required only on creation
    • Use grid/section layout matching established form patterns
    Task 3: Create Users Table Schema for Company Panel

    Configure the table display for listing users within the company context.

    • Create Modules/Core/Filament/Company/Resources/Users/Tables/UsersTable.php
    • Define columns for name, email, role, and created date
    • Add filters for role to allow CUSTOMER_ADMIN to filter by user type
    • Include actions for editing users (inline or modal edit)
    • Add bulk actions if appropriate for the use case
    • Ensure table queries are scoped to current company context
    Task 4: Implement Create User Page with Authorization

    Build the creation page with proper authorization checks and company association logic.

    • Implement CreateUser page class in Modules/Core/Filament/Company/Resources/Users/Pages/
    • Add authorization check in mount() or similar lifecycle method to verify "create-users" permission
    • Override the create process to validate role assignment using the authorization service from Task 1.2
    • Integrate UserService or extend it to handle company association when creating users
    • Ensure created user is automatically linked to creator's current company via company_user pivot table
    • Fire appropriate events (UserWasCreated) after successful creation
    🤖 Prompt for AI agents
    This phase creates a dedicated UserResource in the company panel for
    CUSTOMER_ADMIN user management.
    
    Create directory structure at Modules/Core/Filament/Company/Resources/Users/
    with UserResource.php and Pages subdirectory containing CreateUser, EditUser,
    and ListUsers pages.
    
    Create UserForm.php schema with name, email, and password fields, and role
    selection restricted to CUSTOMER_ADMIN and CUSTOMER only.
    
    Create UsersTable.php schema with columns for name, email, role, created date,
    role filters, edit actions, and company-scoped queries.
    
    Implement CreateUser page with "create-users" permission check, role validation
    using authorization service, automatic company association via company_user
    pivot, and UserWasCreated event firing.
    

    Phase 3: User Service and Business Logic Enhancement

    Extend the user creation service layer to support company-scoped creation and role validation.

    Task 1: Enhance UserService for Company-Scoped Creation

    Modify or extend UserService to handle company associations and role restrictions.

    • Add new method to UserService (e.g., createCompanyUser) that accepts validated input plus company context
    • Implement logic to create user record using existing createUser method
    • Add logic to create company_user pivot relationship after user creation
    • Validate role assignment using authorization service from Task 1.2
    • Return created user or throw validation exceptions for invalid role assignments
    • Maintain backward compatibility with existing createUser() usage in admin panel
    Task 2: Register Company Panel UserResource

    Make the new resource available in the company panel navigation.

    • Update Modules/Core/Providers/CompanyPanelProvider.php to register the new UserResource
    • Add the resource to the resources() array in the panel configuration
    • Verify navigation placement and ordering matches design expectations
    • Ensure proper middleware and authentication are applied by the panel
    🤖 Prompt for AI agents
    This phase enhances the user service layer for company-scoped user creation.
    
    Add createCompanyUser method to UserService that accepts validated input and
    company context, creates user using existing createUser method, establishes
    company_user pivot relationship, validates role assignment using authorization
    service, and maintains backward compatibility.
    
    Register the new UserResource in CompanyPanelProvider by adding it to the
    resources() array in the panel configuration.
    

    Phase 4: Testing and Validation

    Verify the implementation works correctly and respects all security boundaries.

    Task 1: Validate Permission and Authorization Behavior

    Test that access controls function as designed.

    • Verify CUSTOMER_ADMIN users can access user creation in company panel
    • Confirm CUSTOMER and lower roles cannot access user creation
    • Test that role selection dropdown only shows CUSTOMER_ADMIN and CUSTOMER options
    • Validate that attempting to create users with SUPER_ADMIN, ADMIN, or ASSIST roles is blocked
    • Verify authorization checks in CreateUser page prevent unauthorized access
    Task 2: Verify Company Association and Multi-Tenancy

    Ensure users are correctly scoped to companies and tenant boundaries are respected.

    • Test that created users are automatically associated with creator's company
    • Confirm ListUsers table only shows users belonging to current company context
    • Verify that CUSTOMER_ADMIN users cannot see or manage users from other companies
    • Test switching between companies (if applicable) maintains proper user scoping
    • Validate that company_user pivot records are created correctly
    🤖 Prompt for AI agents
    This phase validates the implementation through comprehensive testing.
    
    Test permission-based access: CUSTOMER_ADMIN can create users, lower roles
    cannot, role dropdown shows only CUSTOMER_ADMIN and CUSTOMER options, elevated
    role assignment is blocked, and authorization checks work correctly.
    
    Test multi-tenancy: users are associated with creator's company, ListUsers shows
    only company users, cross-company access is prevented, company switching
    maintains proper scoping, and company_user pivot records are correct.
    

    🚀 Next Steps

    🤖 All AI agent prompts combined
    Task: 1
    
    This phase establishes permissions and authorization for CUSTOMER_ADMIN to
    create users.
    
    Update RolesSeeder to grant "create-users" and "edit-users" permissions to
    CUSTOMER_ADMIN role.
    
    Create an authorization service class in Modules/Core/Services/ that validates
    role assignments, ensuring CUSTOMER_ADMIN can only assign CUSTOMER_ADMIN and
    CUSTOMER roles, and returns clear error messages for invalid role assignments.
    ===============================================================================
    
    Task: 2
    
    This phase creates a dedicated UserResource in the company panel for
    CUSTOMER_ADMIN user management.
    
    Create directory structure at Modules/Core/Filament/Company/Resources/Users/
    with UserResource.php and Pages subdirectory containing CreateUser, EditUser,
    and ListUsers pages.
    
    Create UserForm.php schema with name, email, and password fields, and role
    selection restricted to CUSTOMER_ADMIN and CUSTOMER only.
    
    Create UsersTable.php schema with columns for name, email, role, created date,
    role filters, edit actions, and company-scoped queries.
    
    Implement CreateUser page with "create-users" permission check, role validation
    using authorization service, automatic company association via company_user
    pivot, and UserWasCreated event firing.
    ===============================================================================
    
    Task: 3
    
    This phase enhances the user service layer for company-scoped user creation.
    
    Add createCompanyUser method to UserService that accepts validated input and
    company context, creates user using existing createUser method, establishes
    company_user pivot relationship, validates role assignment using authorization
    service, and maintains backward compatibility.
    
    Register the new UserResource in CompanyPanelProvider by adding it to the
    resources() array in the panel configuration.
    ===============================================================================
    
    Task: 4
    
    This phase validates the implementation through comprehensive testing.
    
    Test permission-based access: CUSTOMER_ADMIN can create users, lower roles
    cannot, role dropdown shows only CUSTOMER_ADMIN and CUSTOMER options, elevated
    role assignment is blocked, and authorization checks work correctly.
    
    Test multi-tenancy: users are associated with creator's company, ListUsers shows
    only company users, cross-company access is prevented, company switching
    maintains proper scoping, and company_user pivot records are correct.
    
    💡 Iterate on the plan with: @coderabbitai <feedback>
    Example Feedback
    - @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2.
    - @coderabbitai For assumption 1 go ahead with option 3 and replan.
    

    💬 Have feedback or questions? Drop into our discord!

  3. added this to the v2.0.0-alpha milestone on Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions