check for 403 on the router, not in service!
This commit is contained in:
@@ -7,6 +7,9 @@ from inse.auth.service import CurrentUserAccessTokenPayloadDep
|
||||
from inse.institutions.institutions_search_client import (
|
||||
InstitutionsSearchClient,
|
||||
)
|
||||
from inse.projects.logic import (
|
||||
is_projects_access_forbidden
|
||||
)
|
||||
from inse.institutions.router import get_institutions_search_client
|
||||
from inse.models.bund_project_details import BundProjectDetails
|
||||
from inse.models.dfg_project_details import DfgProjectDetails
|
||||
@@ -30,6 +33,7 @@ from inse.projects.model import (
|
||||
SortDirection,
|
||||
)
|
||||
from inse.tags import Tags
|
||||
from fastapi import HTTPException as HttpException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -144,8 +148,13 @@ async def get_dfg_projects(
|
||||
sort_direction,
|
||||
fuzzy,
|
||||
)
|
||||
return await projects_service.get_dfg_projects_by_author_id(
|
||||
access_token_metadata=access_token_metadata,
|
||||
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, author_id)
|
||||
if is_forbidden:
|
||||
raise HttpException(
|
||||
status_code=403,
|
||||
detail="Access denied for the provided author ID or institution ID",
|
||||
)
|
||||
return await projects_service.get_dfg_projects(
|
||||
institutions_search_client=institutions_search_client,
|
||||
raw_oa_institution_id=raw_oa_institution_id,
|
||||
author_id=author_id,
|
||||
@@ -259,6 +268,12 @@ async def search_bund_projects(
|
||||
Query(description="Use OpenAlex topic-id resolution if true, otherwise raw keyword search."),
|
||||
] = False,
|
||||
) -> BundProjectPage:
|
||||
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, None)
|
||||
if is_forbidden:
|
||||
raise HttpException(
|
||||
status_code=403,
|
||||
detail="Access denied for the provided author ID or institution ID",
|
||||
)
|
||||
return await projects_service.search_bund_projects_with_filters(
|
||||
access_token_metadata=access_token_metadata,
|
||||
institutions_search_client=institutions_search_client,
|
||||
@@ -438,9 +453,13 @@ async def search_eu_cordis_projects_endpoint(
|
||||
sort_direction,
|
||||
fuzzy,
|
||||
)
|
||||
|
||||
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, author_id)
|
||||
if is_forbidden:
|
||||
raise HttpException(
|
||||
status_code=403,
|
||||
detail="Access denied for the provided author ID or institution ID",
|
||||
)
|
||||
return await search_eu_cordis_projects(
|
||||
access_token_metadata=access_token_metadata,
|
||||
institutions_search_client=institutions_search_client,
|
||||
raw_oa_institution_id=raw_oa_institution_id,
|
||||
author_id=author_id,
|
||||
|
||||
@@ -27,9 +27,7 @@ from inse.projects.eu_cordis_projects_client import (
|
||||
from inse.projects.eu_cordis_projects_client import (
|
||||
search_eu_cordis_projects as _search_eu_cordis_projects_es,
|
||||
)
|
||||
from inse.projects.logic import (
|
||||
get_dfg_author_names_by_ids, is_projects_access_forbidden
|
||||
)
|
||||
|
||||
from inse.projects.model import (
|
||||
BundProjectPage,
|
||||
DfgProjectPage,
|
||||
@@ -158,8 +156,7 @@ async def _get_dfg_project_ids_for_openalex_authors(
|
||||
|
||||
return list(set.intersection(*project_sets))
|
||||
|
||||
async def get_dfg_projects_by_author_id(
|
||||
access_token_metadata: AccessTokenMetadata,
|
||||
async def get_dfg_projects(
|
||||
institutions_search_client: InstitutionsSearchClient,
|
||||
raw_oa_institution_id: str | None,
|
||||
author_id: str | None,
|
||||
@@ -200,12 +197,6 @@ async def get_dfg_projects_by_author_id(
|
||||
)
|
||||
filter_names = []
|
||||
author_project_ids = []
|
||||
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, author_id)
|
||||
if is_forbidden:
|
||||
raise HttpException(
|
||||
status_code=403,
|
||||
detail="Access denied for the provided author ID or institution ID",
|
||||
)
|
||||
if author_id:
|
||||
author_project_ids = await _get_dfg_project_ids_for_openalex_authors([author_id])
|
||||
logger.info("Author project IDs for author_id:%s: %s", author_id, author_project_ids)
|
||||
@@ -421,7 +412,6 @@ async def get_institution_bund_projects_funding_over_time(
|
||||
|
||||
#Bund
|
||||
async def search_bund_projects_with_filters(
|
||||
access_token_metadata: AccessTokenMetadata,
|
||||
institutions_search_client: InstitutionsSearchClient,
|
||||
executing_agency: str | None,
|
||||
raw_oa_institution_id: str | None,
|
||||
@@ -439,12 +429,6 @@ async def search_bund_projects_with_filters(
|
||||
sort_direction: str = "asc",
|
||||
fuzzy: bool = False,
|
||||
) -> BundProjectPage:
|
||||
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, None)
|
||||
if is_forbidden:
|
||||
raise HttpException(
|
||||
status_code=403,
|
||||
detail="Access denied for the provided author ID or institution ID",
|
||||
)
|
||||
institution_aliases = []
|
||||
if raw_oa_institution_id:
|
||||
if institutions_search_client is None:
|
||||
@@ -626,7 +610,6 @@ async def _get_eu_project_ids_for_openalex_authors(
|
||||
|
||||
|
||||
async def search_eu_cordis_projects(
|
||||
access_token_metadata: AccessTokenMetadata,
|
||||
page: int,
|
||||
size: int,
|
||||
project_types: list[EuCordisProjectType] | None = None,
|
||||
@@ -665,12 +648,6 @@ async def search_eu_cordis_projects(
|
||||
funding scheme, status, funding years, country) are ANDed together as in
|
||||
eu_cordis_projects_client.search_eu_cordis_projects.
|
||||
"""
|
||||
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, author_id)
|
||||
if is_forbidden:
|
||||
raise HttpException(
|
||||
status_code=403,
|
||||
detail="Access denied for the provided author ID or institution ID",
|
||||
)
|
||||
resolved_organization_names: list[str] = list(organization_names or [])
|
||||
if raw_oa_institution_id:
|
||||
if institutions_search_client is None:
|
||||
|
||||
Reference in New Issue
Block a user