Skip to content

Commit

Permalink
Merge pull request #1963 from CSCfi/140-merge-fix
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
konolak authored Feb 5, 2025
2 parents cd45daa + c7d2acf commit 60f294e
Show file tree
Hide file tree
Showing 60 changed files with 2,510 additions and 459 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { HttpResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ProfileService } from '@mydata/services/profile.service';
import { UtilityService } from '@shared/services/utility.service';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import { take } from 'rxjs';
import { SecondaryButtonComponent } from '../../../../shared/components/buttons/secondary-button/secondary-button.component';
import { MatProgressSpinner } from '@angular/material/progress-spinner';
import { NgIf } from '@angular/common';
Expand Down Expand Up @@ -44,23 +42,23 @@ export class CancelDeploymentComponent implements OnInit {

cancelDeployment() {
this.loading = true;
this.oidcSecurityService.getAccessToken().subscribe(
token => {
if (token) {
this.profileService
.deleteAccount().then(
(value) => {
this.oidcSecurityService.logoff();
},
(reason) => {
console.error(reason);
},);
} else {
this.router.navigate(['/mydata']);
}
}
);

const token = this.oidcSecurityService.getAccessToken();

const logout = () => this.oidcSecurityService.logoff();

if (token) {
this.profileService
.deleteAccount().then(
(value) => {
this.oidcSecurityService.logoff()
},
(reason) => {
console.error(reason);
},);
} else {
this.router.navigate(['/mydata']);
}
}

continueDeployment() {
Expand Down
14 changes: 8 additions & 6 deletions src/app/mydata/services/orcid-account-linking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class OrcidAccoungLinkingService {
/*
* Get hash. For more explanation, see comments of function getOrcidLink()
*/
async getHash(nonce, sessionState, clientId) {
const input = nonce + sessionState + clientId + 'orcid';
async getHash(nonce, sid, clientId) {
const input = nonce + sid + clientId + 'orcid';
const encoder = new TextEncoder();
const data = encoder.encode(input);
const sha256 = await crypto.subtle.digest('SHA-256', data);
Expand Down Expand Up @@ -105,7 +105,7 @@ export class OrcidAccoungLinkingService {
* This is a random string that your application must generate
* hash:
* This is a Base64 URL encoded hash.
* This hash is generated by Base64 URL encoding a SHA_256 hash of nonce + session_state (from token) + azp (from token) + provider
* This hash is generated by Base64 URL encoding a SHA_256 hash of nonce + sid (from token) + azp (from token) + provider
* Basically you are hashing the random nonce, the user session id, the client id, and the identity provider alias you want to access.
*/
async getOrcidLink() {
Expand All @@ -126,14 +126,16 @@ export class OrcidAccoungLinkingService {
// azp: Authorized party - the party to which the ID Token was issued
const clientId = idTokenPayload.azp;

// Get property 'session_state' from ID token.
const sessionState = idTokenPayload.session_state;
// Get property 'sid' from ID token.
// 2024-12-31: use 'sid' instead of 'session_state'
// https://www.keycloak.org/docs/latest/release_notes/index.html#lightweight-access-token-to-be-even-more-lightweight
const sid = idTokenPayload.sid;

// Get nonce
const nonce = this.getNonce();

// Get hash
const hash = await this.getHash(nonce, sessionState, clientId);
const hash = await this.getHash(nonce, sid, clientId);

// Return ORCID account linking URL
return this.getUrl(keycloakUrl, clientId, redirectUrl, nonce, hash);
Expand Down
1 change: 0 additions & 1 deletion src/app/mydata/services/search-portal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class SearchPortalService {
sortSettings: { active: string; direction: string }
) {
let sortField: string;

switch (sortSettings.active) {
case 'year': {
sortField = this.getDefaultSortField(groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ li.breadcrumb-item.arrow_box.last.arrow_box {

// Responsive
@media (max-width: 991px) {
.breadcrumb {
padding: 0.75rem 0;
}

li.breadcrumb-item.arrow_box.active {
width: 210px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { FundingCallFilterService } from '@portal/services/filters/funding-call-
import { StaticDataService } from '@portal/services/static-data.service';
import { FilterConfigType } from 'src/types';
import { ActiveFiltersListComponent } from '../../../../shared/components/active-filters-list/active-filters-list.component';
import { ProjectFilterService } from '@portal/services/filters/project-filter.service';

@Component({
selector: 'app-active-filters',
Expand Down Expand Up @@ -112,6 +113,7 @@ export class ActiveFiltersComponent
private infrastructureFilters: InfrastructureFilterService,
private organizationFilters: OrganizationFilterService,
private fundingCallFilters: FundingCallFilterService,
private projectFilters: ProjectFilterService,
private newsFilters: NewsFilterService,
private settingsService: SettingsService,
@Inject(PLATFORM_ID) private platformId: object,
Expand Down Expand Up @@ -153,6 +155,9 @@ export class ActiveFiltersComponent
case 'news':
this.filtersConfig = this.newsFilters.filterData;
break;
case 'projects':
this.filtersConfig = this.projectFilters.filterData;
break;

default:
break;
Expand All @@ -167,17 +172,17 @@ export class ActiveFiltersComponent
this.translationFlag = false;
const errorMsg = 'error translating filter';

this.queryParams = this.filterService.filters.subscribe((filter) => {
this.queryParams = this.filterService.filters.subscribe((allFilters) => {
// Get from & to year values from filter list
this.fromYear = parseInt(filter.fromYear[0]?.slice(1), 10);
this.toYear = parseInt(filter.toYear[0]?.slice(1), 10);
const years = filter.year.map((item) => parseInt(item, 10));
this.fromYear = parseInt(allFilters.fromYear[0]?.slice(1), 10);
this.toYear = parseInt(allFilters.toYear[0]?.slice(1), 10);
const years = allFilters.year.map((item) => parseInt(item, 10));
let yearWarning = false;

if (this.fromYear && this.toYear) {
// Check if years missing between range and add warning flag
if (
filter.year.filter(
allFilters.year.filter(
(item) => this.fromYear <= item && item <= this.toYear
).length !==
this.toYear - this.fromYear + 1
Expand All @@ -186,14 +191,14 @@ export class ActiveFiltersComponent
}
} else if (this.fromYear) {
if (
filter.year.filter((item) => this.fromYear <= item).length !==
allFilters.year.filter((item) => this.fromYear <= item).length !==
Math.max(...years) - this.fromYear + 1
) {
yearWarning = true;
}
} else if (this.toYear) {
if (
filter.year.filter((item) => this.toYear >= item).length !==
allFilters.year.filter((item) => this.toYear >= item).length !==
this.toYear + 1 - Math.min(...years)
) {
yearWarning = true;
Expand All @@ -202,21 +207,20 @@ export class ActiveFiltersComponent

// Reset active filter so push doesn't duplicate
this.activeFilters = [];
const newFilters = {};
const filtersFromAllCategories = {};

// Merge and format arrays
Object.keys(filter).forEach((key) => {
newFilters[key] = filter[key].map((val) => {
Object.keys(allFilters).forEach((key) => {
filtersFromAllCategories[key] = allFilters[key].map((val) => {
return {
category: key,
value: val,
translation: this.translations[val] || val,
};
});
this.activeFilters.push(...newFilters[key]);
this.activeFilters.push(...filtersFromAllCategories[key]);
});
const tab = this.tabChangeService.tab;

// Subscribe to aggregation data and shape to get corresponding values
this.filterResponse = this.searchService
.getAllFilters(tab)
Expand Down Expand Up @@ -254,6 +258,10 @@ export class ActiveFiltersComponent
this.response = this.newsFilters.shapeData(response);
break;
}
case 'projects': {
this.response = this.projectFilters.shapeData(response);
break;
}
}

if (response) {
Expand Down Expand Up @@ -302,7 +310,7 @@ export class ActiveFiltersComponent
}

if (val.category === 'date') {
const dateString = filter.date ? filter.date[0] : '';
const dateString = allFilters.date ? allFilters.date[0] : '';
const startDate = dateString?.split('|')[0];
const endDate = dateString?.split('|')[1];
const startDateString = startDate
Expand Down Expand Up @@ -340,10 +348,14 @@ export class ActiveFiltersComponent
// Field of science
if (val.category === 'field' && source.field?.fields) {
const result = source.field.fields.buckets.find(
(key) =>
parseInt(key.fieldId.buckets[0].key, 10) ===
parseInt(val.value, 10)
(key) => {
const res = key.fieldId.buckets.find(item => {
return parseInt(item.key, 10) === parseInt(val.value, 10)
});
return res;
}
);

const foundIndex = this.activeFilters.findIndex(
(x) => x.value === val.value
);
Expand Down Expand Up @@ -498,7 +510,7 @@ export class ActiveFiltersComponent
if (val.category === 'organization' && source.organization) {
// Funding organization name
if (tab === 'fundings') {
setTimeout((t) => {
setTimeout(() => {
if (source.organization.funded.sectorName.buckets) {
source.organization.funded.sectorName.buckets.forEach(
(sector) => {
Expand All @@ -517,7 +529,7 @@ export class ActiveFiltersComponent
}, 1);
// Dataset & persons organization name
} else if (tab === 'datasets' || tab === 'persons') {
setTimeout((t) => {
setTimeout(() => {
if (source.organization.sectorName.buckets) {
source.organization.sectorName.buckets.forEach(
(sector) => {
Expand All @@ -536,7 +548,7 @@ export class ActiveFiltersComponent
}, 1);
// Infrastructure organization name
} else if (tab === 'infrastructures') {
setTimeout((t) => {
setTimeout(() => {
if (source.organization.sector.buckets) {
source.organization.sector.buckets.forEach((sector) => {
if (sector.subData.find((x) => x.key === val.value)) {
Expand Down Expand Up @@ -581,9 +593,23 @@ export class ActiveFiltersComponent
}
});
}
} else {
} else if (tab === 'projects') {
if (source.organizations?.organization?.buckets){
source.organizations.organization.buckets.forEach(
(bucket) => {
if (bucket.key === val.value) {
const foundIndex = this.activeFilters.findIndex(
(x) => x.value === val.value
);
this.activeFilters[foundIndex].translation = bucket.translation;
}
}
);
}
}
else {
// Common usage e.g. in publications, persons, datasets
setTimeout((t) => {
setTimeout(() => {
if (source.organization.sectorName.buckets) {
source.organization.sectorName.buckets.forEach(
(sector) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ <h3 class="header" *ngIf="!mobile && !showButton">
</mat-expansion-panel>
<!-- Items with single checkbox -->
<div class="single-checkbox" *ngFor="let item of currentSingleFilter">
{{item.field}}
<div class="row single">
<div class="col">
<div
Expand Down
Loading

0 comments on commit 60f294e

Please sign in to comment.