[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

@ -57,11 +57,10 @@ export class ClaimsAdminComponent {
}
ngOnInit() {
if (typeof document !== 'undefined') {
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

@ -9,6 +9,7 @@ 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);
@ -33,13 +34,16 @@ export class SubscribeService {
}));
}
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);