Skip to content

Commit

Permalink
feat: add var env. to active token for create users
Browse files Browse the repository at this point in the history
  • Loading branch information
flavien-hugs committed Sep 19, 2024
1 parent db3669b commit c5e7b93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ FRONTEND_PATH_ACTIVATE_ACCOUNT=<ChangeMe>
FRONTEND_PATH_LOGIN=<ChangeMe>
REGISTER_WITH_EMAIL=<ChangeMe>

LIST_ROLES_ENDPOINT_SECURITY_ENABLED=<ChangeMe>
REGISTER_USER_ENDPOINT_SECURITY_ENABLED=<ChangeMe>

# CONFIG DEFAULT ADMIN USER
DEFAULT_ADMIN_FULLNAME=<ChangeMe>
DEFAULT_ADMIN_EMAIL=<ChangeMe>
Expand Down
3 changes: 3 additions & 0 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class AuthBaseConfig(BaseSettings):
LIST_ROLES_ENDPOINT_SECURITY_ENABLED: Optional[bool] = Field(
default=False, alias="LIST_ROLES_ENDPOINT_SECURITY_ENABLED"
)
REGISTER_USER_ENDPOINT_SECURITY_ENABLED: Optional[bool] = Field(
default=False, alias="REGISTER_USER_ENDPOINT_SECURITY_ENABLED"
)

# USER MODEL NAME
USER_MODEL_NAME: str = Field(..., alias="USER_MODEL_NAME")
Expand Down
13 changes: 9 additions & 4 deletions src/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi_pagination import paginate
from pymongo import ASCENDING, DESCENDING

from src.config import settings
from src.middleware import AuthorizedHTTPBearer, CheckPermissionsHandler
from src.models import User, UserOut
from src.schemas import CreateUser, UpdateUser
Expand All @@ -16,10 +17,14 @@

@user_router.post(
"",
dependencies=[
Depends(AuthorizedHTTPBearer),
Depends(CheckPermissionsHandler(required_permissions={"auth:can-create-user"})),
],
dependencies=(
[
Depends(AuthorizedHTTPBearer),
Depends(CheckPermissionsHandler(required_permissions={"auth:can-create-user"})),
]
if settings.REGISTER_USER_ENDPOINT_SECURITY_ENABLED
else []
),
response_model=User,
response_model_exclude={"password", "is_primary"},
status_code=status.HTTP_201_CREATED,
Expand Down

0 comments on commit c5e7b93

Please sign in to comment.