veza/veza-backend-api/internal/models
senke 9f4c2183a2 feat(backend,web): self-service creator role upgrade via /settings
First item of the v1.0.6 backlog surfaced by the v1.0.5 smoke test: a
brand-new account could register, verify email, and log in — but
attempting to upload hit a 403 because `role='user'` doesn't pass the
`RequireContentCreatorRole` middleware. The only way to get past that
gate was an admin DB update.

This commit wires the self-service path decided in the v1.0.6
specification:

  * One-way flip from `role='user'` to `role='creator'`, gated strictly
    on `is_verified=true` (the verification-email flow we restored in
    Fix 2 of the hardening sprint).
  * No KYC, no cooldown, no admin validation. The conscious click
    already requires ownership of the email address.
  * Downgrade is out of scope — a creator who wants back to `user`
    opens a support ticket. Avoids the "my uploads orphaned" edge case.

Backend
  * Migration `977_users_promoted_to_creator_at.sql`: nullable
    `TIMESTAMPTZ` column, partial index for non-null values. NULL
    preserves the semantic for users who never self-promoted
    (out-of-band admin assignments stay distinguishable from organic
    creators for audit/analytics).
  * `models.User`: new `PromotedToCreatorAt *time.Time` field.
  * `handlers.UpgradeToCreator(db, auditService, logger)`:
      - 401 if no `user_id` in context (belt-and-braces — middleware
        should catch this first)
      - 404 if the user row is missing
      - 403 `EMAIL_NOT_VERIFIED` when `is_verified=false`
      - 200 idempotent with `already_elevated=true` when the caller is
        already creator / premium / moderator / admin / artist /
        producer / label (same set accepted by
        `RequireContentCreatorRole`)
      - 200 with the new role + `promoted_to_creator_at` on the happy
        path. The UPDATE is scoped `WHERE role='user'` so a concurrent
        admin assignment can't be silently overwritten; the zero-rows
        case reloads and returns `already_elevated=true`.
      - audit logs a `user.upgrade_creator` action with IP, UA, and
        the role transition metadata. Non-fatal on failure — the
        upgrade itself already committed.
  * Route: `POST /api/v1/users/me/upgrade-creator` under the existing
    protected users group (RequireAuth + CSRF).

Frontend
  * `AccountSettingsCreatorCard`: new card in the Account tab of
    `/settings`. Completely hidden for users already on a creator-tier
    role (no "you're already a creator" clutter). Unverified users see
    a disabled-but-explanatory state with a "Resend verification"
    CTA to `/verify-email/resend`. Verified users see the "Become an
    artist" button, which POSTs to `/users/me/upgrade-creator` and
    refetches the user on success.
  * `upgradeToCreator()` service in `features/settings/services/`.
  * Copy is deliberately explicit that the change is one-way.

Tests
  * 6 Go unit tests covering: happy path (role + timestamp), unverified
    refused, already-creator idempotent (timestamp preserved),
    admin-assigned idempotent (no timestamp overwrite), user-not-found,
    no-auth-context.
  * 7 Vitest tests covering: verified button visible, unverified state
    shown, card hidden for creator, card hidden for admin, success +
    refetch, idempotent message, server error via toast.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 18:35:07 +02:00
