-
Notifications
You must be signed in to change notification settings - Fork 3
Internal only file sharing feature #247
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
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eb3751e
Handle access based on IDP permissions
TimCsaky 834692e
Controls for Internal Only sharing
TimCsaky 87ef692
Styling changes for IDP permission feature
TimCsaky 77f24b3
Prevent exceptions to Internal setting on folders
TimCsaky 4ce733f
Bug fix for viewing public folder when logged in but have no user per…
TimCsaky 563c1d0
IDP permission wording changes
TimCsaky b8daf0f
Split call to COMS permission search to avoid exceeding query string …
TimCsaky d295b4f
Add Internal folders to folder tree if from same bucket as user's
TimCsaky a678177
scope Recycle Bin to Objects with USER permission type
TimCsaky 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| <script setup lang="ts"> | ||
| import { computed, onMounted, ref, watch } from 'vue'; | ||
|
|
||
| import { InputSwitch, useConfirm, useToast } from '@/lib/primevue'; | ||
| import { usePermissionStore } from '@/store'; | ||
| import { Permissions } from '@/utils/constants'; | ||
|
|
||
| import type { Ref } from 'vue'; | ||
|
|
||
| // Props | ||
| type Props = { | ||
| bucketId: string; | ||
| bucketName: string; | ||
| bucketPublic: boolean; | ||
| userId: string; | ||
| }; | ||
|
|
||
| const props = withDefaults(defineProps<Props>(), {}); | ||
|
|
||
| // Store | ||
| const permissionStore = usePermissionStore(); | ||
|
|
||
| // State | ||
| const isInternal: Ref<boolean> = ref(false); | ||
| const fetchBucketInternal = async (): Promise<boolean> => { | ||
| const bucketIdpPermissions = await permissionStore.fetchBucketIdpPermissions({ | ||
| bucketId: props.bucketId, | ||
| permCode: 'READ', | ||
| idp: 'idir' | ||
| }); | ||
| const hasPerms = (bucketIdpPermissions?.length ?? 0) > 0; | ||
|
|
||
| return hasPerms || props.bucketPublic; | ||
| }; | ||
|
|
||
| // check bucket for the IDP permission | ||
| const isBucketInternal: Ref<boolean> = ref(false); | ||
| const isParentBucketInternal: Ref<boolean> = ref(false); | ||
| const fetchParentBucketInternal = async (): Promise<boolean> => { | ||
| const bucketIdpPermissions = await permissionStore.fetchBucketIdpPermissions({ | ||
| bucketId: props.bucketId, | ||
| permCode: 'READ', | ||
| idp: 'idir' | ||
| }); | ||
| return (bucketIdpPermissions?.length ?? 0) > 0; | ||
| }; | ||
|
|
||
| const isToggleEnabled = computed(() => { | ||
| return ( | ||
| !isBucketInternal.value && | ||
| !props.bucketPublic && | ||
| usePermissionStore().isUserElevatedRights() && | ||
| permissionStore.isBucketActionAllowed(props.bucketId, props.userId, Permissions.MANAGE) | ||
| ); | ||
| }); | ||
|
|
||
| // Actions | ||
| const toast = useToast(); | ||
| const confirm = useConfirm(); | ||
|
|
||
| const toggleIdp = async (value: boolean) => { | ||
| if (value) { | ||
| confirm.require({ | ||
| message: "Setting this file to 'Internal only' will allow all IDIR users " + 'to view and download it.', | ||
| header: 'Set file to Internal only?', | ||
| acceptLabel: 'Set to Internal only', | ||
| rejectLabel: 'Cancel', | ||
| accept: () => { | ||
| permissionStore | ||
| .addBucketIdpPermission(props.bucketId, 'idir', 'READ') | ||
| .then(() => { | ||
| isInternal.value = true; | ||
| toast.success('File set to Internal only', `"${props.bucketName}" is now Internal only`); | ||
| }) | ||
| .catch((e) => toast.error('Setting file to Internal only failed', e.response?.data.detail, { life: 0 })); | ||
| }, | ||
| reject: () => (isInternal.value = false), | ||
| onHide: () => (isInternal.value = false) | ||
| }); | ||
| } else | ||
| confirm.require({ | ||
| message: | ||
| "Setting this file to private will remove 'Internal only' access. " + | ||
| 'Only users with permissions will be able to view or download the file.', | ||
| header: 'Set file to private?', | ||
| acceptLabel: 'Set to private', | ||
| rejectLabel: 'Cancel', | ||
| accept: () => { | ||
| permissionStore | ||
| .deleteBucketIdpPermission(props.bucketId, 'idir', 'READ') | ||
| .then(() => { | ||
| isInternal.value = false; | ||
| toast.success('File set to private', `"${props.bucketName}" is no longer 'Internal only'`); | ||
| }) | ||
| .catch((e) => toast.error('Setting file to private failed', e.response?.data.detail, { life: 0 })); | ||
| }, | ||
| reject: () => (isInternal.value = true), | ||
| onHide: () => (isInternal.value = true) | ||
| }); | ||
| }; | ||
|
|
||
| onMounted(async () => { | ||
| isInternal.value = await fetchBucketInternal(); | ||
| isParentBucketInternal.value = await fetchParentBucketInternal(); | ||
| }); | ||
|
|
||
| watch(props, () => { | ||
| if (props.bucketPublic === true) isInternal.value = true; | ||
| else { | ||
| const perms = permissionStore.getBucketIdpPermissions.filter( | ||
| (p: any) => p.permCode === Permissions.READ && p.bucketId === props.bucketId && p.idp === 'idir' | ||
| ); | ||
| if (perms.length > 0) isInternal.value = true; | ||
| else { | ||
| isInternal.value = false; | ||
| } | ||
| } | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <span | ||
| v-tooltip=" | ||
| isToggleEnabled | ||
| ? '' | ||
| : props.bucketPublic | ||
| ? 'Enabled by Public Sharing' | ||
| : 'Change the folder\'s \'Internal only\' setting to update this file' | ||
| " | ||
| > | ||
| <InputSwitch | ||
| :model-value="isInternal" | ||
| aria-label="Toggle to make file Internl only" | ||
| :disabled="!isToggleEnabled" | ||
| @update:model-value="toggleIdp($event)" | ||
| /> | ||
| </span> | ||
| </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
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
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.
Uh oh!
There was an error while loading. Please reload this page.