[Connect]: Change user login check with user management service.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-connect-portal/trunk@57061 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-09-13 07:47:29 +00:00
parent ca08e72dcb
commit 3aaaf93625
9 changed files with 346 additions and 291 deletions

View File

@ -5,10 +5,11 @@ import {EnvProperties} from './openaireLibrary/utils/properties/env-properties';
import {MenuItem, RootMenuItem} from './openaireLibrary/sharedComponents/menu';
import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service';
import {CommunitiesService} from "./openaireLibrary/connect/communities/communities.service";
import {Session} from './openaireLibrary/login/utils/helper.class';
import {Session, User} from './openaireLibrary/login/utils/helper.class';
import {ConnectHelper} from './openaireLibrary/connect/connectHelper';
import {SubscribeService} from './openaireLibrary/utils/subscribe/subscribe.service';
import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
@Component({
//changeDetection: ChangeDetectionStrategy.Default,
@ -18,11 +19,11 @@ import {HelperFunctions} from "./openaireLibrary/utils/HelperFunctions.class";
`],
template: `
<div [class]="(community)?(community.id +'App'):'connectApp'">
<navbar *ngIf="properties && showMenu && !community" portal="connect" [onlyTop]=false
[userMenuItems]=userMenuItems [menuItems]=menuItems
<navbar *ngIf="properties && showMenu && !community && loginCheck" portal="connect" [onlyTop]=false
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
[showMenu]=showMenu [properties]="properties" [showHomeMenuItem]="true"></navbar>
<navbar *ngIf="properties && showMenu && community" portal="connect" [onlyTop]=false [communityId]="community.id"
[userMenuItems]=userMenuItems [menuItems]=menuItems
<navbar *ngIf="properties && showMenu && community && loginCheck" portal="connect" [onlyTop]=false [communityId]="community.id"
[userMenuItems]=userMenuItems [menuItems]=menuItems [user]="user"
[community]=community [showMenu]=showMenu [properties]="properties" [enableSearch]="true"
[showHomeMenuItem]="true"></navbar>
<customization *ngIf="properties && community"></customization>
@ -66,11 +67,13 @@ export class AppComponent {
communities = null;
subscriberOfCommunities = false;
managerOfCommunities = false;
user: User;
loginCheck: boolean = false;
// community: {id:string, name:string, logoUrl:string};
constructor(private route: ActivatedRoute, private propertiesService: EnvironmentSpecificService,
private _communitiesService: CommunitiesService, private _subscribeService: SubscribeService,
private router: Router) {
private router: Router, private userManagementService: UserManagementService) {
router.events.forEach((event) => {
if (event instanceof NavigationStart) {
HelperFunctions.scroll();
@ -84,28 +87,32 @@ export class AppComponent {
this.properties = this.propertiesService.envSpecific;
var communityId: string = "";
this._communitiesService.updateCommunities(this.properties, this.properties.communitiesAPI);
if (this.properties.environment == "development") {
this.showMenu = false;
this.route.queryParams.subscribe(params => {
communityId = (params['communityId']) ? params['communityId'] : '';
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
this.loginCheck = true;
if (this.properties.environment == "development") {
this.showMenu = false;
this.route.queryParams.subscribe(params => {
communityId = (params['communityId']) ? params['communityId'] : '';
this.buildMenu(communityId);
})
} else {
this.showMenu = false;
communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
this.buildMenu(communityId);
})
} else {
this.showMenu = false;
communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
this.buildMenu(communityId);
}
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
if (typeof document !== 'undefined') {
try {
this.isClient = true;
} catch (e) {
}
}
}, error => {
console.log("App couldn't fetch properties");
console.log(error);
});
});
});
}
public buildMenu(communityId: string) {
@ -125,10 +132,10 @@ export class AppComponent {
this.managerOfCommunities && this.subscriberOfCommunities)) {
break;
}
if (Session.isLoggedIn() && com['status'] != "hidden") {
if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
if (this.user && com['status'] != "hidden") {
if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
this.managerOfCommunities = true;
} else if (com.managers.indexOf(Session.getUserEmail()) != -1) {
} else if (com.managers.indexOf(this.user.email) != -1) {
this.managerOfCommunities = true;
}
}
@ -137,9 +144,9 @@ export class AppComponent {
if (communityId && communityId != "" && com.communityId == communityId) {
community = com;
let isCommunityManager: boolean = false;
if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
isCommunityManager = true;
} else if (com.managers.indexOf(Session.getUserEmail()) != -1) {
} else if (com.managers.indexOf(this.user.email) != -1) {
isCommunityManager = true;
}
this.community = {
@ -238,7 +245,7 @@ export class AppComponent {
this.userMenuItems = [
// new MenuItem("","My links","","/myclaims",false,[],["/myclaims"],(data['communityId'] && typeof document !== 'undefined' && ConnectHelper.isProduction(document.location.hostname))?{}:{communityId:data['communityId']}),
];
if (Session.isPortalAdministrator()) {
if (Session.isPortalAdministrator(this.user)) {
//((this.properties.environment == "beta") ? "https://beta.admin.connect.openaire.eu" : "https://admin.explore.openaire.eu") + "/dashboard?communityId=openaire"
this.userMenuItems.push(new MenuItem("", "Manage Helptexts",
((this.properties.environment == "production") ? "https://admin.explore.openaire.eu" : "https://beta.admin.connect.openaire.eu") + "/dashboard?communityId=connect",
@ -258,7 +265,7 @@ export class AppComponent {
console.error("Error fetching your subscribed communities")
});
}*/
if (Session.isLoggedIn()) {
if (this.user) {
this.userMenuItems.push(new MenuItem("my-communities", "My Communities", "",
"/myCommunities", false, [], [], {}));
}

View File

@ -8,12 +8,13 @@ import {PiwikHelper} from "../../utils/piwikHelper";
@Component({
selector: 'openaire-my-claims',
template: `
<my-claims [claimsInfoURL]=claimsInfoURL [communityId]=communityId [piwikSiteId]="piwikSiteId"></my-claims>
<my-claims [claimsInfoURL]=claimsInfoURL [userInfoURL]="userInfoURL" [communityId]=communityId [piwikSiteId]="piwikSiteId"></my-claims>
`
})
export class OpenaireMyClaimsComponent {
claimsInfoURL:string;
userInfoURL: string;
communityId:string;
public piwikSiteId = null;
@ -23,6 +24,7 @@ import {PiwikHelper} from "../../utils/piwikHelper";
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.claimsInfoURL = data.envSpecific.claimsInformationLink;
this.userInfoURL = data.envSpecific.userInfoUrl;
this.route.queryParams.subscribe(
communityId => {
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);

View File

@ -9,7 +9,7 @@ import {ConfigurationService} from '../openaireLibrary/utils/configuration/confi
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
import {ZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communities.service';
import {Session} from '../openaireLibrary/login/utils/helper.class';
import {Session, User} from '../openaireLibrary/login/utils/helper.class';
import {StatisticsForDashboardComponent} from '../statistics/statistics.component';
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
@ -20,6 +20,7 @@ import {SearchCommunityProjectsService} from "../openaireLibrary/connect/project
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({
selector: 'community',
@ -77,6 +78,8 @@ export class CommunityComponent {
searchLinkToAdvancedPublications: string = null;
shareInZenodoPage: string = null;
public routerHelper:RouterHelper = new RouterHelper();
private user: User;
private loginCheck: boolean = false;
constructor(
private element: ElementRef,
@ -93,7 +96,8 @@ export class CommunityComponent {
private _searchResearchResultsService: SearchResearchResultsService,
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
private seoService: SEOService) {
private seoService: SEOService,
private userManagementService: UserManagementService) {
var description = "OpenAIRE - Connect, Community Dashboard, research community";
var title = "OpenAIRE - Connect";
@ -119,7 +123,10 @@ export class CommunityComponent {
this.url = data.envSpecific.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url, false);
this._meta.updateTag({content: this.url}, "property='og:url'");
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
this.loginCheck = true;
})
if (this.communityId != null && this.communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
@ -327,19 +334,19 @@ export class CommunityComponent {
}
showInvite() {
return this.isManager();
return this.loginCheck && this.isManager();
}
isManager() {
var email = Session.getUserEmail();
if(!this.user) {
return false;
}
var email = this.user.email;
var index = -1;
if (email && this.community != null && this.community.managers != null) {
index = this.community.managers.indexOf(email);
}
return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1;
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
}
private handleError(message: string, error) {

View File

@ -11,6 +11,7 @@ import {Session} from '../openaireLibrary/login/utils/helper.class';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {SubscribeComponent} from '../utils/subscribe/subscribe.component';
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({
selector: 'openaire-user',
@ -53,14 +54,17 @@ export class OpenaireUserComponent {
public server: boolean = true;
loggedIn:boolean = false;
constructor(private _subscribeService: SubscribeService,
private _emailService: EmailService, private route: ActivatedRoute){}
private _emailService: EmailService, private route: ActivatedRoute,
private userManagementService: UserManagementService){}
public ngOnInit() {
if( typeof document !== 'undefined') {
this.server = false;
this.loggedIn = Session.isLoggedIn();
}
this.route.data
.subscribe((data: { envSpecific: any }) => {
this.userManagementService.isLoggedIn(data.envSpecific.userInfoUrl).subscribe( isLoggedIn => {
if( typeof document !== 'undefined') {
this.server = false;
this.loggedIn = isLoggedIn;
}
});
this.route.queryParams.subscribe(
communityId => {
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain);

View File

@ -7,13 +7,14 @@ import {SubscribeService} from '../openaireLibrary/utils/subscribe/subscribe.ser
import {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {Session} from '../openaireLibrary/login/utils/helper.class';
import {Session, User} from '../openaireLibrary/login/utils/helper.class';
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({
selector: 'my-communities',
@ -37,6 +38,7 @@ export class MyCommunitiesComponent {
private errorMessages: ErrorMessagesComponent;
properties: EnvProperties;
private user: User;
constructor(
private route: ActivatedRoute,
@ -47,7 +49,8 @@ export class MyCommunitiesComponent {
private _communitiesService: CommunitiesService,
private _subscribeService: SubscribeService,
private helper: HelperService,
private seoService: SEOService) {
private seoService: SEOService,
private userManagementService: UserManagementService) {
var description = "OpenAIRE - Connect, Community Dashboard, research community " +
"| My managing and subscribed to Communities";
@ -73,9 +76,12 @@ export class MyCommunitiesComponent {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
}
this.getCommunities();
//this.getDivContents();
//this.getPageContents();
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.getCommunities();
//this.getDivContents();
//this.getPageContents();
});
});
}
@ -112,7 +118,7 @@ export class MyCommunitiesComponent {
this.sort(communitiesResults);
var subscribedLoading = communitiesResults.length;
var mail = Session.getUserEmail();
var mail = this.user.email;
communitiesResults.forEach((community, index) => {
let showCommunity: boolean = true;
let isManager: boolean = false;
@ -123,7 +129,7 @@ export class MyCommunitiesComponent {
} else {
if (mail == null && community['status'] == "manager") { // no user
showCommunity = false;
} else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
} else if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
isManager = true;
} else if (community.managers.indexOf(mail) != -1) {
isManager = true;

View File

@ -8,11 +8,13 @@ import {ActivatedRoute} from "@angular/router";
import {Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
import {SearchFields} from "../../openaireLibrary/utils/properties/searchFields";
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.service";
import {Session} from "../../openaireLibrary/login/utils/helper.class";
import {Session, User} from "../../openaireLibrary/login/utils/helper.class";
import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service";
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
import {url} from "inspector";
@Component({
selector: 'search-communities',
@ -46,10 +48,12 @@ export class SearchCommunitiesComponent {
public showType = false;
properties:EnvProperties;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
private user: User;
constructor (private route: ActivatedRoute,
private _communitiesService: CommunitiesService,
private _subscribeService: SubscribeService) {
private _subscribeService: SubscribeService,
private userManagementService: UserManagementService) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING;
@ -77,8 +81,10 @@ export class SearchCommunitiesComponent {
}
this.searchPage.refineFields = this.refineFields;
let queryParams = this.searchPage.getQueryParamsFromUrl(params);
this.initCommunities(queryParams);
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.initCommunities(queryParams);
});
});
}
@ -106,12 +112,12 @@ export class SearchCommunitiesComponent {
this.totalResults[i] = data[i];
this.totalResults[i].isManager = false;
this.totalResults[i].isSubscribed = false;
if(Session.isLoggedIn()) {
if(this.user) {
this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]);
}
}
if(Session.isLoggedIn()) {
this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe(
if(this.user) {
this._subscribeService.getCommunitiesSubscribedTo(this.properties, this.user.email).subscribe(
res => {
for (let i = 0; i < this.totalResults.length; i++) {
this.totalResults[i].isSubscribed = (res.indexOf(this.totalResults[i].communityId) != -1);
@ -161,10 +167,10 @@ export class SearchCommunitiesComponent {
if (result.status == 'hidden') {
continue;
} else if (result.status == "manager") {
let mail = Session.getUserEmail();
let mail = this.user.email;
if (mail == null) { // no user
continue;
} else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) {
} else if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
ret.push(result);
} else if (result.managers.indexOf(mail) != -1) {
ret.push(result);
@ -244,7 +250,7 @@ export class SearchCommunitiesComponent {
let typeResults: CommunityInfo[] = this.applyFilter('type', params);
let statusResults: CommunityInfo[] = this.results;
let roleResults: CommunityInfo[] = this.results;
if(Session.isLoggedIn()) {
if(this.user) {
statusResults = this.applyFilter('status', params);
roleResults = this.applyFilter('role', params);
this.resetFilterNumbers('status');
@ -425,7 +431,7 @@ export class SearchCommunitiesComponent {
private isCommunityManager(community: CommunityInfo): boolean {
return Session.isCommunityCurator() || community.managers.indexOf(Session.getUserEmail()) != -1;
return Session.isCommunityCurator(this.user) || community.managers.indexOf(this.user.email) != -1;
}
/**
@ -448,7 +454,7 @@ export class SearchCommunitiesComponent {
} else {
filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS.splice(0, 1);
}
if(Session.isLoggedIn()) {
if(this.user) {
filter_names.push("Status");
filter_ids.push("status");
value_names.push([ "Subscribed", "Non-subscribed"]);

View File

@ -14,13 +14,14 @@ import {EmailService} from '../../../openaireLibrary/utils/email/email.service';
import {CommunityService} from "../../../openaireLibrary/connect/community/community.service";
import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../../openaireLibrary/utils/errorMessages.component';
import {Session} from '../../../openaireLibrary/login/utils/helper.class';
import {Session, User} from '../../../openaireLibrary/login/utils/helper.class';
import {HelperFunctions} from "../../../openaireLibrary/utils/HelperFunctions.class";
import {HelperService} from "../../../openaireLibrary/utils/helper/helper.service";
import {Meta, Title} from "@angular/platform-browser";
import {SEOService} from "../../../openaireLibrary/sharedComponents/SEO/SEO.service";
import {PiwikService} from "../../../openaireLibrary/utils/piwik/piwik.service";
import {PiwikHelper} from "../../piwikHelper";
import {UserManagementService} from "../../../openaireLibrary/services/user-management.service";
@Component({
selector: 'invite',
@ -68,6 +69,7 @@ export class InviteComponent implements OnInit {
public url: string = null;
public pageTitle: string = "Invite";
piwiksub: any;
private user: User;
constructor(
private route: ActivatedRoute,
@ -79,7 +81,8 @@ export class InviteComponent implements OnInit {
private _meta: Meta,
private _title: Title,
private seoService: SEOService,
private _piwikService: PiwikService) {
private _piwikService: PiwikService,
private userManageService: UserManagementService) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
@ -92,59 +95,62 @@ export class InviteComponent implements OnInit {
this.errorMessage = "";
this.missingCommunityId = "";
this.status = this.errorCodes.LOADING;
this.route.queryParams.subscribe(
communityId => {
//if(!this.communityId && typeof document !== 'undefined'){
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if (!this.communityId) {
this.communityId = communityId['communityId'];
}
if(this.longView) {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
this.userManageService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.route.queryParams.subscribe(
communityId => {
//if(!this.communityId && typeof document !== 'undefined'){
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if (!this.communityId) {
this.communityId = communityId['communityId'];
}
this.url = this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, invite");
}
this.communityIdParam = (this.properties.environment != "development") ? {} : {communityId: this.communityId};
if (this.communityId != null && this.communityId != '') {
//this.getDivContents();
this.getPageContents();
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
this.community = community;
this.fullname = Session.getUserFullName();
//console.log("Fullname from session " + Session.getUserFullName());
this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname);
this.email = Composer.initializeInvitationsEmail(community.title);
this.recipients = "";
this.status = this.errorCodes.DONE;
},
error => {
//this.handleError(error)
this.handleError("Error getting community with id: " + this.communityId, error);
this.status = this.errorMessages.getErrorCode(error.status);
if (this.longView) {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
}
);
} else {
this.status = this.errorCodes.DONE;
this.missingCommunityId = "There is no community selected!";
}
this.url = this.properties.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url);
this.updateUrl(this.url);
this.updateTitle(this.pageTitle);
this.updateDescription("OpenAIRE - Connect, Community Gateway, research community, invite");
}
this.communityIdParam = (this.properties.environment != "development") ? {} : {communityId: this.communityId};
if (this.communityId != null && this.communityId != '') {
//this.getDivContents();
this.getPageContents();
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
this.community = community;
this.fullname = this.user.fullname;
//console.log("Fullname from session " + Session.getUserFullName());
});
this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname);
this.email = Composer.initializeInvitationsEmail(community.title);
this.recipients = "";
HelperFunctions.scroll();
this.status = this.errorCodes.DONE;
},
error => {
//this.handleError(error)
this.handleError("Error getting community with id: " + this.communityId, error);
this.status = this.errorMessages.getErrorCode(error.status);
}
);
} else {
this.status = this.errorCodes.DONE;
this.missingCommunityId = "There is no community selected!";
}
});
HelperFunctions.scroll();
});
});
}
ngOnDestroy() {
if(this.piwiksub) {
if (this.piwiksub) {
this.piwiksub.unsubscribe();
}
}
@ -277,15 +283,15 @@ export class InviteComponent implements OnInit {
}
*/
allowEdit() {
var email = Session.getUserEmail();
if (!this.user) {
return false;
}
var email = this.user.email;
var index = -1;
if (email && this.community != null && this.community.managers != null) {
index = this.community.managers.indexOf(email);
}
return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1;
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
}
private handleError(message: string, error) {

View File

@ -6,221 +6,236 @@ import {AlertModal} from '../../openaireLibrary/utils/modal/alert';
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service';
import {EmailService} from "../../openaireLibrary/utils/email/email.service";
import {Session} from '../../openaireLibrary/login/utils/helper.class';
import {Session, User} from '../../openaireLibrary/login/utils/helper.class';
import {Email} from "../../openaireLibrary/utils/email/email";
import {Composer} from "../../openaireLibrary/utils/email/composer";
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
declare var UIkit: any;
@Component({
selector: 'subscribe',
template: `
selector: 'subscribe',
template: `
<span *ngIf="subscribed != null && !showNumbers && showTemplate">
<div *ngIf="!subscribed && showLoginAlert" class="uk-alert-warning uk-animation-slide-bottom" uk-alert="" >
<div *ngIf="!subscribed && showLoginAlert" class="uk-alert-warning uk-animation-slide-bottom" uk-alert="">
<a class="uk-alert-close" uk-close></a>
<p>Please login first to subscribe</p>
</div>
<button *ngIf="!subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')" (click)="subscribe()"> Subscribe</button>
<button *ngIf="subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')" (click)="confirmOpen()"> Unsubscribe</button>
<button *ngIf="!subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')"
(click)="subscribe()"> Subscribe</button>
<button *ngIf="subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')"
(click)="confirmOpen()"> Unsubscribe</button>
</span>
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0 && showTemplate" >
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0 && showTemplate">
<span class="lowOpacityColor"> Members</span> {{subscribers}}
</span>
<modal-alert (alertOutput)="confirmClose($event)">
</modal-alert>
`
`
})
export class SubscribeComponent {
// @Input() showSubscribe:boolean = true;
@Input() showNumbers:boolean;
@Input() communityId:string;
@Input() showTemplate:boolean = true;
@Input() showNumbers: boolean;
@Input() communityId: string;
@Input() showTemplate: boolean = true;
@Output() subscribeEvent = new EventEmitter();
public community = null;
public emailToInformManagers: Email;
loading: boolean = false;
subscribed:boolean = null;
properties:EnvProperties;
subscribers:number= null;
showLoginAlert:Boolean = false;
subscribed: boolean = null;
properties: EnvProperties;
subscribers: number = null;
showLoginAlert: Boolean = false;
@ViewChild(AlertModal) alert;
constructor (private route: ActivatedRoute,
private _subscribeService: SubscribeService,
private _emailService: EmailService,
private _communityService: CommunityService, private router: Router
) {
}
private user: User;
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
if(!this.showNumbers){
let email = Session.getUserEmail();
if(email == null){
this.subscribed = false;
}else{
if(this.communityId){
this._subscribeService.isSubscribedToCommunity(this.properties, this.communityId, email).subscribe (
res => {
this.subscribed = res;
if(this.subscribed){
this.subscribeEvent.emit({
value: "ok"
});
}
},
error => {
this.handleError("Error getting response if email: "+email+" is subscribed to community with id: "+this.communityId, error);
});
}
}
}else{
if(this.communityId){
this._subscribeService.getCommunitySubscribers(this.properties, this.communityId).subscribe (
res => {
this.subscribers = (res && res.subscribers && res.subscribers.length )?res.subscribers.length:0;
},
error => {
this.handleError("Error getting community subscribers for community with id: "+this.communityId, error);
});
}
}
if(this.communityId){
this.emailToInformManagers = {body: "", subject: "", recipients: []};
constructor(private route: ActivatedRoute,
private _subscribeService: SubscribeService,
private _emailService: EmailService,
private _communityService: CommunityService,
private router: Router,
private userManagementService: UserManagementService
) {
}
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe (
community => {
this.community = community;
},
error => {
//console.log('System error retrieving community profile', error)
this.handleError("Error getting community with id: "+this.communityId, error);
}
);
}
});
}
subscribe(){
var email = Session.getUserEmail();
if(email == null){
this.subscribed = false;
// this.showLoginAlert = true;
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.ACTION_REQUIRES_LOGIN, "redirectUrl": this.router.url } });
}else{
this.loading = true;
this.showLoginAlert = false;
this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe (
res => {
this.loading = false;
if(res.status && res.status != 200) {
this.subscribeEvent.emit({
value: "error"
});
UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>',
status : 'warning',
timeout : 3000,
pos : 'top-center'
});
} else {
if(!this.subscribed){
this.subscribed = true;
this.subscribeEvent.emit({
value: "ok"
});
this._emailService.sendEmail(this.properties.adminToolsAPIURL + "/notifyForNewSubscribers/" + this.communityId, Composer.composeEmailToInformManagers(this.community.title, this.communityId, this.community.managers, email)).subscribe(
res => {
//console.log("The email has been sent successfully!")
},
error => {
//console.log(error)
this.handleError("Error notifying managers about new subscribers for community with id: "+this.communityId, error);
}
);
}
public ngOnInit() {
this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific;
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
this.user = user;
if (!this.showNumbers) {
let email = (this.user)?this.user.email:null;
if (email == null) {
this.subscribed = false;
} else {
if (this.communityId) {
this._subscribeService.isSubscribedToCommunity(this.properties, this.communityId, email).subscribe(
res => {
this.subscribed = res;
if (this.subscribed) {
this.subscribeEvent.emit({
value: "ok"
});
}
},
error => {
this.handleError("Error getting response if email: " + email + " is subscribed to community with id: " + this.communityId, error);
});
}
}
},
error => {
this.loading = false;
} else {
if (this.communityId) {
this._subscribeService.getCommunitySubscribers(this.properties, this.communityId).subscribe(
res => {
this.subscribers = (res && res.subscribers && res.subscribers.length) ? res.subscribers.length : 0;
},
error => {
this.handleError("Error getting community subscribers for community with id: " + this.communityId, error);
});
}
}
if (this.communityId) {
this.emailToInformManagers = {body: "", subject: "", recipients: []};
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => {
this.community = community;
},
error => {
//console.log('System error retrieving community profile', error)
this.handleError("Error getting community with id: " + this.communityId, error);
}
);
}
});
});
}
subscribe() {
var email = (this.user)?this.user.email:null;
if (email == null) {
this.subscribed = false;
// this.showLoginAlert = true;
this.router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.ACTION_REQUIRES_LOGIN,
"redirectUrl": this.router.url
}
});
} else {
this.loading = true;
this.showLoginAlert = false;
this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe(
res => {
this.loading = false;
if (res.status && res.status != 200) {
this.subscribeEvent.emit({
value: "error"
});
UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>',
status : 'warning',
timeout : 3000,
pos : 'top-center'
message: '<strong>An error occured. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
//console.log(error)
this.handleError("Error subscribing email: "+email+" to community with id: "+this.communityId, error);
});
}
}
unsubscribe(){
var email = Session.getUserEmail();
if(email == null){
this.subscribed = false;
}else{
this.loading = true;
//this.properties.adminToolsAPIURL
this._subscribeService.unSubscribeToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe (
res => {
this.loading = false;
if(res.status && res.status != 200) {
UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>',
status : 'warning',
timeout : 3000,
pos : 'top-center'
} else {
if (!this.subscribed) {
this.subscribed = true;
this.subscribeEvent.emit({
value: "ok"
});
} else {
//console.log(res);
if(this.subscribed){
this.subscribed = false;
}
}
},
error => {
this.loading = false;
UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>',
status : 'warning',
timeout : 3000,
pos : 'top-center'
});
//console.log(error)
this.handleError("Error unsubscribing email: "+email+" from community with id: "+this.communityId, error);
this._emailService.sendEmail(this.properties.adminToolsAPIURL + "/notifyForNewSubscribers/" + this.communityId, Composer.composeEmailToInformManagers(this.community.title, this.communityId, this.community.managers, email)).subscribe(
res => {
//console.log("The email has been sent successfully!")
},
error => {
//console.log(error)
this.handleError("Error notifying managers about new subscribers for community with id: " + this.communityId, error);
}
);
}
}
},
error => {
this.loading = false;
this.subscribeEvent.emit({
value: "error"
});
}
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
//console.log(error)
this.handleError("Error subscribing email: " + email + " to community with id: " + this.communityId, error);
});
}
}
confirmOpen(){
unsubscribe() {
var email = (this.user)?this.user.email:null;
if (email == null) {
this.subscribed = false;
} else {
this.loading = true;
//this.properties.adminToolsAPIURL
this._subscribeService.unSubscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe(
res => {
this.loading = false;
if (res.status && res.status != 200) {
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
} else {
//console.log(res);
if (this.subscribed) {
console.log('here')
this.subscribed = false;
}
}
},
error => {
this.loading = false;
UIkit.notification({
message: '<strong>An error occured. Please try again!<strong>',
status: 'warning',
timeout: 3000,
pos: 'top-center'
});
//console.log(error)
this.handleError("Error unsubscribing email: " + email + " from community with id: " + this.communityId, error);
});
}
}
this.alert.cancelButton = true;
this.alert.okButton = true;
this.alert.alertTitle = "Unsubscribe community ";
this.alert.message = "Do you want to proceed? ";
this.alert.okButtonText = "Yes";
this.alert.cancelButtonText = "No";
this.alert.open();
}
confirmClose(data){
this.unsubscribe();
}
confirmOpen() {
private handleError(message: string, error) {
console.error("Subscribe (component): "+message, error);
}
this.alert.cancelButton = true;
this.alert.okButton = true;
this.alert.alertTitle = "Unsubscribe community ";
this.alert.message = "Do you want to proceed? ";
this.alert.okButtonText = "Yes";
this.alert.cancelButtonText = "No";
this.alert.open();
}
confirmClose(data) {
this.unsubscribe();
}
private handleError(message: string, error) {
console.error("Subscribe (component): " + message, error);
}
}

View File

@ -37,7 +37,9 @@
"piwikBaseUrl" :"https://analytics.openaire.eu/piwik.php?idsite=",
"piwikSiteId" : "80",
"loginUrl" :"http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/openid_connect_login",
"loginUrl" :"http://rudie.di.uoa.gr:8280/dnet-login/openid_connect_login",
"userInfoUrl" : "http://rudie.di.uoa.gr:8280/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
"logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",