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"
uk-grid="masonry: true" uk-height-match="target: .uk-card; row: false;">
<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 *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>
<ng-container *ngTemplateOutlet="stakeholderCard; context: {stakeholder: stakeholder}"></ng-container>
</div>
</a>
<a *ngIf="!directLink" (click)="confirmModalOpen(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>
<a *ngIf="!directLink && hasPermission(stakeholder)" (click)="confirmModalOpen(stakeholder)">
<ng-container *ngTemplateOutlet="stakeholderCard; context: {stakeholder: stakeholder}"></ng-container>
</a>
<ng-container *ngIf="!hasPermission(stakeholder)">
<ng-container *ngTemplateOutlet="stakeholderCard; context: {stakeholder: stakeholder}"></ng-container>
</ng-container>
</div>
<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">
@ -242,3 +227,16 @@
You will be navigated to a new tab. Are you sure that you want to proceed?
</div>
</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.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) {

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

View File

@ -61,9 +61,8 @@ 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,
@ -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;
@ -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);
},
@ -158,21 +155,6 @@ export class SearchStakeholdersComponent {
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();
}
@ -239,13 +220,13 @@ export class SearchStakeholdersComponent {
let typeResults: StakeholderInfo[] = this.applyFilter('type', params);
let accessResults: StakeholderInfo[] = this.results;
let roleResults: StakeholderInfo[] = this.results;
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');
if (this.user) {
this.resetFilterNumbers('role');
this.updateFilterNumbers(accessResults.filter(value => {
return typeResults.includes(value);
@ -430,13 +411,13 @@ 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);
}
/**
@ -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"]);
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++) {

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