Home remove link if user has not permission to visit a specific dashboard, search stakeholders open visibility filter.

This commit is contained in:
Konstantinos Triantafyllou 2021-10-05 18:15:04 +03:00
parent 386fe30ff7
commit 9c286c3451
5 changed files with 70 additions and 85 deletions

View File

@ -186,32 +186,17 @@
<div class="stakeholders uk-margin-large-top uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-3@m uk-grid uk-flex-top uk-flex-wrap-top" <div class="stakeholders uk-margin-large-top uk-child-width-1-1 uk-child-width-1-2@s uk-child-width-1-3@m uk-grid uk-flex-top uk-flex-wrap-top"
uk-grid="masonry: true" uk-height-match="target: .uk-card; row: false;"> uk-grid="masonry: true" uk-height-match="target: .uk-card; row: false;">
<div *ngFor="let stakeholder of stakeholders" [attr.data-type]="stakeholder.type"> <div *ngFor="let stakeholder of stakeholders" [attr.data-type]="stakeholder.type">
<a *ngIf="directLink" [href]="getStakeholderPageUrl(stakeholder)" target="_blank"> <a *ngIf="directLink && hasPermission(stakeholder)" [href]="getStakeholderPageUrl(stakeholder)" target="_blank">
<div class="uk-card uk-card-default uk-text-center uk-position-relative"> <div class="uk-card uk-card-default uk-text-center uk-position-relative">
<div *ngIf="stakeholder.visibility && stakeholder.visibility !== 'PUBLIC'" <ng-container *ngTemplateOutlet="stakeholderCard; context: {stakeholder: stakeholder}"></ng-container>
class="uk-position-top-right uk-margin-top uk-margin-right uk-flex uk-flex-middle">
<icon [name]="visibilityIcon.get(stakeholder.visibility)"></icon>
<span class="space uk-text-small uk-text-capitalize">{{stakeholder.visibility.toLowerCase()}}</span>
</div>
<img *ngIf="stakeholder.logoUrl && stakeholder.isUpload" class="uk-margin-auto"
[src]="properties.utilsService + '/download/' + stakeholder.logoUrl">
<img *ngIf="stakeholder.logoUrl && !stakeholder.isUpload" class="uk-margin-auto" [src]="stakeholder.logoUrl | urlPrefix">
<div class="uk-text-light uk-margin-medium-top">{{stakeholder.name}}</div>
</div> </div>
</a> </a>
<a *ngIf="!directLink" (click)="confirmModalOpen(stakeholder)"> <a *ngIf="!directLink && hasPermission(stakeholder)" (click)="confirmModalOpen(stakeholder)">
<div class="uk-card uk-card-default uk-text-center"> <ng-container *ngTemplateOutlet="stakeholderCard; context: {stakeholder: stakeholder}"></ng-container>
<div *ngIf="stakeholder.visibility && stakeholder.visibility !== 'PUBLIC'"
class="uk-position-top-right uk-margin-top uk-margin-right uk-flex uk-flex-middle">
<icon [name]="visibilityIcon.get(stakeholder.visibility)"></icon>
<span class="space uk-text-small uk-text-capitalize">{{stakeholder.visibility.toLowerCase()}}</span>
</div>
<img *ngIf="stakeholder.logoUrl && stakeholder.isUpload" class="uk-margin-auto"
[src]="properties.utilsService + '/download/' + stakeholder.logoUrl">
<img *ngIf="stakeholder.logoUrl && !stakeholder.isUpload" class="uk-margin-auto" [src]="stakeholder.logoUrl | urlPrefix">
<div class="uk-text-light uk-margin-medium-top">{{stakeholder.name}}</div>
</div>
</a> </a>
<ng-container *ngIf="!hasPermission(stakeholder)">
<ng-container *ngTemplateOutlet="stakeholderCard; context: {stakeholder: stakeholder}"></ng-container>
</ng-container>
</div> </div>
<div *ngIf="stakeholdersNumber === 0" [attr.data-type]="type" <div *ngIf="stakeholdersNumber === 0" [attr.data-type]="type"
class="uk-text-center uk-text-large uk-width-1-1 uk-margin-large-top uk-padding-large"> class="uk-text-center uk-text-large uk-width-1-1 uk-margin-large-top uk-padding-large">
@ -242,3 +227,16 @@
You will be navigated to a new tab. Are you sure that you want to proceed? You will be navigated to a new tab. Are you sure that you want to proceed?
</div> </div>
</modal-alert> </modal-alert>
<ng-template #stakeholderCard let-stakeholder="stakeholder">
<div class="uk-card uk-card-default uk-text-center">
<div *ngIf="stakeholder.visibility && stakeholder.visibility !== 'PUBLIC'"
class="uk-position-top-right uk-margin-top uk-margin-right uk-flex uk-flex-middle">
<icon [name]="visibilityIcon.get(stakeholder.visibility)"></icon>
<span class="space uk-text-small uk-text-capitalize">{{stakeholder.visibility.toLowerCase()}}</span>
</div>
<img *ngIf="stakeholder.logoUrl && stakeholder.isUpload" class="uk-margin-auto"
[src]="properties.utilsService + '/download/' + stakeholder.logoUrl">
<img *ngIf="stakeholder.logoUrl && !stakeholder.isUpload" class="uk-margin-auto" [src]="stakeholder.logoUrl | urlPrefix">
<div class="uk-text-light uk-margin-medium-top">{{stakeholder.name}}</div>
</div>
</ng-template>

