Skip to content
Snippets Groups Projects
Verified Commit b4bf8b67 authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Disable features for buckets with constraints

#34
parent dbf7d5b9
No related branches found
No related tags found
2 merge requests!84Remove development branch,!29Resolve "Disable features for initial buckets"
...@@ -637,7 +637,7 @@ watch( ...@@ -637,7 +637,7 @@ watch(
<!-- Add bucket permission button --> <!-- Add bucket permission button -->
<button <button
v-if="!authStore.foreignUser" v-if="!authStore.foreignUser"
:hidden="bucketRepository.getBucketPermission(props.bucketName) != null" :hidden="!bucketRepository.permissionFeatureAllowed(props.bucketName)"
type="button" type="button"
class="btn btn-secondary m-2 tooltip-container" class="btn btn-secondary m-2 tooltip-container"
:disabled="errorLoadingObjects" :disabled="errorLoadingObjects"
...@@ -669,7 +669,7 @@ watch( ...@@ -669,7 +669,7 @@ watch(
/> />
<button <button
v-if="!authStore.foreignUser" v-if="!authStore.foreignUser"
:hidden="bucketRepository.getBucketPermission(props.bucketName) != null" :hidden="!bucketRepository.permissionFeatureAllowed(props.bucketName)"
type="button" type="button"
class="btn btn-secondary m-2 tooltip-container" class="btn btn-secondary m-2 tooltip-container"
:disabled="errorLoadingObjects" :disabled="errorLoadingObjects"
...@@ -852,7 +852,7 @@ watch( ...@@ -852,7 +852,7 @@ watch(
<button <button
class="dropdown-item" class="dropdown-item"
type="button" type="button"
:disabled="!writableBucket || !readableBucket" :disabled="!readableBucket"
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#copy-object-modal" data-bs-target="#copy-object-modal"
@click="objectState.copyObject = obj" @click="objectState.copyObject = obj"
......
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { BucketPermissionService, BucketService } from "@/client/s3proxy"; import {
BucketPermissionService,
BucketService,
Constraint,
} from "@/client/s3proxy";
import type { import type {
BucketOut, BucketOut,
BucketIn, BucketIn,
...@@ -18,12 +22,33 @@ export const useBucketStore = defineStore({ ...@@ -18,12 +22,33 @@ export const useBucketStore = defineStore({
ownPermissions: Record<string, BucketPermissionOut>; ownPermissions: Record<string, BucketPermissionOut>;
}), }),
getters: { getters: {
permissionFeatureAllowed(): (bucketName: string) => boolean {
return (bucketName) => {
// If a permission for the bucket exist, then false
if (this.ownPermissions[bucketName] != null) {
return false;
}
const bucket = this.buckets.find((b) => bucketName == b.name);
// If the bucket doesn't exist, then false
if (bucket == null) {
return false;
}
// If there is a constraint on the bucket, then false otherwise true
return bucket.owner_constraint == null;
};
},
writableBuckets(): BucketOut[] { writableBuckets(): BucketOut[] {
return this.buckets.filter( return this.buckets.filter((bucket) => {
(bucket) => const permission = this.ownPermissions[bucket.name];
this.ownPermissions[bucket.name] === undefined || if (permission != null) {
this.ownPermissions[bucket.name].permission !== "READ" return permission.permission !== "READ";
); }
// If the user owns the bucket, check the bucket constraint
return (
bucket.owner_constraint == null ||
bucket.owner_constraint == Constraint.WRITE
);
});
}, },
getBucketPermission(): ( getBucketPermission(): (
bucketName: string bucketName: string
...@@ -31,14 +56,40 @@ export const useBucketStore = defineStore({ ...@@ -31,14 +56,40 @@ export const useBucketStore = defineStore({
return (bucketName) => this.ownPermissions[bucketName]; return (bucketName) => this.ownPermissions[bucketName];
}, },
writableBucket(): (bucketName: string) => boolean { writableBucket(): (bucketName: string) => boolean {
return (bucketName) => return (bucketName) => {
this.ownPermissions[bucketName] === undefined || // If this is a foreign bucket, check that the user has write permission
this.ownPermissions[bucketName].permission !== "READ"; const permission = this.ownPermissions[bucketName];
if (permission != null) {
return permission.permission !== "READ";
}
// If the user owns the bucket, check the bucket constraint
const bucket = this.buckets.find((b) => bucketName == b.name);
if (bucket != null) {
return (
bucket.owner_constraint == null ||
bucket.owner_constraint == Constraint.WRITE
);
}
return false;
};
}, },
readableBucket(): (bucketName: string) => boolean { readableBucket(): (bucketName: string) => boolean {
return (bucketName) => return (bucketName) => {
this.ownPermissions[bucketName] === undefined || // If this is a foreign bucket, check that the user has read permission
this.ownPermissions[bucketName].permission !== "WRITE"; const permission = this.ownPermissions[bucketName];
if (permission != null) {
return permission.permission !== "WRITE";
}
// If the user owns the bucket, check the bucket constraint
const bucket = this.buckets.find((b) => bucketName == b.name);
if (bucket != null) {
return (
bucket.owner_constraint == null ||
bucket.owner_constraint == Constraint.READ
);
}
return false;
};
}, },
}, },
actions: { actions: {
......
...@@ -60,7 +60,6 @@ onMounted(() => { ...@@ -60,7 +60,6 @@ onMounted(() => {
<template> <template>
<DeleteModal <DeleteModal
v-if="!authStore.foreignUser"
modalID="delete-bucket-modal" modalID="delete-bucket-modal"
:object-name-delete="bucketsState.potentialDeleteBucketName" :object-name-delete="bucketsState.potentialDeleteBucketName"
:back-modal-id="undefined" :back-modal-id="undefined"
...@@ -148,7 +147,7 @@ onMounted(() => { ...@@ -148,7 +147,7 @@ onMounted(() => {
:active="false" :active="false"
:loading="true" :loading="true"
:permission="undefined" :permission="undefined"
:deletable="!authStore.foreignUser" :deletable="false"
:bucket="{ :bucket="{
name: '', name: '',
description: '', description: '',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment