Skip to content

Commit 02df2aa

Browse files
authored
Merge pull request #90 from EBISPOT/06/07/22_release
06/07/22 release
2 parents dc84c33 + 12bc399 commit 02df2aa

27 files changed

+698
-127
lines changed

src/app/core/guards/auth.guard.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { Injectable } from '@angular/core';
22
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
33
import { AuthService } from '../services/auth.service';
4+
import { TokenStorageService } from '../services/token-storage.service';
45

56
@Injectable({
67
providedIn: 'root'
78
})
89
export class AuthGuard implements CanActivate {
910

10-
constructor(private authService: AuthService, private router: Router) {
11+
constructor(private authService: AuthService, private tss: TokenStorageService) {
1112
}
1213

1314
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
1415
if (this.authService.loggedIn() && this.authService.isCurator()) {
1516
return true;
1617
} else {
17-
this.router.navigateByUrl('/login').then();
18+
this.tss.signOut(state.url);
1819
return false;
1920
}
2021
}

src/app/core/interceptors/auth.interceptor.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { Injectable } from '@angular/core';
33
import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
44

55
import { TokenStorageService } from '../services/token-storage.service';
6+
import { of } from 'rxjs';
7+
import { catchError } from 'rxjs/operators';
8+
import { Router } from '@angular/router';
9+
import { MatDialog } from '@angular/material/dialog';
610

711
const TOKEN_HEADER_KEY = 'Authorization';
812

@@ -17,7 +21,17 @@ export class AuthInterceptor implements HttpInterceptor {
1721
if (token != null) {
1822
authReq = req.clone({headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer ' + token)});
1923
}
20-
return next.handle(authReq);
24+
return next.handle(authReq).pipe(
25+
catchError(
26+
(err, caught) => {
27+
if (err.status === 401) {
28+
this.tokenStorageService.signOut();
29+
return of(err);
30+
}
31+
throw err;
32+
}
33+
)
34+
);
2135
}
2236
}
2337

src/app/core/models/sample.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface Sample {
2+
GCST: string;
3+
initialSampleDescription: string;
4+
replicateSampleDescription: string;
5+
studyTag: string;
6+
}

src/app/core/models/study.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ export interface Study {
3030
agreedToCc0: boolean;
3131
diseaseTrait: ReportedTrait;
3232
efoTraits: EfoTrait[];
33-
}
33+
backgroundEfoTraits: EfoTrait[];
34+
sumstats_flag: boolean;
35+
pooled_flag: boolean;
36+
gxe_flag: boolean;
37+
}

src/app/core/models/submission.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ export interface Submission {
2424
editTemplate: Provenance;
2525
lockDetails: {lockedBy: Provenance, status: string};
2626
agreedToCc0: boolean;
27+
opentargets_flag: boolean;
28+
userrequested_flag: boolean;
2729
}

src/app/core/services/auth.service.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ export class AuthService {
1919
}
2020

2121
isCurator() {
22-
return this.getDecodedToken().domains.indexOf('self.GWAS_Curator') > -1;
22+
return this.getDecodedToken()?.domains?.indexOf('self.GWAS_Curator') > -1;
2323
}
2424

2525
getDecodedToken() {
2626
const jwtToken = this.tokenStorageService.getToken();
27-
let decoded = jwt_decode(jwtToken);
27+
const decoded = jwt_decode(jwtToken);
2828
if (Date.now() > decoded.exp * 1000) {
29-
decoded = 'SESSION TIMEOUT';
30-
alert(decoded);
3129
this.tokenStorageService.signOut();
32-
this.router.navigateByUrl('/login').then();
3330
}
3431
return decoded;
3532
}
@@ -82,6 +79,6 @@ export class AuthService {
8279
}
8380

8481
logout() {
85-
this.tokenStorageService.signOut();
82+
window.localStorage.removeItem('id_token');
8683
}
8784
}

src/app/core/services/curation-http.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export class CurationHttpService {
4242
).pipe(catchError(CurationHttpService.formatErrors));
4343
}
4444

45+
patch(path: string, body: any = {}, params: HttpParams = new HttpParams()): Observable<any> {
46+
return this.http.patch(
47+
`${environment.CURATION_API_URL}${path}`,
48+
body,
49+
{params}
50+
).pipe(catchError(CurationHttpService.formatErrors));
51+
}
52+
4553
download(path: string, params: HttpParams = new HttpParams()): Observable<any> {
4654
return this.http.get(`${environment.CURATION_API_URL}${path}`, {params, responseType: 'blob'})
4755
.pipe(catchError(CurationHttpService.formatErrors));

src/app/core/services/submission.service.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SubmissionHistory } from '../models/submissionHistory';
88
import { CurationHttpService } from './curation-http.service';
99
import { ReportedTrait } from '../models/reportedTrait';
1010
import { Study } from '../models/study';
11+
import { EfoTrait } from '../models/efoTrait';
1112

