mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
### Changes 🏗️ - add invite-backed beta provisioning with a new `InvitedUser` platform model, Prisma migration, and first-login activation path that materializes `User`, `Profile`, `UserOnboarding`, and `CoPilotUnderstanding` - replace the legacy beta allowlist check with invite-backed gating for email/password signup and Tally pre-seeding during activation - add admin backend APIs and frontend `/admin/users` management UI for listing, creating, revoking, retrying, and bulk-uploading invited users - add the design doc for the beta invite system and extend backend coverage for invite activation, bulk uploads, and auth-route behavior - configuration changes: introduce the new invite/tally schema objects and migration; no new env vars or docker service changes are required ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] `cd autogpt_platform/backend && poetry run format` - [x] `cd autogpt_platform/backend && poetry run pytest -q` (run against an isolated local Postgres database with non-conflicting service port overrides) #### For configuration changes: - [x] `.env.default` is updated or already compatible with my changes - [x] `docker-compose.yml` is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under **Changes**)
93 lines
2.6 KiB
Python
93 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING, Any, Literal, Optional
|
|
|
|
import prisma.enums
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
from backend.data.model import UserTransaction
|
|
from backend.util.models import Pagination
|
|
|
|
if TYPE_CHECKING:
|
|
from backend.data.invited_user import BulkInvitedUsersResult, InvitedUserRecord
|
|
|
|
|
|
class UserHistoryResponse(BaseModel):
|
|
"""Response model for listings with version history"""
|
|
|
|
history: list[UserTransaction]
|
|
pagination: Pagination
|
|
|
|
|
|
class AddUserCreditsResponse(BaseModel):
|
|
new_balance: int
|
|
transaction_key: str
|
|
|
|
|
|
class CreateInvitedUserRequest(BaseModel):
|
|
email: EmailStr
|
|
name: Optional[str] = None
|
|
|
|
|
|
class InvitedUserResponse(BaseModel):
|
|
id: str
|
|
email: str
|
|
status: prisma.enums.InvitedUserStatus
|
|
auth_user_id: Optional[str] = None
|
|
name: Optional[str] = None
|
|
tally_understanding: Optional[dict[str, Any]] = None
|
|
tally_status: prisma.enums.TallyComputationStatus
|
|
tally_computed_at: Optional[datetime] = None
|
|
tally_error: Optional[str] = None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
@classmethod
|
|
def from_record(cls, record: InvitedUserRecord) -> InvitedUserResponse:
|
|
return cls.model_validate(record.model_dump())
|
|
|
|
|
|
class InvitedUsersResponse(BaseModel):
|
|
invited_users: list[InvitedUserResponse]
|
|
pagination: Pagination
|
|
|
|
|
|
class BulkInvitedUserRowResponse(BaseModel):
|
|
row_number: int
|
|
email: Optional[str] = None
|
|
name: Optional[str] = None
|
|
status: Literal["CREATED", "SKIPPED", "ERROR"]
|
|
message: str
|
|
invited_user: Optional[InvitedUserResponse] = None
|
|
|
|
|
|
class BulkInvitedUsersResponse(BaseModel):
|
|
created_count: int
|
|
skipped_count: int
|
|
error_count: int
|
|
results: list[BulkInvitedUserRowResponse]
|
|
|
|
@classmethod
|
|
def from_result(cls, result: BulkInvitedUsersResult) -> BulkInvitedUsersResponse:
|
|
return cls(
|
|
created_count=result.created_count,
|
|
skipped_count=result.skipped_count,
|
|
error_count=result.error_count,
|
|
results=[
|
|
BulkInvitedUserRowResponse(
|
|
row_number=row.row_number,
|
|
email=row.email,
|
|
name=row.name,
|
|
status=row.status,
|
|
message=row.message,
|
|
invited_user=(
|
|
InvitedUserResponse.from_record(row.invited_user)
|
|
if row.invited_user is not None
|
|
else None
|
|
),
|
|
)
|
|
for row in result.results
|
|
],
|
|
)
|