Skip to content
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

feat: remove internal link type #11553

Merged
merged 2 commits into from
Sep 17, 2024
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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-copy-quick-link-action
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Copy quick link action removal

The action for creating/copying quick links for a resource has been removed. Instead, a new action has been added to copy the permanent link of a resource.

https://github.com/owncloud/web/pull/11553
https://github.com/owncloud/web/issues/11544
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-internal-link-removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Internal link removal

The internal link type has been removed because the permanent link makes it obsolete. Existing internal links still resolve correctly to ensure backwards compatibility.

https://github.com/owncloud/web/pull/11553
https://github.com/owncloud/web/issues/11544
22 changes: 13 additions & 9 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
<oc-contextual-helper v-if="helpersEnabled" class="oc-pl-xs" v-bind="viaLinkHelp" />
</div>
<p
v-if="!canCreateLinks({ space, resource })"
v-if="!canCreateLinks"
data-testid="files-links-no-share-permissions-message"
class="oc-mt-m"
v-text="$gettext('You do not have permission to create links')"
/>
<div v-if="quicklink || canCreateLinks({ space, resource })" class="oc-mt-m">
<div v-if="quicklink || canCreateLinks" class="oc-mt-m">
<name-and-copy v-if="quicklink" :link-share="quicklink" />
<create-quick-link
v-else-if="canCreateLinks({ space, resource })"
@create-public-link="addNewLink(true)"
/>
<create-quick-link v-else-if="canCreateLinks" @create-public-link="addNewLink(true)" />
<details-and-edit
v-if="quicklink"
:can-rename="false"
Expand All @@ -29,7 +26,7 @@
/>
<hr class="oc-my-m" />
<oc-button
v-if="canCreateLinks({ space, resource })"
v-if="canCreateLinks"
id="files-file-link-add"
variation="primary"
appearance="raw"
Expand Down Expand Up @@ -137,7 +134,14 @@ export default defineComponent({
const { dispatchModal } = useModals()
const { removeResources } = useResourcesStore()
const { isPasswordEnforcedForLinkType } = useLinkTypes()
const { canShare: canCreateLinks } = useCanShare()
const { canShare } = useCanShare()

const canCreateLinks = computed(() => {
if (!ability.can('create-all', 'PublicLink')) {
return false
}
return canShare({ space: unref(space), resource: unref(resource) })
})

const sharesStore = useSharesStore()
const { updateLink, deleteLink } = sharesStore
Expand Down Expand Up @@ -182,7 +186,7 @@ export default defineComponent({

const canEditLink = (linkShare: LinkShare) => {
return (
canCreateLinks({ space: unref(space), resource: unref(resource) }) &&
unref(canCreateLinks) &&
(can('create-all', 'PublicLink') || linkShare.type === SharingLinkType.Internal)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ import { OcDrop } from 'design-system/src/components'
import { usePasswordPolicyService } from '@ownclouders/web-pkg'
import { useGettext } from 'vue3-gettext'
import SetLinkPasswordModal from '../../../Modals/SetLinkPasswordModal.vue'
import { storeToRefs } from 'pinia'
import { SharingLinkType } from '@ownclouders/web-client/graph/generated'
import DatePickerModal from '../../../Modals/DatePickerModal.vue'
import ExpirationDateIndicator from '../ExpirationDateIndicator.vue'
Expand Down Expand Up @@ -204,7 +203,6 @@ export default defineComponent({
useLinkTypes()

const resourcesStore = useResourcesStore()
const { ancestorMetaData } = storeToRefs(resourcesStore)

const space = inject<Ref<SpaceResource>>('space')
const resource = inject<Ref<Resource>>('resource')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ActionExtension,
useFileActionsCopyQuickLink,
useFileActionsCopyPermanentLink,
useFileActionsOpenShortcut,
useFileActionsShowShares
} from '@ownclouders/web-pkg'
Expand All @@ -14,7 +14,7 @@ import { unref } from 'vue'
export const useFileActions = (): ActionExtension[] => {
const { actions: openShortcutActions } = useFileActionsOpenShortcut()
const { actions: showSharesActions } = useFileActionsShowShares()
const { actions: quickLinkActions } = useFileActionsCopyQuickLink()
const { actions: permanentLinkActions } = useFileActionsCopyPermanentLink()

return [
{
Expand All @@ -33,7 +33,7 @@ export const useFileActions = (): ActionExtension[] => {
id: 'com.github.owncloud.web.files.quick-action.quicklink',
extensionPointIds: [quickActionsExtensionPoint.id],
type: 'action',
action: unref(quickLinkActions)[0]
action: unref(permanentLinkActions)[0]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const collaboratorAction = {
label: () => 'Add people'
}

const quickLinkAction = {
const permanentLinkAction = {
isVisible: vi.fn(() => false),
handler: vi.fn(),
icon: 'link-add',
id: 'quicklink',
name: 'copy-quicklink',
label: () => 'Create and copy quicklink'
id: 'permanent-link',
name: 'copy-permanent-link',
label: () => 'Copy permanent link'
}

const testItem = {
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('QuickActions', () => {
})

it('should not display action buttons where "displayed" is set to false', () => {
const linkActionButton = wrapper.find('.files-quick-action-copy-quicklink')
const linkActionButton = wrapper.find('.files-quick-action-copy-permanent-link')

expect(linkActionButton.exists()).toBeFalsy()
})
Expand Down Expand Up @@ -96,7 +96,7 @@ function getWrapper({ embedModeEnabled = false } = {}) {
}),
mock<ActionExtension>({
extensionPointIds: [quickActionsExtensionPoint.id],
action: quickLinkAction
action: permanentLinkAction
})
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('FileLinks', () => {

describe('when the add-new-link button is clicked', () => {
it('should call createLink', async () => {
const { wrapper, mocks } = getWrapper({ abilities: [] })
const { wrapper, mocks } = getWrapper()
await wrapper.find(selectors.linkAddButton).trigger('click')
expect(mocks.createLinkMock).toHaveBeenCalledTimes(1)
})
Expand All @@ -129,7 +129,7 @@ describe('FileLinks', () => {
canShare: () => true
})

it('existing viewer link is not modifiable', () => {
it('existing link is not modifiable', () => {
const viewerLink = defaultLinksList[0]
viewerLink.type = SharingLinkType.View
const { wrapper } = getWrapper({ resource, abilities: [], links: [viewerLink] })
Expand All @@ -139,15 +139,9 @@ describe('FileLinks', () => {
const isModifiable = detailsAndEdit.props('isModifiable')
expect(isModifiable).toBeFalsy()
})
it('existing internal link is modifiable', () => {
const internalLink = defaultLinksList[0]
internalLink.type = SharingLinkType.Internal
const { wrapper } = getWrapper({ resource, abilities: [], links: [internalLink] })
const detailsAndEdit = wrapper.findComponent<typeof DetailsAndEdit>(
linkListItemDetailsAndEdit
)
const isModifiable = detailsAndEdit.props('isModifiable')
expect(isModifiable).toBeTruthy()
it('new links cannot be created', () => {
const { wrapper } = getWrapper({ resource, abilities: [] })
expect(wrapper.find(selectors.linkAddButton).exists()).toBeFalsy()
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
useConfigStore,
useResourcesStore,
FileContentOptions,
useFileActionsCopyQuickLink,
useFileActionsCopyPermanentLink,
useFileActionsDownloadFile,
useFileActionsShowDetails,
useFileActionsShowShares,
Expand Down Expand Up @@ -141,7 +141,7 @@ export default defineComponent({
const { actions: openWithAppActions } = useFileActionsOpenWithApp({
appId: props.applicationId
})
const { actions: createQuickLinkActions } = useFileActionsCopyQuickLink()
const { actions: copyPermanentLinkActions } = useFileActionsCopyPermanentLink()
const { actions: downloadFileActions } = useFileActionsDownloadFile()
const { actions: showDetailsActions } = useFileActionsShowDetails()
const { actions: showSharesActions } = useFileActionsShowShares()
Expand Down Expand Up @@ -484,7 +484,7 @@ export default defineComponent({
)
})
const menuItemsShare = computed(() => {
return [...unref(showSharesActions), ...unref(createQuickLinkActions)].filter((item) =>
return [...unref(showSharesActions), ...unref(copyPermanentLinkActions)].filter((item) =>
item.isVisible(unref(actionOptions))
)
})
Expand Down
42 changes: 4 additions & 38 deletions packages/web-pkg/src/components/CreateLinkModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,17 @@
<span v-text="$gettext('Options')" />
</oc-button>
</div>
<div v-if="!onlyInternalLinksAllowed" class="link-modal-password oc-mb-m">
<div class="link-modal-password oc-mb-m">
<oc-text-input
v-if="isAdvancedMode"
:key="passwordInputKey"
:model-value="password.value"
type="password"
:password-policy="!selectedLinkTypeIsInternal ? passwordPolicy : null"
:password-policy="passwordPolicy"
:generate-password-method="generatePasswordMethod"
:error-message="password.error"
:description-message="
selectedLinkTypeIsInternal
? $gettext('Password cannot be set for internal links')
: undefined
"
:label="passwordEnforced ? `${$gettext('Password')}*` : $gettext('Password')"
class="link-modal-password-input"
:disabled="selectedLinkTypeIsInternal"
@update:model-value="updatePassword"
/>
<div v-else-if="password.value" class="link-modal-password-text oc-text-small oc-text-muted">
Expand All @@ -52,12 +46,6 @@
class="oc-mt-s"
:min-date="DateTime.now()"
:label="$gettext('Expiry date')"
:disabled="selectedLinkTypeIsInternal"
:description-message="
selectedLinkTypeIsInternal
? $gettext('Expiry date cannot be set for internal links')
: undefined
"
@date-changed="onExpiryDateChanged"
/>
</div>
Expand Down Expand Up @@ -187,10 +175,6 @@ export default defineComponent({
return $gettext('Share link(s)')
}

if (unref(selectedLinkTypeIsInternal)) {
return $gettext('Copy link')
}

return $gettext('Copy link')
})

Expand All @@ -213,12 +197,6 @@ export default defineComponent({
enforcePassword: unref(passwordEnforced)
})

const selectedLinkTypeIsInternal = computed(
() => unref(selectedType) === SharingLinkType.Internal
)
const onlyInternalLinksAllowed = computed(
() => unref(availableLinkTypes).length === 1 && unref(selectedLinkTypeIsInternal)
)
const setAdvancedMode = () => {
isAdvancedMode.value = true
}
Expand Down Expand Up @@ -248,10 +226,8 @@ export default defineComponent({
}

const passwordPolicyFulfilled = computed(() => {
if (!unref(selectedLinkTypeIsInternal)) {
if (!passwordPolicy.check(unref(password).value)) {
return false
}
if (!passwordPolicy.check(unref(password).value)) {
return false
}

return true
Expand Down Expand Up @@ -314,14 +290,6 @@ export default defineComponent({

const updateSelectedLinkType = (type: SharingLinkType) => {
selectedType.value = type
if (unref(selectedLinkTypeIsInternal)) {
password.value = ''
password.error = ''
selectedExpiry.value = undefined

// re-render password because it's the only way to remove policy messages
passwordInputKey.value = uuidV4()
}
}

onMounted(() => {
Expand All @@ -347,8 +315,6 @@ export default defineComponent({
selectedType,
selectedTypeIcon,
selectedTypeDescription,
selectedLinkTypeIsInternal,
onlyInternalLinksAllowed,
isSelectedLinkType,
updateSelectedLinkType,
updatePassword,
Expand Down
6 changes: 3 additions & 3 deletions packages/web-pkg/src/components/FilesList/ContextActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
FileActionOptions,
useExtensionRegistry,
useFileActionsToggleHideShare,
useFileActionsCopyQuickLink,
useFileActionsCopyPermanentLink,
useFileActionsPaste,
useFileActionsShowDetails,
useFileActionsShowShares,
Expand Down Expand Up @@ -47,7 +47,7 @@ export default defineComponent({
const { actions: enableSyncActions } = useFileActionsEnableSync()
const { actions: hideShareActions } = useFileActionsToggleHideShare()
const { actions: copyActions } = useFileActionsCopy()
const { actions: createQuickLinkActions } = useFileActionsCopyQuickLink()
const { actions: copyPermanentLinkActions } = useFileActionsCopyPermanentLink()
const { actions: disableSyncActions } = useFileActionsDisableSync()
const { actions: deleteActions } = useFileActionsDelete()
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive()
Expand Down Expand Up @@ -120,7 +120,7 @@ export default defineComponent({
const menuItemsShare = computed(() => {
return [
...unref(showSharesActions),
...unref(createQuickLinkActions),
...unref(copyPermanentLinkActions),
...unref(extensionsContextActions).filter((a) => a.category === 'share')
].filter((item) => item.isVisible(unref(actionOptions)))
})
Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/composables/actions/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './useFileActions'
export * from './useFileActionsEnableSync'
export * from './useFileActionsToggleHideShare'
export * from './useFileActionsCopy'
export * from './useFileActionsCopyQuicklink'
export * from './useFileActionsCopyPermanentLink'
export * from './useFileActionsDisableSync'
export * from './useFileActionsDelete'
export * from './useFileActionsDownloadArchive'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { computed } from 'vue'
import { useGettext } from 'vue3-gettext'
import { FileAction } from '../types'
import { useClipboard } from '../../clipboard'
import { useMessages } from '../../piniaStores'

export const useFileActionsCopyPermanentLink = () => {
const { showMessage, showErrorMessage } = useMessages()
const { $gettext } = useGettext()
const { copyToClipboard } = useClipboard()

const copyLinkToClipboard = async (url: string) => {
try {
await copyToClipboard(url)
showMessage({ title: $gettext('The link has been copied to your clipboard.') })
} catch (e) {
console.error(e)
showErrorMessage({
title: $gettext('Copy link failed'),
errors: [e]
})
}
}

const actions = computed((): FileAction[] => [
{
name: 'copy-permanent-link',
icon: 'link',
label: () => $gettext('Copy permanent link'),
handler: ({ resources }) => {
const [resource] = resources
const permalink = resource.privateLink
return copyLinkToClipboard(permalink)
},
isVisible: ({ resources }) => {
return resources.length === 1
},
class: 'oc-files-actions-copy-permanent-link-trigger'
}
])

return {
actions
}
}
Loading