Skip to content

Commit

Permalink
Add Terms of Use acceptance feature for User model
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Oct 29, 2024
1 parent b170414 commit aeceac3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class User(Model):
is_2fa_required = fields.BooleanField(default=False)
is_2fa_activated = fields.BooleanField(default=False)
is_ergon_validation_required = fields.BooleanField(default=False)
# Terms of use
is_use_terms_accepted = fields.BooleanField(default=False)
use_terms_accepted_at = fields.DatetimeField(null=True)
# Metadata
is_active = fields.BooleanField(default=True)
is_superuser = fields.BooleanField(default=False)
Expand Down
20 changes: 20 additions & 0 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import asyncio
import datetime
from typing import Annotated, List
from fastapi import APIRouter, Depends, Request
from fastapi_limiter.depends import RateLimiter
Expand Down Expand Up @@ -45,6 +46,7 @@ async def get_user_info(
"role": user.role.job_title if user.role else None,
"email": user.email,
"username": user.username,
"is_use_terms_accepted": user.is_use_terms_accepted,
"cpf": cpf,
}

Expand Down Expand Up @@ -150,6 +152,24 @@ async def get_patient_encounters(
return []


@router_request(
method="POST",
router=router,
path="/user/accept-terms/",
response_model=bool,
)
async def accept_use_terms(
user: Annotated[User, Depends(assert_user_is_active)],
request: Request,
) -> List[Encounter]:

user.is_use_terms_accepted = True
user.use_terms_accepted_at = datetime.datetime.now()
await user.save()

return user


@router.get("/patient/filter_tags")
async def get_filter_tags(_: Annotated[User, Depends(assert_user_is_active)]) -> List[str]:
return [
Expand Down
14 changes: 14 additions & 0 deletions migrations/app/35_20241029140029_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "user" ADD "use_terms_accepted_at" TIMESTAMPTZ;
ALTER TABLE "user" ADD "is_use_terms_accepted" BOOL NOT NULL DEFAULT False;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "user" DROP COLUMN "use_terms_accepted_at";
ALTER TABLE "user" DROP COLUMN "is_use_terms_accepted";"""

0 comments on commit aeceac3

Please sign in to comment.