..
admin.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
announcement.go feat(admin): global announcements CRUD and public banner endpoint 2026-02-25 19:55:21 +01:00
api_key.go v0.9.4 2026-03-05 23:03:43 +01:00
bitrate_adaptation.go [BE-DB-004] be-db: Add created_at and updated_at timestamps to all models 2025-12-24 15:08:43 +01:00
bitrate_adaptation_test.go report generation and future tasks selection 2025-12-08 19:57:54 +01:00
chat_message.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
cloud_file_share.go v0.9.4 2026-03-05 23:03:43 +01:00
cloud_file_version.go feat(cloud): file versioning, restore, and sharing 2026-02-25 13:33:08 +01:00
co_listening_session.go feat(v0.10.7): Collaboration Temps Réel F481-F483 2026-03-10 13:34:16 +01:00
custom_claims.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
daily_track_stats.go feat(v0.11.0): F381-F385 database migrations and models for creator analytics 2026-03-10 16:21:01 +01:00
data_export.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
delivered_status.go feat(chat): Sprint 1 -- migrations, models, repositories for chat rewrite 2026-02-22 20:38:20 +01:00
feature_flag.go v0.9.4 2026-03-05 23:03:43 +01:00
federated_identity.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
gear.go v0.9.4 2026-03-05 23:03:43 +01:00
gear_document.go feat(v0.802): frontend Cloud/Gear, MSW, docs, scope v0.803, archive 2026-02-25 14:00:58 +01:00
gear_image.go feat(v0.501): Sprint 1 -- infrastructure foundations 2026-02-22 18:10:25 +01:00
gear_repair.go feat(v0.802): frontend Cloud/Gear, MSW, docs, scope v0.803, archive 2026-02-25 14:00:58 +01:00
genre.go feat(v0.10.1): Tags & Genres discover - F351-F355 2026-03-09 01:52:56 +01:00
hardware.go v0.9.4 2026-03-05 23:03:43 +01:00
hls_stream.go v0.9.4 2026-03-05 23:03:43 +01:00
hls_stream_test.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
hls_transcode_queue.go v0.9.4 2026-03-05 23:03:43 +01:00
hls_transcode_queue_test.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
live_stream.go v0.9.4 2026-03-05 23:03:43 +01:00
message.go feat(chat): Sprint 1 -- migrations, models, repositories for chat rewrite 2026-02-22 20:38:20 +01:00
message_reaction.go feat(chat): Sprint 1 -- migrations, models, repositories for chat rewrite 2026-02-22 20:38:20 +01:00
mfa_config.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
notification.go incus deployement fully implemented, Makefile updated and make fmt ran 2026-01-13 19:47:57 +01:00
playback_analytics.go v0.9.4 2026-03-05 23:03:43 +01:00
playback_analytics_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
playlist.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
playlist_collaborator.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
playlist_collaborator_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
playlist_follow.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
playlist_share_link.go v0.9.4 2026-03-05 23:03:43 +01:00
playlist_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
playlist_version.go v0.9.4 2026-03-05 23:03:43 +01:00
queue.go v0.9.4 2026-03-05 23:03:43 +01:00
queue_session.go v0.9.4 2026-03-05 23:03:43 +01:00
read_receipt.go feat(chat): Sprint 1 -- migrations, models, repositories for chat rewrite 2026-02-22 20:38:20 +01:00
recovery_code.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
refresh_token.go [BE-DB-004] be-db: Add created_at and updated_at timestamps to all models 2025-12-24 15:08:43 +01:00
report.go feat(admin): moderation queue with reports CRUD 2026-02-25 19:53:04 +01:00
requests.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
responses.go [INT-008] int: Standardize date/time formats 2025-12-25 15:16:38 +01:00
role.go [T0-006] test(backend): Ajout tests service role - Progression couverture 2026-01-04 01:44:21 +01:00
role_test.go report generation and future tasks selection 2025-12-08 19:57:54 +01:00
room.go stabilizing veza-backend-api: phase 1 2025-12-16 11:23:49 -05:00
room_invitation.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
royalty.go v0.9.4 2026-03-05 23:03:43 +01:00
seller_stripe_account.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
session.go stabilizing veza-backend-api: phase 1 2025-12-16 11:23:49 -05:00
storage_quota.go feat(v0.501): Sprint 1 -- infrastructure foundations 2026-02-22 18:10:25 +01:00
tag.go feat(v0.10.1): Tags & Genres discover - F351-F355 2026-03-09 01:52:56 +01:00
track.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
track_comment.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
track_comment_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
track_history.go v0.9.4 2026-03-05 23:03:43 +01:00
track_history_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
track_like.go v0.9.4 2026-03-05 23:03:43 +01:00
track_like_test.go report generation and future tasks selection 2025-12-08 19:57:54 +01:00
track_lyrics.go feat(tracks): add lyrics model and endpoints (E3) 2026-02-20 15:36:28 +01:00
track_play.go v0.9.4 2026-03-05 23:03:43 +01:00
track_play_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
track_repost.go feat(v0.10.3): Commentaires & Interactions Sociales - F201-F215 2026-03-09 10:30:47 +01:00
track_share.go STABILISATION: phase 3–5 – API contract, tests & chat-server hardening 2025-12-06 17:21:59 +01:00
track_share_test.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
track_status.go adding initial backend API (Go) 2025-12-03 20:29:37 +01:00
track_stem.go feat(v0.10.7): Collaboration Temps Réel F481-F483 2026-03-10 13:34:16 +01:00
track_version.go report generation and future tasks selection 2025-12-08 19:57:54 +01:00
track_version_test.go report generation and future tasks selection 2025-12-08 19:57:54 +01:00
user.go feat(backend,web): self-service creator role upgrade via /settings 2026-04-16 18:35:07 +02:00
user_file.go feat(v0.501): Sprint 1 -- infrastructure foundations 2026-02-22 18:10:25 +01:00
user_folder.go feat(v0.501): Sprint 1 -- infrastructure foundations 2026-02-22 18:10:25 +01:00
user_genre_tag_follow.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
user_presence.go feat: backend — config, handlers, services, logging, migration 2026-03-23 15:46:57 +01:00
user_settings.go v0.9.4 2026-03-05 23:03:43 +01:00
webauthn_credential.go feat(v0.13.3): complete - Polish Sécurité Avancée 2026-03-13 10:09:01 +01:00
webhook.go incus deployement fully implemented, Makefile updated and make fmt ran 2026-01-13 19:47:57 +01:00