feat(auth): auto-create admin user profiles with highest tier and complimentary flag
- Add `is_complimentary` column to UserProfile model (migration 019) - Update `_ensure_user_profile` to accept `is_admin` param; admins get highest subscription tier, is_complimentary=True, onboarding skipped - Call `_ensure_user_profile` from all login paths (OAuth, local user, admin creds) - Add `is_complimentary` to UserProfileUpsert schema, response helpers, list_users, get_user, upsert_user_profile in admin API - Add complimentary toggle to admin users UI with gift badge in table - Write 18 new tests covering complimentary plan and admin auto-creation - Update SubscriptionTiers.md documentation Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -55,6 +55,35 @@ When a user's `subscription_billing_cycle` is set to `yearly`:
|
||||
|
||||
Setting `UserProfile.allow_overage = True` bypasses monthly quota checks entirely for that user. Usage is still tracked so future billing integrations can charge retroactively. This field is not yet exposed in the admin UI.
|
||||
|
||||
## is_complimentary Flag (Complimentary Plans)
|
||||
|
||||
Setting `UserProfile.is_complimentary = True` marks a user as being on a **complimentary (uncharged) plan**. The user retains all quota benefits of their assigned subscription tier but is **never billed via Stripe**. This is useful for:
|
||||
|
||||
- **Admin accounts** — automatically set on every admin user profile at login time.
|
||||
- **Gifted access** — granting full plan benefits to partners, testers, or sponsored users.
|
||||
|
||||
### Admin Auto-Provisioning
|
||||
|
||||
When an admin user logs in for the first time (via OAuth, local account, or the built-in admin credentials), DocuElevate automatically:
|
||||
|
||||
1. Creates a `UserProfile` row if one does not already exist.
|
||||
2. Assigns the **highest available subscription tier** (currently `business`).
|
||||
3. Sets `is_complimentary = True` so the account is never billed.
|
||||
4. Sets `onboarding_completed = True` so admins skip the first-time setup wizard.
|
||||
|
||||
On subsequent logins for existing admin profiles:
|
||||
- `is_complimentary` is ensured to be `True`.
|
||||
- If the profile was still on the `free` tier it is upgraded to the highest tier.
|
||||
- All other admin-managed settings (custom limits, notes, etc.) are preserved.
|
||||
|
||||
### Managing via Admin UI
|
||||
|
||||
The **User Management** page (`/admin/users`) shows a green gift icon (🎁) next to the plan badge for any user with `is_complimentary = True`. The toggle is available in the user edit modal under **Billing**.
|
||||
|
||||
### API Field
|
||||
|
||||
`is_complimentary` is exposed in the `PUT /api/admin/users/{user_id}` body and in all user detail responses.
|
||||
|
||||
## Plan Designer
|
||||
|
||||
Navigate to `/admin/plans` (admin only) to:
|
||||
|
||||
Reference in New Issue
Block a user