Adding chtlawfirm to the api
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter
|
||||
|
||||
from beanie import Document, PydanticObjectId
|
||||
from pydantic import Field, computed_field
|
||||
from hub.auth import auth_router, register_router, password_router, verification_router, users_router, \
|
||||
google_oauth_router, discord_oauth_router
|
||||
from hub.firm.routes import router as firm_router
|
||||
|
||||
hub_router = APIRouter()
|
||||
|
||||
class CrudDocument(Document):
|
||||
_id: str
|
||||
created_at: datetime = Field(default=datetime.utcnow(), nullable=False, title="Créé le")
|
||||
created_by: PydanticObjectId = Field()
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False, title="Modifié le")
|
||||
updated_by: PydanticObjectId = Field()
|
||||
|
||||
@computed_field
|
||||
def label(self) -> str:
|
||||
return self.compute_label()
|
||||
|
||||
def compute_label(self) -> str:
|
||||
return ""
|
||||
hub_router.include_router(register_router, tags=["Auth"], )
|
||||
hub_router.include_router(auth_router, prefix="/auth", tags=["Auth"], )
|
||||
hub_router.include_router(google_oauth_router, prefix="/auth/google", tags=["Auth"])
|
||||
hub_router.include_router(discord_oauth_router, prefix="/auth/discord", tags=["Auth"])
|
||||
hub_router.include_router(verification_router, prefix="/auth/verification", tags=["Auth"], )
|
||||
hub_router.include_router(users_router, prefix="/users", tags=["Users"], )
|
||||
hub_router.include_router(password_router, prefix="/users", tags=["Users"], )
|
||||
hub_router.include_router(firm_router, prefix="/users/firms", tags=["Users"], )
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
from typing import Any
|
||||
|
||||
from beanie import PydanticObjectId, Document
|
||||
from fastapi import Depends, Response, status
|
||||
from fastapi import Depends, Response, status, APIRouter
|
||||
from fastapi_users import BaseUserManager, FastAPIUsers, schemas, models
|
||||
from fastapi_users.authentication import AuthenticationBackend, CookieTransport, Strategy
|
||||
from fastapi_users.authentication.strategy import AccessTokenDatabase, DatabaseStrategy
|
||||
@@ -77,9 +77,12 @@ class CookieTransportOauth(CookieTransport):
|
||||
|
||||
cookie_transport = CookieTransportMe(cookie_name="rpkapiusersauth")
|
||||
auth_backend = AuthenticationBackendMe(name="db", transport=cookie_transport, get_strategy=get_database_strategy, )
|
||||
|
||||
fastapi_users = FastAPIUsers[User, PydanticObjectId](get_user_manager, [auth_backend])
|
||||
|
||||
get_current_user = fastapi_users.current_user(active=True)
|
||||
get_current_superuser = fastapi_users.current_user(active=True, superuser=True)
|
||||
|
||||
|
||||
auth_router = fastapi_users.get_auth_router(auth_backend, requires_verification=True)
|
||||
register_router = fastapi_users.get_register_router(UserSchema, schemas.BaseUserCreate)
|
||||
password_router = fastapi_users.get_reset_password_router()
|
||||
@@ -91,6 +94,3 @@ auth_backend = AuthenticationBackend(name="db", transport=cookie_transport, get_
|
||||
|
||||
google_oauth_router = fastapi_users.get_oauth_router(google_oauth_client, auth_backend, SECRET, is_verified_by_default=True)
|
||||
discord_oauth_router = fastapi_users.get_oauth_router(discord_oauth_client, auth_backend, SECRET, is_verified_by_default=True)
|
||||
|
||||
get_current_user = fastapi_users.current_user(active=True)
|
||||
get_current_superuser = fastapi_users.current_user(active=True, superuser=True)
|
||||
|
||||
19
api/rpk-api/hub/core/__init__.py
Normal file
19
api/rpk-api/hub/core/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from datetime import datetime
|
||||
|
||||
from beanie import Document, PydanticObjectId
|
||||
from pydantic import Field, computed_field
|
||||
|
||||
|
||||
class CrudDocument(Document):
|
||||
_id: str
|
||||
created_at: datetime = Field(default=datetime.utcnow(), nullable=False, title="Créé le")
|
||||
created_by: PydanticObjectId = Field()
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False, title="Modifié le")
|
||||
updated_by: PydanticObjectId = Field()
|
||||
|
||||
@computed_field
|
||||
def label(self) -> str:
|
||||
return self.compute_label()
|
||||
|
||||
def compute_label(self) -> str:
|
||||
return ""
|
||||
@@ -2,7 +2,7 @@ from beanie import PydanticObjectId
|
||||
from pydantic import Field, BaseModel
|
||||
from pymongo import IndexModel
|
||||
|
||||
from hub import CrudDocument
|
||||
from hub.core import CrudDocument
|
||||
|
||||
class Firm(CrudDocument):
|
||||
name: str = Field()
|
||||
|
||||
Reference in New Issue
Block a user