From 9c286c3451e4705f0591e5f05902b36adaa60c23 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 5 Oct 2021 18:15:04 +0300 Subject: [PATCH] Home remove link if user has not permission to visit a specific dashboard, search stakeholders open visibility filter. --- src/app/home/home.component.html | 42 ++++---- src/app/home/home.component.ts | 13 ++- src/app/openaireLibrary | 2 +- .../search-stakeholders.component.ts | 96 ++++++++----------- src/assets/common-assets | 2 +- 5 files changed, 70 insertions(+), 85 deletions(-) diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index d73d83b..e7085d4 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -186,32 +186,17 @@
- +
-
- - {{stakeholder.visibility.toLowerCase()}} -
- - -
{{stakeholder.name}}
+
- -
-
- - {{stakeholder.visibility.toLowerCase()}} -
- - -
{{stakeholder.name}}
-
+
+ + + +
@@ -242,3 +227,16 @@ You will be navigated to a new tab. Are you sure that you want to proceed?
+ +
+
+ + {{stakeholder.visibility.toLowerCase()}} +
+ + +
{{stakeholder.name}}
+
+
diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 4393802..25807d3 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -244,7 +244,6 @@ export class HomeComponent { this.subscriberErrorMessage = ""; this.subscriptions.push(this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe( stakeholders => { - stakeholders = stakeholders.filter(stakeholder => stakeholder.visibility !== 'PRIVATE'); if (!stakeholders || stakeholders.length == 0) { this.status = this.errorCodes.NONE; } else { @@ -259,8 +258,12 @@ export class HomeComponent { )); } - private isStakeholderManager() { - return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user); + private isManager(stakeholder: Stakeholder) { + return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user); + } + + private isMember(stakeholder: Stakeholder) { + return Session.isMember(stakeholder.type, stakeholder.alias, this.user); } public confirmModalOpen(result: Stakeholder) { @@ -301,6 +304,10 @@ export class HomeComponent { this.clearTimeouts(); } + hasPermission(stakeholder: Stakeholder) { + return stakeholder.visibility === "PUBLIC" || this.isManager(stakeholder) || this.isMember(stakeholder); + } + private handleError(message: string, error): number { var code = ""; if (!error.status) { diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index 18dd137..0b3e699 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit 18dd1379ad151d4988d7c58ae63a8ad8bfad5602 +Subproject commit 0b3e699796585c12ed06744d69a0e95e7629aa63 diff --git a/src/app/search-stakeholders/search-stakeholders.component.ts b/src/app/search-stakeholders/search-stakeholders.component.ts index e79cf45..dc2de78 100644 --- a/src/app/search-stakeholders/search-stakeholders.component.ts +++ b/src/app/search-stakeholders/search-stakeholders.component.ts @@ -61,10 +61,9 @@ export class SearchStakeholdersComponent { public keyword = ""; public searchLink; properties: EnvProperties = properties; - @ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent; + @ViewChild(NewSearchPageComponent, {static: true}) searchPage: NewSearchPageComponent; private user: User; - private userFilterLoaded: boolean = false; - + constructor(private route: ActivatedRoute, private _stakeholderService: StakeholderService, private userManagementService: UserManagementService) { @@ -72,7 +71,7 @@ export class SearchStakeholdersComponent { this.errorMessages = new ErrorMessagesComponent(); this.searchUtils.status = this.errorCodes.LOADING; } - + public ngOnInit() { this.piwikSiteId = this.properties.piwikSiteId; this.baseUrl = this.properties.searchLinkToStakeholders; @@ -92,8 +91,7 @@ export class SearchStakeholdersComponent { this.searchLink = this.properties.searchLinkToStakeholders; this.selectedFields = []; this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "stakeholder", null); - - let queryParams = params;//this.searchPage.getQueryParamsFromUrl(params); + let queryParams = params; if (typeof document !== 'undefined') { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.user = user; @@ -104,7 +102,7 @@ export class SearchStakeholdersComponent { } })); } - + ngOnDestroy() { this.subscriptions.forEach(subscription => { if (subscription instanceof Subscriber) { @@ -112,8 +110,8 @@ export class SearchStakeholdersComponent { } }); } - - + + /** * Initialize stakeholders from Communities APIs * @@ -125,11 +123,10 @@ export class SearchStakeholdersComponent { if (!data) { return; } - data = data.filter(stakeholder => stakeholder.visibility !== 'PRIVATE'); for (let i = 0; i < data.length; i++) { this.totalResults[i] = data[i]; - this.totalResults[i].isManager = this.isStakeholderManager(data[i]); - this.totalResults[i].isMember = this.isStakeholderMember(data[i]); + this.totalResults[i].isManager = this.isManager(data[i]); + this.totalResults[i].isMember = this.isMember(data[i]); } this._getResults(params); }, @@ -140,8 +137,8 @@ export class SearchStakeholdersComponent { } )); } - - + + /** * Get all stakeholders from mock API and apply permission access validator, * keyword searching, filter, paging and sorting. @@ -157,22 +154,7 @@ export class SearchStakeholdersComponent { this.searchUtils.totalResults = 0; this.applyParams(params); } - - /** - * Return the stakeholders in which user has permission to view or manage. - */ - private showFunders() { - let ret = []; - for (let result of this.results) { - if(result.visibility === 'PUBLIC' || - (result.visibility === 'RESTRICTED' && this.isStakeholderMember(result)) - ) { - ret.push(result); - } - } - this.results = ret; - } - + /** * Apply permission access validator, * keyword searching, filter, paging and sorting. @@ -181,7 +163,6 @@ export class SearchStakeholdersComponent { * @param status */ public applyParams(params) { - this.showFunders(); if (this.keyword && this.keyword != '') { this.searchForKeywords(); } @@ -207,8 +188,8 @@ export class SearchStakeholdersComponent { } } } - - + + /** * Parse the given keywords into array and check if any of the requirements field of a funder includes * one of the given words. @@ -228,7 +209,7 @@ export class SearchStakeholdersComponent { } this.results = ret; } - + /** * Check the current results if they satisfy the values of each filter category and * update the number of possible results in each value. @@ -239,13 +220,13 @@ export class SearchStakeholdersComponent { let typeResults: StakeholderInfo[] = this.applyFilter('type', params); let accessResults: StakeholderInfo[] = this.results; let roleResults: StakeholderInfo[] = this.results; + accessResults = this.applyFilter('access', params); + roleResults = this.applyFilter('role', params); + this.resetFilterNumbers('access'); + this.updateFilterNumbers(typeResults.filter(value => { + return roleResults.includes(value); + }), 'access'); if (this.user) { - accessResults = this.applyFilter('access', params); - roleResults = this.applyFilter('role', params); - this.resetFilterNumbers('access'); - this.updateFilterNumbers(typeResults.filter(value => { - return roleResults.includes(value); - }), 'access'); this.resetFilterNumbers('role'); this.updateFilterNumbers(accessResults.filter(value => { return typeResults.includes(value); @@ -262,7 +243,7 @@ export class SearchStakeholdersComponent { return roleResults.includes(value); }); } - + /** * Apply filter with filterId and return the results * @@ -337,7 +318,7 @@ export class SearchStakeholdersComponent { } return results; } - + /** * Reset the values of filter with id filterId with zero. * @@ -353,7 +334,7 @@ export class SearchStakeholdersComponent { } } } - + /** * Update the values of filter with id filterId based on * results. @@ -392,7 +373,7 @@ export class SearchStakeholdersComponent { } } } - + /** * Sorting results based on sortBy. */ @@ -429,16 +410,16 @@ export class SearchStakeholdersComponent { }) } } - - private isStakeholderManager(stakeholder) { + + private isManager(stakeholder) { return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user); } - - private isStakeholderMember(stakeholder) { - return this.isStakeholderManager(stakeholder) || Session.isSubscribedTo(stakeholder.type, stakeholder.alias, this.user); + + private isMember(stakeholder) { + return this.isManager(stakeholder) || Session.isSubscribedTo(stakeholder.type, stakeholder.alias, this.user); } - + /** * Create Search Stakeholder filters. * @@ -452,16 +433,15 @@ export class SearchStakeholdersComponent { filter_ids.push("type"); value_names.push(["Funders", "Research Initiatives", "Organizations"]); value_original_ids.push(["funder", "ri", "organization"]); - if (this.user) { - filter_names.push("Accessibility"); - filter_ids.push("access"); - value_names.push(["Public", "Restricted"]); - value_original_ids.push(["public", "restricted"]); + filter_names.push("Accessibility"); + filter_ids.push("access"); + value_names.push(["Public", "Restricted"]); + value_original_ids.push(["public", "restricted"]); + if(this.user) { filter_names.push("Role"); filter_ids.push("role"); value_names.push(["Manager", "Member"]); value_original_ids.push(["manager", "member"]); - this.userFilterLoaded = true; } let filters: Filter[] = []; for (let i = 0; i < filter_names.length; i++) { @@ -484,9 +464,9 @@ export class SearchStakeholdersComponent { } return filters; } - + private handleError(message: string, error) { console.error('Communities Search Page: ' + message, error); } - + } diff --git a/src/assets/common-assets b/src/assets/common-assets index 10dbbb5..3637903 160000 --- a/src/assets/common-assets +++ b/src/assets/common-assets @@ -1 +1 @@ -Subproject commit 10dbbb5610afa279837add9be683938e86acd659 +Subproject commit 363790356aeb20339fab6d36516864ab44931dd7