From 125d7857ce7401e685a0f52fbbd6fd948b9aefa8 Mon Sep 17 00:00:00 2001 From: Abizrh Date: Tue, 12 Aug 2025 11:32:36 +0700 Subject: [PATCH 1/8] =?UTF-8?q?=E2=9C=A8=20feat=20(rbac):=20implement=20ro?= =?UTF-8?q?le-based=20access=20control?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/app/patient/entry-form.vue | 39 +++++++++-- app/components/layout/Header.vue | 2 +- app/components/pub/form/block.vue | 2 +- app/components/pub/form/field-group.vue | 10 ++- app/components/pub/form/label.vue | 72 ++++++++++++++++++++ app/components/pub/nav/footer/cs.vue | 4 +- app/components/pub/ui/input/Input.vue | 10 ++- app/composables/useRBAC.ts | 48 +++++++++++++ app/layouts/default.vue | 83 ++++++++++++++++++++++- app/lib/page-permission.ts | 10 +++ app/middleware/auth.global.ts | 14 ++-- app/middleware/rbac.ts | 37 ++++++++++ app/models/role.ts | 22 ++++++ app/pages/(features)/patient/add.vue | 31 ++++++++- app/pages/(features)/patient/index.vue | 31 ++++++++- app/pages/auth/login.vue | 1 + 16 files changed, 394 insertions(+), 22 deletions(-) create mode 100644 app/components/pub/form/label.vue create mode 100644 app/composables/useRBAC.ts create mode 100644 app/lib/page-permission.ts create mode 100644 app/middleware/rbac.ts create mode 100644 app/models/role.ts diff --git a/app/components/app/patient/entry-form.vue b/app/components/app/patient/entry-form.vue index 89d8b1bf..b75af1c3 100644 --- a/app/components/app/patient/entry-form.vue +++ b/app/components/app/patient/entry-form.vue @@ -1,9 +1,38 @@ - + diff --git a/app/components/layout/Header.vue b/app/components/layout/Header.vue index 1da0a9ac..369b29ea 100644 --- a/app/components/layout/Header.vue +++ b/app/components/layout/Header.vue @@ -37,7 +37,7 @@ watch( if (val) { links.value = setLinks() } - } + }, ) diff --git a/app/components/pub/form/block.vue b/app/components/pub/form/block.vue index 5f4988d5..27015f7a 100644 --- a/app/components/pub/form/block.vue +++ b/app/components/pub/form/block.vue @@ -5,7 +5,7 @@ defineProps<{ diff --git a/app/components/pub/form/field-group.vue b/app/components/pub/form/field-group.vue index 8e901636..784870a7 100644 --- a/app/components/pub/form/field-group.vue +++ b/app/components/pub/form/field-group.vue @@ -34,7 +34,15 @@ const classVal = computed(() => { diff --git a/app/components/pub/form/label.vue b/app/components/pub/form/label.vue new file mode 100644 index 00000000..b1ad2d55 --- /dev/null +++ b/app/components/pub/form/label.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/app/components/pub/nav/footer/cs.vue b/app/components/pub/nav/footer/cs.vue index 96725a05..c7786b76 100644 --- a/app/components/pub/nav/footer/cs.vue +++ b/app/components/pub/nav/footer/cs.vue @@ -1,9 +1,9 @@ diff --git a/eslint.config.js b/eslint.config.js index e786c1c0..4879bee5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -18,14 +18,14 @@ export default withNuxt( { rules: { // Basic rules - quotes: ['error', 'single', { avoidEscape: true }], + 'quotes': ['error', 'single', { avoidEscape: true }], 'style/no-trailing-spaces': ['error', { ignoreComments: true }], 'no-console': 'off', // Relax strict formatting rules 'style/brace-style': 'off', // Allow inline if - curly: ['error', 'multi-line'], // Only require braces for multi-line + 'curly': ['error', 'multi-line'], // Only require braces for multi-line 'style/arrow-parens': 'off', // UnoCSS - make it warning instead of error, or disable completely @@ -48,6 +48,6 @@ export default withNuxt( rules: { 'style/no-trailing-spaces': 'off', }, - } - ) + }, + ), ) diff --git a/package.json b/package.json index a77d07a3..74a2234b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nuxt-app", - "private": true, "type": "module", + "private": true, "scripts": { "build": "nuxt build", "dev": "nuxt dev", diff --git a/server/api/[...req].ts b/server/api/[...req].ts index 88e27d59..3fd45b16 100644 --- a/server/api/[...req].ts +++ b/server/api/[...req].ts @@ -23,7 +23,7 @@ export default defineEventHandler(async (event) => { if (headers['content-type']) forwardHeaders.set('Content-Type', headers['content-type']) forwardHeaders.set('Authorization', `Bearer ${bearer}`) - let body: any = undefined + let body: any if (['POST', 'PATCH'].includes(method!)) { if (headers['content-type']?.includes('multipart/form-data')) { body = await readBody(event) diff --git a/uno.config.ts b/uno.config.ts index 48e7c051..fb109dd6 100644 --- a/uno.config.ts +++ b/uno.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, presetWind, presetAttributify, presetIcons } from 'unocss' +import { defineConfig, presetAttributify, presetIcons, presetWind } from 'unocss' export default defineConfig({ presets: [