Restrict access to Bookdrop and Metadata Manager pages for unauthorized users (#1363)
This commit is contained in:
@@ -20,6 +20,7 @@ import {StatsComponent} from './features/stats/component/stats-component';
|
|||||||
import {EpubReaderComponent} from './features/readers/epub-reader/component/epub-reader.component';
|
import {EpubReaderComponent} from './features/readers/epub-reader/component/epub-reader.component';
|
||||||
import {PdfReaderComponent} from './features/readers/pdf-reader/pdf-reader.component';
|
import {PdfReaderComponent} from './features/readers/pdf-reader/pdf-reader.component';
|
||||||
import {BookdropFileReviewComponent} from './features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component';
|
import {BookdropFileReviewComponent} from './features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component';
|
||||||
|
import {ManageLibraryGuard} from './core/security/guards/manage-library.guard';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{
|
{
|
||||||
@@ -47,8 +48,8 @@ export const routes: Routes = [
|
|||||||
{path: 'series/:seriesName', component: SeriesPageComponent, canActivate: [AuthGuard]},
|
{path: 'series/:seriesName', component: SeriesPageComponent, canActivate: [AuthGuard]},
|
||||||
{path: 'magic-shelf/:magicShelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
{path: 'magic-shelf/:magicShelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]},
|
||||||
{path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]},
|
{path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]},
|
||||||
{path: 'bookdrop', component: BookdropFileReviewComponent, canActivate: [AuthGuard]},
|
{path: 'bookdrop', component: BookdropFileReviewComponent, canActivate: [ManageLibraryGuard]},
|
||||||
{path: 'metadata-manager', component: MetadataManagerComponent, canActivate: [AuthGuard]},
|
{path: 'metadata-manager', component: MetadataManagerComponent, canActivate: [ManageLibraryGuard]},
|
||||||
{path: 'stats', component: StatsComponent, canActivate: [AuthGuard]},
|
{path: 'stats', component: StatsComponent, canActivate: [AuthGuard]},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import {inject} from '@angular/core';
|
||||||
|
import {CanActivateFn, Router} from '@angular/router';
|
||||||
|
import {UserService} from '../../../features/settings/user-management/user.service';
|
||||||
|
import {map} from 'rxjs/operators';
|
||||||
|
|
||||||
|
export const ManageLibraryGuard: CanActivateFn = () => {
|
||||||
|
const userService = inject(UserService);
|
||||||
|
const router = inject(Router);
|
||||||
|
|
||||||
|
return userService.userState$.pipe(
|
||||||
|
map(state => {
|
||||||
|
const user = state.user;
|
||||||
|
if (user && (user.permissions.admin || user.permissions.canManipulateLibrary)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
router.navigate(['/dashboard']);
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@ import {BehaviorSubject, Subscription} from 'rxjs';
|
|||||||
import {map, filter, take} from 'rxjs/operators';
|
import {map, filter, take} from 'rxjs/operators';
|
||||||
import {BookdropFileApiService} from './bookdrop-file-api.service';
|
import {BookdropFileApiService} from './bookdrop-file-api.service';
|
||||||
import {AuthService} from '../../../shared/service/auth.service';
|
import {AuthService} from '../../../shared/service/auth.service';
|
||||||
|
import {UserService} from '../../settings/user-management/user.service';
|
||||||
|
|
||||||
export interface BookdropFileNotification {
|
export interface BookdropFileNotification {
|
||||||
pendingCount: number;
|
pendingCount: number;
|
||||||
@@ -28,11 +29,22 @@ export class BookdropFileService implements OnDestroy {
|
|||||||
private apiService = inject(BookdropFileApiService);
|
private apiService = inject(BookdropFileApiService);
|
||||||
private authService = inject(AuthService);
|
private authService = inject(AuthService);
|
||||||
private subscriptions = new Subscription();
|
private subscriptions = new Subscription();
|
||||||
|
private userService = inject(UserService);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.authService.token$
|
this.userService.userState$
|
||||||
.pipe(filter(t => !!t), take(1))
|
.pipe(
|
||||||
.subscribe(() => this.refresh());
|
filter(state => state.loaded && !!state.user),
|
||||||
|
take(1)
|
||||||
|
)
|
||||||
|
.subscribe(state => {
|
||||||
|
const user = state.user!;
|
||||||
|
if (user.permissions.admin || user.permissions.canManipulateLibrary) {
|
||||||
|
this.authService.token$
|
||||||
|
.pipe(filter(t => !!t), take(1))
|
||||||
|
.subscribe(() => this.refresh());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleIncomingFile(summary: BookdropFileNotification): void {
|
handleIncomingFile(summary: BookdropFileNotification): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user