[Trunk | Library]:
1. subscribe.service.ts: a. Method "subscribeToCommunity()" renamed to "subscribeToCommunityByEmail()" and method "unSubscribeToCommunity()" renamed to "unSubscribeToCommunityByEmail()". b. Add methods: "getNumberOfCommunitySubscribers()", "subscribeToCommunity()", "unSubscribeToCommunity()". c. Method "isSubscribedToCommunity()": API changed to return true/ false without revealing users' emails (no processing needed here anymore). d. Methods: "isSubscribedToCommunity()", "subscribeToCommunity()", "unSubscribeToCommunity()" - DO NOT SEND user email, API will do the work via token ("X-XSRF-TOKEN" header). 2. connectSubscriber.guard.ts: Use new method "isSubscribedToCommunity()" without email parameter (subscribe.service). git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58459 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
2940114ff5
commit
71a4d35c43
|
@ -31,7 +31,7 @@ export class ConnectSubscriberGuard implements CanActivate {
|
||||||
if(communityDomain) {
|
if(communityDomain) {
|
||||||
community = communityDomain;
|
community = communityDomain;
|
||||||
}
|
}
|
||||||
return this.subscribeService.isSubscribedToCommunity(properties, community, email)
|
return this.subscribeService.isSubscribedToCommunity(properties, community)
|
||||||
} else {
|
} else {
|
||||||
return of(false);
|
return of(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {HttpClient} from '@angular/common/http';
|
||||||
import {map} from "rxjs/operators";
|
import {map} from "rxjs/operators";
|
||||||
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
||||||
import {EnvProperties} from "../properties/env-properties";
|
import {EnvProperties} from "../properties/env-properties";
|
||||||
|
import {COOKIE} from "../../login/utils/helper.class";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubscribeService {
|
export class SubscribeService {
|
||||||
|
@ -15,32 +16,45 @@ export class SubscribeService {
|
||||||
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
||||||
}
|
}
|
||||||
|
|
||||||
isSubscribedToCommunity(properties: EnvProperties, pid: string, email: string) {
|
getNumberOfCommunitySubscribers(properties: EnvProperties, pid: string) {
|
||||||
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers";
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/count";
|
||||||
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
||||||
|
}
|
||||||
|
|
||||||
|
isSubscribedToCommunity(properties: EnvProperties, pid: string) {
|
||||||
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/";
|
||||||
|
return this.http.post<boolean>(url, {}, CustomOptions.getAuthOptionsWithBody())
|
||||||
.pipe(map(res => {
|
.pipe(map(res => {
|
||||||
if (res['status'] && res['status'] != 200) {
|
// if (res['status'] && res['status'] != 200) {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
if (res['subscribers'] && res['subscribers'] != null) {
|
// if (res['subscribers'] && res['subscribers'] != null) {
|
||||||
|
//
|
||||||
for (var i = 0; i < res['subscribers'].length; i++) {
|
// for (var i = 0; i < res['subscribers'].length; i++) {
|
||||||
if (res['subscribers'][i] != null && res['subscribers'][i].email == email) {
|
// if (res['subscribers'][i] != null && res['subscribers'][i].email == email) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
|
return res;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToCommunity(properties: EnvProperties, pid: string, email: string) {
|
subscribeToCommunity(properties: EnvProperties, pid: string) {
|
||||||
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
unSubscribeToCommunity(properties: EnvProperties, pid: string) {
|
||||||
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) {
|
||||||
let subscriber = {"email": email};
|
let subscriber = {"email": email};
|
||||||
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
unSubscribeToCommunity(properties: EnvProperties, pid: string, email: string) {
|
unSubscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) {
|
||||||
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue