Adds restrictions on DMP edit view when user not creator.

This commit is contained in:
gkolokythas 2019-12-19 15:48:24 +02:00
parent 462f6dcb61
commit 4daa6c4eb2
7 changed files with 36 additions and 15 deletions

View File

@ -13,16 +13,16 @@
<mat-icon class="more-horiz">more_horiz</mat-icon> <mat-icon class="more-horiz">more_horiz</mat-icon>
</button> </button>
<mat-menu #actionsMenu="matMenu"> <mat-menu #actionsMenu="matMenu">
<button mat-menu-item *ngIf="!isPublic" (click)="newVersion(dmp.id, dmp.label)"> <button mat-menu-item *ngIf="!isPublic && isUserOwner" (click)="newVersion(dmp.id, dmp.label)">
<mat-icon>queue</mat-icon>{{'DMP-LISTING.ACTIONS.NEW-VERSION' | translate}} <mat-icon>queue</mat-icon>{{'DMP-LISTING.ACTIONS.NEW-VERSION' | translate}}
</button> </button>
<button mat-menu-item *ngIf="!isPublic" (click)="viewVersions(dmp.groupId, dmp.label)"> <button mat-menu-item *ngIf="!isPublic" (click)="viewVersions(dmp.groupId, dmp.label)">
<mat-icon>library_books</mat-icon>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}} <mat-icon>library_books</mat-icon>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}}
</button> </button>
<button mat-menu-item (click)="clone(dmp.id)" class="menu-item"> <button mat-menu-item *ngIf="!isPublic" (click)="clone(dmp.id)" class="menu-item">
<mat-icon>add</mat-icon>{{ 'DMP-LISTING.ACTIONS.CLONE' | translate }} <mat-icon>add</mat-icon>{{ 'DMP-LISTING.ACTIONS.CLONE' | translate }}
</button> </button>
<button mat-menu-item (click)="delete()" class="menu-item"> <button mat-menu-item *ngIf="!isPublic && isUserOwner" (click)="delete()" class="menu-item">
<mat-icon>delete</mat-icon>{{ 'DMP-LISTING.ACTIONS.DELETE' | translate }} <mat-icon>delete</mat-icon>{{ 'DMP-LISTING.ACTIONS.DELETE' | translate }}
</button> </button>
</mat-menu> </mat-menu>
@ -58,14 +58,14 @@
<i class="material-icons-outlined mr-2">view_agenda</i> <i class="material-icons-outlined mr-2">view_agenda</i>
{{ 'SIDE-BAR.GENERAL' | translate }} {{ 'SIDE-BAR.GENERAL' | translate }}
</ng-template> </ng-template>
<app-general-tab [formGroup]="formGroup"></app-general-tab> <app-general-tab [formGroup]="formGroup" [isUserOwner]="isUserOwner"></app-general-tab>
</mat-tab> </mat-tab>
<mat-tab> <mat-tab>
<ng-template mat-tab-label> <ng-template mat-tab-label>
<mat-icon class="mr-2">work_outline</mat-icon> <mat-icon class="mr-2">work_outline</mat-icon>
{{ 'DMP-LISTING.COLUMNS.GRANT' | translate }} {{ 'DMP-LISTING.COLUMNS.GRANT' | translate }}
</ng-template> </ng-template>
<app-grant-tab [grantformGroup]="formGroup.get('grant')" [projectFormGroup]="formGroup.get('project')" [funderFormGroup]="formGroup.get('funder')" [isFinalized]="isFinalized" [isNew]="isNew"></app-grant-tab> <app-grant-tab [grantformGroup]="formGroup.get('grant')" [projectFormGroup]="formGroup.get('project')" [funderFormGroup]="formGroup.get('funder')" [isFinalized]="isFinalized" [isNew]="isNew" [isUserOwner]="isUserOwner"></app-grant-tab>
</mat-tab> </mat-tab>
<mat-tab *ngIf="!isNew"> <mat-tab *ngIf="!isNew">
<ng-template mat-tab-label> <ng-template mat-tab-label>

View File

