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>
</button>
<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}}
</button>
<button mat-menu-item *ngIf="!isPublic" (click)="viewVersions(dmp.groupId, dmp.label)">
<mat-icon>library_books</mat-icon>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}}
</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 }}
</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 }}
</button>
</mat-menu>
@ -58,14 +58,14 @@
<i class="material-icons-outlined mr-2">view_agenda</i>
{{ 'SIDE-BAR.GENERAL' | translate }}
</ng-template>
<app-general-tab [formGroup]="formGroup"></app-general-tab>
<app-general-tab [formGroup]="formGroup" [isUserOwner]="isUserOwner"></app-general-tab>
</mat-tab>
<mat-tab>
<ng-template mat-tab-label>
<mat-icon class="mr-2">work_outline</mat-icon>
{{ 'DMP-LISTING.COLUMNS.GRANT' | translate }}
</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 *ngIf="!isNew">
<ng-template mat-tab-label>

View File

@ -4,7 +4,6 @@ import { FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Params, Router } from '@angular/router';
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 { DmpProfileDefinition } from '@app/core/model/dmp-profile/dmp-profile';
import { DmpProfileListing } from '@app/core/model/dmp-profile/dmp-profile-listing';
@ -19,7 +18,7 @@ import { AuthService } from '@app/core/services/auth/auth.service';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { DmpEditorModel } from '@app/ui/dmp/editor/dmp-editor.model';
import { DmpFinalizeDialogComponent, DmpFinalizeDialogInput } from '@app/ui/dmp/editor/dmp-finalize-dialog/dmp-finalize-dialog.component';
import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model';
@ -35,7 +34,8 @@ import { TranslateService } from '@ngx-translate/core';
import * as FileSaver from 'file-saver';
import { Observable, of as observableOf } from 'rxjs';
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({
selector: 'app-dmp-editor-component',
@ -61,6 +61,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
filteredOptions: DmpProfileListing[];
selectedDmpProfileDefinition: DmpProfileDefinition;
DynamicDmpFieldResolverComponent: any;
isUserOwner: boolean = true;
constructor(
private dmpProfileService: DmpProfileService,
@ -70,6 +71,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
private language: TranslateService,
private dialog: MatDialog,
private uiNotificationService: UiNotificationService,
private authentication: AuthService,
private authService: AuthService,
private formService: FormService
) {
@ -108,6 +110,11 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
this.dmp.funder = new FunderFormModel();
this.dmp.fromModel(data);
this.formGroup = this.dmp.buildForm();
this.setIsUserOwner();
if (this.isUserOwner) {
this.isFinalized = true;
this.formGroup.disable();
}
//this.registerFormEventsForDmpProfile(this.dmp.definition);
if (!this.editMode || this.dmp.status === DmpStatus.Finalized) {
this.isFinalized = true;
@ -201,6 +208,13 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC
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() {
this.breadCrumbs = observableOf([
{

View File

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

View File

@ -68,7 +68,7 @@
</app-single-auto-complete>
</mat-form-field>
</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>
</div>

View File

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

View File

@ -24,7 +24,7 @@
<!-- Toggle Between Add Funder or Use Existing -->
<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()">
<mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}}</span>
@ -63,7 +63,7 @@
<!-- Toggle Between Add Grant or Use Existing -->
<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()">
<mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}}</span>
@ -104,7 +104,7 @@
<!-- Toggle Between Add Project or Use Existing -->
<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()">
<mat-icon>settings_backup_restore</mat-icon>
<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() isNewVersion: boolean;
@Input() isNew: boolean;
@Input() isUserOwner: boolean;
isCreateNew = false;
isCreateNewProject = false;
@ -143,7 +144,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
this.grantformGroup.get('existGrant').disable();
this.grantformGroup.get('label').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('label').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('label').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('label').disable();
this.projectFormGroup.get('description').disable();
@ -178,7 +179,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
if (this.isCreateNewFunder) {
this.funderFormGroup.get('existFunder').disable();
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('label').disable();
} else {