feat(backend): Implement Day 6 Role Management API
Add complete role management functionality for tenant administrators to manage user roles within their tenants.
Changes:
- Extended IUserTenantRoleRepository with pagination, role counting, and last owner check methods
- Extended IUserRepository with GetByIdAsync(Guid) and GetByIdsAsync for flexible user retrieval
- Extended IRefreshTokenRepository with GetByUserAndTenantAsync and UpdateRangeAsync
- Implemented repository methods in Infrastructure layer
- Created DTOs: UserWithRoleDto and PagedResultDto<T>
- Implemented ListTenantUsersQuery with pagination support
- Implemented AssignUserRoleCommand to assign/update user roles
- Implemented RemoveUserFromTenantCommand with token revocation
- Created TenantUsersController with 4 endpoints (list, assign, remove, get-roles)
- Added comprehensive PowerShell test script
Security Features:
- Only TenantOwner can assign/update/remove roles
- Prevents removal of last TenantOwner (lockout protection)
- Prevents manual assignment of AIAgent role (reserved for MCP)
- Cross-tenant access protection
- Automatic refresh token revocation when user removed
API Endpoints:
- GET /api/tenants/{id}/users - List users with roles (paginated)
- POST /api/tenants/{id}/users/{userId}/role - Assign/update role
- DELETE /api/tenants/{id}/users/{userId} - Remove user from tenant
- GET /api/tenants/roles - Get available roles
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,18 @@ public interface IUserRepository
|
||||
/// </summary>
|
||||
Task<User?> GetByIdAsync(UserId userId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get user by Guid ID
|
||||
/// </summary>
|
||||
Task<User?> GetByIdAsync(Guid userId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get multiple users by their IDs
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<User>> GetByIdsAsync(
|
||||
IEnumerable<Guid> userIds,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get user by email within a tenant
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user