diff --git a/SharpbinV3.Client/src/lib/components/Navbar.svelte b/SharpbinV3.Client/src/lib/components/Navbar.svelte index 6100879..49fbf50 100644 --- a/SharpbinV3.Client/src/lib/components/Navbar.svelte +++ b/SharpbinV3.Client/src/lib/components/Navbar.svelte @@ -2,7 +2,7 @@ import { user } from '$lib/stores/user'; import { resolve } from '$app/paths'; import { page } from '$app/state'; - import { clearTokens } from '$lib/utils/auth'; + import { clearTokens, hasRole } from '$lib/utils/auth'; import logo from '$lib/assets/favicon.svg'; import type { PageData } from '../../routes/$types'; import { slide } from 'svelte/transition'; @@ -50,7 +50,7 @@ {#if $user}
- {#if $user.roles.includes(1) || $user.roles.includes(255)} + {#if hasRole($user.roles, 2) || hasRole($user.roles, 4)} Reports (menuOpen = false)}>Recent Pastes {#if $user} - {#if $user.roles.includes(1) || $user.roles.includes(255)} + {#if hasRole($user.roles, 2) || hasRole($user.roles, 4)} (userRoles & role) !== 0; + +export const getUserRoles = (userRoles: number): Role[] => + (Object.keys(roles) as Role[]).filter((role) => hasRole(userRoles, roles[role])); diff --git a/SharpbinV3.Client/src/lib/utils/totp.ts b/SharpbinV3.Client/src/lib/utils/totp.ts index 88711a1..acacecf 100644 --- a/SharpbinV3.Client/src/lib/utils/totp.ts +++ b/SharpbinV3.Client/src/lib/utils/totp.ts @@ -10,9 +10,9 @@ export function parseTotpEnabled(tokenValue: string | null) { } } -export function needsAdminTotp(totpEnabled: boolean, currentRoles: number[], nextRoles: number[]) { +export function needsAdminTotp(totpEnabled: boolean, currentRoles: number, nextRoles: number) { if (!totpEnabled) return false; - const nextHasAdmin = nextRoles.includes(255); - const alreadyAdmin = currentRoles.includes(255); + const nextHasAdmin = (nextRoles & 4) !== 0; + const alreadyAdmin = (currentRoles & 4) !== 0; return nextHasAdmin && !alreadyAdmin; } diff --git a/SharpbinV3.Client/src/routes/+page.svelte b/SharpbinV3.Client/src/routes/+page.svelte index 61b6563..85fde63 100644 --- a/SharpbinV3.Client/src/routes/+page.svelte +++ b/SharpbinV3.Client/src/routes/+page.svelte @@ -473,7 +473,7 @@ {/if} @@ -485,7 +485,7 @@ {error}
{/if} - {#if $user?.roles && $user.roles.includes(403)} + {#if $user?.isBanned}
Report {/if} - {#if $user && ($user.uuid === data.paste?.author?.uuid || $user.roles.some((r) => r === 1 || r === 255))} + {#if $user && ($user.uuid === data.paste?.author?.uuid || hasRole($user.roles, 2) || hasRole($user.roles, 4))} {#if !editing} {#if !isBinary}
- {#if !isOwner && !$user?.roles?.some((r) => r === 403)} + {#if !isOwner && !$user?.isBanned}
{/if}
- {#if isOwner || $user?.roles?.some((r) => r === 255 || r === 1)} + {#if isOwner || ($user?.roles && (hasRole($user.roles, roles.Admin) || hasRole($user.roles, roles.Moderator)))}