Revision 51261
Added by Argiro Kokogiannaki over 6 years ago
modules/uoa-services-library/trunk/ng-openaire-library/src/app/login/connectAdminLoginGuard.guard.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; |
|
3 |
import {Observable} from 'rxjs/Observable'; |
|
4 |
import {Session} from './utils/helper.class'; |
|
5 |
import {ErrorCodes} from './utils/guardHelper.class'; |
|
6 |
|
|
7 |
@Injectable() |
|
8 |
export class ConnectAdminLoginGuard implements CanActivate { |
|
9 |
|
|
10 |
constructor(private router: Router) {} |
|
11 |
|
|
12 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
|
13 |
console.log("aaa"); |
|
14 |
console.log(state.url); |
|
15 |
var user; |
|
16 |
var loggedIn = false; |
|
17 |
var isAdmin = false; |
|
18 |
var errorCode = ErrorCodes.NOT_LOGGIN; |
|
19 |
if(Session.isLoggedIn()){ |
|
20 |
loggedIn = true; |
|
21 |
if(!Session.isValidAndRemove()){ |
|
22 |
loggedIn = false; |
|
23 |
errorCode = ErrorCodes.NOT_VALID; |
|
24 |
}else { |
|
25 |
isAdmin = Session.isConnectAdminUser(); |
|
26 |
if(!isAdmin){ |
|
27 |
errorCode = ErrorCodes.NOT_CONNECT_ADMIN; |
|
28 |
} |
|
29 |
// if(state.url.indexOf("community")==-1){ |
|
30 |
// errorCode = ErrorCodes.NO_COMMUNITY; |
|
31 |
// } |
|
32 |
} |
|
33 |
}else{ |
|
34 |
errorCode =ErrorCodes.NOT_LOGGIN; |
|
35 |
} |
|
36 |
|
|
37 |
if(!loggedIn){ |
|
38 |
// this.guardHelper.redirect("/user-info",errorCode,state.url); |
|
39 |
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); |
|
40 |
|
|
41 |
return false; |
|
42 |
}else if(!isAdmin){ |
|
43 |
// this.guardHelper.redirect("/user-info",errorCode,state.url); |
|
44 |
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); |
|
45 |
return false; |
|
46 |
}else{ |
|
47 |
return true; |
|
48 |
} |
|
49 |
} |
|
50 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/community/community.service.ts | ||
---|---|---|
14 | 14 |
getCommunity(url: string) { |
15 | 15 |
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunity(res)); |
16 | 16 |
} |
17 |
|
|
17 |
iscommunityManager(url: string, manager:string){ |
|
18 |
return this.http.get(url).map(res => <any> res.json()).map(res => this.parseCommunity(res)).map(community => community.managers.indexOf(manager)!=-1); |
|
19 |
} |
|
18 | 20 |
parseCommunity(data:any): CommunityInfo { |
19 | 21 |
|
20 | 22 |
let length = Array.isArray(data) ? data.length :1; |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/communityGuard/communityErrorPage.component.ts | ||
---|---|---|
1 |
import { Component, Input } from '@angular/core'; |
|
2 |
import { Location } from '@angular/common'; |
|
3 |
import { Meta} from '../../sharedComponents/metaService'; |
|
4 |
import {ActivatedRoute} from '@angular/router'; |
|
5 |
|
|
6 |
@Component({ |
|
7 |
selector: 'community-error', |
|
8 |
template: ` |
|
9 |
<div id="tm-main" class=" uk-section uk-margin-small-top tm-middle" > |
|
10 |
<div uk-grid uk-grid> |
|
11 |
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first "> |
|
12 |
|
|
13 |
<div class="uk-container"> |
|
14 |
<h2> |
|
15 |
There is no community selected! |
|
16 |
</h2> |
|
17 |
<br> |
|
18 |
|
|
19 |
<p> |
|
20 |
If you are a community manager, click to manage from user menu. |
|
21 |
</p> |
|
22 |
|
|
23 |
|
|
24 |
</div> |
|
25 |
</div> |
|
26 |
</div> |
|
27 |
</div> |
|
28 |
` |
|
29 |
}) |
|
30 |
|
|
31 |
export class CommunityErrorPageComponent { |
|
32 |
public page: string; |
|
33 |
|
|
34 |
constructor (private _location: Location, private _meta: Meta,private route: ActivatedRoute) { |
|
35 |
this._meta.setTitle("OpenAIRE | Error page"); |
|
36 |
this.page = _location.path(true); |
|
37 |
//this.page = _router.url; |
|
38 |
//this.page = location.href; |
|
39 |
} |
|
40 |
ngOnInit() { |
|
41 |
this.route.queryParams.subscribe(data => { |
|
42 |
|
|
43 |
|
|
44 |
this.page = data['page']; |
|
45 |
if(!this.page){ |
|
46 |
this.page = this._location.path(true); |
|
47 |
} |
|
48 |
}); |
|
49 |
} |
|
50 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/communityGuard/connectAdminLoginGuard.guard.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; |
|
3 |
import {Observable} from 'rxjs/Observable'; |
|
4 |
import {Session} from '../../login/utils/helper.class'; |
|
5 |
import {ErrorCodes} from '../../login/utils/guardHelper.class'; |
|
6 |
import {CommunityService} from '../community/community.service'; |
|
7 |
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service'; |
|
8 |
import { mergeMap } from 'rxjs/operators'; |
|
9 |
|
|
10 |
@Injectable() |
|
11 |
export class ConnectAdminLoginGuard implements CanActivate { |
|
12 |
|
|
13 |
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService ) {} |
|
14 |
|
|
15 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
|
16 |
console.log("aaa"); |
|
17 |
console.log(state.url); |
|
18 |
var user; |
|
19 |
var loggedIn = false; |
|
20 |
var isAdmin = false; |
|
21 |
var errorCode = ErrorCodes.NOT_LOGGIN; |
|
22 |
let community = (route.queryParams["communityId"]); |
|
23 |
if(Session.isLoggedIn()){ |
|
24 |
loggedIn = true; |
|
25 |
if(!Session.isValidAndRemove()){ |
|
26 |
loggedIn = false; |
|
27 |
errorCode = ErrorCodes.NOT_VALID; |
|
28 |
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); |
|
29 |
|
|
30 |
return false; |
|
31 |
}else if(Session.isPortalAdministrator()) { |
|
32 |
console.log("is Admin"); |
|
33 |
isAdmin = true; |
|
34 |
return true; |
|
35 |
}else { |
|
36 |
// let first = Observable.timer(10,500).map(r => { return {source:1,value:r}; }).take(4); |
|
37 |
// let second = Observable.timer(10,500).map(r => { return {source:2,value:r}; }).take(4); |
|
38 |
// first.merge(second).subscribe(res => this.mergeStream.push(res)); |
|
39 |
let obs = this.propertiesService.subscribeEnvironment().map(res=>res["communityAPI"]).mergeMap(url => { |
|
40 |
return this.communityService.iscommunityManager(url+community,Session.getUserEmail())}); |
|
41 |
obs.filter(enabled => !enabled) |
|
42 |
.subscribe(() => this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } })); |
|
43 |
return obs; |
|
44 |
} |
|
45 |
}else{ |
|
46 |
errorCode =ErrorCodes.NOT_LOGGIN; |
|
47 |
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); |
|
48 |
|
|
49 |
return false; |
|
50 |
} |
|
51 |
|
|
52 |
// if(!loggedIn){ |
|
53 |
// // this.guardHelper.redirect("/user-info",errorCode,state.url); |
|
54 |
// this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); |
|
55 |
// |
|
56 |
// return false; |
|
57 |
// }else{ |
|
58 |
// return true; |
|
59 |
// } |
|
60 |
} |
|
61 |
/* |
|
62 |
constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService) {} |
|
63 |
|
|
64 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
|
65 |
|
|
66 |
let customRedirect = route.data['redirect']; |
|
67 |
let api = route.data['api']; |
|
68 |
let community = route.data['community'] |
|
69 |
if(!community){ |
|
70 |
community = (route.queryParams["communityId"])?route.queryParams["communityId"]:route.queryParams["community"]; |
|
71 |
} |
|
72 |
if(community){ |
|
73 |
let isEnabled = this.config.isPageEnabled(api, community,"/"+state.url.split("?")[0].substring(1)); |
|
74 |
let redirect = !!customRedirect ? customRedirect : '/error'; |
|
75 |
|
|
76 |
isEnabled.filter(enabled => !enabled) |
|
77 |
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": state.url } })); |
|
78 |
return isEnabled; |
|
79 |
} |
|
80 |
return true; |
|
81 |
} |
|
82 |
*/ |
|
83 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/communityGuard/isCommunity.guard.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import {ActivatedRoute, Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; |
|
3 |
import {Observable} from 'rxjs/Observable'; |
|
4 |
import 'rxjs/add/operator/filter'; |
|
5 |
|
|
6 |
@Injectable() |
|
7 |
export class IsCommunity implements CanActivate { |
|
8 |
|
|
9 |
constructor(private route: ActivatedRoute,private router: Router) {} |
|
10 |
|
|
11 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
|
12 |
let community = (route.queryParams["communityId"]); |
|
13 |
if(community && community!="undefined"){ |
|
14 |
return true; |
|
15 |
}else{ |
|
16 |
this.router.navigate(['errorcommunity']); |
|
17 |
} |
|
18 |
return false; |
|
19 |
} |
|
20 |
} |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/connect/communityGuard/communityError.module.ts | ||
---|---|---|
1 |
import { NgModule} from '@angular/core'; |
|
2 |
import { CommonModule } from '@angular/common'; |
|
3 |
import { FormsModule } from '@angular/forms'; |
|
4 |
|
|
5 |
import {CommunityErrorPageComponent } from './communityErrorPage.component'; |
|
6 |
import {MetaModule} from '../../sharedComponents/metaService.module'; |
|
7 |
|
|
8 |
@NgModule({ |
|
9 |
imports: [ |
|
10 |
CommonModule, FormsModule, MetaModule |
|
11 |
], |
|
12 |
providers:[], |
|
13 |
declarations: [ |
|
14 |
CommunityErrorPageComponent |
|
15 |
], exports:[CommunityErrorPageComponent] |
|
16 |
}) |
|
17 |
export class CommunityErrorModule { } |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/properties/environment-specific.service.ts | ||
---|---|---|
55 | 55 |
|
56 | 56 |
return Promise.resolve(this.envSpecificNull); |
57 | 57 |
} |
58 |
public subscribeEnvironment() { |
|
59 |
// Only want to do this once - if root page is revisited, it calls this again. |
|
60 |
if (this.envSpecific === null || this.envSpecific === undefined) { |
|
61 |
console.log('Loading env-properties.json'); |
|
58 | 62 |
|
63 |
return this.http.get(this.propertiesUrl) |
|
64 |
.map((data) => data.json()); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
return Observable.of(this.envSpecific); |
|
69 |
} |
|
70 |
|
|
71 |
|
|
59 | 72 |
public setEnvProperties(es: EnvProperties) { |
60 | 73 |
// This has already been set so bail out. |
61 | 74 |
if (es === null || es === undefined) { |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/login/utils/helper.class.ts | ||
---|---|---|
145 | 145 |
// console.log("Is admin:"+ isAdmin) |
146 | 146 |
return (isAdmin); |
147 | 147 |
} |
148 |
public static isConnectAdminUser():boolean {
|
|
148 |
public static isPortalAdministrator():boolean {
|
|
149 | 149 |
var isAdmin = false; |
150 | 150 |
if(Session.isLoggedIn()){ |
151 | 151 |
var roles = ["urn:mace:openminted.eu:aai.openminted.eu:group:OpenAIRE+Portal+Administrator"] |
modules/uoa-services-library/trunk/ng-openaire-library/src/app/app-routing.module.ts | ||
---|---|---|
55 | 55 |
|
56 | 56 |
const routes: Routes = [ |
57 | 57 |
|
58 |
{ path: '', component: SearchComponent, resolve: { envSpecific: EnvironmentSpecificResolver }, canActivate: [ IsRouteEnabled], data: { |
|
59 |
redirect: '/error',api: "http://duffy.di.uoa.gr:8080/uoa-admin-tools", community :"openaire"}}, |
|
58 |
{ path: '', component: SearchComponent, resolve: { envSpecific: EnvironmentSpecificResolver }, canActivate: [ ]}, |
|
60 | 59 |
{ path: 'home', component: SearchComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
61 | 60 |
{ path: 'search/publication', component: PublicationComponent , resolve: { envSpecific: EnvironmentSpecificResolver } }, |
62 | 61 |
{ path: 'search/dataset', component: DatasetComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
... | ... | |
70 | 69 |
{ path: 'participate/deposit-publications', component: DepositPublicationsComponent , resolve: { envSpecific: EnvironmentSpecificResolver } }, |
71 | 70 |
{ path: 'participate/deposit-publications-result', component: DepositPublicationsResultComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
72 | 71 |
{ path: 'search/find', component: SearchComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
73 |
{ path: 'search/find/publications', component: SearchPublicationsComponent , resolve: { envSpecific: EnvironmentSpecificResolver }, canActivate: [ IsRouteEnabled], data: { |
|
74 |
redirect: '/error',api: "http://duffy.di.uoa.gr:8080/uoa-admin-tools", community :"openaire"} }, |
|
72 |
{ path: 'search/find/publications', component: SearchPublicationsComponent , resolve: { envSpecific: EnvironmentSpecificResolver }, canActivate: [ ] }, |
|
75 | 73 |
{ path: 'search/find/datasets', component:SearchDatasetsComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
76 | 74 |
{ path: 'search/find/software', component:SearchSoftwareComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
77 | 75 |
{ path: 'search/find/projects', component:SearchProjectsComponent, resolve: { envSpecific: EnvironmentSpecificResolver } }, |
Also available in: Unified diff
Add a mathod in community service to check if a user is a manager of a community| change connectAdminLoginGuard to really ask for a community manager| correct some links in properties json