Skip to content

Commit

Permalink
fix: permissions check for rooms and documents KMCNG-2691
Browse files Browse the repository at this point in the history
  • Loading branch information
amirch1 committed Dec 18, 2024
1 parent cbd44ca commit 99d0b4a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- *ngIf="_analyticsAllowed"-->
<!-- [label]="'applications.content.entries.viewAnalytics' | translate"-->
<!-- (click)="_openRoomAnalytics()"></button>-->
<button type="button" pButton class="kButtonDefault kEntryActions" icon="kIconmore"
<button *ngIf="_showActions" type="button" pButton class="kButtonDefault kEntryActions" icon="kIconmore"
(click)="actionsmenu.toggle($event)"></button>
<button pButton class="kButtonBranded kSaveBtn"
[label]="'app.common.save' | translate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,9 @@ export class DocumentComponent implements OnInit, OnDestroy {
public _analyticsAllowed = false;
public _enablePrevButton: boolean;
public _enableNextButton: boolean;
public _items: CustomMenuItem[] = [
{
label: this._appLocalization.get('applications.content.table.download'),
commandName: 'download',
styleClass: ''
},
{
label: this._appLocalization.get('applications.content.table.delete'),
commandName: 'delete',
styleClass: 'kDanger'
}
];
public _items: CustomMenuItem[] = [];
public _menuItems: CustomMenuItem[] = [];
public _showActions = true;

public get _enableSaveBtn(): boolean {
return this._documentStore.documentIsDirty; // TODO [kmc] check for room update permissions once added to the backend
Expand Down Expand Up @@ -94,6 +84,21 @@ export class DocumentComponent implements OnInit, OnDestroy {
}

ngOnInit() {
this._showActions = this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD) || this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DELETE);
if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD)) {
this._items.push({
label: this._appLocalization.get('applications.content.table.download'),
commandName: 'download',
styleClass: ''
});
}
if (this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DELETE)) {
this._items.push({
label: this._appLocalization.get('applications.content.table.delete'),
commandName: 'delete',
styleClass: 'kDanger'
});
}
let errorMessage;
this._documentStore.notifications$
.pipe(cancelOnDestroy(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<th data-cid="status" [ngStyle]="{'width': '160px'}" pResizableColumn>
{{'applications.content.table.status' | translate}}
</th>
<th [ngStyle]="{'width': '80px'}"></th>
<th *ngIf="_showActionsColumn" [ngStyle]="{'width': '80px'}"></th>
</tr>
</ng-template>

Expand Down Expand Up @@ -80,7 +80,7 @@
</span>
</td>

<td [ngStyle]="{'width': '80px'}">
<td *ngIf="_showActionsColumn" [ngStyle]="{'width': '80px'}">
<div class="kDocumentsTableActions">
<button class="kMoreActionsButton" type="button" pButton icon="kIconmore" (click)="openActionsMenu($event, document)"></button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -67,6 +68,9 @@ export class DocumentsTableComponent implements AfterViewInit, OnInit, OnDestroy
private _analyticsNewMainViewService: AnalyticsNewMainViewService,
private _cdRef: ChangeDetectorRef,
private _el: ElementRef<HTMLElement>) {
this._showActionsColumn = this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA) ||
this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DELETE) ||
this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD);
}

ngOnInit() {
Expand Down Expand Up @@ -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});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<col data-cid="name">
<col data-cid="roomId" [ngStyle]="{'width': '160px'}">
<col data-cid="createdAt" [ngStyle]="{'width': '180px'}">
<col [ngStyle]="{'width': '80px'}">
<col *ngIf="_showActionsColumn" [ngStyle]="{'width': '80px'}">
</colgroup>
</ng-template>
<ng-template pTemplate="header">
Expand All @@ -36,7 +36,7 @@
{{'applications.content.table.createdOn' | translate}}
<p-sortIcon [field]="'createdAt'"></p-sortIcon>
</th>
<th [ngStyle]="{'width': '80px'}"></th>
<th *ngIf="_showActionsColumn" [ngStyle]="{'width': '80px'}"></th>
</tr>
</ng-template>

Expand Down Expand Up @@ -69,7 +69,7 @@
</span>
</td>

<td [ngStyle]="{'width': '80px'}">
<td *ngIf="_showActionsColumn" [ngStyle]="{'width': '80px'}">
<div class="kRoomsTableActions">
<button class="kMoreActionsButton" type="button" pButton icon="kIconmore" (click)="openActionsMenu($event, room)"></button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -63,6 +63,8 @@ export class RoomsTableComponent implements AfterViewInit, OnInit, OnDestroy {
private _analyticsNewMainViewService: AnalyticsNewMainViewService,
private _cdRef: ChangeDetectorRef,
private _el: ElementRef<HTMLElement>) {
this._showActionsColumn = this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_METADATA) ||
this._permissionsService.hasPermission(KMCPermissions.CONTENT_MANAGE_DOWNLOAD);
}

ngOnInit() {
Expand Down Expand Up @@ -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});
}

Expand Down

0 comments on commit 99d0b4a

Please sign in to comment.