Skip to content

Commit 8baa2a7

Browse files
authored
Allow admins to edit collections on frontend (#3207)
1 parent a5427f7 commit 8baa2a7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

apps/frontend/src/pages/collection/[id].vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
3-
<ModalConfirm
4-
v-if="auth.user && auth.user.id === creator.id"
3+
<ConfirmModal
4+
v-if="canEdit"
55
ref="deleteModal"
66
:title="formatMessage(messages.deleteModalTitle)"
77
:description="formatMessage(messages.deleteModalDescription)"
@@ -387,12 +387,13 @@ import {
387387
Avatar,
388388
Button,
389389
commonMessages,
390+
ConfirmModal,
390391
} from "@modrinth/ui";
391392
393+
import { isAdmin } from "@modrinth/utils";
392394
import WorldIcon from "assets/images/utils/world.svg";
393395
import UpToDate from "assets/images/illustrations/up_to_date.svg";
394396
import { addNotification } from "~/composables/notifs.js";
395-
import ModalConfirm from "~/components/ui/ModalConfirm.vue";
396397
import NavRow from "~/components/ui/NavRow.vue";
397398
import ProjectCard from "~/components/ui/ProjectCard.vue";
398399
import AdPlaceholder from "~/components/ui/AdPlaceholder.vue";
@@ -596,7 +597,7 @@ useSeoMeta({
596597
const canEdit = computed(
597598
() =>
598599
auth.value.user &&
599-
auth.value.user.id === collection.value.user &&
600+
(auth.value.user.id === collection.value.user || isAdmin(auth.value.user)) &&
600601
collection.value.id !== "following",
601602
);
602603
@@ -685,7 +686,11 @@ async function deleteCollection() {
685686
method: "DELETE",
686687
apiVersion: 3,
687688
});
688-
await navigateTo("/dashboard/collections");
689+
if (auth.value.user.id === collection.value.user) {
690+
await navigateTo("/dashboard/collections");
691+
} else {
692+
await navigateTo(`/user/${collection.value.user}/collections`);
693+
}
689694
} catch (err) {
690695
addNotification({
691696
group: "main",

packages/utils/users.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ export const isStaff = (user) => {
88
return user && STAFF_ROLES.includes(user.role)
99
}
1010

11+
export const isAdmin = (user) => {
12+
return user && user.role === 'admin'
13+
}
14+
1115
export const STAFF_ROLES = ['moderator', 'admin']

0 commit comments

Comments
 (0)