replaced the is_forbidden function with check function from auth
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
2026-08-11 08:53:25 +02:00
parent c0e231a32b
commit e4b3d0a9a9
2 changed files with 7 additions and 45 deletions
-36
View File
@@ -9,42 +9,6 @@ from inse.projects.model import EuCordisProjectType
logger = logging.getLogger(__name__)
async def is_projects_access_forbidden(
access_token_metadata: AccessTokenMetadata,
raw_oa_institution_id: str | None,
raw_oa_author_id: str | None,
) -> bool:
"""
Determines if access to projects is forbidden based on the provided access token metadata
and the raw OpenAlex institution and author IDs.
Args:
access_token_metadata (AccessTokenMetadata): Metadata from the access token.
raw_oa_institution_id (str | None): The raw OpenAlex institution ID.
raw_oa_author_id (str | None): The raw OpenAlex author ID.
Returns:
bool: True if access is forbidden, False otherwise.
"""
effective_institution_id = access_token_metadata.effective_institution_id
if raw_oa_institution_id and effective_institution_id != raw_oa_institution_id:
return True
if raw_oa_author_id:
authors_profile = await author_service.get_author_by_id(raw_oa_author_id)
if not authors_profile:
return True # Author not found, access forbidden
authors_last_known_institution_ids = [inst.id.split("/")[-1] for inst in (authors_profile.last_known_institutions)]
authors_affiliation_institution_ids = [aff.institution.id.split("/")[-1] for aff in (authors_profile.affiliations)]
print(f"Author's last known institution IDs: {authors_last_known_institution_ids}, {authors_affiliation_institution_ids}")
if effective_institution_id not in authors_last_known_institution_ids and effective_institution_id not in authors_affiliation_institution_ids:
return True # Effective institution ID does not match any of the author's last known institutions
return False
async def get_dfg_author_names_by_ids(author_ids: list[int]) -> list[str] | None:
try:
body = {
+7 -9
View File
@@ -7,9 +7,6 @@ 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
@@ -33,6 +30,7 @@ from inse.projects.model import (
SortDirection,
)
from inse.tags import Tags
from inse.auth.service import can_fetch_gdpr_relevant_data
from fastapi import HTTPException as HttpException
logger = logging.getLogger(__name__)
@@ -146,8 +144,8 @@ async def get_dfg_projects(
sort_direction,
fuzzy,
)
is_forbidden = await is_projects_access_forbidden(access_token_metadata, raw_oa_institution_id, author_id)
if is_forbidden:
is_allowed = await can_fetch_gdpr_relevant_data(access_token = access_token_metadata, raw_oa_author_id = author_id, raw_oa_institution_id = raw_oa_institution_id)
if not is_allowed:
raise HttpException(
status_code=403,
detail="Access denied for the provided author ID or institution ID",
@@ -266,8 +264,8 @@ 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:
is_allowed = await can_fetch_gdpr_relevant_data(access_token = access_token_metadata, raw_oa_author_id = None, raw_oa_institution_id = raw_oa_institution_id)
if not is_allowed:
raise HttpException(
status_code=403,
detail="Access denied for the provided author ID or institution ID",
@@ -450,8 +448,8 @@ 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:
is_allowed = await can_fetch_gdpr_relevant_data(access_token = access_token_metadata, raw_oa_author_id = author_id, raw_oa_institution_id = raw_oa_institution_id)
if not is_allowed:
raise HttpException(
status_code=403,
detail="Access denied for the provided author ID or institution ID",