[FA-misc] Delete novel now authorizes based on group
This commit is contained in:
@@ -5,6 +5,7 @@ using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.Shared.Constants;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using HotChocolate.Authorization;
|
||||
using HotChocolate.Types;
|
||||
@@ -21,19 +22,8 @@ public class Mutation
|
||||
return await service.QueueNovelImport(novelUrl);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public async Task<ChapterPullRequested> FetchChapterContents(
|
||||
Guid importId,
|
||||
uint novelId,
|
||||
uint volumeId,
|
||||
uint chapterOrder,
|
||||
NovelUpdateService service)
|
||||
{
|
||||
return await service.QueueChapterPull(importId, novelId, volumeId, chapterOrder);
|
||||
}
|
||||
|
||||
[Error<KeyNotFoundException>]
|
||||
[Authorize]
|
||||
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||
public async Task<bool> DeleteNovel(uint novelId, NovelUpdateService service)
|
||||
{
|
||||
await service.DeleteNovel(novelId);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { writable, derived } from 'svelte/store';
|
||||
import { writable, derived, get } from 'svelte/store';
|
||||
import type { User } from 'oidc-client-ts';
|
||||
import { userManager, isOidcConfigured } from './oidcConfig';
|
||||
|
||||
@@ -8,6 +8,15 @@ export const isLoading = writable(true);
|
||||
export const isAuthenticated = derived(user, ($user) => $user !== null);
|
||||
export const isConfigured = isOidcConfigured;
|
||||
|
||||
export const userGroups = derived(user, ($user) => {
|
||||
const groups = $user?.profile?.groups;
|
||||
return Array.isArray(groups) ? (groups as string[]) : [];
|
||||
});
|
||||
|
||||
export function hasGroup(groupName: string): boolean {
|
||||
return get(userGroups).includes(groupName);
|
||||
}
|
||||
|
||||
// Cookie management
|
||||
function setCookieFromUser(u: User) {
|
||||
if (!u?.access_token) return;
|
||||
|
||||
@@ -35,7 +35,8 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { client } from '$lib/graphql/client';
|
||||
import { NovelDocument, ImportNovelDocument, DeleteNovelDocument, GetBookmarksDocument } from '$lib/graphql/__generated__/graphql';
|
||||
import { isAuthenticated } from '$lib/auth/authStore';
|
||||
import { isAuthenticated, hasGroup } from '$lib/auth/authStore';
|
||||
import { Groups } from '$lib/constants/groups';
|
||||
import { Card, CardContent, CardHeader } from '$lib/components/ui/card';
|
||||
import { Badge } from '$lib/components/ui/badge';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
@@ -483,6 +484,7 @@
|
||||
{/if}
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
{#if hasGroup(Groups.Admin)}
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
@@ -492,6 +494,7 @@
|
||||
<Trash2 class="h-3 w-3" />
|
||||
Delete
|
||||
</Button>
|
||||
{/if}
|
||||
<AddToReadingListButton novelId={novel.id} />
|
||||
{/if}
|
||||
{#if refreshSuccess}
|
||||
|
||||
3
fictionarchive-web-astro/src/lib/constants/groups.ts
Normal file
3
fictionarchive-web-astro/src/lib/constants/groups.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const Groups = {
|
||||
Admin: 'admin'
|
||||
} as const;
|
||||
Reference in New Issue
Block a user