Feature: Improve RxStompConfig and book card menu permissions
• Utilize beforeConnect in RxStompConfig to ensure token retrieval at connection time. • Dynamically generate the book card menu based on user permissions instead of hiding items.
This commit is contained in:
@@ -15,6 +15,7 @@ import {MetadataRefreshRequest} from '../../../../metadata/model/request/metadat
|
|||||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||||
import {NgIf} from '@angular/common';
|
import {NgIf} from '@angular/common';
|
||||||
import {UserService} from '../../../../user.service';
|
import {UserService} from '../../../../user.service';
|
||||||
|
import {filter} from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-book-card',
|
selector: 'app-book-card',
|
||||||
@@ -41,9 +42,11 @@ export class BookCardComponent implements OnInit {
|
|||||||
private userPermissions: any;
|
private userPermissions: any;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.userService.userData$
|
||||||
|
.pipe(filter(userData => !!userData))
|
||||||
|
.subscribe((userData) => {
|
||||||
|
this.userPermissions = userData.permissions;
|
||||||
this.initMenu();
|
this.initMenu();
|
||||||
this.userService.userData$.subscribe((userData) => {
|
|
||||||
this.userPermissions = userData?.permissions;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +78,21 @@ export class BookCardComponent implements OnInit {
|
|||||||
icon: 'pi pi-info-circle',
|
icon: 'pi pi-info-circle',
|
||||||
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'view'),
|
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'view'),
|
||||||
},
|
},
|
||||||
|
...this.getPermissionBasedMenuItems(),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPermissionBasedMenuItems(): MenuItem[] {
|
||||||
|
const items: MenuItem[] = [];
|
||||||
|
|
||||||
|
if (this.hasEditMetadataPermission()) {
|
||||||
|
items.push(
|
||||||
{
|
{
|
||||||
label: 'Match Book',
|
label: 'Match Book',
|
||||||
icon: 'pi pi-sparkles',
|
icon: 'pi pi-sparkles',
|
||||||
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'match'),
|
command: () => this.metadataDialogService.openBookMetadataCenterDialog(this.book.id, 'match'),
|
||||||
disabled: !this.hasEditMetadataPermission()
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Quick Refresh',
|
label: 'Quick Refresh',
|
||||||
@@ -92,7 +105,6 @@ export class BookCardComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
|
this.bookService.autoRefreshMetadata(metadataRefreshRequest).subscribe();
|
||||||
},
|
},
|
||||||
disabled: !this.hasEditMetadataPermission()
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Granular Refresh',
|
label: 'Granular Refresh',
|
||||||
@@ -108,19 +120,21 @@ export class BookCardComponent implements OnInit {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
disabled: !this.hasEditMetadataPermission()
|
}
|
||||||
},
|
);
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if (this.hasDownloadPermission()) {
|
||||||
|
items.push({
|
||||||
label: 'Download',
|
label: 'Download',
|
||||||
icon: 'pi pi-download',
|
icon: 'pi pi-download',
|
||||||
command: () => {
|
command: () => {
|
||||||
this.bookService.downloadFile(this.book.id);
|
this.bookService.downloadFile(this.book.id);
|
||||||
},
|
},
|
||||||
disabled: !this.hasDownloadPermission()
|
});
|
||||||
},
|
}
|
||||||
],
|
|
||||||
},
|
return items;
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private openShelfDialog(): void {
|
private openShelfDialog(): void {
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import {AuthService} from '../../core/service/auth.service';
|
|||||||
export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
export function createRxStompConfig(authService: AuthService): RxStompConfig {
|
||||||
return {
|
return {
|
||||||
brokerURL: API_CONFIG.BROKER_URL,
|
brokerURL: API_CONFIG.BROKER_URL,
|
||||||
connectHeaders: {
|
|
||||||
Authorization: `Bearer ${authService.getToken()}`,
|
|
||||||
},
|
|
||||||
heartbeatIncoming: 0,
|
heartbeatIncoming: 0,
|
||||||
heartbeatOutgoing: 20000,
|
heartbeatOutgoing: 20000,
|
||||||
reconnectDelay: 200,
|
reconnectDelay: 200,
|
||||||
|
beforeConnect: (stomp) => {
|
||||||
|
stomp.stompClient.connectHeaders = {'Authorization': `Bearer ${authService.getToken()}`};
|
||||||
|
},
|
||||||
debug: (msg: string): void => {
|
debug: (msg: string): void => {
|
||||||
//console.log(new Date(), msg);
|
//console.log(new Date(), msg);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user