Skip to content

Commit

Permalink
Merge pull request #1638 from CSCfi/CSCTTV-3110v2
Browse files Browse the repository at this point in the history
Cscttv 3110v2
  • Loading branch information
konolak authored Feb 8, 2023
2 parents 3b98c95 + d76c3d0 commit 41d8fb5
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 17,684 deletions.
17,544 changes: 71 additions & 17,473 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@gorniv/ngx-transfer-http": "^2.2.9",
"@nguniversal/common": "^13.1.1",
"@nguniversal/express-engine": "^13.1.1",
"angular-auth-oidc-client": "^13.1.0",
"angular-auth-oidc-client": "^14.1.5",
"array-flat-polyfill": "^1.0.1",
"body-parser": "^1.19.2",
"bootstrap": "^5.1.3",
Expand Down Expand Up @@ -123,4 +123,4 @@
"optionalDependencies": {
"esbuild-android-arm64": "^0.15.13"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,57 +187,45 @@ export class AccountSettingsComponent implements OnInit {
this.connProblemHideProfile = false;
this.profileService
.hideProfile()
.pipe(take(1))
.subscribe({
next: (res: any) => {
.then(
(value) => {
this.hideProfileInProgress = false;
if (res.ok && res.body.success) {
this.dialog.closeAll();
sessionStorage.setItem('profileHidden', 'true');
this.isProfileHidden = true;
this.snackbarService.show(
$localize`:@@profileHiddenToast:Profiilin piilottaminen onnistui. Profiilisi piilotetaan Tiedejatutkimus.fi -palvelusta muutaman minuutin kuluttua.`,
'success'
);

$localize`:@@profileHiddenToast:Profiilin piilottaminen onnistui. Profiilisi piilotetaan Tiedejatutkimus.fi -palvelusta muutaman minuutin kuluttua.`,
'success'
);
//this.reset();
}
},
error: (error) => {
(reason) => {
this.hideProfileInProgress = false;
if (!error.ok) {
this.connProblemHideProfile = true;
}
},
});
this.connProblemHideProfile = true;
},);
}

deleteProfile() {
this.deleteProfileInProgress = true;
this.connProblemDeleteProfile = false;
this.profileService
.deleteProfile()
.pipe(take(1))
.subscribe({
next: (res: any) => {
.then(
(value) => {
this.deleteProfileInProgress = false;
if (res.ok && res.body.success) {
this.dialog.closeAll();
this.reset();
this.dialog.closeAll();
this.reset();

// Wait for dialog to close
setTimeout(() => {
this.oidcSecurityService.logoff();
// Wait for dialog to close
setTimeout(() => {
this.oidcSecurityService.logoff();
}, 500);
}

},
error: (error) => {
(reason) => {
this.deleteProfileInProgress = false;
if (!error.ok) {
this.connProblemDeleteProfile = true;
}
},
});
this.connProblemDeleteProfile = true;
},);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,24 @@ export class DataSourcesSelectionActionsComponent implements OnInit, OnDestroy {
this.closeDialog();
}

patchItems(action: Action) {
async patchItems(action: Action) {
const patchItemsArr = this.patchService.confirmedPayLoad;

const filteredItems = patchItemsArr.filter((item) =>
action === 'publish' ? item.show : !item.show
);

this.patchItemsSub = this.profileService
.patchObjects(filteredItems)
.pipe(take(1))
.subscribe((res: HttpResponse<any>) => {
if (res.body.success) {
this.profileService
.patchObjects(filteredItems).then(
(value) => {
this.onPatchSuccess.emit(filteredItems);
// Enable hide profile button in account settings section, if it has been disabled
sessionStorage.removeItem('profileHidden');
this.snackbarService.showPatchMessage('success');
} else {
},
(reason) => {
this.snackbarService.showPatchMessage('error');
}
});
},);
}

// Used as callback function in filter pipe
Expand Down
31 changes: 4 additions & 27 deletions src/app/mydata/components/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,39 +274,16 @@ export class ProfileComponent implements OnInit, OnDestroy {
* Patch items to backend
*/
private async patchItemsPromise() {
return new Promise((resolve, reject) => {
const patchItems = this.patchService.confirmedPayLoad;
this.profileService
.patchObjects(patchItems)
.pipe(takeUntil(this.unsubscribe))
.subscribe({
next: (result) => {
resolve(true);
},
error: (error) => {
reject(error);
},
});
});
const patchItems = this.patchService.confirmedPayLoad;
return this.profileService
.patchObjects(patchItems);
}

/*
* Patch datasets to backend
*/
private async handleDatasetsPromise() {
return new Promise((resolve, reject) => {
this.datasetsService
.addDatasets()
.pipe(takeUntil(this.unsubscribe))
.subscribe({
next: (result) => {
resolve(true);
},
error: (error) => {
reject(error);
},
});
});
return this.datasetsService.addDatasets();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export class CancelDeploymentComponent implements OnInit {

if (token) {
this.profileService
.deleteAccount()
.pipe(take(1))
.subscribe((res: HttpResponse<any>) => {
if (res.ok) {
logout();
}
});
.deleteAccount().then(
(value) => {
this.oidcSecurityService.logoff()
},
(reason) => {
console.error(reason);
},);
} else {
this.router.navigate(['/mydata']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ export class OrcidDataFetchComponent implements OnInit, OnDestroy {
orcidDataFetchInfo3 = $localize`:@@orcidDataFetchInfo3:Tässä vaiheessa emme vielä julkaise profiiliasi.`;
orcidDataFetchInfo4 = $localize`:@@orcidDataFetchInfo4:Voit hallinnoida tietojesi julkisuutta seuraavaksi aukeavassa profiilieditorissa.`;

fetchOrcidData() {

// Create profile when proceeding from step 4. Get ORCID data after profile creation
async createProfile() {
this.profileService
.createProfile().then(
(value) => {
this.loading = true;
this.getOrcidData();
},
(reason) => {
console.error(reason);
},);
}

async fetchOrcidData() {
if (!this.orcid) {
this.profileService.handleOrcidNotLinked();
} else {
this.accountLinkSub = this.profileService
.accountlink()
.subscribe((response: { body: { success: string } }) => {
if (response.body.success) {
this.loading = true;
this.createProfile();
} else {
console.error('Unable to link ORCID');
}
});
this.profileService
.accountlink().then(
(value) => {
this.loading = true;
this.createProfile();
},
(reason) => {
console.error(reason);
console.error('Unable to link ORCID');
},);
}
}

// Create profile when proceeding from step 4. Get ORCID data after profile creation
createProfile() {
this.createProfileSub = this.profileService
.createProfile()
.pipe(take(1))
.subscribe((data: any) => {
if (data.ok) {
this.getOrcidData();
} else {
// TODO: Alert problem
}
});
}

async getOrcidData() {
const response: any = await this.profileService.getOrcidData().toPromise();
const response: any = await this.profileService.getOrcidData();
if (response.ok) {
this.dialog.closeAll();
this.loading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@ export class ServiceDeploymentComponent implements OnInit, OnDestroy {

// Initialize Identity Provider configuration and enable ORCID data fetch in step 4
if (this.step === 4) {
this.IDPLinkSub = this.profileService
.accountlink()
.pipe(switchMap(() => this.oidcSecurityService.forceRefreshSession()))
.subscribe(() => {
const idTokenPayload =
this.oidcSecurityService.getPayloadFromIdToken();
this.orcid = idTokenPayload.orcid;
this.profileService.setUserData(idTokenPayload);
});
this.profileService
.accountlink().then(
(value) => {
this.IDPLinkSub = this.oidcSecurityService.forceRefreshSession()
.subscribe(() => {
this.oidcSecurityService.getPayloadFromIdToken().subscribe(data => {
this.orcid = data.orcid;
this.profileService.setUserData(data);
});
});
},
(reason) => {
console.error(reason);
},);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/mydata/models/profile.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ProfileAdapter implements Adapter<Profile> {
) {}

adapt(item: any): Profile {
const data = item.body.data;
const data = item.data;

const mapModel = (adapter, data) => Object.values(adapter.adapt(data));

Expand Down
34 changes: 21 additions & 13 deletions src/app/mydata/resolvers/mydata-profile-resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export class MyDataProfileResolverService implements Resolve<any>, OnDestroy {

constructor(private profileService: ProfileService) {}

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {

await this.profileService
.getProfileData().then((value) => {
});

/*
* Get MyData profile data before rendering route.
* Data is stored in profile service.
Expand All @@ -35,18 +40,21 @@ export class MyDataProfileResolverService implements Resolve<any>, OnDestroy {
return new Promise((resolve) => {
this.profileService
.getProfileData()
.pipe(takeUntil(this.unsubscribeOnDestroy))
.subscribe((response) => {
// Store original data in service
this.profileService.setCurrentProfileData(
cloneDeep(response.profileData)
);

resolve({
name: getName(response.profileData),
profileData: response.profileData,
});
});
.then(
(value) => {
if (value) {
this.profileService.setCurrentProfileData(
cloneDeep(value.profileData)
);
resolve({
name: getName(value.profileData),
profileData: value.profileData,
});
}
},
(reason) => {
console.error('error', reason);
},);
});
} else {
return {
Expand Down
9 changes: 3 additions & 6 deletions src/app/mydata/resolvers/orcid-profile-resolver.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { ProfileService } from '@mydata/services/profile.service';
import { AppSettingsService } from '@shared/services/app-settings.service';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import { Subject, takeUntil } from 'rxjs';
import {firstValueFrom, Subject, takeUntil} from 'rxjs';

@Injectable({
providedIn: 'root',
Expand All @@ -41,20 +41,17 @@ export class OrcidProfileResolverService implements Resolve<any>, OnDestroy {
return new Promise((resolve) => {
this.oidcSecurityService.userData$
.pipe(takeUntil(this.unsubscribeOnDestroy))
.subscribe((data) => {
.subscribe(async (data) => {
if (data.userData) {
const idTokenPayload =
this.oidcSecurityService.getPayloadFromIdToken();

await firstValueFrom(this.oidcSecurityService.getPayloadFromIdToken());
// Create object that holds necessary ORCID profile items
const userData = {
...data.userData,
orcid: idTokenPayload.orcid,
};

this.profileService.setOrcidUserProfile(userData);
this.appSettingsService.setOrcid(userData.orcid);

resolve(userData);
} else {
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/app/mydata/services/orcid-account-linking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import {firstValueFrom} from "rxjs";

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -109,10 +110,10 @@ export class OrcidAccoungLinkingService {
*/
async getOrcidLink() {
// Auth configuration
const authConfig = this.oidcSecurityService.getConfiguration();
const authConfig = await firstValueFrom(this.oidcSecurityService.getConfiguration());

// Get ID token
const idTokenPayload = this.oidcSecurityService.getPayloadFromIdToken();
const idTokenPayload = await firstValueFrom(this.oidcSecurityService.getPayloadFromIdToken());

// Keycloak base URL
const keycloakUrl = authConfig.authority;
Expand Down
Loading

0 comments on commit 41d8fb5

Please sign in to comment.