Skip to content

Commit

Permalink
allow group managers to access group management page (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey authored Jul 23, 2024
1 parent 07b1383 commit 50dedbd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/lib/assets/unauthorized.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 14 additions & 6 deletions src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<script lang="ts">
import { page } from "$app/stores";
import notFound from "$lib/assets/not_found.svg";
import error from "$lib/assets/error.svg";
import notFoundAsset from "$lib/assets/not_found.svg";
import errorAsset from "$lib/assets/error.svg";
import unauthorizedAsset from "$lib/assets/unauthorized.svg";
type ErrorInfo = {
image: string;
message: string;
};
const errors: Record<number, ErrorInfo> = {
401: {
image: unauthorizedAsset,
message: "Not Authorized"
},
404: {
image: notFound,
image: notFoundAsset,
message: "The page you were looking for wasn't found"
},
500: {
image: error,
image: errorAsset,
message: "Something went wrong"
}
};
const error = errors[$page.status] ? errors[$page.status] : errors[500];
const errorMessage = $page.error?.message || error.message;
</script>

<div class="flex flex-col items-center justify-center space-y-4 pt-4">
<p class="text-4xl">{$page.status}</p>
<img class="w-3/4 md:w-1/3" alt={errors[$page.status].message} src={errors[$page.status].image} />
<p class="text-2xl">{errors[$page.status].message}</p>
<img class="w-3/4 md:w-1/3" alt={errorMessage} src={error.image} />
<p class="text-2xl">{errorMessage}</p>
</div>
15 changes: 13 additions & 2 deletions src/routes/admin/groups/[groupId]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import { Role } from "$lib/schema";
import { error, redirect } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
import { client } from "$lib/server/prisma";

export const load: PageServerLoad = async ({ locals, url }) => {
export const load: PageServerLoad = async ({ locals, url, params }) => {
if (!locals.user) {
redirect(302, `/login?ref=/admin`);
}
if (locals.user.roleId !== Role.ADMIN) {
const userGroupRoleId = await client.userGroupMembership.findFirst({
where: {
userId: locals.user.id,
groupId: params.groupId
},
select: {
roleId: true
}
});

if (!(locals.user.roleId === Role.ADMIN || userGroupRoleId?.roleId === Role.GROUP_MANAGER)) {
error(401, "Not authorized to view admin panel");
}

Expand Down

0 comments on commit 50dedbd

Please sign in to comment.