-
Notifications
You must be signed in to change notification settings - Fork 3
Public Folders #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TimCsaky
wants to merge
5
commits into
master
Choose a base branch
from
pub
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Public Folders #236
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68e8ac4
Public Folders
TimCsaky 309a859
BucketTable, ListObjectsView: add labels for public folders
norrisng-bc 065c0c1
Disable BucketPublicToggle if parent bucket is public
norrisng-bc 2ec8604
ListObjectsView: implement no-auth access if public folder
norrisng-bc 0cca435
Correctly handle public folders in ShareButton modal TabPanels
norrisng-bc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <script setup lang="ts"> | ||
| import { ref, watch, computed, onMounted } from 'vue'; | ||
|
|
||
| import { InputSwitch, useConfirm, useToast } from '@/lib/primevue'; | ||
| import { useBucketStore, usePermissionStore } from '@/store'; | ||
| import { Permissions } from '@/utils/constants'; | ||
|
|
||
| import type { Ref } from 'vue'; | ||
| import { getBucketPath, trimUrl } from '@/utils/utils'; | ||
|
|
||
| // Props | ||
| type Props = { | ||
| bucketId: string; | ||
| bucketName: string; | ||
| bucketPublic: boolean; | ||
| userId: string; | ||
| }; | ||
|
|
||
| const props = withDefaults(defineProps<Props>(), {}); | ||
|
|
||
| // Store | ||
| const bucketStore = useBucketStore(); | ||
| const permissionStore = usePermissionStore(); | ||
|
|
||
| // State | ||
| const isPublic: Ref<boolean> = ref(props.bucketPublic); | ||
| const isParentPublic = ref<boolean>(false); | ||
|
|
||
| // Actions | ||
| const toast = useToast(); | ||
| const confirm = useConfirm(); | ||
|
|
||
| const togglePublic = async (setPublicValue: boolean) => { | ||
| if (setPublicValue) { | ||
| confirm.require({ | ||
| message: | ||
| 'Please confirm that you want to set folder to public. ' + | ||
| 'This allows the share link to be accessible by anyone, even without credentials.', | ||
| header: 'Confirm set to public', | ||
| acceptLabel: 'Confirm', | ||
| rejectLabel: 'Cancel', | ||
| accept: () => { | ||
| bucketStore | ||
| .togglePublic(props.bucketId, true) | ||
| .then(() => { | ||
| toast.success(`"${props.bucketName}" set to public`); | ||
| }) | ||
| .catch((e) => toast.error('Changing public state', e.response?.data.detail ?? e, { life: 0 })); | ||
| }, | ||
| reject: () => (isPublic.value = false), | ||
| onHide: () => (isPublic.value = false) | ||
| }); | ||
| } else | ||
| bucketStore | ||
| .togglePublic(props.bucketId, false) | ||
| .then(() => { | ||
| toast.success(`"${props.bucketName}" is no longer public`); | ||
| }) | ||
| .catch((e) => toast.error('Changing public state', e.response?.data.detail ?? e, { life: 0 })); | ||
| }; | ||
|
|
||
| const isParentBucketPublic = (): boolean => { | ||
| // @ts-ignore: bucketId will always be provided | ||
| const currBucketPath = getBucketPath(bucketStore.getBucket(props.bucketId)); | ||
| const parentPath = currBucketPath.substring(0, currBucketPath.lastIndexOf('/')); | ||
| const parentBucket = bucketStore.getBucketByFullPath(parentPath); | ||
|
|
||
| const isTopLevelBucket = trimUrl(currBucketPath) === trimUrl(parentPath); | ||
|
|
||
| // top-level buckets by definition won't have a parent bucket restricting public status | ||
| return isTopLevelBucket ? false : parentBucket?.public ?? false; | ||
| }; | ||
|
|
||
| const isToggleEnabled = computed(() => { | ||
| return ( | ||
| !isParentPublic.value && | ||
| usePermissionStore().isUserElevatedRights() && | ||
| permissionStore.isObjectActionAllowed(props.bucketId, props.userId, Permissions.MANAGE, props.bucketId as string) | ||
| ); | ||
| }); | ||
|
|
||
| onMounted(async () => { | ||
| isPublic.value = props.bucketPublic; | ||
| isParentPublic.value = await isParentBucketPublic(); | ||
| }); | ||
|
|
||
| watch(props, () => { | ||
| isPublic.value = props.bucketPublic; | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <InputSwitch | ||
| v-model="isPublic" | ||
| aria-label="Toggle to make public" | ||
| :disabled="!isToggleEnabled" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe not a requirement now.. but at some point would be good to add a tooltip indicating why it's disabled. |
||
| @change="togglePublic(isPublic)" | ||
| /> | ||
| </template> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think using the store is ok for now..
but i think it requires that the user has visited the 'my files' page already to load any parent folders into the store.