Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix group management page permissions #119

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading