diff --git a/client/src/app/core/repositories/users/group-repository.service.ts b/client/src/app/core/repositories/users/group-repository.service.ts index e7e4c98ee..042d1e4f1 100644 --- a/client/src/app/core/repositories/users/group-repository.service.ts +++ b/client/src/app/core/repositories/users/group-repository.service.ts @@ -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 { /** * 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 { */ private sortPermsPerApp(): void { this.constants.get('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 { 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 { * 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 = []; diff --git a/client/src/app/site/users/components/group-list/group-list.component.html b/client/src/app/site/users/components/group-list/group-list.component.html index 295a40307..5e09fd5af 100644 --- a/client/src/app/site/users/components/group-list/group-list.component.html +++ b/client/src/app/site/users/components/group-list/group-list.component.html @@ -27,7 +27,7 @@ All your changes are saved immediately. - + diff --git a/client/src/app/site/users/components/group-list/group-list.component.ts b/client/src/app/site/users/components/group-list/group-list.component.ts index 74e592044..1da2ee52e 100644 --- a/client/src/app/site/users/components/group-list/group-list.component.ts +++ b/client/src/app/site/users/components/group-list/group-list.component.ts @@ -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);