Add history permission into client

Requires the permission "core.can_see_history" to see the history in the navigation.
Disables navigating in the timeline and clearing the history for everyone than than the super admin
This commit is contained in:
Sean Engelhardt 2019-02-21 11:40:56 +01:00
parent d06a4a5c6d
commit a86af342eb
3 changed files with 25 additions and 14 deletions

View File

@ -4,7 +4,10 @@
<!-- Menu --> <!-- Menu -->
<div class="menu-slot"> <div class="menu-slot">
<button type="button" mat-icon-button [matMenuTriggerFor]="historyMenu"><mat-icon>more_vert</mat-icon></button> <!-- Hidden for everyone but the superadmin -->
<button *osPerms="'superadmin'" type="button" mat-icon-button [matMenuTriggerFor]="historyMenu">
<mat-icon>more_vert</mat-icon>
</button>
</div> </div>
</os-head-bar> </os-head-bar>

View File

@ -10,6 +10,7 @@ import { History } from 'app/shared/models/core/history';
import { HistoryRepositoryService } from 'app/core/repositories/history/history-repository.service'; import { HistoryRepositoryService } from 'app/core/repositories/history/history-repository.service';
import { isDetailNavigable } from 'app/shared/models/base/detail-navigable'; import { isDetailNavigable } from 'app/shared/models/base/detail-navigable';
import { ListViewBaseComponent } from 'app/site/base/list-view-base'; import { ListViewBaseComponent } from 'app/site/base/list-view-base';
import { OperatorService } from 'app/core/core-services/operator.service';
import { ViewHistory } from '../../models/view-history'; import { ViewHistory } from '../../models/view-history';
import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service';
@ -36,6 +37,9 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
* @param translate Handle translations * @param translate Handle translations
* @param matSnackBar Showing errors and messages * @param matSnackBar Showing errors and messages
* @param repo The history repository * @param repo The history repository
* @param viewModelStore Access view models
* @param router route to pages
* @param operator checks if the user is a super admin
*/ */
public constructor( public constructor(
titleService: Title, titleService: Title,
@ -43,7 +47,8 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
matSnackBar: MatSnackBar, matSnackBar: MatSnackBar,
private repo: HistoryRepositoryService, private repo: HistoryRepositoryService,
private viewModelStore: ViewModelStoreService, private viewModelStore: ViewModelStoreService,
private router: Router private router: Router,
private operator: OperatorService
) { ) {
super(titleService, translate, matSnackBar); super(titleService, translate, matSnackBar);
} }
@ -105,17 +110,18 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
* @param history Represents the selected element * @param history Represents the selected element
*/ */
public async onClickRow(history: ViewHistory): Promise<void> { public async onClickRow(history: ViewHistory): Promise<void> {
await this.repo.browseHistory(history); if (this.operator.isInGroupIds(2)) {
const element = this.viewModelStore.get(history.getCollectionString(), history.getModelId()); await this.repo.browseHistory(history);
let message = this.translate.instant('OpenSlides is temporarily reset to following timestamp:'); const element = this.viewModelStore.get(history.getCollectionString(), history.getModelId());
console.log(message); let message = this.translate.instant('OpenSlides is temporarily reset to following timestamp:');
message += ' ' + history.getLocaleString('DE-de'); message += ' ' + history.getLocaleString('DE-de');
if (isDetailNavigable(element)) { if (isDetailNavigable(element)) {
this.raiseError(message); this.raiseError(message);
this.router.navigate([element.getDetailStateURL()]); this.router.navigate([element.getDetailStateURL()]);
} else { } else {
this.raiseError(message); this.raiseError(message);
}
} }
} }
@ -123,7 +129,9 @@ export class HistoryListComponent extends ListViewBaseComponent<ViewHistory, His
* Handler for the delete all button * Handler for the delete all button
*/ */
public onDeleteAllButton(): void { public onDeleteAllButton(): void {
this.repo.delete(); if (this.operator.isInGroupIds(2)) {
this.repo.delete();
}
} }
/** /**

View File

@ -23,7 +23,7 @@ export const HistoryAppConfig: AppConfig = {
displayName: 'History', displayName: 'History',
icon: 'history', icon: 'history',
weight: 1200, weight: 1200,
permission: 'core.view_history' permission: 'core.can_see_history'
} }
] ]
}; };