- Add api_tokens table with role-based access (researcher, developer, viewer)
- Add POST /auth/token/generate endpoint for creating tokens
- Add GET /auth/tokens endpoint for listing user's tokens
- Add DELETE /auth/tokens/{token_id} endpoint for revoking tokens
- Add agent_type field to documents (research, development, general)
- Implement role-based access control for documents:
- researcher: access to research and general documents
- developer: access to development and general documents
- viewer: read-only access
- Update document model and schemas with agent_type field
- Add comprehensive tests for API token functionality
- All existing tests pass (73 total)
55 lines
1.0 KiB
Python
55 lines
1.0 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class AgentCreate(BaseModel):
|
|
username: str = Field(..., min_length=3, max_length=50)
|
|
password: str = Field(..., min_length=6)
|
|
|
|
|
|
class AgentResponse(BaseModel):
|
|
id: str
|
|
username: str
|
|
role: str
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class AgentLogin(BaseModel):
|
|
username: str
|
|
password: str
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class RefreshResponse(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class ApiTokenCreate(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
role: str = Field(..., pattern="^(researcher|developer|viewer)$")
|
|
|
|
|
|
class ApiTokenResponse(BaseModel):
|
|
id: str
|
|
name: str
|
|
role: str
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class ApiTokenGenerateResponse(BaseModel):
|
|
token: str
|
|
name: str
|
|
role: str
|
|
|
|
model_config = {"from_attributes": True}
|