* feat(chalice): upgraded dependencies * feat(chalice): changed path analysis schema * feat(DB): click coordinate support * feat(chalice): changed path analysis issues schema feat(chalice): upgraded dependencies * fix(chalice): fixed pydantic issue * refactor(chalice): refresh token validator * feat(chalice): role restrictions * feat(chalice): EE path analysis changes * refactor(DB): changed creation queries refactor(DB): changed delte queries feat(DB): support new path analysis payload * feat(chalice): save path analysis card * feat(chalice): restrict access * feat(chalice): restrict access * feat(chalice): EE save new path analysis card * refactor(chalice): path analysis * feat(chalice): path analysis new query * fix(chalice): configurable CH config * fix(chalice): assist autocomplete * refactor(chalice): refactored permissions * refactor(chalice): changed log level * refactor(chalice): upgraded dependencies * refactor(chalice): changed path analysis query * refactor(chalice): changed path analysis query * refactor(chalice): upgraded dependencies refactor(alerts): upgraded dependencies refactor(crons): upgraded dependencies * feat(chalice): path analysis ignore start point * feat(chalice): path analysis in progress * refactor(chalice): path analysis changed link sort * refactor(chalice): path analysis changed link sort * refactor(chalice): path analysis changed link sort * refactor(chalice): path analysis new query refactor(chalice): authorizers * refactor(chalice): refactored authorizer * fix(chalice): fixed create card of PathAnalysis * refactor(chalice): compute link-percentage for Path Analysis * refactor(chalice): remove null starting point from Path Analysis * feat(chalice): path analysis CH query * refactor(chalice): changed Path Analysis links-value fix(chalice): fixed search notes for EE * feat(chalice): path analysis enhanced query results * feat(chalice): include timezone in search sessions response * refactor(chalice): refactored logs * refactor(chalice): refactored logs feat(chalice): get path analysis issues
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
import logging
|
|
|
|
from fastapi import Request
|
|
from starlette import status
|
|
from starlette.exceptions import HTTPException
|
|
|
|
import schemas
|
|
from chalicelib.core import projects
|
|
from or_dependencies import OR_context
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ProjectAuthorizer:
|
|
def __init__(self, project_identifier):
|
|
self.project_identifier: str = project_identifier
|
|
|
|
async def __call__(self, request: Request) -> None:
|
|
if len(request.path_params.keys()) == 0 or request.path_params.get(self.project_identifier) is None:
|
|
return
|
|
current_user: schemas.CurrentContext = await OR_context(request)
|
|
value = request.path_params[self.project_identifier]
|
|
user_id = current_user.user_id if request.state.authorizer_identity == "jwt" else None
|
|
if (self.project_identifier == "projectId" \
|
|
and not projects.is_authorized(project_id=value, tenant_id=current_user.tenant_id,
|
|
user_id=user_id)) \
|
|
or (self.project_identifier == "projectKey" \
|
|
and not projects.is_authorized(
|
|
project_id=projects.get_internal_project_id(value),
|
|
tenant_id=current_user.tenant_id, user_id=user_id)):
|
|
logger.debug("unauthorized project")
|
|
logger.debug(value)
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="unauthorized project.")
|