WIP: Permissions

This commit is contained in:
aditya.chandel
2025-02-16 09:39:04 -07:00
parent 8a4da1997b
commit 80681e1757
29 changed files with 267 additions and 122 deletions
@@ -1,5 +1,4 @@
<ng-container>
<div *ngIf="root && item.visible !== false" class="layout-menuitem-root-text">{{ item.label }}</div>
<a *ngIf="(!item.routerLink || item.items) && item.visible !== false" [attr.href]="item.url"
@@ -16,7 +15,7 @@
<a *ngIf="(item.routerLink && !item.items) && item.visible !== false" (click)="itemClick($event)"
[ngClass]="item.class"
[routerLink]="item.routerLink" routerLinkActive="active-route"
[routerLinkActiveOptions]="item.routerLinkActiveOptions||{ paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling"
[preserveFragment]="item.preserveFragment"
[skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state"
@@ -29,7 +28,7 @@
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
</a>
<span *ngIf="(item.routerLink && !item.items) && item.visible !== false">
<ng-container *ngIf="item.type === 'Library' || item.type === 'Shelf'">
<ng-container *ngIf="(item.type === 'Library' || item.type === 'Shelf') && canManipulateLibrary">
<p-button
(click)="entitymenu.toggle($event)"
(mouseover)="hovered = true"
@@ -46,9 +45,14 @@
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
</ng-container>
<ng-container *ngIf="item.type === 'Library' && !canManipulateLibrary">
<p class="text-[var(--primary-color)] pr-1">
{{ (item.bookCount$ | async)?.toString() || '0' }}
</p>
</ng-container>
<ng-container *ngIf="item.type === 'All Books'">
<p
class="text-[var(--primary-color)] pr-1">
<p class="text-[var(--primary-color)] pr-1">
{{ (item.bookCount$ | async)?.toString() || '0' }}
</p>
</ng-container>
@@ -9,11 +9,12 @@ import {Ripple} from 'primeng/ripple';
import {Button} from 'primeng/button';
import {Menu} from 'primeng/menu';
import {MenuItem} from 'primeng/api';
import {UserService} from '../../../user.service';
@Component({
selector: '[app-menuitem]',
templateUrl: './app.menuitem.component.html',
styleUrl: './app.menuitem.component.scss',
styleUrls: ['./app.menuitem.component.scss'],
imports: [
RouterLink,
RouterLinkActive,
@@ -44,13 +45,20 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
@Input() parentKey!: string;
hovered = false;
active = false;
menuSourceSubscription: Subscription;
menuResetSubscription: Subscription;
key: string = "";
constructor(public router: Router, private menuService: MenuService) {
canManipulateLibrary: boolean = false;
menuSourceSubscription: Subscription;
menuResetSubscription: Subscription;
constructor(public router: Router, private menuService: MenuService, private userService: UserService) {
this.userService.userData$.subscribe(userData => {
if (userData) {
this.canManipulateLibrary = userData.permissions.canManipulateLibrary;
}
});
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
Promise.resolve(null).then(() => {
if (value.routeEvent) {
@@ -21,14 +21,14 @@
<app-book-searcher></app-book-searcher>
<ul class="topbar-items pl-6">
<div class="flex gap-6">
<li>
<a class="topbar-item">
<li *ngIf="userService.userData$ | async as userData">
<a class="topbar-item" *ngIf="userData.permissions.canManipulateLibrary">
<i class="pi pi-plus-circle text-surface-700 dark:text-surface-100" (click)="openLibraryCreatorDialog()"
pTooltip="Create New Library" tooltipPosition="top"></i>
</a>
</li>
<li>
<a class="topbar-item">
<li *ngIf="userService.userData$ | async as userData">
<a class="topbar-item" *ngIf="userData.permissions.canUpload">
<i class="pi pi-upload text-surface-700 dark:text-surface-100" (click)="openFileUploadDialog()"
pTooltip="Upload Book" tooltipPosition="top"></i>
</a>
@@ -8,7 +8,7 @@ import {TooltipModule} from 'primeng/tooltip';
import {FormsModule} from '@angular/forms';
import {InputTextModule} from 'primeng/inputtext';
import {BookSearcherComponent} from '../../../book/components/book-searcher/book-searcher.component';
import {NgClass, NgIf} from '@angular/common';
import {AsyncPipe, NgClass, NgIf} from '@angular/common';
import {EventService} from '../../../shared/websocket/event.service';
import {Button} from 'primeng/button';
import {StyleClass} from 'primeng/styleclass';
@@ -17,6 +17,7 @@ import {ThemeConfiguratorComponent} from '../theme-configurator/theme-configurat
import {LiveNotificationBoxComponent} from '../../../core/component/live-notification-box/live-notification-box.component';
import {BookUploaderComponent} from '../../../utilities/component/book-uploader/book-uploader.component';
import {AuthService} from '../../../core/service/auth.service';
import {UserService} from '../../../user.service';
@Component({
selector: 'app-topbar',
@@ -34,7 +35,8 @@ import {AuthService} from '../../../core/service/auth.service';
NgClass,
Divider,
LiveNotificationBoxComponent,
NgIf
NgIf,
AsyncPipe
],
})
export class AppTopBarComponent implements OnDestroy {
@@ -50,7 +52,8 @@ export class AppTopBarComponent implements OnDestroy {
@ViewChild('topbarmenu') menu!: ElementRef;
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService,
private eventService: EventService, private router: Router, private authService: AuthService) {
private eventService: EventService, private router: Router, private authService: AuthService,
protected userService: UserService) {
this.eventService.eventHighlight$.subscribe(highlight => {
this.eventHighlight = highlight;
});