View File

@ -244,7 +244,6 @@ export class HomeComponent {
this.subscriberErrorMessage = ""; this.subscriberErrorMessage = "";
this.subscriptions.push(this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe( this.subscriptions.push(this._stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL).subscribe(
stakeholders => { stakeholders => {
stakeholders = stakeholders.filter(stakeholder => stakeholder.visibility !== 'PRIVATE');
if (!stakeholders || stakeholders.length == 0) { if (!stakeholders || stakeholders.length == 0) {
this.status = this.errorCodes.NONE; this.status = this.errorCodes.NONE;
} else { } else {
@ -259,8 +258,12 @@ export class HomeComponent {
)); ));
} }
private isStakeholderManager() { private isManager(stakeholder: Stakeholder) {
return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user); 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) { public confirmModalOpen(result: Stakeholder) {
@ -301,6 +304,10 @@ export class HomeComponent {
this.clearTimeouts(); this.clearTimeouts();
} }
hasPermission(stakeholder: Stakeholder) {
return stakeholder.visibility === "PUBLIC" || this.isManager(stakeholder) || this.isMember(stakeholder);
}
private handleError(message: string, error): number { private handleError(message: string, error): number {
var code = ""; var code = "";
if (!error.status) { if (!error.status) {

@ -1 +1 @@
Subproject commit 18dd1379ad151d4988d7c58ae63a8ad8bfad5602 Subproject commit 0b3e699796585c12ed06744d69a0e95e7629aa63

View File

@ -61,10 +61,9 @@ export class SearchStakeholdersComponent {
public keyword = ""; public keyword = "";
public searchLink; public searchLink;
properties: EnvProperties = properties; properties: EnvProperties = properties;
@ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent; @ViewChild(NewSearchPageComponent, {static: true}) searchPage: NewSearchPageComponent;
private user: User; private user: User;
private userFilterLoaded: boolean = false;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private _stakeholderService: StakeholderService, private _stakeholderService: StakeholderService,
private userManagementService: UserManagementService) { private userManagementService: UserManagementService) {
@ -72,7 +71,7 @@ export class SearchStakeholdersComponent {
this.errorMessages = new ErrorMessagesComponent(); this.errorMessages = new ErrorMessagesComponent();
this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.status = this.errorCodes.LOADING;
} }
public ngOnInit() { public ngOnInit() {
this.piwikSiteId = this.properties.piwikSiteId; this.piwikSiteId = this.properties.piwikSiteId;
this.baseUrl = this.properties.searchLinkToStakeholders; this.baseUrl = this.properties.searchLinkToStakeholders;
@ -92,8 +91,7 @@ export class SearchStakeholdersComponent {
this.searchLink = this.properties.searchLinkToStakeholders; this.searchLink = this.properties.searchLinkToStakeholders;
this.selectedFields = []; this.selectedFields = [];
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "stakeholder", null); this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, null, params, "stakeholder", null);
let queryParams = params;
let queryParams = params;//this.searchPage.getQueryParamsFromUrl(params);
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user; this.user = user;
@ -104,7 +102,7 @@ export class SearchStakeholdersComponent {
} }
})); }));
} }
ngOnDestroy() { ngOnDestroy() {
this.subscriptions.forEach(subscription => { this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) { if (subscription instanceof Subscriber) {
@ -112,8 +110,8 @@ export class SearchStakeholdersComponent {
} }
}); });
} }
/** /**
* Initialize stakeholders from Communities APIs * Initialize stakeholders from Communities APIs
* *
@ -125,11 +123,10 @@ export class SearchStakeholdersComponent {
if (!data) { if (!data) {
return; return;
} }
data = data.filter(stakeholder => stakeholder.visibility !== 'PRIVATE');
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
this.totalResults[i] = data[i]; this.totalResults[i] = data[i];
this.totalResults[i].isManager = this.isStakeholderManager(data[i]); this.totalResults[i].isManager = this.isManager(data[i]);
this.totalResults[i].isMember = this.isStakeholderMember(data[i]); this.totalResults[i].isMember = this.isMember(data[i]);
} }
this._getResults(params); this._getResults(params);
}, },
@ -140,8 +137,8 @@ export class SearchStakeholdersComponent {
} }
)); ));
} }
/** /**
* Get all stakeholders from mock API and apply permission access validator, * Get all stakeholders from mock API and apply permission access validator,
* keyword searching, filter, paging and sorting. * keyword searching, filter, paging and sorting.
@ -157,22 +154,7 @@ export class SearchStakeholdersComponent {
this.searchUtils.totalResults = 0; this.searchUtils.totalResults = 0;
this.applyParams(params); 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, * Apply permission access validator,
* keyword searching, filter, paging and sorting. * keyword searching, filter, paging and sorting.
@ -181,7 +163,6 @@ export class SearchStakeholdersComponent {
* @param status * @param status
*/ */
public applyParams(params) { public applyParams(params) {
this.showFunders();
if (this.keyword && this.keyword != '') { if (this.keyword && this.keyword != '') {
this.searchForKeywords(); 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 * Parse the given keywords into array and check if any of the requirements field of a funder includes
* one of the given words. * one of the given words.
@ -228,7 +209,7 @@ export class SearchStakeholdersComponent {
} }
this.results = ret; this.results = ret;
} }
/** /**
* Check the current results if they satisfy the values of each filter category and * Check the current results if they satisfy the values of each filter category and
* update the number of possible results in each value. * update the number of possible results in each value.
@ -239,13 +220,13 @@ export class SearchStakeholdersComponent {
let typeResults: StakeholderInfo[] = this.applyFilter('type', params); let typeResults: StakeholderInfo[] = this.applyFilter('type', params);
let accessResults: StakeholderInfo[] = this.results; let accessResults: StakeholderInfo[] = this.results;
let roleResults: 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) { 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.resetFilterNumbers('role');
this.updateFilterNumbers(accessResults.filter(value => { this.updateFilterNumbers(accessResults.filter(value => {
return typeResults.includes(value); return typeResults.includes(value);
@ -262,7 +243,7 @@ export class SearchStakeholdersComponent {
return roleResults.includes(value); return roleResults.includes(value);
}); });
} }
/** /**
* Apply filter with filterId and return the results * Apply filter with filterId and return the results
* *
@ -337,7 +318,7 @@ export class SearchStakeholdersComponent {
} }
return results; return results;
} }
/** /**
* Reset the values of filter with id filterId with zero. * 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 * Update the values of filter with id filterId based on
* results. * results.
@ -392,7 +373,7 @@ export class SearchStakeholdersComponent {
} }
} }
} }
/** /**
* Sorting results based on sortBy. * 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) return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user)
|| Session.isCommunityCurator(this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user); || Session.isCommunityCurator(this.user) || Session.isManager(stakeholder.type, stakeholder.alias, this.user);
} }
private isStakeholderMember(stakeholder) { private isMember(stakeholder) {
return this.isStakeholderManager(stakeholder) || Session.isSubscribedTo(stakeholder.type, stakeholder.alias, this.user); return this.isManager(stakeholder) || Session.isSubscribedTo(stakeholder.type, stakeholder.alias, this.user);
} }
/** /**
* Create Search Stakeholder filters. * Create Search Stakeholder filters.
* *
@ -452,16 +433,15 @@ export class SearchStakeholdersComponent {
filter_ids.push("type"); filter_ids.push("type");
value_names.push(["Funders", "Research Initiatives", "Organizations"]); value_names.push(["Funders", "Research Initiatives", "Organizations"]);
value_original_ids.push(["funder", "ri", "organization"]); value_original_ids.push(["funder", "ri", "organization"]);
if (this.user) { filter_names.push("Accessibility");
filter_names.push("Accessibility"); filter_ids.push("access");
filter_ids.push("access"); value_names.push(["Public", "Restricted"]);
value_names.push(["Public", "Restricted"]); value_original_ids.push(["public", "restricted"]);
value_original_ids.push(["public", "restricted"]); if(this.user) {
filter_names.push("Role"); filter_names.push("Role");
filter_ids.push("role"); filter_ids.push("role");
value_names.push(["Manager", "Member"]); value_names.push(["Manager", "Member"]);
value_original_ids.push(["manager", "member"]); value_original_ids.push(["manager", "member"]);
this.userFilterLoaded = true;
} }
let filters: Filter[] = []; let filters: Filter[] = [];
for (let i = 0; i < filter_names.length; i++) { for (let i = 0; i < filter_names.length; i++) {
@ -484,9 +464,9 @@ export class SearchStakeholdersComponent {
} }
return filters; return filters;
} }
private handleError(message: string, error) { private handleError(message: string, error) {
console.error('Communities Search Page: ' + message, error); console.error('Communities Search Page: ' + message, error);
} }
} }

@ -1 +1 @@
Subproject commit 10dbbb5610afa279837add9be683938e86acd659 Subproject commit 363790356aeb20339fab6d36516864ab44931dd7