This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, List | |
from app import crud, models, schemas | |
from app.api import deps | |
from app.constants.role import Role | |
from app.core.config import settings | |
from fastapi import APIRouter, Body, Depends, HTTPException, Security | |
from fastapi.encoders import jsonable_encoder | |
from pydantic.networks import EmailStr | |
from pydantic.types import UUID4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from typing import Optional | |
from app.schemas.user_role import UserRole | |
from pydantic import UUID4, BaseModel, EmailStr | |
# Shared properties | |
class UserBase(BaseModel): | |
email: Optional[EmailStr] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from uuid import uuid4 | |
from app.db.base_class import Base | |
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String | |
from sqlalchemy.dialects.postgresql import UUID | |
from sqlalchemy.orm import relationship | |
class User(Base): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
from typing import Any | |
from app import crud, models, schemas | |
from app.api import deps | |
from app.core import security | |
from app.core.config import settings | |
from fastapi import APIRouter, Body, Depends, HTTPException | |
from fastapi.security import OAuth2PasswordRequestForm | |
from sqlalchemy.orm import Session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
from typing import Any, Union | |
from app.core.config import settings | |
from jose import jwt | |
from passlib.context import CryptContext | |
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") | |
ALGORITHM = "HS256" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@router.get("", response_model=List[schemas.User]) | |
def read_users( | |
db: Session = Depends(deps.get_db), | |
skip: int = 0, | |
limit: int = 100, | |
current_user: models.User = Security( | |
deps.get_current_active_user, | |
scopes=[Role.ADMIN["name"], Role.SUPER_ADMIN["name"]], | |
), | |
) -> Any: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Generator | |
from app import crud, models, schemas | |
from app.constants.role import Role | |
from app.core import security | |
from app.core.config import settings | |
from app.db.session import SessionLocal | |
from fastapi import Depends, HTTPException, Security, status | |
from fastapi.security import OAuth2PasswordBearer, SecurityScopes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Role: | |
""" | |
Constants for the various roles scoped in the application ecosystem | |
""" | |
GUEST = { | |
"name": "GUEST", | |
"description": "A Guest Account", | |
} | |
ACCOUNT_ADMIN = { |