@ -4,7 +4,6 @@ import { FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Params, Router } from '@angular/router'; import { ActivatedRoute, Params, Router } from '@angular/router';
import { DmpStatus } from '@app/core/common/enum/dmp-status'; import { DmpStatus } from '@app/core/common/enum/dmp-status';
import { Status } from '@app/core/common/enum/Status';
import { DataTableRequest } from '@app/core/model/data-table/data-table-request'; import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
import { DmpProfileDefinition } from '@app/core/model/dmp-profile/dmp-profile'; import { DmpProfileDefinition } from '@app/core/model/dmp-profile/dmp-profile';
import { DmpProfileListing } from '@app/core/model/dmp-profile/dmp-profile-listing'; import { DmpProfileListing } from '@app/core/model/dmp-profile/dmp-profile-listing';
@ -35,7 +34,8 @@ import { TranslateService } from '@ngx-translate/core';
import * as FileSaver from 'file-saver'; import * as FileSaver from 'file-saver';
import { Observable, of as observableOf } from 'rxjs'; import { Observable, of as observableOf } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators'; import { map, takeUntil } from 'rxjs/operators';
import { Guid } from '@common/types/guid'; import { Principal } from "@app/core/model/auth/Principal";
import { Role } from "@app/core/common/enum/role";
@Component({ @Component({
selector: 'app-dmp-editor-component', selector: 'app-dmp-editor-component',
@ -61,6 +61,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
filteredOptions: DmpProfileListing[]; filteredOptions: DmpProfileListing[];
selectedDmpProfileDefinition: DmpProfileDefinition; selectedDmpProfileDefinition: DmpProfileDefinition;
DynamicDmpFieldResolverComponent: any; DynamicDmpFieldResolverComponent: any;
isUserOwner: boolean = true;
constructor( constructor(
private dmpProfileService: DmpProfileService, private dmpProfileService: DmpProfileService,
@ -70,6 +71,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
private language: TranslateService, private language: TranslateService,
private dialog: MatDialog, private dialog: MatDialog,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private authentication: AuthService,
private authService: AuthService, private authService: AuthService,
private formService: FormService private formService: FormService
) { ) {
@ -108,6 +110,11 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
this.dmp.funder = new FunderFormModel(); this.dmp.funder = new FunderFormModel();
this.dmp.fromModel(data); this.dmp.fromModel(data);
this.formGroup = this.dmp.buildForm(); this.formGroup = this.dmp.buildForm();
this.setIsUserOwner();
if (this.isUserOwner) {
this.isFinalized = true;
this.formGroup.disable();
}
//this.registerFormEventsForDmpProfile(this.dmp.definition); //this.registerFormEventsForDmpProfile(this.dmp.definition);
if (!this.editMode || this.dmp.status === DmpStatus.Finalized) { if (!this.editMode || this.dmp.status === DmpStatus.Finalized) {
this.isFinalized = true; this.isFinalized = true;
@ -201,6 +208,13 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
return this.authService.current() != null; return this.authService.current() != null;
} }
setIsUserOwner() {
if (this.dmp) {
const principal: Principal = this.authentication.current();
this.isUserOwner = principal.id === this.dmp.users.find(x => x.role === Role.Owner).id;
}
}
registerFormEventsForNewItem() { registerFormEventsForNewItem() {
this.breadCrumbs = observableOf([ this.breadCrumbs = observableOf([
{ {

View File

@ -26,6 +26,7 @@ export class DynamicDmpFieldResolverComponent implements OnInit, OnDestroy {
@Input() dmpProfileId: string; @Input() dmpProfileId: string;
@Input() dmpProfileDefinition: DmpProfileDefinition; @Input() dmpProfileDefinition: DmpProfileDefinition;
@Input() formGroup: FormGroup; @Input() formGroup: FormGroup;
@Input() isUserOwner: boolean;
constructor( constructor(
private dmpProfileService: DmpProfileService private dmpProfileService: DmpProfileService

View File

@ -68,7 +68,7 @@
</app-single-auto-complete> </app-single-auto-complete>
</mat-form-field> </mat-form-field>
</div> </div>
<app-dynamic-dmp-field-resolver *ngIf="selectedDmpProfileDefinition" [formGroup]="formGroup" [dmpProfileDefinition]="selectedDmpProfileDefinition" [dmpProfileId]="formGroup.get('profile').value.id"> <app-dynamic-dmp-field-resolver *ngIf="selectedDmpProfileDefinition" [formGroup]="formGroup" [dmpProfileDefinition]="selectedDmpProfileDefinition" [dmpProfileId]="formGroup.get('profile').value.id" [isUserOwner]="isUserOwner">
</app-dynamic-dmp-field-resolver> </app-dynamic-dmp-field-resolver>
</div> </div>

View File

@ -30,6 +30,7 @@ export class GeneralTabComponent extends BaseComponent implements OnInit {
@Input() formGroup: FormGroup = null; @Input() formGroup: FormGroup = null;
@Input() isNewVersion: boolean; @Input() isNewVersion: boolean;
@Input() isUserOwner: boolean;
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterProfiles.bind(this), filterFn: this.filterProfiles.bind(this),
@ -80,6 +81,10 @@ export class GeneralTabComponent extends BaseComponent implements OnInit {
if (this.isNewVersion) { if (this.isNewVersion) {
this.formGroup.get('label').disable(); this.formGroup.get('label').disable();
} }
if (!this.isUserOwner) {
this.formGroup.disable();
}
} }
registerFormEventsForDmpProfile(definitionProperties?: DmpProfileDefinition): void { registerFormEventsForDmpProfile(definitionProperties?: DmpProfileDefinition): void {

View File

@ -24,7 +24,7 @@
<!-- Toggle Between Add Funder or Use Existing --> <!-- Toggle Between Add Funder or Use Existing -->
<div class="col d-flex"> <div class="col d-flex">
<div class="row" *ngIf="!isFinalized"> <div class="row" *ngIf="!isFinalized && isUserOwner">
<div class="col-12 add-entity" *ngIf="isCreateNewFunder" (click)="createFunder()"> <div class="col-12 add-entity" *ngIf="isCreateNewFunder" (click)="createFunder()">
<mat-icon>settings_backup_restore</mat-icon> <mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}}</span> <span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}}</span>
@ -63,7 +63,7 @@
<!-- Toggle Between Add Grant or Use Existing --> <!-- Toggle Between Add Grant or Use Existing -->
<div class="col d-flex"> <div class="col d-flex">
<div class="row" *ngIf="!isFinalized"> <div class="row" *ngIf="!isFinalized && isUserOwner">
<div class="col-12 add-entity" *ngIf="isCreateNew" (click)="createGrant()"> <div class="col-12 add-entity" *ngIf="isCreateNew" (click)="createGrant()">
<mat-icon>settings_backup_restore</mat-icon> <mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}}</span> <span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}}</span>
@ -104,7 +104,7 @@
<!-- Toggle Between Add Project or Use Existing --> <!-- Toggle Between Add Project or Use Existing -->
<div class="col d-flex"> <div class="col d-flex">
<div class="row" *ngIf="!isFinalized"> <div class="row" *ngIf="!isFinalized && isUserOwner">
<div class="col-12 add-entity" *ngIf="isCreateNewProject" (click)="createProject()"> <div class="col-12 add-entity" *ngIf="isCreateNewProject" (click)="createProject()">
<mat-icon>settings_backup_restore</mat-icon> <mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-PROJECT' | translate}}</span> <span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-PROJECT' | translate}}</span>

View File

@ -26,6 +26,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
@Input() isFinalized: boolean; @Input() isFinalized: boolean;
@Input() isNewVersion: boolean; @Input() isNewVersion: boolean;
@Input() isNew: boolean; @Input() isNew: boolean;
@Input() isUserOwner: boolean;
isCreateNew = false; isCreateNew = false;
isCreateNewProject = false; isCreateNewProject = false;
@ -143,7 +144,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('existGrant').disable();
this.grantformGroup.get('label').enable(); this.grantformGroup.get('label').enable();
this.grantformGroup.get('description').enable(); this.grantformGroup.get('description').enable();
} else if (this.isFinalized || this.isNewVersion) { } else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) {
this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('existGrant').disable();
this.grantformGroup.get('label').disable(); this.grantformGroup.get('label').disable();
this.grantformGroup.get('description').disable(); this.grantformGroup.get('description').disable();
@ -161,7 +162,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
this.projectFormGroup.get('existProject').disable(); this.projectFormGroup.get('existProject').disable();
this.projectFormGroup.get('label').enable(); this.projectFormGroup.get('label').enable();
this.projectFormGroup.get('description').enable(); this.projectFormGroup.get('description').enable();
} else if (this.isFinalized || this.isNewVersion) { } else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) {
this.projectFormGroup.get('existProject').disable(); this.projectFormGroup.get('existProject').disable();
this.projectFormGroup.get('label').disable(); this.projectFormGroup.get('label').disable();
this.projectFormGroup.get('description').disable(); this.projectFormGroup.get('description').disable();
@ -178,7 +179,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
if (this.isCreateNewFunder) { if (this.isCreateNewFunder) {
this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('existFunder').disable();
this.funderFormGroup.get('label').enable(); this.funderFormGroup.get('label').enable();
} else if (this.isFinalized || this.isNewVersion) { } else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) {
this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('existFunder').disable();
this.funderFormGroup.get('label').disable(); this.funderFormGroup.get('label').disable();
} else { } else {