RED-3394: Dossier hard delete permissions

This commit is contained in:
Adina Țeudan 2022-02-10 12:58:07 +02:00
parent da8369173f
commit 4672c58703
3 changed files with 16 additions and 3 deletions

View File

@ -34,7 +34,7 @@
<iqser-circle-button
(action)="hardDelete()"
*ngIf="listingService.areSomeSelected$ | async"
*ngIf="canHardDeleteSelected$ | async"
[tooltip]="'trash.bulk.delete' | translate"
[type]="circleButtonTypes.dark"
icon="iqser:trash"
@ -88,6 +88,7 @@
<iqser-circle-button
(action)="hardDelete([entity])"
*ngIf="entity.canHardDelete"
[tooltip]="'trash.action.delete' | translate"
[type]="circleButtonTypes.dark"
icon="iqser:trash"

View File

@ -20,9 +20,11 @@ import { distinctUntilChanged, map } from 'rxjs/operators';
import { getLeftDateTime } from '@utils/functions';
import { RouterHistoryService } from '@services/router-history.service';
import { IDossier } from '@red/domain';
import { PermissionsService } from '@services/permissions.service';
interface DossierListItem extends IDossier, IListable {
readonly canRestore: boolean;
readonly canHardDelete: boolean;
readonly restoreDate: string;
}
@ -36,6 +38,7 @@ export class TrashScreenComponent extends ListingComponent<DossierListItem> impl
readonly circleButtonTypes = CircleButtonTypes;
readonly tableHeaderLabel = _('trash.table-header.title');
readonly canRestoreSelected$ = this._canRestoreSelected$;
readonly canHardDeleteSelected$ = this._canHardDeleteSelected$;
readonly tableColumnConfigs: TableColumnConfig<DossierListItem>[] = [
{ label: _('trash.table-col-names.name'), sortByKey: 'searchKey' },
{ label: _('trash.table-col-names.owner'), class: 'user-column' },
@ -46,6 +49,7 @@ export class TrashScreenComponent extends ListingComponent<DossierListItem> impl
constructor(
protected readonly _injector: Injector,
private readonly _loadingService: LoadingService,
private readonly _permissionsService: PermissionsService,
private readonly _dossiersService: DossiersService,
readonly routerHistoryService: RouterHistoryService,
private readonly _configService: ConfigService,
@ -61,6 +65,13 @@ export class TrashScreenComponent extends ListingComponent<DossierListItem> impl
);
}
private get _canHardDeleteSelected$(): Observable<boolean> {
return this.listingService.selectedEntities$.pipe(
map(entities => entities.length && !entities.find(dossier => !dossier.canHardDelete)),
distinctUntilChanged(),
);
}
disabledFn = (dossier: DossierListItem) => !dossier.canRestore;
async ngOnInit(): Promise<void> {
@ -118,6 +129,7 @@ export class TrashScreenComponent extends ListingComponent<DossierListItem> impl
searchKey: dossier.dossierName,
restoreDate,
canRestore: this._canRestoreDossier(restoreDate),
canHardDelete: this._permissionsService.canDeleteDossier(dossier),
// Because of migrations, for some this is not set
softDeletedTime: dossier.softDeletedTime || '-',
};

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { UserService } from './user.service';
import { Dossier, File, IComment } from '@red/domain';
import { Dossier, File, IComment, IDossier } from '@red/domain';
import { DossiersService } from './entity-services/dossiers.service';
@Injectable({
@ -127,7 +127,7 @@ export class PermissionsService {
return this.isApprover(dossier) && files.reduce((prev, file) => prev && file.isApproved, true);
}
canDeleteDossier(dossier: Dossier): boolean {
canDeleteDossier(dossier: IDossier): boolean {
return dossier.ownerId === this._userService.currentUser.id;
}