Merge pull request #4721 from FinnStutzenstein/fixPermissionSorting

Fix sorting of permissions if plugins are available
This commit is contained in:
Finn Stutzenstein 2019-05-20 17:20:38 +02:00 committed by GitHub
commit e4dfd75ab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -22,7 +22,7 @@ interface Permission {
/**
* Set rules to define the shape of an app permission
*/
interface AppPermission {
export interface AppPermissions {
name: string;
permissions: Permission[];
}
@ -39,7 +39,7 @@ export class GroupRepositoryService extends BaseRepository<ViewGroup, Group> {
/**
* holds sorted permissions per app.
*/
public appPermissions: AppPermission[] = [];
public appPermissions: AppPermissions[] = [];
/**
* Constructor calls the parent constructor
@ -107,6 +107,7 @@ export class GroupRepositoryService extends BaseRepository<ViewGroup, Group> {
*/
private sortPermsPerApp(): void {
this.constants.get<any>('permissions').subscribe(perms => {
let pluginCounter = 0;
for (const perm of perms) {
// extract the apps name
const permApp = perm.value.split('.')[0];
@ -135,12 +136,20 @@ export class GroupRepositoryService extends BaseRepository<ViewGroup, Group> {
break;
default:
// plugins
const displayName = `${permApp.charAt(0).toUpperCase}${permApp.slice(1)}`;
// check if the plugin exists as app
const displayName = `${permApp.charAt(0).toUpperCase()}${permApp.slice(1)}`;
// check if the plugin exists as app. The appPermissions array might have empty
// entries, so pay attention in the findIndex below.
const result = this.appPermissions.findIndex(app => {
return app.name === displayName;
return app ? app.name === displayName : false;
});
const pluginId = result === -1 ? this.appPermissions.length : result;
let pluginId: number;
if (result >= 0) {
pluginId = result;
} else {
// Ensure plugins to be behind the 7 core apps.
pluginId = pluginCounter + 7;
pluginCounter++;
}
this.addAppPerm(pluginId, perm, displayName);
break;
}
@ -156,8 +165,8 @@ export class GroupRepositoryService extends BaseRepository<ViewGroup, Group> {
* order, we could simply reverse the whole permissions.
*/
private sortPermsByPower(): void {
this.appPermissions.forEach((app: AppPermission, index: number) => {
if (index === 5) {
this.appPermissions.forEach((app: AppPermissions) => {
if (app.name === 'Users') {
app.permissions.reverse();
} else {
const see = [];

View File

@ -27,7 +27,7 @@
<span translate>All your changes are saved immediately.</span>
</div>
<mat-accordion *ngFor="let app of repo.appPermissions">
<mat-accordion *ngFor="let app of appPermissions">
<mat-expansion-panel class="mat-elevation-z0" [expanded]=true>
<mat-expansion-panel-header>
<mat-panel-title>

View File

@ -4,7 +4,7 @@ import { TranslateService } from '@ngx-translate/core';
import { MatTableDataSource, MatSnackBar } from '@angular/material';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { GroupRepositoryService } from 'app/core/repositories/users/group-repository.service';
import { GroupRepositoryService, AppPermissions } from 'app/core/repositories/users/group-repository.service';
import { ViewGroup } from '../../models/view-group';
import { Group } from 'app/shared/models/users/group';
import { BaseViewComponent } from '../../../base/base-view';
@ -47,6 +47,10 @@ export class GroupListComponent extends BaseViewComponent implements OnInit {
@ViewChild('groupForm')
public groupForm: FormGroup;
public get appPermissions(): AppPermissions[] {
return this.repo.appPermissions;
}
/**
* Constructor
*
@ -60,7 +64,7 @@ export class GroupListComponent extends BaseViewComponent implements OnInit {
titleService: Title,
protected translate: TranslateService, // protected required for ng-translate-extract
matSnackBar: MatSnackBar,
public repo: GroupRepositoryService,
private repo: GroupRepositoryService,
private promptService: PromptService
) {
super(titleService, translate, matSnackBar);