Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions frontend/src/components/bucket/BucketChildConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { object, string } from 'yup';

import TextInput from '@/components/form/TextInput.vue';
import { Button, Dialog, Message, useToast } from '@/lib/primevue';
import { useAuthStore, useBucketStore, useNavStore } from '@/store';
import { useBucketStore, useNavStore } from '@/store';
import { onDialogHide } from '@/utils/utils';

import type { Ref } from 'vue';
Expand All @@ -19,7 +19,6 @@ const props = defineProps<{

// Store
const bucketStore = useBucketStore();
const { getUserId } = storeToRefs(useAuthStore());
const { focusedElement } = storeToRefs(useNavStore());

// Form validation
Expand Down Expand Up @@ -49,8 +48,8 @@ const onSubmit = async (values: any) => {
};
// create bucket
await bucketStore.createBucketChild(props.parentBucket.bucketId, formData.subKey, formData.bucketName);
// refresh stores
await bucketStore.fetchBuckets({ userId: getUserId.value, objectPerms: true });
// refresh bucket store
await bucketStore.refreshBucketList();
showDialog(false);
toast.success('Adding subfolder', 'Folder configuration successful');
} catch (error: any) {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/bucket/BucketConfigForm.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
import { storeToRefs } from 'pinia';

Check warning on line 3 in frontend/src/components/bucket/BucketConfigForm.vue

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (20.x)

'storeToRefs' is defined but never used

Check warning on line 3 in frontend/src/components/bucket/BucketConfigForm.vue

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (18.x)

'storeToRefs' is defined but never used

Check warning on line 3 in frontend/src/components/bucket/BucketConfigForm.vue

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (16.x)

'storeToRefs' is defined but never used

Check warning on line 3 in frontend/src/components/bucket/BucketConfigForm.vue

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (16.x)

'storeToRefs' is defined but never used

Check warning on line 3 in frontend/src/components/bucket/BucketConfigForm.vue

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (18.x)

'storeToRefs' is defined but never used

Check warning on line 3 in frontend/src/components/bucket/BucketConfigForm.vue

View workflow job for this annotation

GitHub Actions / Unit Tests (Frontend) (20.x)

'storeToRefs' is defined but never used
import { Form } from 'vee-validate';
import { object, string } from 'yup';
import { differenceInSeconds } from 'date-fns';
Expand All @@ -10,7 +10,7 @@
import { SyncButton } from '@/components/common';

import { Button, useToast } from '@/lib/primevue';
import { useAuthStore, useBucketStore } from '@/store';
import { useBucketStore } from '@/store';
import { ButtonMode } from '@/utils/enums';
import { differential, getBucketPath, joinPath } from '@/utils/utils';

Expand Down Expand Up @@ -40,7 +40,6 @@

// Store
const bucketStore = useBucketStore();
const { getUserId } = storeToRefs(useAuthStore());

// Default form values
const initialValues: BucketForm = {
Expand Down Expand Up @@ -100,7 +99,7 @@
}

// refresh bucket list
await bucketStore.fetchBuckets({ userId: getUserId.value, objectPerms: true });
await bucketStore.refreshBucketList();

// trim trailing "//", if present
const currBucketPath = getBucketPath(initialValues as Bucket).endsWith('//')
Expand Down
34 changes: 3 additions & 31 deletions frontend/src/components/bucket/BucketList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { ref, onMounted } from 'vue';

import { BucketConfigForm, BucketSidebar, BucketTable } from '@/components/bucket';
import { Button, Dialog, Message } from '@/lib/primevue';
import { useAuthStore, useBucketStore, useConfigStore, usePermissionStore } from '@/store';
import { bucketService } from '@/services';
import { useBucketStore, useConfigStore, usePermissionStore } from '@/store';

import { BucketConfig, Permissions } from '@/utils/constants';
import { BucketConfig } from '@/utils/constants';
import { onDialogHide } from '@/utils/utils';

import type { Ref } from 'vue';
import type { Bucket } from '@/types';

// Store
const bucketStore = useBucketStore();
const { getProfile, getUserId } = storeToRefs(useAuthStore());
const { getConfig } = storeToRefs(useConfigStore());

// State
Expand Down Expand Up @@ -45,33 +43,7 @@ const closeBucketConfig = () => {
};

onMounted(async () => {
// fetch buckets with current user's READ permission (enforced by COMS privacy mode)
const buckets = await bucketStore.fetchBuckets({
userId: getUserId.value,
objectPerms: true
});
// get all subfolders of each bucket based on current users IDP
// so they shpw up in the folder tree
if (buckets && buckets.length > 0 && usePermissionStore().isUserElevatedRights()) {
const uniqueBuckets = buckets.filter(
(b, i, arr) => arr.findIndex((item) => item.bucket === b.bucket && item.endpoint === b.endpoint) === i
);
uniqueBuckets.forEach(async (bucket) => {
const allFolders = (
await bucketService.searchBuckets({
endpoint: bucket.endpoint,
bucket: bucket.bucket
})
).data;
await bucketStore.fetchBuckets({
bucketId: allFolders.slice(0, 1000).map((b: any) => b.bucketId),
userId: getUserId.value,
idp: (getProfile.value as any)?.identity_provider,
permCode: Permissions.READ,
objectPerms: true
});
});
}
await bucketStore.refreshBucketList();
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/bucket/BucketTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const confirmDeleteBucket = (bucketId: string) => {

async function deleteBucket(bucketId: string, recursive = true) {
await bucketStore.deleteBucket(bucketId, recursive);
await bucketStore.fetchBuckets({ userId: getUserId.value, objectPerms: true });
await bucketStore.refreshBucketList();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/object/DeletedObjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function showPermissions(objectId: string) {

onMounted(async () => {
loading.value = true;
await bucketStore.fetchBuckets({ userId: getUserId.value, objectPerms: true });
await bucketStore.refreshBucketList();

lazyParams.value = {
first: 0,
Expand Down
39 changes: 36 additions & 3 deletions frontend/src/store/bucketStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computed, ref } from 'vue';
import { useToast } from '@/lib/primevue';
import { bucketService } from '@/services';
import { useAppStore, useAuthStore, usePermissionStore } from '@/store';
import { Permissions } from '@/utils/constants';
import { getBucketPath } from '@/utils/utils';

import type { Ref } from 'vue';
Expand Down Expand Up @@ -104,17 +105,17 @@ export const useBucketStore = defineStore('bucket', () => {

// Get a unique list of bucket IDs the user has access to
// based on user permissions..
const permResponse = await permissionStore.fetchBucketPermissions({ ...params, idp: undefined });
const userPermResponse = await permissionStore.fetchBucketPermissions({ ...params, idp: undefined });
// and check IDP permissions (if current user's idp is provided in params)
const IdpPermResponse = params?.idp
? await permissionStore.fetchBucketIdpPermissions({ ...params, userId: undefined })
: undefined;

// if permissions found
if (permResponse || IdpPermResponse) {
if (userPermResponse || IdpPermResponse) {
const uniqueIds: Array<string> = [
...new Set<string>(
permResponse
userPermResponse
?.map((x: { bucketId: string }) => x.bucketId)
.concat(IdpPermResponse?.map((x: { bucketId: string }) => x.bucketId) || [])
)
Expand All @@ -139,6 +140,37 @@ export const useBucketStore = defineStore('bucket', () => {
}
}

async function refreshBucketList() {
// fetch buckets with current user's READ permission (enforced by COMS privacy mode)
const buckets = await fetchBuckets({
userId: authStore.getUserId,
objectPerms: true
});

// get all subfolders of each bucket based on current user's IDP,
// so they show up in the folder tree
if (buckets && buckets.length > 0 && usePermissionStore().isUserElevatedRights()) {
const uniqueBuckets = buckets.filter(
(b, i, arr) => arr.findIndex((item) => item.bucket === b.bucket && item.endpoint === b.endpoint) === i
);
uniqueBuckets.forEach(async (bucket) => {
const allFolders = (
await bucketService.searchBuckets({
endpoint: bucket.endpoint,
bucket: bucket.bucket
})
).data;
await fetchBuckets({
bucketId: allFolders.slice(0, 1000).map((b: any) => b.bucketId),
userId: authStore.getUserId,
idp: (authStore.getProfile as any)?.identity_provider,
permCode: Permissions.READ,
objectPerms: true
});
});
}
}

async function updateBucket(bucketId: string, bucket: Bucket) {
try {
appStore.beginIndeterminateLoading();
Expand Down Expand Up @@ -196,6 +228,7 @@ export const useBucketStore = defineStore('bucket', () => {
fetchBucket,
// fetchPublicBucket,
fetchBuckets,
refreshBucketList,
syncBucket,
syncBucketStatus,
togglePublic,
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/views/list/ListObjectsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const props = withDefaults(defineProps<Props>(), {
});

// Store
const authStore = useAuthStore();
const bucketStore = useBucketStore();
const { getProfile, getUserId, getIsAuthenticated } = storeToRefs(useAuthStore());
const permissionStore = usePermissionStore();
Expand Down Expand Up @@ -94,7 +95,11 @@ const confirmDeleteBucket = (bucketId: string) => {
};
async function deleteBucket(bucketId: string, recursive = true) {
await bucketStore.deleteBucket(bucketId, recursive);
await bucketStore.fetchBuckets({ userId: getUserId.value, objectPerms: true });
await bucketStore.fetchBuckets({
userId: getUserId.value,
objectPerms: true,
idp: authStore.getProfile?.identity_provider as string | undefined
});
}

// check if in a subfolder or at highest level of mounted folders
Expand Down
Loading