Add extended permissions for bulk metadata, reading progress, and read status actions (#2091)

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-01 11:41:22 -07:00
committed by GitHub
co-authored by acx10
parent 60524ee8a6
commit e0dec6f2f6
34 changed files with 1117 additions and 331 deletions
@@ -295,7 +295,7 @@
<div class="flex justify-center w-2/4">
@if (entityType$ | async; as entityType) {
<div class="flex gap-2 md:gap-6">
@if (userState.user!.permissions.canEditMetadata) {
@if (hasMetadataMenuItems) {
<p-tieredMenu #menu [model]="metadataMenuItems" [popup]="true" appendTo="body"/>
<p-button
(click)="menu.toggle($event)"
@@ -324,7 +324,7 @@
tooltipPosition="top">
</p-button>
}
@if (userState.user!.permissions.canEditMetadata) {
@if (userState.user!.permissions.canBulkLockUnlockMetadata) {
<p-button
outlined="true"
icon="pi pi-lock"
@@ -333,6 +333,8 @@
pTooltip="Lock/Unlock metadata"
tooltipPosition="top">
</p-button>
}
@if (userState.user!.permissions.canMoveOrganizeFiles) {
<p-button
outlined="true"
icon="pi pi-arrows-h"
@@ -342,17 +344,19 @@
tooltipPosition="top">
</p-button>
}
<div class="card flex justify-center">
<p-button
(click)="menu.toggle($event)"
pTooltip="More actions"
tooltipPosition="top"
outlined="true"
severity="info"
icon="pi pi-ellipsis-v">
</p-button>
<p-tieredMenu #menu [model]="tieredMenuItems" [popup]="true" appendTo="body"/>
</div>
@if (hasBulkReadActionsItems) {
<div class="card flex justify-center">
<p-button
(click)="menu.toggle($event)"
pTooltip="More actions"
tooltipPosition="top"
outlined="true"
severity="info"
icon="pi pi-ellipsis-v">
</p-button>
<p-tieredMenu #menu [model]="bulkReadActionsMenuItems" [popup]="true" appendTo="body"/>
</div>
}
</div>
}
<p-divider layout="vertical"></p-divider>
@@ -149,7 +149,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
lastAppliedSort: SortOption | null = null;
private settingFiltersFromUrl = false;
protected metadataMenuItems: MenuItem[] | undefined;
protected tieredMenuItems: MenuItem[] | undefined;
protected bulkReadActionsMenuItems: MenuItem[] | undefined;
currentBooks: Book[] = [];
lastSelectedIndex: number | null = null;
showFilter = false;
@@ -254,14 +254,19 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
this.clearFilter();
});
this.metadataMenuItems = this.bookMenuService.getMetadataMenuItems(
() => this.autoFetchMetadata(),
() => this.fetchMetadata(),
() => this.bulkEditMetadata(),
() => this.multiBookEditMetadata(),
() => this.regenerateCoversForSelected(),
);
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
this.userService.userState$.pipe(filter(u => !!u?.user && u.loaded))
.subscribe(userState => {
this.metadataMenuItems = this.bookMenuService.getMetadataMenuItems(
() => this.autoFetchMetadata(),
() => this.fetchMetadata(),
() => this.bulkEditMetadata(),
() => this.multiBookEditMetadata(),
() => this.regenerateCoversForSelected(),
userState.user
);
});
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
combineLatest([
this.activatedRoute.paramMap,
@@ -502,19 +507,19 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
this.handleBookSelection(book, !isUnselectingRange);
}
}
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
}
handleBookSelect(book: Book, selected: boolean): void {
this.handleBookSelection(book, selected);
this.isDrawerVisible = this.selectedBooks.size > 0;
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
}
onSelectedBooksChange(selectedBookIds: Set<number>): void {
this.selectedBooks = new Set(selectedBookIds);
this.isDrawerVisible = this.selectedBooks.size > 0;
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
}
selectAllBooks(): void {
@@ -525,7 +530,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
if (this.bookTableComponent) {
this.bookTableComponent.selectAllBooks();
}
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
}
deselectAllBooks(): void {
@@ -534,7 +539,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
if (this.bookTableComponent) {
this.bookTableComponent.clearSelectedBooks();
}
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user());
}
confirmDeleteBooks(): void {
@@ -924,4 +929,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
get seriesViewEnabled(): boolean {
return Boolean(this.userService.getCurrentUser()?.userSettings?.enableSeriesView);
}
get hasMetadataMenuItems(): boolean {
return this.metadataMenuItems!.length > 0;
}
get hasBulkReadActionsItems(): boolean {
return this.bulkReadActionsMenuItems!.length > 0;
}
user() {
return this.userService.getCurrentUser();
}
}
@@ -10,7 +10,7 @@ import {FormsModule} from '@angular/forms';
import {MetadataRefreshType} from '../../../../metadata/model/request/metadata-refresh-type.enum';
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
import {NgClass} from '@angular/common';
import {UserService} from '../../../../settings/user-management/user.service';
import {User, UserService} from '../../../../settings/user-management/user.service';
import {filter, Subject} from 'rxjs';
import {EmailService} from '../../../../settings/email-v2/email.service';
import {TieredMenu} from 'primeng/tieredmenu';
@@ -64,10 +64,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
private bookDialogHelperService = inject(BookDialogHelperService);
private bookNavigationService = inject(BookNavigationService);
private userPermissions: any;
private metadataCenterViewMode: 'route' | 'dialog' = 'route';
private destroy$ = new Subject<void>();
protected readStatusHelper = inject(ReadStatusHelper);
private user: User | null = null;
ngOnInit(): void {
this.userService.userState$
@@ -77,8 +77,8 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
takeUntil(this.destroy$)
)
.subscribe(userState => {
this.userPermissions = userState.user?.permissions;
this.metadataCenterViewMode = userState?.user?.userSettings.metadataCenterViewMode ?? 'route';
this.user = userState.user;
this.metadataCenterViewMode = userState.user?.userSettings?.metadataCenterViewMode ?? 'route';
this.initMenu();
});
}
@@ -157,15 +157,14 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
private needsAdditionalFilesData(): boolean {
// Don't need to load if already loaded
if (this.additionalFilesLoaded) {
return false;
}
const hasNoAlternativeFormats = !this.book.alternativeFormats || this.book.alternativeFormats.length === 0;
const hasNoSupplementaryFiles = !this.book.supplementaryFiles || this.book.supplementaryFiles.length === 0;
return (this.hasDownloadPermission() || this.hasDeleteBookPermission()) &&
hasNoAlternativeFormats && hasNoSupplementaryFiles;
const canDownload = !!this.user?.permissions.canDownload;
const canDeleteBook = !!this.user?.permissions.canDeleteBook;
return (canDownload || canDeleteBook) && hasNoAlternativeFormats && hasNoSupplementaryFiles;
}
private initMenu() {
@@ -192,7 +191,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
private getPermissionBasedMenuItems(): MenuItem[] {
const items: MenuItem[] = [];
if (this.hasDownloadPermission()) {
if (this.user?.permissions.canDownload) {
const hasAdditionalFiles = (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) ||
(this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0);
@@ -204,7 +203,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
items: downloadItems
});
} else if (this.additionalFilesLoaded) {
// Data has been loaded but no additional files exist
items.push({
label: 'Download',
icon: 'pi pi-download',
@@ -213,7 +211,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
});
} else {
// Data not loaded yet
items.push({
label: 'Download',
icon: this.isSubMenuLoading ? 'pi pi-spin pi-spinner' : 'pi pi-download',
@@ -222,7 +219,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
}
if (this.hasDeleteBookPermission()) {
if (this.user?.permissions.canDeleteBook) {
const hasAdditionalFiles = (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) ||
(this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0);
@@ -234,7 +231,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
items: deleteItems
});
} else if (this.additionalFilesLoaded) {
// Data has been loaded but no additional files exist - show delete book option
items.push({
label: 'Delete',
icon: 'pi pi-trash',
@@ -253,7 +249,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
});
} else {
// Data not loaded yet
items.push({
label: 'Delete',
icon: this.isSubMenuLoading ? 'pi pi-spin pi-spinner' : 'pi pi-trash',
@@ -262,7 +257,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
}
if (this.hasEmailBookPermission()) {
if (this.user?.permissions.canEmailBook) {
items.push(
{
label: 'Email Book',
@@ -301,7 +296,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
});
}
if (this.hasEditMetadataPermission()) {
if (this.user?.permissions.canEditMetadata) {
items.push({
label: 'Metadata',
icon: 'pi pi-database',
@@ -343,98 +338,102 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
private moreMenuItems(): MenuItem[] {
const items: MenuItem[] = [];
const moreActions: MenuItem[] = [];
if (this.hasEditMetadataPermission()) {
items.push({
label: 'More Actions',
icon: 'pi pi-ellipsis-h',
items: [
{
label: 'Organize File',
icon: 'pi pi-arrows-h',
command: () => {
this.bookDialogHelperService.openFileMoverDialog(new Set([this.book.id]));
}
},
{
label: 'Read Status',
icon: 'pi pi-book',
items: Object.entries(readStatusLabels).map(([status, label]) => ({
label,
command: () => {
this.bookService.updateBookReadStatus(this.book.id, status as ReadStatus).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Read Status Updated',
detail: `Marked as "${label}"`,
life: 2000
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: 'Could not update read status.',
life: 3000
});
}
});
}
}))
},
{
label: 'Reset Booklore Progress',
icon: 'pi pi-undo',
command: () => {
this.bookService.resetProgress(this.book.id, ResetProgressTypes.BOOKLORE).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'Booklore reading progress has been reset.',
life: 1500
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset Booklore progress.',
life: 1500
});
}
});
},
},
{
label: 'Reset KOReader Progress',
icon: 'pi pi-undo',
command: () => {
this.bookService.resetProgress(this.book.id, ResetProgressTypes.KOREADER).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'KOReader reading progress has been reset.',
life: 1500
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset KOReader progress.',
life: 1500
});
}
});
},
}
]
if (this.user?.permissions.canMoveOrganizeFiles) {
moreActions.push({
label: 'Organize File',
icon: 'pi pi-arrows-h',
command: () => {
this.bookDialogHelperService.openFileMoverDialog(new Set([this.book.id]));
}
});
}
moreActions.push(
{
label: 'Read Status',
icon: 'pi pi-book',
items: Object.entries(readStatusLabels).map(([status, label]) => ({
label,
command: () => {
this.bookService.updateBookReadStatus(this.book.id, status as ReadStatus).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Read Status Updated',
detail: `Marked as "${label}"`,
life: 2000
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: 'Could not update read status.',
life: 3000
});
}
});
}
}))
},
{
label: 'Reset Booklore Progress',
icon: 'pi pi-undo',
command: () => {
this.bookService.resetProgress(this.book.id, ResetProgressTypes.BOOKLORE).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'Booklore reading progress has been reset.',
life: 1500
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset Booklore progress.',
life: 1500
});
}
});
},
},
{
label: 'Reset KOReader Progress',
icon: 'pi pi-undo',
command: () => {
this.bookService.resetProgress(this.book.id, ResetProgressTypes.KOREADER).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Progress Reset',
detail: 'KOReader reading progress has been reset.',
life: 1500
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset KOReader progress.',
life: 1500
});
}
});
},
}
);
items.push({
label: 'More Actions',
icon: 'pi pi-ellipsis-h',
items: moreActions
});
return items;
}
@@ -470,7 +469,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
private getDownloadMenuItems(): MenuItem[] {
const items: MenuItem[] = [];
// Add main book file first
items.push({
label: `${this.book.fileName || 'Book File'}`,
icon: 'pi pi-file',
@@ -479,12 +477,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
});
// Add separator if there are additional files
if (this.hasAdditionalFiles()) {
items.push({separator: true});
}
// Add alternative formats
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) {
this.book.alternativeFormats.forEach(format => {
const extension = this.getFileExtension(format.filePath);
@@ -496,13 +492,11 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
});
}
// Add separator if both alternative formats and supplementary files exist
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0 &&
this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
items.push({separator: true});
}
// Add supplementary files
if (this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
this.book.supplementaryFiles.forEach(file => {
const extension = this.getFileExtension(file.filePath);
@@ -520,7 +514,6 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
private getDeleteMenuItems(): MenuItem[] {
const items: MenuItem[] = [];
// Add main book deletion
items.push({
label: 'Book',
icon: 'pi pi-book',
@@ -539,12 +532,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
}
});
// Add separator if there are additional files
if (this.hasAdditionalFiles()) {
items.push({separator: true});
}
// Add alternative formats
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0) {
this.book.alternativeFormats.forEach(format => {
const extension = this.getFileExtension(format.filePath);
@@ -556,13 +547,11 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
});
}
// Add separator if both alternative formats and supplementary files exist
if (this.book.alternativeFormats && this.book.alternativeFormats.length > 0 &&
this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
items.push({separator: true});
}
// Add supplementary files
if (this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0) {
this.book.supplementaryFiles.forEach(file => {
const extension = this.getFileExtension(file.filePath);
@@ -646,30 +635,10 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy {
return sizeKb != null ? `${(sizeKb / 1024).toFixed(2)} MB` : '-';
}
private isAdmin(): boolean {
return this.userPermissions?.admin ?? false;
}
private hasEditMetadataPermission(): boolean {
return this.isAdmin() || (this.userPermissions?.canEditMetadata ?? false);
}
canReadBook(): boolean {
return this.book?.bookType !== 'FB2';
}
private hasDownloadPermission(): boolean {
return this.isAdmin() || (this.userPermissions?.canDownload ?? false);
}
private hasEmailBookPermission(): boolean {
return this.isAdmin() || (this.userPermissions?.canEmailBook ?? false);
}
private hasDeleteBookPermission(): boolean {
return this.isAdmin() || (this.userPermissions?.canDeleteBook ?? false);
}
private lastMouseEvent: MouseEvent | null = null;
captureMouseEvent(event: MouseEvent): void {
@@ -1,12 +1,14 @@
import {inject, Injectable} from '@angular/core';
import {ConfirmationService, MessageService} from 'primeng/api';
import {MenuItem} from 'primeng/api';
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
import {BookService} from './book.service';
import {readStatusLabels} from '../components/book-browser/book-filter/book-filter.component';
import {ReadStatus} from '../model/book.model';
import {ResetProgressTypes} from '../../../shared/constants/reset-progress-type';
import {finalize} from 'rxjs';
import {LoadingService} from '../../../core/services/loading.service';
import {User} from '../../settings/user-management/user.service';
import {APIException} from '../../../shared/models/api-exception.model';
import {HttpErrorResponse} from '@angular/common/http';
@Injectable({
providedIn: 'root'
@@ -23,41 +25,59 @@ export class BookMenuService {
fetchMetadata: () => void,
bulkEditMetadata: () => void,
multiBookEditMetadata: () => void,
regenerateCovers: () => void): MenuItem[] {
return [
{
regenerateCovers: () => void,
user: User | null): MenuItem[] {
const permissions = user?.permissions;
const items: MenuItem[] = [];
if (permissions?.canBulkAutoFetchMetadata) {
items.push({
label: 'Auto Fetch Metadata',
icon: 'pi pi-bolt',
command: autoFetchMetadata
},
{
});
}
if (permissions?.canBulkCustomFetchMetadata) {
items.push({
label: 'Custom Fetch Metadata',
icon: 'pi pi-sync',
command: fetchMetadata
},
{
});
}
if (permissions?.canBulkEditMetadata) {
items.push({
label: 'Bulk Metadata Editor',
icon: 'pi pi-table',
command: bulkEditMetadata
},
{
});
items.push({
label: 'Multi-Book Metadata Editor',
icon: 'pi pi-clone',
command: multiBookEditMetadata
},
{
});
}
if (permissions?.canBulkRegenerateCover) {
items.push({
label: 'Regenerate Covers',
icon: 'pi pi-image',
command: regenerateCovers
}
];
});
}
return items;
}
getTieredMenuItems(selectedBooks: Set<number>): MenuItem[] {
getBulkReadActionsMenu(selectedBooks: Set<number>, user: User | null): MenuItem[] {
const count = selectedBooks.size;
const permissions = user?.permissions;
const items: MenuItem[] = [];
return [
{
if (permissions?.canBulkResetBookReadStatus) {
items.push({
label: 'Update Read Status',
icon: 'pi pi-book',
items: Object.entries(readStatusLabels).map(([status, label]) => ({
@@ -83,11 +103,12 @@ export class BookMenuService {
life: 2000
});
},
error: () => {
error: (err: HttpErrorResponse) => {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Update Failed',
detail: 'Could not update read status.',
detail: apiError?.message || 'Could not update read status.',
life: 3000
});
}
@@ -96,8 +117,11 @@ export class BookMenuService {
});
}
}))
},
{
});
}
if (permissions?.canBulkResetBookloreReadProgress) {
items.push({
label: 'Reset Booklore Progress',
icon: 'pi pi-undo',
command: () => {
@@ -121,20 +145,24 @@ export class BookMenuService {
life: 1500
});
},
error: () => {
error: (err: HttpErrorResponse) => {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset progress.',
life: 1500
detail: apiError?.message || 'Could not reset progress.',
life: 3000
});
}
});
}
});
}
},
{
});
}
if (permissions?.canBulkResetKoReaderReadProgress) {
items.push({
label: 'Reset KOReader Progress',
icon: 'pi pi-undo',
command: () => {
@@ -158,19 +186,22 @@ export class BookMenuService {
life: 1500
});
},
error: () => {
error: (err: HttpErrorResponse) => {
const apiError = err.error as APIException;
this.messageService.add({
severity: 'error',
summary: 'Failed',
detail: 'Could not reset progress.',
life: 1500
detail: apiError?.message || 'Could not reset progress.',
life: 3000
});
}
});
}
});
}
}
];
});
}
return items;
}
}