From 99d0b4ac5e933eb1f00800ec349a1b6a65c2c6ae Mon Sep 17 00:00:00 2001 From: amirch1 Date: Wed, 18 Dec 2024 10:29:28 +0200 Subject: [PATCH] fix: permissions check for rooms and documents KMCNG-2691 --- .../document/document.component.html | 2 +- .../document/document.component.ts | 29 +++++++++++-------- .../documents-table.component.html | 4 +-- .../documents-table.component.ts | 29 ++++++++++++------- .../rooms-table/rooms-table.component.html | 6 ++-- .../rooms-table/rooms-table.component.ts | 22 +++++++++----- 6 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/applications/content-documents-app/document/document.component.html b/src/applications/content-documents-app/document/document.component.html index a86d6ccc9..602092619 100644 --- a/src/applications/content-documents-app/document/document.component.html +++ b/src/applications/content-documents-app/document/document.component.html @@ -11,7 +11,7 @@ - diff --git a/src/applications/content-documents-app/documents/documents-table/documents-table.component.ts b/src/applications/content-documents-app/documents/documents-table/documents-table.component.ts index 67f8319bf..ea99b3af9 100644 --- a/src/applications/content-documents-app/documents/documents-table/documents-table.component.ts +++ b/src/applications/content-documents-app/documents/documents-table/documents-table.component.ts @@ -13,7 +13,7 @@ import {Menu} from 'primeng/menu'; import {KalturaDocumentEntry} from 'kaltura-ngx-client'; import {AppLocalization} from '@kaltura-ng/mc-shared'; import {globalConfig} from 'config/global'; -import {KMCPermissionsService} from 'app-shared/kmc-shared/kmc-permissions'; +import {KMCPermissions, KMCPermissionsService} from 'app-shared/kmc-shared/kmc-permissions'; import {ColumnsResizeManagerService, ResizableColumnsTableName} from 'app-shared/kmc-shared/columns-resize-manager'; import {MenuItem} from 'primeng/api'; import {AnalyticsNewMainViewService} from "app-shared/kmc-shared/kmc-views"; @@ -55,6 +55,7 @@ export class DocumentsTableComponent implements AfterViewInit, OnInit, OnDestroy public _documents: KalturaDocumentEntry[] = []; public _items: MenuItem[]; public _defaultSortOrder = globalConfig.client.views.tables.defaultSortOrder; + public _showActionsColumn = true; public rowTrackBy: Function = (index: number, item: any) => item.id; public _loadThumbnailWithKs = false; @@ -67,6 +68,9 @@ export class DocumentsTableComponent implements AfterViewInit, OnInit, OnDestroy private _analyticsNewMainViewService: AnalyticsNewMainViewService, private _cdRef: ChangeDetectorRef, private _el: ElementRef) { + this._showActionsColumn = this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA) || + this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DELETE) || + this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD); } ngOnInit() { @@ -101,27 +105,32 @@ export class DocumentsTableComponent implements AfterViewInit, OnInit, OnDestroy } buildMenu(document: KalturaDocumentEntry): void { - this._items = [ - { + this._items = []; + if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA)) { + this._items.push({ id: 'view', label: this._appLocalization.get('applications.content.table.view'), command: () => this.onActionSelected('view', document) - }, - { + }); + } + if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD)) { + this._items.push({ id: 'download', label: this._appLocalization.get('applications.content.table.download'), command: () => this.onActionSelected('download', document) - }, - { - id: 'delete', + }); + } + if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DELETE)) { + this._items.push({ label: this._appLocalization.get('applications.content.table.delete'), styleClass: 'kDanger', command: () => this.onActionSelected('delete', document) - } - ]; + }); + } } onActionSelected(action: string, document: KalturaDocumentEntry) { + if (action === 'view' && !this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA)) return; this.actionSelected.emit({'action': action, 'document': document}); } diff --git a/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.html b/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.html index 1e351eaa6..60ec94be7 100644 --- a/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.html +++ b/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.html @@ -19,7 +19,7 @@ - + @@ -36,7 +36,7 @@ {{'applications.content.table.createdOn' | translate}} - + @@ -69,7 +69,7 @@ - +
diff --git a/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.ts b/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.ts index b6a3a81a5..f8b305089 100644 --- a/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.ts +++ b/src/applications/content-rooms-app/rooms/rooms-table/rooms-table.component.ts @@ -13,7 +13,7 @@ import {Menu} from 'primeng/menu'; import {KalturaBaseEntry, KalturaRoomEntry} from 'kaltura-ngx-client'; import {AppLocalization} from '@kaltura-ng/mc-shared'; import {globalConfig} from 'config/global'; -import {KMCPermissionsService} from 'app-shared/kmc-shared/kmc-permissions'; +import {KMCPermissions, KMCPermissionsService} from 'app-shared/kmc-shared/kmc-permissions'; import {ColumnsResizeManagerService, ResizableColumnsTableName} from 'app-shared/kmc-shared/columns-resize-manager'; import {MenuItem} from 'primeng/api'; import {AnalyticsNewMainViewService} from "app-shared/kmc-shared/kmc-views"; @@ -54,7 +54,7 @@ export class RoomsTableComponent implements AfterViewInit, OnInit, OnDestroy { public _rooms: KalturaRoomEntry[] = []; public _items: MenuItem[]; public _defaultSortOrder = globalConfig.client.views.tables.defaultSortOrder; - + public _showActionsColumn = true; public rowTrackBy: Function = (index: number, item: any) => item.id; constructor(public _columnsResizeManager: ColumnsResizeManagerService, @@ -63,6 +63,8 @@ export class RoomsTableComponent implements AfterViewInit, OnInit, OnDestroy { private _analyticsNewMainViewService: AnalyticsNewMainViewService, private _cdRef: ChangeDetectorRef, private _el: ElementRef) { + this._showActionsColumn = this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA) || + this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD); } ngOnInit() { @@ -95,22 +97,26 @@ export class RoomsTableComponent implements AfterViewInit, OnInit, OnDestroy { } buildMenu(room: KalturaRoomEntry): void { - this._items = [ - { + this._items = []; + if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA)) { + this._items.push({ id: 'view', label: this._appLocalization.get('applications.content.table.view'), command: () => this.onActionSelected('view', room) - }, - { + }); + } + if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DELETE)) { + this._items.push({ id: 'delete', label: this._appLocalization.get('applications.content.table.delete'), styleClass: 'kDanger', command: () => this.onActionSelected('delete', room) - } - ]; + }); + } } onActionSelected(action: string, room: KalturaRoomEntry) { + if (action === 'view' && !this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA)) return; this.actionSelected.emit({'action': action, 'room': room}); }