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

View File

@ -8,12 +8,13 @@ import {PiwikHelper} from "../../utils/piwikHelper";
@Component({ @Component({
selector: 'openaire-my-claims', selector: 'openaire-my-claims',
template: ` 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 { export class OpenaireMyClaimsComponent {
claimsInfoURL:string; claimsInfoURL:string;
userInfoURL: string;
communityId:string; communityId:string;
public piwikSiteId = null; public piwikSiteId = null;
@ -23,6 +24,7 @@ import {PiwikHelper} from "../../utils/piwikHelper";
this.route.data this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => { .subscribe((data: { envSpecific: EnvProperties }) => {
this.claimsInfoURL = data.envSpecific.claimsInformationLink; this.claimsInfoURL = data.envSpecific.claimsInformationLink;
this.userInfoURL = data.envSpecific.userInfoUrl;
this.route.queryParams.subscribe( this.route.queryParams.subscribe(
communityId => { communityId => {
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain); 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 {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service'; import {SearchZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/searchZenodoCommunities.service';
import {ZenodoCommunitiesService} from '../openaireLibrary/connect/zenodoCommunities/zenodo-communities.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 {StatisticsForDashboardComponent} from '../statistics/statistics.component';
import {StringUtils} from '../openaireLibrary/utils/string-utils.class'; 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 {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class"; import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({ @Component({
selector: 'community', selector: 'community',
@ -77,6 +78,8 @@ export class CommunityComponent {
searchLinkToAdvancedPublications: string = null; searchLinkToAdvancedPublications: string = null;
shareInZenodoPage: string = null; shareInZenodoPage: string = null;
public routerHelper:RouterHelper = new RouterHelper(); public routerHelper:RouterHelper = new RouterHelper();
private user: User;
private loginCheck: boolean = false;
constructor( constructor(
private element: ElementRef, private element: ElementRef,
@ -93,7 +96,8 @@ export class CommunityComponent {
private _searchResearchResultsService: SearchResearchResultsService, private _searchResearchResultsService: SearchResearchResultsService,
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService, private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService,
private _ΖenodoCommunitieService: ZenodoCommunitiesService, private _ΖenodoCommunitieService: ZenodoCommunitiesService,
private seoService: SEOService) { private seoService: SEOService,
private userManagementService: UserManagementService) {
var description = "OpenAIRE - Connect, Community Dashboard, research community"; var description = "OpenAIRE - Connect, Community Dashboard, research community";
var title = "OpenAIRE - Connect"; var title = "OpenAIRE - Connect";
@ -119,7 +123,10 @@ export class CommunityComponent {
this.url = data.envSpecific.baseLink + this._router.url; this.url = data.envSpecific.baseLink + this._router.url;
this.seoService.createLinkForCanonicalURL(this.url, false); this.seoService.createLinkForCanonicalURL(this.url, false);
this._meta.updateTag({content: this.url}, "property='og:url'"); 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 != '') { if (this.communityId != null && this.communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe( this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => { community => {
@ -327,19 +334,19 @@ export class CommunityComponent {
} }
showInvite() { showInvite() {
return this.loginCheck && this.isManager();
return this.isManager();
} }
isManager() { isManager() {
var email = Session.getUserEmail(); if(!this.user) {
return false;
}
var email = this.user.email;
var index = -1; var index = -1;
if (email && this.community != null && this.community.managers != null) { if (email && this.community != null && this.community.managers != null) {
index = this.community.managers.indexOf(email); index = this.community.managers.indexOf(email);
} }
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1;
} }
private handleError(message: string, error) { 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 {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {SubscribeComponent} from '../utils/subscribe/subscribe.component'; import {SubscribeComponent} from '../utils/subscribe/subscribe.component';
import {ConnectHelper} from '../openaireLibrary/connect/connectHelper'; import {ConnectHelper} from '../openaireLibrary/connect/connectHelper';
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({ @Component({
selector: 'openaire-user', selector: 'openaire-user',
@ -53,14 +54,17 @@ export class OpenaireUserComponent {
public server: boolean = true; public server: boolean = true;
loggedIn:boolean = false; loggedIn:boolean = false;
constructor(private _subscribeService: SubscribeService, constructor(private _subscribeService: SubscribeService,
private _emailService: EmailService, private route: ActivatedRoute){} private _emailService: EmailService, private route: ActivatedRoute,
private userManagementService: UserManagementService){}
public ngOnInit() { public ngOnInit() {
if( typeof document !== 'undefined') {
this.server = false;
this.loggedIn = Session.isLoggedIn();
}
this.route.data this.route.data
.subscribe((data: { envSpecific: any }) => { .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( this.route.queryParams.subscribe(
communityId => { communityId => {
this.communityId = ConnectHelper.getCommunityFromDomain(data.envSpecific.domain); 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 {CommunityInfo} from '../openaireLibrary/connect/community/communityInfo';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; 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 {StringUtils} from '../openaireLibrary/utils/string-utils.class';
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component'; import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
import {HelperService} from "../openaireLibrary/utils/helper/helper.service"; import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
@Component({ @Component({
selector: 'my-communities', selector: 'my-communities',
@ -37,6 +38,7 @@ export class MyCommunitiesComponent {
private errorMessages: ErrorMessagesComponent; private errorMessages: ErrorMessagesComponent;
properties: EnvProperties; properties: EnvProperties;
private user: User;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -47,7 +49,8 @@ export class MyCommunitiesComponent {
private _communitiesService: CommunitiesService, private _communitiesService: CommunitiesService,
private _subscribeService: SubscribeService, private _subscribeService: SubscribeService,
private helper: HelperService, private helper: HelperService,
private seoService: SEOService) { private seoService: SEOService,
private userManagementService: UserManagementService) {
var description = "OpenAIRE - Connect, Community Dashboard, research community " + var description = "OpenAIRE - Connect, Community Dashboard, research community " +
"| My managing and subscribed to Communities"; "| My managing and subscribed to Communities";
@ -73,10 +76,13 @@ export class MyCommunitiesComponent {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe(); this.piwiksub = this._piwikService.trackView(this.properties, "OpenAIRE Connect", this.properties.piwikSiteId).subscribe();
} }
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.getCommunities(); this.getCommunities();
//this.getDivContents(); //this.getDivContents();
//this.getPageContents(); //this.getPageContents();
}); });
});
} }
private getPageContents() { private getPageContents() {
@ -112,7 +118,7 @@ export class MyCommunitiesComponent {
this.sort(communitiesResults); this.sort(communitiesResults);
var subscribedLoading = communitiesResults.length; var subscribedLoading = communitiesResults.length;
var mail = Session.getUserEmail(); var mail = this.user.email;
communitiesResults.forEach((community, index) => { communitiesResults.forEach((community, index) => {
let showCommunity: boolean = true; let showCommunity: boolean = true;
let isManager: boolean = false; let isManager: boolean = false;
@ -123,7 +129,7 @@ export class MyCommunitiesComponent {
} else { } else {
if (mail == null && community['status'] == "manager") { // no user if (mail == null && community['status'] == "manager") { // no user
showCommunity = false; showCommunity = false;
} else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { } else if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
isManager = true; isManager = true;
} else if (community.managers.indexOf(mail) != -1) { } else if (community.managers.indexOf(mail) != -1) {
isManager = true; isManager = true;

View File

@ -8,11 +8,13 @@ import {ActivatedRoute} from "@angular/router";
import {Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class"; import {Filter, Value} from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
import {SearchFields} from "../../openaireLibrary/utils/properties/searchFields"; import {SearchFields} from "../../openaireLibrary/utils/properties/searchFields";
import {CommunitiesService} from "../../openaireLibrary/connect/communities/communities.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 {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo"; import {CommunityInfo} from "../../openaireLibrary/connect/community/communityInfo";
import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service"; import {SubscribeService} from "../../openaireLibrary/utils/subscribe/subscribe.service";
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class"; import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class"; import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
import {url} from "inspector";
@Component({ @Component({
selector: 'search-communities', selector: 'search-communities',
@ -46,10 +48,12 @@ export class SearchCommunitiesComponent {
public showType = false; public showType = false;
properties:EnvProperties; properties:EnvProperties;
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
private user: User;
constructor (private route: ActivatedRoute, constructor (private route: ActivatedRoute,
private _communitiesService: CommunitiesService, private _communitiesService: CommunitiesService,
private _subscribeService: SubscribeService) { private _subscribeService: SubscribeService,
private userManagementService: UserManagementService) {
this.errorCodes = new ErrorCodes(); this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent(); this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.status = this.errorCodes.LOADING;
@ -77,9 +81,11 @@ export class SearchCommunitiesComponent {
} }
this.searchPage.refineFields = this.refineFields; this.searchPage.refineFields = this.refineFields;
let queryParams = this.searchPage.getQueryParamsFromUrl(params); let queryParams = this.searchPage.getQueryParamsFromUrl(params);
this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.initCommunities(queryParams); this.initCommunities(queryParams);
}); });
});
} }
public ngOnDestroy() { public ngOnDestroy() {
@ -106,12 +112,12 @@ export class SearchCommunitiesComponent {
this.totalResults[i] = data[i]; this.totalResults[i] = data[i];
this.totalResults[i].isManager = false; this.totalResults[i].isManager = false;
this.totalResults[i].isSubscribed = false; this.totalResults[i].isSubscribed = false;
if(Session.isLoggedIn()) { if(this.user) {
this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]); this.totalResults[i].isManager = this.isCommunityManager(this.totalResults[i]);
} }
} }
if(Session.isLoggedIn()) { if(this.user) {
this._subscribeService.getCommunitiesSubscribedTo(this.properties, Session.getUserEmail()).subscribe( this._subscribeService.getCommunitiesSubscribedTo(this.properties, this.user.email).subscribe(
res => { res => {
for (let i = 0; i < this.totalResults.length; i++) { for (let i = 0; i < this.totalResults.length; i++) {
this.totalResults[i].isSubscribed = (res.indexOf(this.totalResults[i].communityId) != -1); this.totalResults[i].isSubscribed = (res.indexOf(this.totalResults[i].communityId) != -1);
@ -161,10 +167,10 @@ export class SearchCommunitiesComponent {
if (result.status == 'hidden') { if (result.status == 'hidden') {
continue; continue;
} else if (result.status == "manager") { } else if (result.status == "manager") {
let mail = Session.getUserEmail(); let mail = this.user.email;
if (mail == null) { // no user if (mail == null) { // no user
continue; continue;
} else if (Session.isCommunityCurator() || Session.isPortalAdministrator()) { } else if (Session.isCommunityCurator(this.user) || Session.isPortalAdministrator(this.user)) {
ret.push(result); ret.push(result);
} else if (result.managers.indexOf(mail) != -1) { } else if (result.managers.indexOf(mail) != -1) {
ret.push(result); ret.push(result);
@ -244,7 +250,7 @@ export class SearchCommunitiesComponent {
let typeResults: CommunityInfo[] = this.applyFilter('type', params); let typeResults: CommunityInfo[] = this.applyFilter('type', params);
let statusResults: CommunityInfo[] = this.results; let statusResults: CommunityInfo[] = this.results;
let roleResults: CommunityInfo[] = this.results; let roleResults: CommunityInfo[] = this.results;
if(Session.isLoggedIn()) { if(this.user) {
statusResults = this.applyFilter('status', params); statusResults = this.applyFilter('status', params);
roleResults = this.applyFilter('role', params); roleResults = this.applyFilter('role', params);
this.resetFilterNumbers('status'); this.resetFilterNumbers('status');
@ -425,7 +431,7 @@ export class SearchCommunitiesComponent {
private isCommunityManager(community: CommunityInfo): boolean { 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 { } else {
filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS.splice(0, 1); filter_original_ids = searchFields.COMMUNITIES_SEARCH_FIELDS.splice(0, 1);
} }
if(Session.isLoggedIn()) { if(this.user) {
filter_names.push("Status"); filter_names.push("Status");
filter_ids.push("status"); filter_ids.push("status");
value_names.push([ "Subscribed", "Non-subscribed"]); 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 {CommunityService} from "../../../openaireLibrary/connect/community/community.service";
import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes'; import {ErrorCodes} from '../../../openaireLibrary/utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../../../openaireLibrary/utils/errorMessages.component'; 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 {HelperFunctions} from "../../../openaireLibrary/utils/HelperFunctions.class";
import {HelperService} from "../../../openaireLibrary/utils/helper/helper.service"; import {HelperService} from "../../../openaireLibrary/utils/helper/helper.service";
import {Meta, Title} from "@angular/platform-browser"; import {Meta, Title} from "@angular/platform-browser";
import {SEOService} from "../../../openaireLibrary/sharedComponents/SEO/SEO.service"; import {SEOService} from "../../../openaireLibrary/sharedComponents/SEO/SEO.service";
import {PiwikService} from "../../../openaireLibrary/utils/piwik/piwik.service"; import {PiwikService} from "../../../openaireLibrary/utils/piwik/piwik.service";
import {PiwikHelper} from "../../piwikHelper"; import {PiwikHelper} from "../../piwikHelper";
import {UserManagementService} from "../../../openaireLibrary/services/user-management.service";
@Component({ @Component({
selector: 'invite', selector: 'invite',
@ -68,6 +69,7 @@ export class InviteComponent implements OnInit {
public url: string = null; public url: string = null;
public pageTitle: string = "Invite"; public pageTitle: string = "Invite";
piwiksub: any; piwiksub: any;
private user: User;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -79,7 +81,8 @@ export class InviteComponent implements OnInit {
private _meta: Meta, private _meta: Meta,
private _title: Title, private _title: Title,
private seoService: SEOService, private seoService: SEOService,
private _piwikService: PiwikService) { private _piwikService: PiwikService,
private userManageService: UserManagementService) {
this.errorCodes = new ErrorCodes(); this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent(); this.errorMessages = new ErrorMessagesComponent();
@ -92,6 +95,8 @@ export class InviteComponent implements OnInit {
this.errorMessage = ""; this.errorMessage = "";
this.missingCommunityId = ""; this.missingCommunityId = "";
this.status = this.errorCodes.LOADING; this.status = this.errorCodes.LOADING;
this.userManageService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.route.queryParams.subscribe( this.route.queryParams.subscribe(
communityId => { communityId => {
//if(!this.communityId && typeof document !== 'undefined'){ //if(!this.communityId && typeof document !== 'undefined'){
@ -100,7 +105,7 @@ export class InviteComponent implements OnInit {
this.communityId = communityId['communityId']; this.communityId = communityId['communityId'];
} }
if(this.longView) { if (this.longView) {
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) { 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.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, PiwikHelper.getSiteId(this.communityId, this.properties.environment)).subscribe();
} }
@ -117,7 +122,7 @@ export class InviteComponent implements OnInit {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe( this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => { community => {
this.community = community; this.community = community;
this.fullname = Session.getUserFullName(); this.fullname = this.user.fullname;
//console.log("Fullname from session " + Session.getUserFullName()); //console.log("Fullname from session " + Session.getUserFullName());
this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname); this.body = Composer.initializeInvitationsBody(this.communityId, this.community.title, this.fullname);
@ -141,10 +146,11 @@ export class InviteComponent implements OnInit {
HelperFunctions.scroll(); HelperFunctions.scroll();
}); });
});
} }
ngOnDestroy() { ngOnDestroy() {
if(this.piwiksub) { if (this.piwiksub) {
this.piwiksub.unsubscribe(); this.piwiksub.unsubscribe();
} }
} }
@ -277,15 +283,15 @@ export class InviteComponent implements OnInit {
} }
*/ */
allowEdit() { allowEdit() {
var email = Session.getUserEmail(); if (!this.user) {
return false;
}
var email = this.user.email;
var index = -1; var index = -1;
if (email && this.community != null && this.community.managers != null) { if (email && this.community != null && this.community.managers != null) {
index = this.community.managers.indexOf(email); index = this.community.managers.indexOf(email);
} }
return Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || index != -1;
return Session.isPortalAdministrator() || Session.isCommunityCurator() || index != -1;
} }
private handleError(message: string, error) { private handleError(message: string, error) {

View File

@ -6,11 +6,12 @@ import {AlertModal} from '../../openaireLibrary/utils/modal/alert';
import {CommunityService} from '../../openaireLibrary/connect/community/community.service'; import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service'; import {SubscribeService} from '../../openaireLibrary/utils/subscribe/subscribe.service';
import {EmailService} from "../../openaireLibrary/utils/email/email.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 {Email} from "../../openaireLibrary/utils/email/email";
import {Composer} from "../../openaireLibrary/utils/email/composer"; import {Composer} from "../../openaireLibrary/utils/email/composer";
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class'; import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
import {UserManagementService} from "../../openaireLibrary/services/user-management.service";
declare var UIkit: any; declare var UIkit: any;
@ -19,15 +20,17 @@ declare var UIkit: any;
template: ` template: `
<span *ngIf="subscribed != null && !showNumbers && showTemplate"> <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> <a class="uk-alert-close" uk-close></a>
<p>Please login first to subscribe</p> <p>Please login first to subscribe</p>
</div> </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' : '')"
<button *ngIf="subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')" (click)="confirmOpen()"> Unsubscribe</button> (click)="subscribe()"> Subscribe</button>
<button *ngIf="subscribed" [class]="'uk-button uk-button-primary' + (loading ? ' uk-disabled' : '')"
(click)="confirmOpen()"> Unsubscribe</button>
</span> </span>
<span *ngIf="showNumbers && subscribers !=null && subscribers > 0 && showTemplate" > <span *ngIf="showNumbers && subscribers !=null && subscribers > 0 && showTemplate">
<span class="lowOpacityColor"> Members</span> {{subscribers}} <span class="lowOpacityColor"> Members</span> {{subscribers}}
</span> </span>
<modal-alert (alertOutput)="confirmClose($event)"> <modal-alert (alertOutput)="confirmClose($event)">
@ -37,24 +40,28 @@ declare var UIkit: any;
export class SubscribeComponent { export class SubscribeComponent {
// @Input() showSubscribe:boolean = true; // @Input() showSubscribe:boolean = true;
@Input() showNumbers:boolean; @Input() showNumbers: boolean;
@Input() communityId:string; @Input() communityId: string;
@Input() showTemplate:boolean = true; @Input() showTemplate: boolean = true;
@Output() subscribeEvent = new EventEmitter(); @Output() subscribeEvent = new EventEmitter();
public community = null; public community = null;
public emailToInformManagers: Email; public emailToInformManagers: Email;
loading: boolean = false; loading: boolean = false;
subscribed:boolean = null; subscribed: boolean = null;
properties:EnvProperties; properties: EnvProperties;
subscribers:number= null; subscribers: number = null;
showLoginAlert:Boolean = false; showLoginAlert: Boolean = false;
@ViewChild(AlertModal) alert; @ViewChild(AlertModal) alert;
constructor (private route: ActivatedRoute, private user: User;
constructor(private route: ActivatedRoute,
private _subscribeService: SubscribeService, private _subscribeService: SubscribeService,
private _emailService: EmailService, private _emailService: EmailService,
private _communityService: CommunityService, private router: Router private _communityService: CommunityService,
private router: Router,
private userManagementService: UserManagementService
) { ) {
} }
@ -62,79 +69,85 @@ export class SubscribeComponent {
this.route.data this.route.data
.subscribe((data: { envSpecific: EnvProperties }) => { .subscribe((data: { envSpecific: EnvProperties }) => {
this.properties = data.envSpecific; this.properties = data.envSpecific;
if(!this.showNumbers){ this.userManagementService.getUserInfo(this.properties.userInfoUrl).subscribe( user => {
let email = Session.getUserEmail(); this.user = user;
if(email == null){ if (!this.showNumbers) {
let email = (this.user)?this.user.email:null;
if (email == null) {
this.subscribed = false; this.subscribed = false;
}else{ } else {
if(this.communityId){ if (this.communityId) {
this._subscribeService.isSubscribedToCommunity(this.properties, this.communityId, email).subscribe ( this._subscribeService.isSubscribedToCommunity(this.properties, this.communityId, email).subscribe(
res => { res => {
this.subscribed = res; this.subscribed = res;
if(this.subscribed){ if (this.subscribed) {
this.subscribeEvent.emit({ this.subscribeEvent.emit({
value: "ok" value: "ok"
}); });
} }
}, },
error => { error => {
this.handleError("Error getting response if email: "+email+" is subscribed to community with id: "+this.communityId, error); this.handleError("Error getting response if email: " + email + " is subscribed to community with id: " + this.communityId, error);
}); });
} }
} }
}else{ } else {
if(this.communityId){ if (this.communityId) {
this._subscribeService.getCommunitySubscribers(this.properties, this.communityId).subscribe ( this._subscribeService.getCommunitySubscribers(this.properties, this.communityId).subscribe(
res => { res => {
this.subscribers = (res && res.subscribers && res.subscribers.length )?res.subscribers.length:0; this.subscribers = (res && res.subscribers && res.subscribers.length) ? res.subscribers.length : 0;
}, },
error => { error => {
this.handleError("Error getting community subscribers for community with id: "+this.communityId, error); this.handleError("Error getting community subscribers for community with id: " + this.communityId, error);
}); });
} }
} }
if(this.communityId){ if (this.communityId) {
this.emailToInformManagers = {body: "", subject: "", recipients: []}; this.emailToInformManagers = {body: "", subject: "", recipients: []};
this._communityService.getCommunity(this.properties, this.properties.communityAPI+this.communityId).subscribe ( this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe(
community => { community => {
this.community = community; this.community = community;
}, },
error => { error => {
//console.log('System error retrieving community profile', error) //console.log('System error retrieving community profile', error)
this.handleError("Error getting community with id: "+this.communityId, error); this.handleError("Error getting community with id: " + this.communityId, error);
} }
); );
} }
}); });
});
} }
subscribe(){ subscribe() {
var email = Session.getUserEmail(); var email = (this.user)?this.user.email:null;
if(email == null){ if (email == null) {
this.subscribed = false; this.subscribed = false;
// this.showLoginAlert = true; // this.showLoginAlert = true;
this.router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.ACTION_REQUIRES_LOGIN, "redirectUrl": this.router.url } }); this.router.navigate(['/user-info'], {
}else{ queryParams: {
"errorCode": LoginErrorCodes.ACTION_REQUIRES_LOGIN,
"redirectUrl": this.router.url
}
});
} else {
this.loading = true; this.loading = true;
this.showLoginAlert = false; this.showLoginAlert = false;
this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe ( this._subscribeService.subscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe(
res => { res => {
this.loading = false; this.loading = false;
if(res.status && res.status != 200) { if (res.status && res.status != 200) {
this.subscribeEvent.emit({ this.subscribeEvent.emit({
value: "error" value: "error"
}); });
UIkit.notification({ UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>', message: '<strong>An error occured. Please try again!<strong>',
status : 'warning', status: 'warning',
timeout : 3000, timeout: 3000,
pos : 'top-center' pos: 'top-center'
}); });
} else { } else {
if(!this.subscribed){ if (!this.subscribed) {
this.subscribed = true; this.subscribed = true;
this.subscribeEvent.emit({ this.subscribeEvent.emit({
value: "ok" value: "ok"
@ -145,7 +158,7 @@ export class SubscribeComponent {
}, },
error => { error => {
//console.log(error) //console.log(error)
this.handleError("Error notifying managers about new subscribers for community with id: "+this.communityId, error); this.handleError("Error notifying managers about new subscribers for community with id: " + this.communityId, error);
} }
); );
} }
@ -157,37 +170,38 @@ export class SubscribeComponent {
value: "error" value: "error"
}); });
UIkit.notification({ UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>', message: '<strong>An error occured. Please try again!<strong>',
status : 'warning', status: 'warning',
timeout : 3000, timeout: 3000,
pos : 'top-center' pos: 'top-center'
}); });
//console.log(error) //console.log(error)
this.handleError("Error subscribing email: "+email+" to community with id: "+this.communityId, error); this.handleError("Error subscribing email: " + email + " to community with id: " + this.communityId, error);
}); });
} }
} }
unsubscribe(){ unsubscribe() {
var email = Session.getUserEmail(); var email = (this.user)?this.user.email:null;
if(email == null){ if (email == null) {
this.subscribed = false; this.subscribed = false;
}else{ } else {
this.loading = true; this.loading = true;
//this.properties.adminToolsAPIURL //this.properties.adminToolsAPIURL
this._subscribeService.unSubscribeToCommunity(this.communityId, email,this.properties.adminToolsAPIURL).subscribe ( this._subscribeService.unSubscribeToCommunity(this.communityId, email, this.properties.adminToolsAPIURL).subscribe(
res => { res => {
this.loading = false; this.loading = false;
if(res.status && res.status != 200) { if (res.status && res.status != 200) {
UIkit.notification({ UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>', message: '<strong>An error occured. Please try again!<strong>',
status : 'warning', status: 'warning',
timeout : 3000, timeout: 3000,
pos : 'top-center' pos: 'top-center'
}); });
} else { } else {
//console.log(res); //console.log(res);
if(this.subscribed){ if (this.subscribed) {
console.log('here')
this.subscribed = false; this.subscribed = false;
} }
} }
@ -195,18 +209,18 @@ export class SubscribeComponent {
error => { error => {
this.loading = false; this.loading = false;
UIkit.notification({ UIkit.notification({
message : '<strong>An error occured. Please try again!<strong>', message: '<strong>An error occured. Please try again!<strong>',
status : 'warning', status: 'warning',
timeout : 3000, timeout: 3000,
pos : 'top-center' pos: 'top-center'
}); });
//console.log(error) //console.log(error)
this.handleError("Error unsubscribing email: "+email+" from community with id: "+this.communityId, error); this.handleError("Error unsubscribing email: " + email + " from community with id: " + this.communityId, error);
}); });
} }
} }
confirmOpen(){ confirmOpen() {
this.alert.cancelButton = true; this.alert.cancelButton = true;
this.alert.okButton = true; this.alert.okButton = true;
@ -216,11 +230,12 @@ export class SubscribeComponent {
this.alert.cancelButtonText = "No"; this.alert.cancelButtonText = "No";
this.alert.open(); this.alert.open();
} }
confirmClose(data){
confirmClose(data) {
this.unsubscribe(); this.unsubscribe();
} }
private handleError(message: string, error) { private handleError(message: string, error) {
console.error("Subscribe (component): "+message, error); console.error("Subscribe (component): " + message, error);
} }
} }

View File

@ -37,7 +37,9 @@
"piwikBaseUrl" :"https://analytics.openaire.eu/piwik.php?idsite=", "piwikBaseUrl" :"https://analytics.openaire.eu/piwik.php?idsite=",
"piwikSiteId" : "80", "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=", "logoutUrl" :"https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",