From 5015c02355eae5b20e51b6a34b64696717ef6291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Marie=CC=81thoz?= Date: Thu, 18 Jan 2024 11:30:25 +0100 Subject: [PATCH] files: add files permissions to organisations and collections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-by: Johnny MarieĢthoz --- projects/sonar/src/app/app-routing.module.ts | 110 +++++++++---------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/projects/sonar/src/app/app-routing.module.ts b/projects/sonar/src/app/app-routing.module.ts index d399abe..7f4bb64 100644 --- a/projects/sonar/src/app/app-routing.module.ts +++ b/projects/sonar/src/app/app-routing.module.ts @@ -83,6 +83,56 @@ const routes: Routes = [ ] } ]; +const fileConfig = { + enabled: true, + orderList: (a: any, b: any) => { + return a.metadata.order - b.metadata.order; + }, + infoExcludedFields: [ + 'restriction', + 'type', + 'links', + 'thumbnail', + 'permissions', + ], + canAdd: () => of({ can: true, message: '' }), + canRead: (record: any, file: any) => { + if (file && file?.metadata?.permissions?.read) { + return of({ + can: file.metadata.permissions.read, + message: '', + }); + } + return of({ can: false, message: '' }); + }, + canUpdateMetadata: (record: any, file: any) => { + if (file && file?.metadata?.permissions?.update) { + return of({ + can: file.metadata.permissions.update, + message: '', + }); + } + return of({ can: false, message: '' }); + }, + canUpdate: (record: any, file: any) => { + if (file && file?.metadata?.permissions?.update) { + return of({ + can: file.metadata.permissions.update, + message: '', + }); + } + return of({ can: false, message: '' }); + }, + canDelete: (record: any, file: any) => { + if (file && file?.metadata?.permissions?.delete) { + return of({ + can: file.metadata.permissions.delete, + message: '', + }); + } + return of({ can: false, message: '' }); + }, +} @NgModule({ imports: [RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })], @@ -209,62 +259,14 @@ export class AppRoutingModule { editorSettings: { longMode: true, }, - files: { - enabled: true, + files: {...fileConfig, filterList: (item: any) => { return ( item.metadata && item.metadata.type && item.metadata.type === 'file' ); - }, - orderList: (a: any, b: any) => { - return a.metadata.order - b.metadata.order; - }, - infoExcludedFields: [ - 'restriction', - 'type', - 'links', - 'thumbnail', - 'permissions', - ], - canAdd: () => of({ can: true, message: '' }), - canRead: (record: any, file: any) => { - if (file && file?.metadata?.permissions?.read) { - return of({ - can: file.metadata.permissions.read, - message: '', - }); - } - return of({ can: false, message: '' }); - }, - canUpdateMetadata: (record: any, file: any) => { - if (file && file?.metadata?.permissions?.update) { - return of({ - can: file.metadata.permissions.update, - message: '', - }); - } - return of({ can: false, message: '' }); - }, - canUpdate: (record: any, file: any) => { - if (file && file?.metadata?.permissions?.update) { - return of({ - can: file.metadata.permissions.update, - message: '', - }); - } - return of({ can: false, message: '' }); - }, - canDelete: (record: any, file: any) => { - if (file && file?.metadata?.permissions?.delete) { - return of({ - can: file.metadata.permissions.delete, - message: '', - }); - } - return of({ can: false, message: '' }); - }, + } }, searchFields: [ { @@ -318,9 +320,7 @@ export class AppRoutingModule { type: 'organisations', briefView: OrganisationComponent, detailView: OrganisationDetailComponent, - files: { - enabled: true, - }, + files: fileConfig, sortOptions: [ { label: _('Relevance'), @@ -400,9 +400,7 @@ export class AppRoutingModule { label: 'Collections', briefView: CollectionBriefViewComponent, detailView: CollectionDetailComponent, - files: { - enabled: true, - }, + files: fileConfig, editorSettings: { longMode: true, },