[Library]: Check if is Client on userInfo method.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57547 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-11-08 12:07:39 +00:00
parent 4316c70b9a
commit 68ebe44682
8 changed files with 68 additions and 63 deletions

View File

@ -1,19 +1,19 @@
import {Component, Input} from '@angular/core';
import {Title, Meta} from '@angular/platform-browser';
import {Component, Input} from '@angular/core';
import {Title, Meta} from '@angular/platform-browser';
import {User} from "../../login/utils/helper.class";
import {UserManagementService} from "../../services/user-management.service";
@Component({
selector: 'claims-admin',
template: `
selector: 'claims-admin',
template: `
<div id="tm-main" [class]="((isConnect)?'':'uk-section') +' uk-padding-remove-top tm-middle'" >
<div id="tm-main" [class]="((isConnect)?'':'uk-section') +' uk-padding-remove-top tm-middle'">
<div uk-grid uk-grid>
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
<div class="uk-container">
<div class="uk-article-title custom-article-title">
Manage links
Manage links
</div>
<div>
<!--div class="uk-text-right">
@ -21,9 +21,9 @@ import {UserManagementService} from "../../services/user-management.service";
<a *ngIf="isConnect && fetchBy && fetchBy == 'Context' && externalPortalUrl" [href]="externalPortalUrl+'/participate/claim'" target="_blank">Claim more links?</a>
</div-->
<displayClaims *ngIf="user" [user]="user" [enableDelete]=true [myClaims]=false
[isAdmin]=true [fetchBy]= "(fetchId=='openaire')?null:fetchBy"
[isAdmin]=true [fetchBy]="(fetchId=='openaire')?null:fetchBy"
[fetchId]="(fetchId=='openaire')?null:fetchId"
[communityId]="(fetchBy && fetchBy == 'Context' && fetchId && fetchId!='openaire')?fetchId:null"
[communityId]="(fetchBy && fetchBy == 'Context' && fetchId && fetchId!='openaire')?fetchId:null"
[externalPortalUrl]=externalPortalUrl [claimsInfoURL]=claimsInfoURL
title="Manage links"></displayClaims>
</div>
@ -32,24 +32,24 @@ import {UserManagementService} from "../../services/user-management.service";
</div>
</div>
`,
`,
})
export class ClaimsAdminComponent {
@Input() fetchBy:string;
@Input() fetchId:string;
@Input() isConnect:boolean = false;
@Input() externalPortalUrl:string;
@Input() claimsInfoURL:string;
@Input() fetchBy: string;
@Input() fetchId: string;
@Input() isConnect: boolean = false;
@Input() externalPortalUrl: string;
@Input() claimsInfoURL: string;
@Input() userInfoURL: string;
public user: User = null;
constructor ( private _meta: Meta, private _title: Title,
private userManagementService: UserManagementService) {
constructor(private _meta: Meta, private _title: Title,
private userManagementService: UserManagementService) {
var titleConnect = "OpenAIRE Connect | Manage links ";
var title = "OpenAIRE | Manage links ";
if(this.isConnect) {
if (this.isConnect) {
this._title.setTitle(titleConnect);
} else {
this._title.setTitle(title);
@ -57,11 +57,10 @@ export class ClaimsAdminComponent {
}
ngOnInit() {
if (typeof document !== 'undefined') {
this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => {
this.user = user;
});
}
this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => {
this.user = user;
});
}
}

View File

@ -28,7 +28,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
if (user) {
email = user.email;
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {

View File

@ -21,7 +21,7 @@ export class ConnectSubscriberGuard implements CanActivate {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
email = user.email;

View File

@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate {
return true;
} else {
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map(user => {
return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map(user => {
return Session.isPortalAdministrator(user);
}));
}));

View File

@ -26,7 +26,7 @@ export class AdminLoginGuard implements CanActivate{
check(path: string): Observable<boolean> {
let errorCode = LoginErrorCodes.NOT_LOGIN;
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
if(user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}

View File

@ -26,7 +26,7 @@ export class ClaimsCuratorGuard implements CanActivate {
check(path: string): Observable<boolean> |boolean {
let errorCode = LoginErrorCodes.NOT_LOGIN;
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
if(user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}

View File

@ -14,7 +14,9 @@ export class UserManagementService {
public getUserInfo(url: string): Observable<User> {
const token = COOKIE.getCookie('AccessToken');
return this.http.get<User>(url + token).pipe(map(userInfo => {
if(!token) {
return of(null);
} else return this.http.get<User>(url + token).pipe(map(userInfo => {
return this.parseUserInfo(userInfo);
})).pipe(timeout(2000), catchError(() => {
return of(null);

View File

@ -7,41 +7,45 @@ import {EnvProperties} from "../properties/env-properties";
@Injectable()
export class SubscribeService {
constructor(private http:HttpClient) {
}
getCommunitySubscribers(properties: EnvProperties, pid:string){
let url = properties.adminToolsAPIURL+ "/community/"+pid+"/subscribers";
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
}
constructor(private http: HttpClient) {
}
isSubscribedToCommunity(properties: EnvProperties, pid:string, email:string){
let url = properties.adminToolsAPIURL + "/community/"+pid+"/subscribers";
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => {
if(res['status'] && res['status'] != 200) {
return null;
}
if(res['subscribers'] && res['subscribers'] != null){
getCommunitySubscribers(properties: EnvProperties, pid: string) {
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers";
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
}
for(var i =0; i< res['subscribers'].length; i++ ){
if(res['subscribers'][i]!=null && res['subscribers'][i].email == email){
return true;
}
}
}
return false;
isSubscribedToCommunity(properties: EnvProperties, pid: string, email: string) {
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers";
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
.pipe(map(res => {
if (res['status'] && res['status'] != 200) {
return null;
}
if (res['subscribers'] && res['subscribers'] != null) {
}));
}
subscribeToCommunity(pid:string, email:string, url:string){
let subscriber = {"email":email};
return this.http.post<any>(url+"/community/"+pid+"/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
}
unSubscribeToCommunity(pid:string, email:string, url:string){
return this.http.post<any>(url+"/community/"+pid+"/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
}
getCommunitiesSubscribedTo(properties: EnvProperties, email:string){
let url = properties.adminToolsAPIURL+"/subscriber/communities?email="+email;
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
}
for (var i = 0; i < res['subscribers'].length; i++) {
if (res['subscribers'][i] != null && res['subscribers'][i].email == email) {
return true;
}
}
}
return false;
}));
}
subscribeToCommunity(pid: string, email: string, url: string) {
let subscriber = {"email": email};
return this.http.post<any>(url + "/community/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
}
unSubscribeToCommunity(pid: string, email: string, url: string) {
return this.http.post<any>(url + "/community/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
}
getCommunitiesSubscribedTo(properties: EnvProperties, email: string) {
let url = properties.adminToolsAPIURL + "/subscriber/communities?email=" + email;
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
}
}