feat(auth): make email the unique login identifier
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled

Login is now by email, not username. username still exists internally
(JWT sub claim, audit logs, Jira actor attribution, SSO provisioning all
still key off it) but is now always kept equal to email everywhere a user
is created or their email changes — never a separately-chosen value.

- User.email is now unique + NOT NULL (migration b067 backfills any
  missing/blank email from username first, so existing rows — notably
  the seeded admin, which historically had none — never violate it).
- /auth/login and the (unused but updated for consistency)
  authenticate_user() now query by email.
- create_user (legacy, unreferenced but kept) and
  create_user_without_password both derive username from email.
- update_user keeps username in sync when email changes, and rejects
  duplicate emails.
- seed.py reads ADMIN_EMAIL (new env var, wired through install.sh and
  docker-compose.prod.yml) for the initial admin; falls back to an
  email-shaped ADMIN_USERNAME or a placeholder that's flagged for the
  operator to fix.
- admin_config.py's import bundle now matches/creates users by email,
  skipping (not crashing on) entries with no email.
- sso_service.py always sets username = email for SSO-provisioned users.
- LoginPage/auth.ts updated to email input/copy (wire field name stays
  'username' — that's the OAuth2PasswordRequestForm spec, not the value).
This commit is contained in:
kitos
2026-07-23 14:39:36 +02:00
parent 0a6cb5510c
commit 504dfc52f5
21 changed files with 184 additions and 81 deletions
@@ -0,0 +1,33 @@
"""Make users.email the unique login identifier (NOT NULL + unique index).
Backfills any missing/blank email from username first, so existing rows
(e.g. the seeded admin, which historically had no email) never violate
the new constraint.
Revision ID: b067
Revises: b066
Create Date: 2026-07-23
"""
from alembic import op
import sqlalchemy as sa
revision = "b067"
down_revision = "b066"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute(
"UPDATE users SET email = username WHERE email IS NULL OR email = ''"
)
op.alter_column("users", "email", existing_type=sa.String(), nullable=False)
op.create_unique_constraint("uq_users_email", "users", ["email"])
op.create_index("ix_users_email", "users", ["email"])
def downgrade() -> None:
op.drop_index("ix_users_email", table_name="users")
op.drop_constraint("uq_users_email", "users", type_="unique")
op.alter_column("users", "email", existing_type=sa.String(), nullable=True)