1213
@Injectable({
1314
providedIn: 'root'
@@ -115,6 +116,11 @@ export class SubmissionService {
115116
return this.curationHttp.get('/submissions/' + submissionId + '/studies/' + studyId);
116117
}
117118

119+
downloadBulkStudyMultiTraitUploadTemplate() {
120+
121+
return this.curationHttp.download('/reported-traits/templates?file=study-multi-trait');
122+
}
123+
118124
downloadBulkStudyTraitUploadTemplate() {
119125

120126
return this.curationHttp.download('/reported-traits/templates?file=study-trait');
@@ -125,14 +131,46 @@ export class SubmissionService {
125131
return this.curationHttp.download('/reported-traits/templates?file=study-efo-trait');
126132
}
127133

134+
downloadSamplesPrefilledTemplate(submissionId: string) {
135+
136+
return this.curationHttp.download('/submissions/' + submissionId + '/studies/sampledescription/files');
137+
}
138+
128139
editReportedTraits(trait: ReportedTrait, submissionId, study: Study) {
129140

130141
return this.curationHttp.put('/submissions/' + submissionId + '/studies/' + study.studyId,
131142
{diseaseTrait: trait, study_tag: study.study_tag});
132143
}
133144

145+
editEfoTraits(efoTraits: EfoTrait[], submissionId, study: Study) {
146+
147+
return this.curationHttp.put('/submissions/' + submissionId + '/studies/' + study.studyId,
148+
{efoTraits, study_tag: study.study_tag});
149+
}
150+
151+
editBgEfoTraits(backgroundEfoTraits: EfoTrait[], submissionId, study: Study) {
152+
153+
return this.curationHttp.put('/submissions/' + submissionId + '/studies/' + study.studyId,
154+
{backgroundEfoTraits, study_tag: study.study_tag});
155+
}
156+
134157
filterSubmissions(filtersString: string, size: number, page: number, sort: string, order: string) {
135158
const params = filtersString + '&size=' + String(size) + '&sort=' + sort + ',' + order;
136159
return this.curationHttp.get('/submissions?' + params);
137160
}
161+
162+
patchSubmission(submission: Submission) {
163+
164+
return this.curationHttp.patch('/submissions/' + submission.submissionId, submission);
165+
}
166+
167+
getSubmissionSamples(size: number, page: number, sort: string, order: string, submissionId: string) {
168+
169+
let params: HttpParams = new HttpParams();
170+
params = params
171+
.set('size', String(size))
172+
.set('page', String(page))
173+
.set('sort', sort + ',' + order);
174+
return this.curationHttp.get('/submissions/' + submissionId + '/studies/sampledescription', params);
175+
}
138176
}

src/app/core/services/token-storage.service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Injectable } from '@angular/core';
2+
import { Router, RouterStateSnapshot } from '@angular/router';
3+
import { MatDialog } from '@angular/material/dialog';
24

35
const TOKEN_KEY = 'id_token';
46

@@ -7,11 +9,14 @@ const TOKEN_KEY = 'id_token';
79
})
810
export class TokenStorageService {
911

10-
constructor() {
12+
constructor(private router: Router, private dialog: MatDialog) {
1113
}
1214

13-
signOut() {
14-
window.localStorage.clear();
15+
signOut(guardReturnUri?: string) {
16+
setTimeout('alert("SESSION EXPIRED")', 1);
17+
this.dialog.closeAll();
18+
this.router.navigate(['/login'], {queryParams: {returnUrl: guardReturnUri ? guardReturnUri : 'home'}}).then();
19+
window.localStorage.removeItem(TOKEN_KEY);
1520
}
1621

1722
public saveToken(token: string) {

src/app/feature/authentication/pages/login/login.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, HostListener, OnInit } from '@angular/core';
22
import { AuthService } from '../../../../core/services/auth.service';
3-
import { Router } from '@angular/router';
3+
import { ActivatedRoute, Router } from '@angular/router';
44
import { environment } from '../../../../../environments/environment';
55

66
@Component({
@@ -11,11 +11,13 @@ import { environment } from '../../../../../environments/environment';
1111
export class LoginComponent implements OnInit {
1212
window: any;
1313
bgImage: string;
14-
constructor(private authService: AuthService, private router: Router) {}
14+
private returnUrl: string;
15+
constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute) {}
1516

1617
ngOnInit(): void {
1718
if (this.authService.loggedIn()) { this.router.navigateByUrl('/').then(); }
1819
this.randomBgImage();
20+
this.returnUrl = this.route.snapshot.queryParams.returnUrl || '/';
1921
}
2022

2123
login() {
@@ -27,7 +29,7 @@ export class LoginComponent implements OnInit {
2729
if (event.origin === environment.AAPURL) {
2830
this.authService.saveToken(event.data);
2931
this.window.close();
30-
this.router.navigateByUrl('/').then();
32+
this.router.navigateByUrl(this.returnUrl).then();
3133
}
3234
}
3335

0 commit comments

Comments
 (0)