Skip to content

Add Moderator role with user management permissions#70

Merged
rom98759 merged 4 commits intocodastream:mainfrom
rom98759:moderator
Feb 13, 2026
Merged

Add Moderator role with user management permissions#70
rom98759 merged 4 commits intocodastream:mainfrom
rom98759:moderator

Conversation

@rom98759
Copy link
Collaborator

New Moderator role with specific permissions:

View users list

Delete / reset user 2FA

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a new MODERATOR role to the application's role-based access control (RBAC) system, sitting between USER and ADMIN in the hierarchy. The moderator role provides limited administrative capabilities: viewing the users list and disabling 2FA for users, without the ability to modify or delete user accounts.

Changes:

  • Adds MODERATOR role to the role hierarchy with appropriate permissions (view users, disable 2FA)
  • Updates frontend UI to display moderator badges and conditional access to admin panel
  • Implements separate routing for moderator-accessible endpoints vs admin-only endpoints
  • Adds permission helper functions in the admin UI for role-based feature visibility

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
srcs/shared/core/src/schemas/base.schema.ts Adds 'MODERATOR' to roleShema enum (with typo and case inconsistency)
srcs/shared/core/src/logging/logging.ts Adds ROLE_MODERATOR_REQUIRED logging constant (unused)
srcs/nginx/src/types/react-types.ts Adds MODERATOR to React Roles enum (case mismatch with backend)
srcs/nginx/src/html/dashboard.html Adds moderator badge styling and admin panel access for moderators
srcs/nginx/src/html/admin.html Implements permission-based UI for moderator vs admin actions, adds moderator stats card, quick 2FA disable button
srcs/auth/src/utils/constants.ts Adds MODERATOR to UserRole enum, updates role hierarchy to 3 levels, updates error message
srcs/auth/src/services/auth.service.ts Updates role hierarchy map to include moderator level
srcs/auth/src/routes/admin.routes.ts Splits routes into adminRoutes (admin-only) and moderatorRoutes (moderator+) with separate authorization hooks
srcs/auth/src/index.ts Registers both admin and moderator route plugins
srcs/auth/src/controllers/admin.controller.ts Updates role validation to use Object.values(UserRole) for dynamic validation

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rom98759 rom98759 self-assigned this Feb 11, 2026
@rom98759 rom98759 added the feature New feature or request label Feb 11, 2026
@rom98759 rom98759 requested a review from jmtth February 12, 2026 15:08
Copy link
Owner

@codastream codastream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • fait-on la localisation dans le panneau admin ? peut-etre trop de complications
  • il y a peut-être un moyen de profiter des modifs dans auth pour limiter les erreurs ESLint (no explicit any)

Sinon, c'est bon !

NB : j'ai simplement revu le code, sans faire tourner l'app

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pour éviter les as any, peut-on définir une interface

AuthenticatedRequest extends FastifyRequest {
   authUser: {
      id: number;
      username: string;
      role: string;
   };
}

que l'on utiliserait à la place de FastifyRequest pour les requêtes de authService nécessitant une authentification (hors login, register)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth service a acces au package core. Si il y a besoin de traduire les messages d'erreur, on pourrait reutiliser les errorCodes de core, pour que le frontend dispose des mémes clés

.regex(/^(?=.*[!@#$%^&*])/, 'Password must contain at least one special character (!@#$%^&*)');

export const roleShema = z.enum(['GUEST', 'USER', 'ADMIN']);
export const roleSchema = z.enum(['user', 'moderator', 'admin']);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pour l'instant le roleSchema n'est pas utilisé (il y a avait un usage temporaire dans DevLogin)

@rom98759 rom98759 merged commit b74ad7a into codastream:main Feb 13, 2026
4 checks passed
@rom98759 rom98759 deleted the moderator branch February 13, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants