feature/keywords-analysis #271

Merged
genja merged 5 commits from feature/keywords-analysis into dev 2026-08-11 08:57:52 +02:00
15 changed files with 63 additions and 93 deletions
@@ -261,11 +261,10 @@ async def search(
payload["sort"] = sort
if aggs is not None:
payload["aggs"] = aggs
if track_total_hits:
payload["track_total_hits"] = True
if highlight is not None:
payload["highlight"] = highlight
payload["track_total_hits"] = True # always track total hits for accurate pagination and counts
if len(payload) == 0:
raise ValueError(
"At least one of 'query', 'body', 'source', 'size', 'offset', 'sort', 'aggs' must be provided"
-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",
@@ -15,10 +15,6 @@ import { ResolverStateService } from '../../app/shared/services/resolver-state.s
standalone: true,
})
export class SkTextDirective implements OnChanges {
/**
* Optional manual loading state.
* The directive also reacts to global route/resolver loading.
*/
@Input() skText = false;
private readonly el = inject(ElementRef<HTMLElement>);
@@ -37,8 +37,11 @@
<mat-icon>circle</mat-icon>
<span>{{ getStatusDisplay(dfgProject.funding_end) }}</span>
</div>
@if (dfgProject.link) {
<a [href]="dfgProject.link" target="_blank" class="primary-action">
@if (dfgProject.page_url) {
<a
[href]="dfgProject.page_url"
target="_blank"
class="primary-action">
<mat-icon>open_in_new</mat-icon>
<span>Zum Projekt</span>
</a>
@@ -218,10 +221,7 @@
</div>
@if (getInstitutionsList().length > 0) {
<div class="institution-grid">
@for (
institution of getInstitutionsList();
track institution.institute_id + (institution.role_key || '')
) {
@for (institution of getInstitutionsList(); track $index) {
<div
(click)="
searchForInstitutionName(getInstitutionName(institution))
@@ -12,7 +12,7 @@ import { AppAuthorTooltipComponent } from '../app-author-tooltip/app-author-tool
import { MatIconModule } from '@angular/material/icon';
import { ComponentTooltipDirective } from '../../../directives/component-tooltip.directive';
import { MatChipsModule } from '@angular/material/chips';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
@Component({
host: {
'[style.--border-width]': 'isSelected() ? "2px" : "1px"',
@@ -22,7 +22,12 @@ import { MatChipsModule } from '@angular/material/chips';
'[class.is-mini-size]': 'isMiniSize()',
},
selector: 'app-author-chip',
imports: [MatIconModule, MatChipsModule, ComponentTooltipDirective],
imports: [
MatIconModule,
MatChipsModule,
ComponentTooltipDirective,
SkTextDirective,
],
templateUrl: './app-author-chip.component.html',
styleUrl: './app-author-chip.component.scss',
})
@@ -13,7 +13,7 @@ import { ComponentTooltipDirective } from '../../../directives/component-tooltip
import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors';
import { MatIconModule } from '@angular/material/icon';
import { AppTopicTooltipComponent } from '../app-topic-tooltip/app-topic-tooltip.component';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
@Component({
host: {
'[style.--topic-color]': 'color()',
@@ -23,7 +23,12 @@ import { AppTopicTooltipComponent } from '../app-topic-tooltip/app-topic-tooltip
'[class.is-mini-size]': 'isMiniSize()',
},
selector: 'app-topic-chip-2',
imports: [MatChipsModule, ComponentTooltipDirective, MatIconModule],
imports: [
MatChipsModule,
ComponentTooltipDirective,
MatIconModule,
SkTextDirective,
],
templateUrl: './app-topic-chip.component.html',
styleUrl: './app-topic-chip.component.scss',
})
@@ -11,15 +11,23 @@
[pageSizeOptions]="[10, 25, 50]" />
<ng-template #fundingStartTmp let-element>
{{ getStartDate(element) | date: 'dd.MM.yyyy' }}
<span>
{{ getStartDate(element) | date: 'dd.MM.yyyy' }}
</span>
</ng-template>
<ng-template #fundingEndTmp let-element>
{{ getEndDate(element) | date: 'dd.MM.yyyy' }}
<span>
{{ getEndDate(element) | date: 'dd.MM.yyyy' }}
</span>
</ng-template>
<ng-template #fundingAmountTmp let-element>
{{ getFundingAmount(element) | currency: 'EUR' : 'symbol' : '1.0-0' : 'de' }}
<span>
{{
getFundingAmount(element) | currency: 'EUR' : 'symbol' : '1.0-0' : 'de'
}}
</span>
</ng-template>
<ng-template #actionsTmp let-element>
@@ -31,20 +39,6 @@
<mat-icon>open_in_new</mat-icon>
</a>
</ng-template>
<ng-template #detailRowTmp let-element>
<div class="classification-container">
@for (classification of element.subject_classifications; track $index) {
<p>
{{ classification.wissenschaftsbereich || '-' }}
→ {{ classification.fachkollegium || '-' }} →
{{ classification.fachgebiet || '-' }} →
{{ classification.fach || '-' }}
</p>
} @empty {
<span>-</span>
}
</div>
</ng-template>
<ng-template #institutionsTmp let-project>
@let institutions = getProjectInstitutions(project);
@@ -79,7 +73,7 @@
matTooltipPosition="above"
(click)="toggleFundingTypeFilter(project.funding_type)">
<app-chip [color]="getFundingTypeColor(project.funding_type)">
{{ project.funding_type }}
<span>{{ project.funding_type }}</span>
</app-chip>
</button>
} @else {
@@ -25,6 +25,7 @@ import { ChipComponent } from '../chip/chip.component';
import { MatTooltip } from '@angular/material/tooltip';
import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors';
import { bundProjectQueryParamKeys } from '../../../resolvers/bund-projects.resolver';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
import { ChipOverflowToggleComponent } from '../chip-overflow-toggle/chip-overflow-toggle.component';
@Component({
selector: 'app-bund-project-table',
@@ -40,6 +41,7 @@ import { ChipOverflowToggleComponent } from '../chip-overflow-toggle/chip-overfl
DatePipe,
ChipComponent,
AppTopicChipComponent,
SkTextDirective,
],
templateUrl: './bund-project-table.component.html',
styleUrl: './bund-project-table.component.scss',
@@ -30,7 +30,7 @@
context: { $implicit: row }
"></ng-container>
} @else if (col.type === 'accessor') {
{{ row[col.accessorKey] }}
<span>{{ row[col.accessorKey] }}</span>
}
</td>
</ng-container>
@@ -20,7 +20,7 @@ import {
} from '@angular/material/sort';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { ActivatedRoute, Router } from '@angular/router';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
export interface BaseColumn<T> {
id: string;
header: string;
@@ -43,7 +43,7 @@ export type GenericColumn<T> = AccessorColumn<T> | DisplayColumn<T>;
@Component({
selector: 'app-data-table',
standalone: true,
imports: [MatTableModule, NgTemplateOutlet, MatSortModule],
imports: [MatTableModule, NgTemplateOutlet, MatSortModule, SkTextDirective],
templateUrl: './data-table.component.html',
styleUrl: './data-table.component.scss',
})
@@ -11,11 +11,13 @@
[pageSizeOptions]="[10, 25, 50]" />
<ng-template #fundingEndTmp let-element>
{{
element.funding_end == '2999' || element.funding_end == null
? 'laufend'
: element.funding_end
}}
<span>
{{
element.funding_end == '2999' || element.funding_end == null
? 'laufend'
: element.funding_end
}}</span
>
</ng-template>
<ng-template #actionsTmp let-element>
@@ -23,6 +23,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { DfgPersonSummary } from '../../../api/model/dfgPersonSummary';
import { MatTooltip } from '@angular/material/tooltip';
import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
import { ChipOverflowToggleComponent } from '../chip-overflow-toggle/chip-overflow-toggle.component';
@Component({
selector: 'app-dfg-project-table',
@@ -35,6 +36,7 @@ import { ChipOverflowToggleComponent } from '../chip-overflow-toggle/chip-overfl
QueryParamPaginatorComponent,
MatTooltip,
AppTopicChipComponent,
SkTextDirective,
],
templateUrl: './dfg-project-table.component.html',
styleUrl: './dfg-project-table.component.scss',
@@ -20,7 +20,7 @@
matTooltipPosition="above"
(click)="toggleTypeFilter(project.project_type)">
<app-chip [color]="getProjectTypeColor(project.project_type)">
{{ getProjectTypeLabel(project) }}
<span>{{ getProjectTypeLabel(project) }}</span>
</app-chip>
</button>
} @else {
@@ -29,15 +29,17 @@
</ng-template>
<ng-template #fundingStartTmp let-element>
{{ getStartDate(element) | date: 'dd.MM.yyyy' }}
<span>{{ getStartDate(element) | date: 'dd.MM.yyyy' }}</span>
</ng-template>
<ng-template #fundingEndTmp let-element>
{{ getEndDate(element) | date: 'dd.MM.yyyy' }}
<span>{{ getEndDate(element) | date: 'dd.MM.yyyy' }}</span>
</ng-template>
<ng-template #fundingAmountTmp let-element>
{{ getFundingAmount(element) | currency: 'EUR' : 'symbol' : '1.0-0' : 'de' }}
<span>{{
getFundingAmount(element) | currency: 'EUR' : 'symbol' : '1.0-0' : 'de'
}}</span>
</ng-template>
<ng-template #authorsTmp let-project>
@@ -14,7 +14,7 @@ import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import { MatTooltip } from '@angular/material/tooltip';
import { CurrencyPipe, DatePipe } from '@angular/common';
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
import {
DataTableComponent,
GenericColumn,
@@ -48,6 +48,7 @@ import { ChipOverflowToggleComponent } from '../chip-overflow-toggle/chip-overfl
AppTopicChipComponent,
ChipComponent,
AppAuthorChipComponent,
SkTextDirective,
],
templateUrl: './eu-project-table.component.html',
styleUrl: './eu-project-table.component.scss',