From 1925f468df317a6a7da594ee0c82ac7c8cf080ca Mon Sep 17 00:00:00 2001 From: Teages Date: Fri, 29 Mar 2024 10:40:21 +0800 Subject: [PATCH 01/15] fix: moderator has permission to edit other's level and collections --- pages/collections/[id]/manage.vue | 3 ++- pages/levels/[id]/manage.vue | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pages/collections/[id]/manage.vue b/pages/collections/[id]/manage.vue index d92e79759..233b84c08 100644 --- a/pages/collections/[id]/manage.vue +++ b/pages/collections/[id]/manage.vue @@ -50,6 +50,7 @@ const query = gql(` my { user { id + role } } } @@ -61,7 +62,7 @@ const { data, error } = await useAsyncQuery(query, { const hasPermission = computed(() => { return data.value?.collection?.owner?.id === data.value?.my?.user?.id - || ['admin', 'moderator'].includes(user.value?.role ?? '') + || ['admin', 'moderator'].includes((data.value?.my?.user?.role ?? '').toLowerCase()) }) if (collectionId && !data.value?.collection) { showError(error.value?.message ?? createError({ diff --git a/pages/levels/[id]/manage.vue b/pages/levels/[id]/manage.vue index b37709c3c..64a37c409 100644 --- a/pages/levels/[id]/manage.vue +++ b/pages/levels/[id]/manage.vue @@ -68,6 +68,7 @@ const query = gql(` my { user { id + role } } } @@ -79,7 +80,7 @@ const { data, error } = await useAsyncQuery(query, { const hasPermission = computed(() => { return data.value?.level?.owner?.id === data.value?.my?.user?.id - || ['admin', 'moderator'].includes(user.value?.role ?? '') + || ['admin', 'moderator'].includes((data.value?.my?.user?.role ?? '').toLowerCase()) }) if (levelId && !data.value?.level) { showError(error.value?.message ?? createError({ From 6e395c4cfea2618c3043a77d47fbe71b26e759b3 Mon Sep 17 00:00:00 2001 From: Teages Date: Fri, 29 Mar 2024 11:24:06 +0800 Subject: [PATCH 02/15] chore: speed up testing --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f07a613f..3fd2e8b3e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "pnpm test && nuxt build", "start": "node .output/server/index.mjs", "dev": "nuxt dev", - "test": "nuxt prepare && pnpm lint && pnpm tsc", + "test": "pnpm tsc && pnpm lint", "dev:local": "cross-env NODE_APP_INSTANCE=local nuxt dev", "gql": "npx cross-env NODE_ENV=production node ./cli/codegen-update.js", "gql:local": "npx cross-env NODE_APP_INSTANCE=local node ./cli/codegen-update.js", From a1ff7dc2464192884f125423604da1fe39666c2f Mon Sep 17 00:00:00 2001 From: Teages Date: Fri, 29 Mar 2024 12:45:59 +0800 Subject: [PATCH 03/15] fix: inherit attributes for Avatar --- components/User/Avatar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/User/Avatar.vue b/components/User/Avatar.vue index a201faf8e..da4f59bba 100644 --- a/components/User/Avatar.vue +++ b/components/User/Avatar.vue @@ -45,7 +45,7 @@ const [DefineAvatarBody, AvatarBody] = createReusableTemplate() - + From 09026f33f2701deb23e1e62f10c26f287522c405 Mon Sep 17 00:00:00 2001 From: Teages Date: Sat, 30 Mar 2024 02:34:32 +0800 Subject: [PATCH 04/15] fix: better auth composable --- app.vue | 10 ------ components/Donation/Verifier.vue | 3 +- components/NavBar.vue | 8 ++--- components/SearchBar/Record.vue | 4 +-- components/User/ProfileDialog.vue | 3 +- composables/auth.ts | 51 ++++++++++++++++++++-------- middleware/auth.global.ts | 8 +++++ pages/collections/[id]/index.vue | 4 +-- pages/collections/[id]/manage.vue | 2 -- pages/levels/[id]/index.vue | 4 +-- pages/levels/[id]/manage.vue | 2 -- pages/levels/[id]/manage/listing.vue | 10 +++--- pages/posts/[id]/index.vue | 4 +-- pages/posts/[id]/manage.vue | 4 +-- pages/profile/[id].vue | 9 ++--- pages/records/index.vue | 2 +- pages/session/link.vue | 3 +- pages/session/login.vue | 5 +-- pages/session/signup.vue | 4 +-- pages/settings/security.vue | 3 +- pages/studio.vue | 4 +-- pages/studio/posts.vue | 6 ++-- pages/studio/sudo.vue | 8 ++--- pages/studio/users.vue | 6 ++-- 24 files changed, 92 insertions(+), 75 deletions(-) create mode 100644 middleware/auth.global.ts diff --git a/app.vue b/app.vue index 9f97e2cdd..59da07cca 100644 --- a/app.vue +++ b/app.vue @@ -1,14 +1,4 @@