95 lines
4.6 KiB
Python
95 lines
4.6 KiB
Python
from datetime import datetime
|
|
from typing import Annotated
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
from uuid import UUID
|
|
|
|
|
|
class Base(BaseModel):
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
|
|
class PermissionsCreate(Base):
|
|
permission:Annotated[str, Field(..., max_length=30, description="permission name")]
|
|
|
|
|
|
class PermissionsOut(Base):
|
|
id:Annotated[int, Field(..., description="id of the permission")]
|
|
permission:Annotated[str, Field(..., max_length=30, description="permission name")]
|
|
|
|
|
|
class PermissionsGroupsCreate(Base):
|
|
|
|
group:Annotated[str, Field(..., max_length=255, description="group name for the permissions")]
|
|
|
|
|
|
class PermissionsGroupsOut(Base):
|
|
|
|
id:Annotated[int, Field(..., description="id of the permission group")]
|
|
group:Annotated[str, Field(..., max_length=255, description="group name for the permissions")]
|
|
|
|
class UserCreate(Base):
|
|
|
|
first_name:Annotated[str, Field(..., max_length=64,description="first name of the user")]
|
|
last_name:Annotated[str, Field(...,max_length=64, description="last name of the user")]
|
|
middle_name:Annotated[str, Field(...,max_length=64, description="middle name of the user")]
|
|
email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")]
|
|
plain_password:Annotated[str, Field(...,min_length=8,max_length=72, description="plain password of the user")]
|
|
status:Annotated[bool, Field(..., description="status of the user")]
|
|
|
|
direct_permissions:Annotated[list[str], Field(..., description="permissions of the user")]
|
|
group:Annotated[list[str], Field(..., description="permissions groups of the user")]
|
|
|
|
class UserOut(Base):
|
|
|
|
first_name:Annotated[str, Field(..., max_length=64,description="first name of the user")]
|
|
last_name:Annotated[str, Field(..., max_length=64,description="last name of the user")]
|
|
middle_name:Annotated[str, Field(..., max_length=64, description="middle name of the user")]
|
|
email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")]
|
|
|
|
direct_permissions:Annotated[list[PermissionsOut], Field(..., description="permissions of the user")]
|
|
group:Annotated[list[PermissionsGroupsOut], Field(..., description="permissions groups of the user")]
|
|
|
|
|
|
class UserOutDB(UserOut):
|
|
id:Annotated[UUID, Field(..., description="Id of the user")]
|
|
status:Annotated[bool, Field(..., description="status of the user")]
|
|
hashed_password:Annotated[str, Field(..., description="hashed password of the user")]
|
|
|
|
class UserUpdate(Base):
|
|
|
|
first_name:Annotated[str|None, Field(None, max_length=64, description="first name of the user")]
|
|
last_name:Annotated[str|None, Field(None, max_length=64,description="last name of the user")]
|
|
middle_name:Annotated[str|None, Field(None, max_length=64,description="middle name of the user")]
|
|
email:Annotated[EmailStr|None, Field(None, min_length=5, max_length=255, description="email of the user")]
|
|
status:Annotated[bool|None, Field(None, description="status of the user")]
|
|
direct_permissions:Annotated[list[str]|None, Field(None, description="permissions of the user")]
|
|
group:Annotated[list[str]|None, Field(None, description="permissions groups of the user")]
|
|
|
|
|
|
class RefreshTokensCreate(Base):
|
|
|
|
id:Annotated[UUID, Field(..., description="jti")]
|
|
user_id:Annotated[UUID, Field(..., description="foreign key for the user")]
|
|
token_hash:Annotated[str, Field(...,max_length=255, description="token hash")]
|
|
device_info:Annotated[str, Field(...,max_length=255, description="User device info")]
|
|
ip_address:Annotated[str, Field(...,max_length=45, description="ip v4/v6 of the user")]
|
|
expires_at:Annotated[datetime, Field(..., description="when token is going to be expired")]
|
|
|
|
class RefreshTokensUpdate(Base):
|
|
is_revoked:Annotated[bool, Field(..., description="revoke token if logout was made")]
|
|
replaced_by:Annotated[UUID, Field(...,description="old_jti")]
|
|
|
|
class RefreshTokensOut(Base):
|
|
|
|
user_id:Annotated[UUID, Field(..., description="foreign key for the user")]
|
|
token_hash:Annotated[str, Field(..., max_length=255,description="token hash")]
|
|
device_info:Annotated[str, Field(..., max_length=255, description="User device info")]
|
|
ip_address:Annotated[str, Field(...,max_length=45, description="ip v4/v6 of the user")]
|
|
is_revoked:Annotated[bool|None, Field(None, description="revoke token if logout was made")]
|
|
expires_at:Annotated[datetime, Field(..., description="when token is going to be expired")]
|
|
replaced_by:Annotated[UUID|None, Field(..., description="Old refresh token")]
|
|
|
|
class RefreshRequest(Base):
|
|
refresh_token:str
|