Skip to content

Commit

Permalink
feat: updated request domain check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Sep 6, 2023
1 parent 0124849 commit f4e05b2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
async def check_domain(
request: Request, session: Annotated[AsyncSession, Depends(get_session)]
) -> None:
if request.user.is_authenticated:
if request_needs_domain_check(request) and await email_domain_denied(
session, request.user.email
):
if request_needs_domain_check(request):
if not request.user.is_authenticated:
raise HTTPException(status_code=HTTPStatus.FORBIDDEN)
if await email_domain_denied(session, request.user.email):
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="email domain denied"
)


def request_needs_domain_check(request: Request) -> bool:
open_endpoints = os.getenv("OPEN_ENDPOINT_PATHS", "/v1/admin/me,/v1/institutions")
open_endpoints = os.getenv(
"OPEN_ENDPOINT_PATHS",
"/v1/admin/me,/v1/institutions,/v1/institutions/domains/allowed",
)
open_methods = os.getenv("OPEN_ENDPOINT_METHODS", "GET")
endpoints = open_endpoints.split(",")
methods = open_methods.split(",")
Expand Down

0 comments on commit f4e05b2

Please sign in to comment.