forked from sr2/cloud-api
fix: preapproval endpoints with new root path
This commit is contained in:
parent
90943c3d18
commit
d404ab3ea3
1 changed files with 5 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ Exports:
|
|||
- org_model_body_dependency: org_model: Gets org model from db, if it exists. Uses org_id from request body. Also verifies if the org has been approved.
|
||||
"""
|
||||
from typing import Annotated, Optional
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from fastapi import Depends, Query, Request
|
||||
|
||||
|
|
@ -17,12 +18,14 @@ from src.organisation.exceptions import OrgNotFoundException, AwaitingApprovalEx
|
|||
from src.organisation.constants import Status as OrgStatus
|
||||
|
||||
|
||||
def get_org_model(db, request: Request, org_id: int):
|
||||
def get_org_model(db: Session, request: Request, org_id: int):
|
||||
org_model = db.get(Org, org_id)
|
||||
if org_model is None:
|
||||
raise OrgNotFoundException(org_id)
|
||||
|
||||
pre_approval_endpoints = ["PATCH/org/status", "PATCH/org/questionnaire", "GET/org/id", "GET/org/contact", "PATCH/org/contact"]
|
||||
root = "/api/v1"
|
||||
|
||||
pre_approval_endpoints = [f"PATCH{root}/org/status", f"PATCH{root}/org/questionnaire", f"GET{root}/org/id", f"GET{root}/org/contact", f"PATCH{root}/org/contact"]
|
||||
current_request = f"{request.method}{request.url.path}"
|
||||
if current_request not in pre_approval_endpoints and org_model.status != OrgStatus.APPROVED:
|
||||
raise AwaitingApprovalException(org_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue