Merge pull request #4867 from tsiegleauq/file-manager-permissions

Add permissions to media files
This commit is contained in:
Sean 2019-07-23 11:19:48 +02:00 committed by GitHub
commit e28f0f6685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 18 deletions

View File

@ -42,14 +42,17 @@
mat-button mat-button
[matMenuTriggerFor]="singleMediafileMenu" [matMenuTriggerFor]="singleMediafileMenu"
[matMenuTriggerData]="{ mediafile: directory }" [matMenuTriggerData]="{ mediafile: directory }"
*ngIf="last" *ngIf="last && showFileMenu(directory)"
> >
<os-icon-container icon="arrow_drop_down" swap="true" size="large"> <os-icon-container icon="arrow_drop_down" swap="true" size="large">
{{ directory.title }} {{ directory.title }}
</os-icon-container> </os-icon-container>
</button> </button>
<span class="folder fake-folder folder-text" *ngIf="last && !showFileMenu(directory)">
{{ directory.title }}
</span> </span>
<span class="visibility" *ngIf="directory && directory.inherited_access_groups_id !== true"> </span>
<span class="visibility" *ngIf="canEdit && directory && directory.inherited_access_groups_id !== true">
<span class="visible-for" *ngIf="directory.has_inherited_access_groups" translate> <span class="visible-for" *ngIf="directory.has_inherited_access_groups" translate>
<os-icon-container <os-icon-container
icon="visibility" icon="visibility"
@ -66,7 +69,14 @@
</div> </div>
<!-- the actual file manager --> <!-- the actual file manager -->
<pbl-ngrid class="file-manager-table ngrid-hide-head" showHeader="false" vScrollAuto [dataSource]="dataSource" [columns]="columnSet"> <pbl-ngrid
class="file-manager-table ngrid-hide-head"
showHeader="false"
vScrollAuto
[dataSource]="dataSource"
[columns]="columnSet"
[hideColumns]="hiddenColumns"
>
<!-- Icon column --> <!-- Icon column -->
<div *pblNgridCellDef="'icon'; row as mediafile" class="fill clickable"> <div *pblNgridCellDef="'icon'; row as mediafile" class="fill clickable">
<a class="detail-link" target="_blank" [routerLink]="mediafile.url" *ngIf="mediafile.is_file"> </a> <a class="detail-link" target="_blank" [routerLink]="mediafile.url" *ngIf="mediafile.is_file"> </a>
@ -110,12 +120,13 @@
</div> </div>
</div> </div>
<!-- Indicator column --> <!-- Menu column -->
<div *pblNgridCellDef="'menu'; row as mediafile" class="fill"> <div *pblNgridCellDef="'menu'; row as mediafile" class="fill">
<button <button
mat-icon-button mat-icon-button
[matMenuTriggerFor]="singleMediafileMenu" [matMenuTriggerFor]="singleMediafileMenu"
[matMenuTriggerData]="{ mediafile: mediafile }" [matMenuTriggerData]="{ mediafile: mediafile }"
*ngIf="showFileMenu(mediafile)"
> >
<mat-icon>more_vert</mat-icon> <mat-icon>more_vert</mat-icon>
</button> </button>
@ -136,7 +147,7 @@
<mat-menu #singleMediafileMenu="matMenu"> <mat-menu #singleMediafileMenu="matMenu">
<ng-template matMenuContent let-mediafile="mediafile"> <ng-template matMenuContent let-mediafile="mediafile">
<!-- Exclusive for images --> <!-- Exclusive for images -->
<div *ngIf="mediafile.isImage()"> <div *ngIf="mediafile.isImage() && canEdit">
<div *ngFor="let action of logoActions"> <div *ngFor="let action of logoActions">
<ng-container <ng-container
*ngTemplateOutlet="manageButton; context: { mediafile: mediafile, action: action }" *ngTemplateOutlet="manageButton; context: { mediafile: mediafile, action: action }"
@ -145,7 +156,7 @@
</div> </div>
<!-- Exclusive for fonts --> <!-- Exclusive for fonts -->
<div *ngIf="mediafile.isFont()"> <div *ngIf="mediafile.isFont() && canEdit">
<div *ngFor="let action of fontActions"> <div *ngFor="let action of fontActions">
<ng-container <ng-container
*ngTemplateOutlet="manageButton; context: { mediafile: mediafile, action: action }" *ngTemplateOutlet="manageButton; context: { mediafile: mediafile, action: action }"
@ -161,6 +172,7 @@
[menuItem]="true" [menuItem]="true"
></os-projector-button> ></os-projector-button>
<os-speaker-button [object]="mediafile" [menuItem]="true"></os-speaker-button> <os-speaker-button [object]="mediafile" [menuItem]="true"></os-speaker-button>
<div *ngIf="canEdit">
<button mat-menu-item (click)="onEditFile(mediafile)"> <button mat-menu-item (click)="onEditFile(mediafile)">
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
<span translate>Edit</span> <span translate>Edit</span>
@ -173,6 +185,7 @@
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
<span translate>Delete</span> <span translate>Delete</span>
</button> </button>
</div>
</ng-template> </ng-template>
</mat-menu> </mat-menu>

View File

@ -24,6 +24,10 @@
height: $size; height: $size;
} }
.fake-folder {
padding: 0 16px;
}
.folder-text { .folder-text {
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;

View File

@ -70,6 +70,17 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit,
return this.operator.hasPerms('mediafiles.can_manage'); return this.operator.hasPerms('mediafiles.can_manage');
} }
/**
* Determine if the file menu should generally be accessible, according to the users permission
*/
public get canAccessFileMenu(): boolean {
return (
this.operator.hasPerms('core.can_manage_projector') ||
this.operator.hasPerms('agenda.can_see_list_of_speakers') ||
this.canEdit
);
}
/** /**
* The form to edit Files * The form to edit Files
*/ */
@ -82,6 +93,22 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit,
@ViewChild('fileEditDialog', { static: true }) @ViewChild('fileEditDialog', { static: true })
public fileEditDialog: TemplateRef<string>; public fileEditDialog: TemplateRef<string>;
/**
* Determine generally hidden columns
*/
public get hiddenColumns(): string[] {
const hidden = [];
if (!this.canEdit) {
hidden.push('info');
}
if (!this.canAccessFileMenu) {
hidden.push('menu');
}
return hidden;
}
/** /**
* Create the column set * Create the column set
*/ */
@ -194,6 +221,19 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit,
this.clearSubscriptions(); this.clearSubscriptions();
} }
/**
* Determine if the given file has any extra option to show.
* @param file the file to check
* @returns wether the extra menu should be accessible
*/
public showFileMenu(file: ViewMediafile): boolean {
return (
this.operator.hasPerms('agenda.can_see_list_of_speakers') ||
(file.isProjectable() && this.operator.hasPerms('core.can_manage_projector')) ||
this.canEdit
);
}
public getDateFromTimestamp(timestamp: string): string { public getDateFromTimestamp(timestamp: string): string {
return new Date(timestamp).toLocaleString(this.translate.currentLang); return new Date(timestamp).toLocaleString(this.translate.currentLang);
} }