[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:
parent
4316c70b9a
commit
68ebe44682
|
@ -1,19 +1,19 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import {Component, Input} from '@angular/core';
|
||||||
import {Title, Meta} from '@angular/platform-browser';
|
import {Title, Meta} from '@angular/platform-browser';
|
||||||
import {User} from "../../login/utils/helper.class";
|
import {User} from "../../login/utils/helper.class";
|
||||||
import {UserManagementService} from "../../services/user-management.service";
|
import {UserManagementService} from "../../services/user-management.service";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'claims-admin',
|
selector: 'claims-admin',
|
||||||
template: `
|
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 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-container">
|
||||||
<div class="uk-article-title custom-article-title">
|
<div class="uk-article-title custom-article-title">
|
||||||
Manage links
|
Manage links
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<!--div class="uk-text-right">
|
<!--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>
|
<a *ngIf="isConnect && fetchBy && fetchBy == 'Context' && externalPortalUrl" [href]="externalPortalUrl+'/participate/claim'" target="_blank">Claim more links?</a>
|
||||||
</div-->
|
</div-->
|
||||||
<displayClaims *ngIf="user" [user]="user" [enableDelete]=true [myClaims]=false
|
<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"
|
[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
|
[externalPortalUrl]=externalPortalUrl [claimsInfoURL]=claimsInfoURL
|
||||||
title="Manage links"></displayClaims>
|
title="Manage links"></displayClaims>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,24 +32,24 @@ import {UserManagementService} from "../../services/user-management.service";
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
`,
|
`,
|
||||||
|
|
||||||
})
|
})
|
||||||
export class ClaimsAdminComponent {
|
export class ClaimsAdminComponent {
|
||||||
@Input() fetchBy:string;
|
@Input() fetchBy: string;
|
||||||
@Input() fetchId:string;
|
@Input() fetchId: string;
|
||||||
@Input() isConnect:boolean = false;
|
@Input() isConnect: boolean = false;
|
||||||
@Input() externalPortalUrl:string;
|
@Input() externalPortalUrl: string;
|
||||||
@Input() claimsInfoURL:string;
|
@Input() claimsInfoURL: string;
|
||||||
@Input() userInfoURL: string;
|
@Input() userInfoURL: string;
|
||||||
public user: User = null;
|
public user: User = null;
|
||||||
|
|
||||||
constructor ( private _meta: Meta, private _title: Title,
|
constructor(private _meta: Meta, private _title: Title,
|
||||||
private userManagementService: UserManagementService) {
|
private userManagementService: UserManagementService) {
|
||||||
var titleConnect = "OpenAIRE Connect | Manage links ";
|
var titleConnect = "OpenAIRE Connect | Manage links ";
|
||||||
var title = "OpenAIRE | Manage links ";
|
var title = "OpenAIRE | Manage links ";
|
||||||
|
|
||||||
if(this.isConnect) {
|
if (this.isConnect) {
|
||||||
this._title.setTitle(titleConnect);
|
this._title.setTitle(titleConnect);
|
||||||
} else {
|
} else {
|
||||||
this._title.setTitle(title);
|
this._title.setTitle(title);
|
||||||
|
@ -57,11 +57,10 @@ export class ClaimsAdminComponent {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (typeof document !== 'undefined') {
|
this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => {
|
||||||
this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => {
|
this.user = user;
|
||||||
this.user = user;
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let email = null;
|
let email = null;
|
||||||
const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
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) {
|
if (user) {
|
||||||
email = user.email;
|
email = user.email;
|
||||||
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {
|
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ export class ConnectSubscriberGuard implements CanActivate {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let email = null;
|
let email = null;
|
||||||
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
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) {
|
if (user) {
|
||||||
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||||
email = user.email;
|
email = user.email;
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
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);
|
return Session.isPortalAdministrator(user);
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class AdminLoginGuard implements CanActivate{
|
||||||
check(path: string): Observable<boolean> {
|
check(path: string): Observable<boolean> {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
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) {
|
if(user) {
|
||||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class ClaimsCuratorGuard implements CanActivate {
|
||||||
check(path: string): Observable<boolean> |boolean {
|
check(path: string): Observable<boolean> |boolean {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
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) {
|
if(user) {
|
||||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,9 @@ export class UserManagementService {
|
||||||
|
|
||||||
public getUserInfo(url: string): Observable<User> {
|
public getUserInfo(url: string): Observable<User> {
|
||||||
const token = COOKIE.getCookie('AccessToken');
|
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);
|
return this.parseUserInfo(userInfo);
|
||||||
})).pipe(timeout(2000), catchError(() => {
|
})).pipe(timeout(2000), catchError(() => {
|
||||||
return of(null);
|
return of(null);
|
||||||
|
|
|
@ -7,41 +7,45 @@ import {EnvProperties} from "../properties/env-properties";
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubscribeService {
|
export class SubscribeService {
|
||||||
|
|
||||||
constructor(private http:HttpClient) {
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
isSubscribedToCommunity(properties: EnvProperties, pid:string, email:string){
|
getCommunitySubscribers(properties: EnvProperties, pid: string) {
|
||||||
let url = properties.adminToolsAPIURL + "/community/"+pid+"/subscribers";
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers";
|
||||||
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
||||||
.pipe(map(res => {
|
}
|
||||||
if(res['status'] && res['status'] != 200) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if(res['subscribers'] && res['subscribers'] != null){
|
|
||||||
|
|
||||||
for(var i =0; i< res['subscribers'].length; i++ ){
|
isSubscribedToCommunity(properties: EnvProperties, pid: string, email: string) {
|
||||||
if(res['subscribers'][i]!=null && res['subscribers'][i].email == email){
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers";
|
||||||
return true;
|
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
||||||
}
|
.pipe(map(res => {
|
||||||
}
|
if (res['status'] && res['status'] != 200) {
|
||||||
}
|
return null;
|
||||||
return false;
|
}
|
||||||
|
if (res['subscribers'] && res['subscribers'] != null) {
|
||||||
|
|
||||||
}));
|
for (var i = 0; i < res['subscribers'].length; i++) {
|
||||||
}
|
if (res['subscribers'][i] != null && res['subscribers'][i].email == email) {
|
||||||
subscribeToCommunity(pid:string, email:string, url:string){
|
return true;
|
||||||
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 false;
|
||||||
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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue