From 43e39f981bf6bc8a7b85d4589f7494a66167a108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20G=C3=B6bel?= <dgoebel@techfak.uni-bielefeld.de> Date: Thu, 2 Mar 2023 11:11:10 +0100 Subject: [PATCH] Disable features for unauthorized user #33 --- src/components/BucketListItem.vue | 3 ++- src/components/BucketView.vue | 8 +++++++- src/components/NavbarTop.vue | 2 +- src/stores/auth.ts | 11 ++++++++++- src/stores/buckets.ts | 5 +++-- src/views/LoginView.vue | 2 +- src/views/object-storage/BucketsView.vue | 11 ++++++++++- 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/components/BucketListItem.vue b/src/components/BucketListItem.vue index 05eb966..cddcc0a 100644 --- a/src/components/BucketListItem.vue +++ b/src/components/BucketListItem.vue @@ -19,6 +19,7 @@ const props = defineProps<{ active: boolean; bucket: BucketOut; loading: boolean; + deletable: boolean; }>(); const randomIDSuffix = Math.random().toString(16).substr(2, 8); @@ -88,7 +89,7 @@ onMounted(() => { <span class="text-truncate" style="width: 80%">{{ bucket.name }}</span> <div> <bootstrap-icon - v-if="props.active && permission == null" + v-if="props.active && permission == null && props.deletable" icon="trash-fill" class="delete-icon me-2" :width="16" diff --git a/src/components/BucketView.vue b/src/components/BucketView.vue index 33cfd60..b4fa99f 100644 --- a/src/components/BucketView.vue +++ b/src/components/BucketView.vue @@ -636,6 +636,7 @@ watch( /> <!-- Add bucket permission button --> <button + v-if="!authStore.foreignUser" :hidden="bucketRepository.getBucketPermission(props.bucketName) != null" type="button" class="btn btn-secondary m-2 tooltip-container" @@ -653,6 +654,7 @@ watch( <span class="visually-hidden">Add Bucket Permission</span> </button> <permission-modal + v-if="!authStore.foreignUser" modalID="create-permission-modal" :bucket-name="props.bucketName" :sub-folders="folderStructure" @@ -666,6 +668,7 @@ watch( " /> <button + v-if="!authStore.foreignUser" :hidden="bucketRepository.getBucketPermission(props.bucketName) != null" type="button" class="btn btn-secondary m-2 tooltip-container" @@ -683,7 +686,10 @@ watch( <span class="visually-hidden">View Bucket Permissions</span> </button> <permission-list-modal - v-if="bucketRepository.getBucketPermission(props.bucketName) == null" + v-if=" + bucketRepository.getBucketPermission(props.bucketName) == null && + !authStore.foreignUser + " :bucket-name="props.bucketName" :sub-folders="folderStructure" modalID="permission-list-modal" diff --git a/src/components/NavbarTop.vue b/src/components/NavbarTop.vue index 6404057..2f8132b 100644 --- a/src/components/NavbarTop.vue +++ b/src/components/NavbarTop.vue @@ -69,7 +69,7 @@ onBeforeUnmount(() => { height="24" class="d-inline-block align-text-top me-2" /> - S3 Proxy + CloWM </router-link> <button class="navbar-toggler" diff --git a/src/stores/auth.ts b/src/stores/auth.ts index b677420..8cc0dfd 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -1,6 +1,6 @@ import { defineStore } from "pinia"; import type { User } from "@/client/auth"; -import { UserService } from "@/client/auth"; +import { UserService, RoleEnum } from "@/client/auth"; import { S3KeyService } from "@/client/s3proxy"; import type { S3Key } from "@/client/s3proxy"; import { OpenAPI as S3ProxyOpenAPI } from "@/client/s3proxy"; @@ -23,6 +23,15 @@ export const useAuthStore = defineStore({ } as RootState), getters: { authenticated: (state) => state.token != null, + foreignUser: (state) => + state.user?.roles?.includes(RoleEnum.FOREIGN_USER) ?? true, + normalUser: (state) => state.user?.roles?.includes(RoleEnum.USER) ?? false, + workflowReviewer: (state) => + state.user?.roles?.includes(RoleEnum.REVIEWER) ?? false, + workflowDev: (state) => + state.user?.roles?.includes(RoleEnum.DEVELOPER) ?? false, + workflowAdmin: (state) => + state.user?.roles?.includes(RoleEnum.ADMINISTRATOR) ?? false, }, actions: { setToken(token: string | null) { diff --git a/src/stores/buckets.ts b/src/stores/buckets.ts index 1da89ef..71da446 100644 --- a/src/stores/buckets.ts +++ b/src/stores/buckets.ts @@ -52,7 +52,7 @@ export const useBucketStore = defineStore({ onFinally: (() => void) | null | undefined = null ) { const authStore = useAuthStore(); - if (authStore.user != null) { + if (authStore.user != null && !authStore.foreignUser) { BucketPermissionService.bucketPermissionListPermissionsPerUser( authStore.user.uid ) @@ -80,7 +80,8 @@ export const useBucketStore = defineStore({ onRejected: ((reason: any) => void) | null | undefined = null, onFinally: (() => void) | null | undefined = null ) { - BucketService.bucketListBuckets() + const authStore = useAuthStore(); + BucketService.bucketListBuckets(authStore.user?.uid) .then((buckets) => { this.buckets = buckets; onFulfilled?.(buckets); diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 796abe4..14337c4 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -60,7 +60,7 @@ onMounted(() => { <div class="card text-center bg-dark ms-md-auto position-fixed top-50 start-50 translate-middle" > - <div class="card-header text-dark bg-light">S3Proxy</div> + <div class="card-header text-dark bg-light">CloWM</div> <div class="card-body p-5"> <h5 class="card-title text-light">Login</h5> <p class="card-text text-secondary"> diff --git a/src/views/object-storage/BucketsView.vue b/src/views/object-storage/BucketsView.vue index 75900ca..74b45aa 100644 --- a/src/views/object-storage/BucketsView.vue +++ b/src/views/object-storage/BucketsView.vue @@ -9,10 +9,12 @@ import DeleteModal from "@/components/Modals/DeleteModal.vue"; import BucketListItem from "@/components/BucketListItem.vue"; import { useBucketStore } from "@/stores/buckets"; import { Modal } from "bootstrap"; +import { useAuthStore } from "@/stores/auth"; const route = useRoute(); const router = useRouter(); const bucketRepository = useBucketStore(); +const authStore = useAuthStore(); const bucketsState = reactive({ filterString: "", @@ -58,6 +60,7 @@ onMounted(() => { <template> <DeleteModal + v-if="!authStore.foreignUser" modalID="delete-bucket-modal" :object-name-delete="bucketsState.potentialDeleteBucketName" :back-modal-id="undefined" @@ -65,7 +68,10 @@ onMounted(() => { confirmedDeleteBucket(bucketsState.potentialDeleteBucketName) " /> - <CreateBucketModal modalID="create-bucket-modal" /> + <CreateBucketModal + modalID="create-bucket-modal" + v-if="!authStore.foreignUser" + /> <div class="row m-2 border-bottom border-light mt-4"> <div class="col-12"></div> <h1 class="mb-2 text-light">Buckets</h1> @@ -82,6 +88,7 @@ onMounted(() => { <span class="visually-hidden">Refresh Buckets</span> </button> <button + v-if="!authStore.foreignUser" type="button" class="btn btn-light" data-bs-toggle="modal" @@ -115,6 +122,7 @@ onMounted(() => { route.params.bucketName != null && route.params.bucketName === bucket.name " + :deletable="!authStore.foreignUser" :bucket="bucket" :loading="false" @delete-bucket="deleteBucket" @@ -140,6 +148,7 @@ onMounted(() => { :active="false" :loading="true" :permission="undefined" + :deletable="!authStore.foreignUser" :bucket="{ name: '', description: '', -- GitLab