Skip to content

Feature/66 account management - #94

Merged
anis022 merged 11 commits into
developfrom
feature/66-account-management
Dec 4, 2026
Merged

anis022 merged 11 commits into
developfrom
feature/66-account-management

Conversation

@maayjayy

@maayjayy maayjayy commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #66

Overview

  • Goal: let an administrator add employees, edit their account, change their role and remove or give back their access
  • API api/accounts (all routes Admin only, ManageAccounts): list, roles, get, history, add, edit, change role, deactivate, reactivate
  • New table user_account_changes: every change with the admin who made it and the before and after values (migration AddUserAccountChanges, SQL script 0012)
  • Simultaneous edits: users uses PostgreSQL's xmin column as a version, so a second save on a changed account returns 409 instead of overwriting it (no new column)
  • Safeguards: the last active admin cannot lose the role or be deactivated (rows locked with FOR UPDATE, so two admins cannot deactivate each other at the same time), and an admin cannot change their own role or remove their own access
  • /api/me now returns the employee's app role
  • Desktop: temporary Accounts screen (admins only), with a confirmation before changing a role or the access, and the message "You do not have access to this app" for a deactivated or never-added account
  • Docs: users-roles.md (history table, admin handover) and roles-permissions.md

Testing

Automated tests (Docker must be running): all 745 pass with dotnet test.

  • ActiveAccountTests: a deactivated or never-added account is refused on every route, with the same answer, even with a valid token
  • AuthenticationTests: /api/me returns the role, and a role change takes effect on the next request
  • AccountServiceTests: add, unique email regardless of case, edit with version check (also when another admin saves in between), role, deactivate and reactivate, history, last admin (also two admins at the same time), own account
  • AccountEndpointTests: 401, 403 for every non-admin role on every route, 201 and the new employee can then sign in, 400, 404, 409, data created by an employee stays attributed to them after deactivation and reactivation

Manual test in the app with the test account: add, edit, change role, remove and give back access, own account buttons disabled, "no access" message after deactivating my own account in the local database.

Screenshots / Screencasts

All screenshots of the manual test (11)

1. Home page: signed in as an Admin, with the Accounts button
Screenshot 2026-11-27 at 12 38 00 PM

2. Accounts screen: only the first admin
Screenshot 2026-11-27 at 12 38 18 PM

3. Employee added (Supply, not signed in yet)
Accounts

4. Confirmation before changing the role
Screenshot 2026-11-27 at 12 39 14 PM

5. Role changed to Supply Director
Pasted Graphic

6. Confirmation before removing access
Accounts

7. Access removed: the account is kept and marked Deactivated
Pasted Graphic 2

8. Confirmation before giving the access back
Pasted Graphic 3

9. Access given back
Accounts

10. Own account: role and access buttons disabled
image

11. Deactivated account: neutral message at sign-in
Pasted Graphic 9

Checklist

  • Code is neat, readable, and works
  • Code is commented where appropriate and well-documented
  • Commit messages follow our guidelines
  • Issue number is linked
  • Branch is linked
  • Reviewers are assigned (one of your tech leads)

Notes

  • Every route now requires an active account (default policy in Program.cs). Before, routes without a permission (GET catalog items, prices, BC mappings, /api/me) accepted any valid Microsoft token, even for a deactivated or never-added account. For new API tests: create an active user first (ReplaceUsersWithAsync or SignInAsAsync), otherwise the route returns 403. I adjusted AuthenticationTests (now uses a real database) and CatalogItemPricesEndpointTests (adds an active user).
  • "An administrator cannot deactivate themselves or change their own role" was marked "to confirm": I blocked it. To hand over the role, the admin promotes someone, who then removes the old admin's access (documented in users-roles.md).
  • The 4 existing roles are used. The issue says the list is to be confirmed with the client.
  • user_account_changes links to users, so test helpers that delete all users need the history emptied first (same as the mapping tables in [Issue]: BC-to-grid mapping: storage, confirmation and reuse #73).

@maayjayy maayjayy added this to the Sprint 3 milestone Nov 27, 2026
@maayjayy maayjayy self-assigned this Nov 27, 2026
@maayjayy maayjayy linked an issue Nov 27, 2026 that may be closed by this pull request
15 tasks done
@anis022
anis022 removed the request for review from lauriechammah December 4, 2026 06:15

@anis022 anis022 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good

@anis022
anis022 merged commit f9bb579 into develop Dec 4, 2026
1 check passed
@anis022
anis022 deleted the feature/66-account-management branch December 4, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: Account management: add, edit, change role and deactivate

2 participants