Skip to content

feat: add bulk user management - #529

Open
leojustry-f wants to merge 2 commits into
maillab:mainfrom
leojustry-f:feature/batch-user-management
Open

feat: add bulk user management#529
leojustry-f wants to merge 2 commits into
maillab:mainfrom
leojustry-f:feature/batch-user-management

Conversation

@leojustry-f

Copy link
Copy Markdown

Summary

This PR adds administrator-facing bulk user management to the Users page.

  • Create 1–100 users in one operation with an optional email prefix and optional shared password. Missing values are generated server-side using crypto.getRandomValues().
  • Import users from CSV, XLS, or XLSX. The downloadable template contains only email,password; the administrator selects one default role in the import dialog, and that role is applied consistently to every imported row.
  • Display the credentials created during the current successful batch immediately, with copy and CSV download actions.
  • Export selected existing users to CSV with email, an intentionally blank password, and password_status=not_stored_one_way_hash.

Access control

The three bulk operations use independent permission keys:

Operation Permission key
Batch create user:batch-create
Batch import user:batch-import
Export selected users user:export

The permissions are seeded idempotently but are initially assigned to no standard role. Consequently, only super administrators can see and use these operations by default. Administrators can grant each capability separately through the existing permission-control UI. Both the Vue controls and Worker endpoints enforce the respective permission.

Password handling

Cloud Mail stores passwords as salted, one-way hashes rather than recoverable plaintext. Plaintext credentials are therefore available only for successful rows during the batch creation/import operation that generated them. They are never persisted for later retrieval. Existing-user exports explicitly leave password blank and include a machine-readable status instead of suggesting that a usable password can be recovered from the hash.

Implementation notes

  • Batch operations are capped at 100 rows and report per-row failures without discarding successful rows.
  • The existing account-creation path is reused for validation, hashing, account creation, and registration metadata.
  • Import processing ignores any unexpected type column in source files so that the role selected in the dialog remains authoritative.
  • Local Worker tests use the existing wrangler-test.toml; the unsupported AI binding is omitted only from the local test configuration.

Validation

The following checks completed successfully:

pnpm --dir mail-vue build
node --test mail-vue/test/user-batch-file-utils.test.mjs
pnpm --dir mail-worker exec vitest run
pnpm --dir mail-worker exec wrangler deploy --dry-run --outdir <temporary-dir>

In addition, the adjusted Worker candidate was deployed and manually verified in production before this PR was opened. The existing Vite warning for chunks larger than 500 kB is non-blocking and was not introduced by this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant