Files
co-lite/openspec/specs/admin-users/spec.md
T

6.7 KiB

admin-users Specification

Purpose

Admins with the Users module manage staff accounts: who can log in, which roles they hold, and which company they belong to.

Requirements

Requirement: User list

The system SHALL list admin users only (never members), paginated on the server, searchable by name, username or email, filterable by active state, and sortable by column.

  • GIVEN admin users sales1 and sales2 and a member m100
  • WHEN an admin with BO_USERS searches for sales
  • THEN the list shows sales1 and sales2 and not m100

Requirement: Create user

The system SHALL let an admin with BO_USERS create an admin user with name, username, email, one or more roles, and an initial password with its confirmation. Username and email SHALL be unique within the user's company, so the same username or email may exist in another company. A username SHALL NOT contain @. The password SHALL match its confirmation and pass the admin password rules. The new user SHALL be saved with a pending password change and SHALL NOT be sent an email.

Scenario: New user

  • WHEN an INS admin creates user sales1 with email sales1@example.com, role Sales and a valid initial password
  • THEN the user is saved as active in INS with a pending password change
  • AND sales1 can sign in with company ins and that password and must choose a new password before anything else
  • AND no email is sent

Scenario: Duplicate username

  • GIVEN a user sales1 exists in INS
  • WHEN an admin creates another INS user with username sales1
  • THEN the save is refused and the form shows that the username is taken

Scenario: Same username in another company

  • GIVEN a user sales1 exists in INS
  • WHEN a CV admin creates user sales1 in CV
  • THEN the user is created

Scenario: Weak or mismatched initial password

  • WHEN an admin creates a user with a password that fails the admin password rules, or that does not match its confirmation
  • THEN the save is refused with a message on the form
  • AND no user is created

Requirement: Edit and deactivate user

The system SHALL let an admin with BO_USERS change a user's name, email, roles and active state. A deactivated user SHALL NOT be able to log in, and a session they already hold SHALL be refused on its next /api/admin/** call. An admin SHALL NOT be able to deactivate their own account. An admin who is not super admin SHALL NOT change the roles on their own account. No admin SHALL assign ROLE_ADMIN or ROLE_MEMBER when creating or editing a user.

Scenario: Deactivate

  • GIVEN user sales1 is signed in
  • WHEN an admin deactivates sales1
  • THEN sales1's next /api/admin/** call responds 401
  • AND sales1 can no longer log in

Scenario: Self-deactivation

  • WHEN an admin tries to deactivate their own account
  • THEN the save is refused with a message

Scenario: Own roles

  • GIVEN an admin who is not super admin and holds ROLE_SALES
  • WHEN they save their own account with a different set of roles
  • THEN the save is refused with a message and their roles are unchanged

Scenario: Hidden roles

  • WHEN an admin creates or edits a user with ROLE_ADMIN or ROLE_MEMBER in the roles
  • THEN the save is refused with a message

Requirement: Admin-triggered password reset

The system SHALL let an admin with BO_USERS give an active admin user a new password in one of two ways: an emailed reset, where the system emails a generated temporary password, or a temporary password the admin types with its confirmation. Either way the user's old password SHALL stop working, and the user SHALL be required to change the password at the next login. A typed password SHALL pass the admin password rules. No password SHALL be logged or returned in a response.

Scenario: Reset

  • WHEN an admin resets sales1's password by email
  • THEN sales1's old password stops working
  • AND a temporary password is emailed to sales1's email address

Scenario: Admin sets a temporary password

  • GIVEN an active user sales1
  • WHEN an admin sets a temporary password for sales1 that passes the rules and matches its confirmation
  • THEN sales1's old password stops working
  • AND sales1 can sign in with the temporary password and must choose a new password before anything else

Scenario: Weak or mismatched temporary password

  • WHEN an admin sets a temporary password that fails the admin password rules, or that does not match its confirmation
  • THEN the request is refused with a message
  • AND sales1's password is unchanged

Scenario: No direct password set

  • WHEN an admin calls POST /api/admin/users/{id}/changePassword
  • THEN the endpoint does not exist and no password changes

Requirement: Company membership

Every admin user other than a super admin SHALL belong to exactly one company. A company user's new user SHALL belong to the creating user's company, whatever the request says. A super admin SHALL choose the company of a new user, or no company to create another super admin.

Scenario: Company in the request is ignored

  • WHEN an INS user's create-user request carries the CV company id
  • THEN the new user belongs to INS

Scenario: Super admin chooses the company

  • WHEN a super admin creates a user and chooses CV
  • THEN the new user belongs to CV

Requirement: Temporary password refusals

The system SHALL refuse to set a temporary password for a disabled user, for the caller's own account, and for a super admin when the caller is not a super admin, and SHALL leave that user's password unchanged.

Scenario: Disabled user

  • GIVEN user sales2 is deactivated
  • WHEN an admin sets a temporary password for sales2
  • THEN the request is refused and sales2's password is unchanged

Scenario: Own account

  • WHEN an admin sets a temporary password for their own account
  • THEN the request is refused

Scenario: Super admin target

  • GIVEN the caller is not a super admin
  • WHEN they set a temporary password for a super admin
  • THEN the request is refused and the super admin's password is unchanged

Requirement: Generated temporary passwords are unpredictable

Every temporary password the system generates for an admin user SHALL come from a cryptographically secure random source. This covers the emailed admin reset and admin forgot-password.

Scenario: Generated passwords do not repeat

  • WHEN the system generates 1,000 temporary passwords of 12 characters
  • THEN all of them are different
  • AND every character comes from the generator's alphabet