feat: admin invite codes with plan assignment + user detail page
- Migration 030: add email, assigned_plan, trial_duration_days, email_sent_at
to invite_codes with CHECK constraints
- Resend email integration (graceful degradation when API key not set)
- Invite codes now support plan assignment (free/pro/team) and trial duration (1-90 days)
- Registration applies invite code plan/trial to new subscription
- Auto-downgrade expired trials on authenticated access
- Enriched GET /admin/users/{id} with account, subscription, sessions, audit logs
- New endpoints: PUT /admin/users/{id}/subscription/plan and extend-trial
- Frontend: enhanced invite codes page with email, plan, trial fields
- Frontend: new user detail page at /admin/users/:userId
- Fixed API path drift: /invite-codes -> /invites
- 11 new backend tests, 416 total passing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -46,6 +46,13 @@ class InviteCode(Base):
|
||||
DateTime(timezone=True),
|
||||
nullable=True
|
||||
)
|
||||
email: Mapped[Optional[str]] = mapped_column(String(255), nullable=True, index=True)
|
||||
assigned_plan: Mapped[str] = mapped_column(String(50), nullable=False, server_default="free")
|
||||
trial_duration_days: Mapped[Optional[int]] = mapped_column(nullable=True)
|
||||
email_sent_at: Mapped[Optional[datetime]] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=True
|
||||
)
|
||||
note: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
@@ -84,3 +91,11 @@ class InviteCode(Base):
|
||||
def is_valid(self) -> bool:
|
||||
"""Check if the invite code is valid (not used and not expired)."""
|
||||
return not self.is_used and not self.is_expired
|
||||
|
||||
@property
|
||||
def has_trial(self) -> bool:
|
||||
return self.trial_duration_days is not None and self.trial_duration_days > 0
|
||||
|
||||
@property
|
||||
def email_sent(self) -> bool:
|
||||
return self.email_sent_at is not None
|
||||
|
||||
Reference in New Issue
Block a user