Skip to content

Commit

Permalink
Merge pull request #10421 from owncloud/remove-share-status
Browse files Browse the repository at this point in the history
refactor: remove share status in favour of syncEnabled
  • Loading branch information
JammingBen authored Jan 31, 2024
2 parents 752ab3a + 8fcd572 commit 634c0f8
Show file tree
Hide file tree
Showing 34 changed files with 204 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<resource-table
v-else
v-model:selectedIds="selectedResourcesIds"
:data-test-share-status="shareStatus"
:is-side-bar-open="isSideBarOpen"
:fields-displayed="displayedFields"
sidebar-closed
Expand All @@ -33,13 +32,13 @@
@row-mounted="rowMounted"
@sort="sortHandler"
>
<template #status="{ resource }">
<template #syncEnabled="{ resource }">
<div
:key="resource.getDomSelector() + resource.status"
:key="resource.getDomSelector()"
class="oc-text-nowrap oc-flex oc-flex-middle oc-flex-right"
>
<oc-icon
v-if="getShowSyncedIcon(resource)"
v-if="resource.syncEnabled"
v-oc-tooltip="$gettext('Synced with your devices')"
name="loop-right"
class="sync-enabled"
Expand Down Expand Up @@ -104,12 +103,11 @@ import { VisibilityObserver } from '@ownclouders/web-pkg'
import { SortDir, useGetMatchingSpace } from '@ownclouders/web-pkg'
import { createLocationSpaces } from '@ownclouders/web-pkg'
import ListInfo from '../../components/FilesList/ListInfo.vue'
import { ShareResource, ShareStatus } from '@ownclouders/web-client/src/helpers/share'
import { IncomingShareResource } from '@ownclouders/web-client/src/helpers/share'
import { ContextActions } from '@ownclouders/web-pkg'
import { NoContentMessage } from '@ownclouders/web-pkg'
import { useSelectedResources } from '@ownclouders/web-pkg'
import { RouteLocationNamedRaw } from 'vue-router'
import { Resource } from '@ownclouders/web-client/src/helpers'
import { CreateTargetRouteOptions } from '@ownclouders/web-pkg'
import { createFileRouteOptions } from '@ownclouders/web-pkg'
Expand All @@ -134,13 +132,9 @@ export default defineComponent({
default: ''
},
items: {
type: Array as PropType<ShareResource[]>,
type: Array as PropType<IncomingShareResource[]>,
required: true
},
shareStatus: {
type: Number,
default: ShareStatus.accepted
},
sortBy: {
type: String,
required: false,
Expand Down Expand Up @@ -228,13 +222,12 @@ export default defineComponent({
},
data: () => ({
ShareStatus,
showMore: false
}),
computed: {
displayedFields() {
return ['name', 'status', 'owner', 'sdate', 'sharedWith']
return ['name', 'syncEnabled', 'owner', 'sdate', 'sharedWith']
},
countFiles() {
return this.items.filter((s) => s.type !== 'folder').length
Expand All @@ -259,7 +252,7 @@ export default defineComponent({
visibilityObserver.disconnect()
},
methods: {
rowMounted(resource: Resource, component) {
rowMounted(resource: IncomingShareResource, component) {
const loadPreview = async () => {
const preview = await this.$previewService.loadPreview(
{
Expand All @@ -284,9 +277,6 @@ export default defineComponent({
onExit: debounced.cancel
})
},
getShowSyncedIcon(resource: ShareResource) {
return resource.status === ShareStatus.accepted
},
toggleShowMore() {
this.showMore = !this.showMore
}
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/views/shares/SharedViaLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import { Resource } from '@ownclouders/web-client'
import { useGetMatchingSpace } from '@ownclouders/web-pkg'
import SharesNavigation from 'web-app-files/src/components/AppBar/SharesNavigation.vue'
import { storeToRefs } from 'pinia'
import { ShareResource } from '@ownclouders/web-client/src/helpers'
import { OutgoingShareResource } from '@ownclouders/web-client/src/helpers'
const visibilityObserver = new VisibilityObserver()
Expand Down Expand Up @@ -118,7 +118,7 @@ export default defineComponent({
const { totalResourcesCount } = storeToRefs(resourcesStore)
const { loadResourcesTask, selectedResourcesIds, paginatedResources } =
useResourcesViewDefaults<ShareResource, any, any[]>()
useResourcesViewDefaults<OutgoingShareResource, any, any[]>()
resourcesStore.$onAction((action) => {
if (action.name !== 'updateResourceField') {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/views/shares/SharedWithMe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import { useGroupingSettings } from '@ownclouders/web-pkg'
import SharesNavigation from 'web-app-files/src/components/AppBar/SharesNavigation.vue'
import { useGettext } from 'vue3-gettext'
import { useOpenWithDefaultApp, defaultFuseOptions } from '@ownclouders/web-pkg'
import { ShareResource, ShareTypes } from '@ownclouders/web-client/src/helpers'
import { IncomingShareResource, ShareTypes } from '@ownclouders/web-client/src/helpers'
import { uniq } from 'lodash-es'
export default defineComponent({
Expand Down Expand Up @@ -146,7 +146,7 @@ export default defineComponent({
isSideBarOpen,
paginatedResources,
scrollToResourceFromRoute
} = useResourcesViewDefaults<ShareResource, any, any>()
} = useResourcesViewDefaults<IncomingShareResource, any, any>()
const { $gettext } = useGettext()
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app-files/src/views/shares/SharedWithOthers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import { Resource } from '@ownclouders/web-client'
import { useGroupingSettings } from '@ownclouders/web-pkg'
import { useGetMatchingSpace } from '@ownclouders/web-pkg'
import SharesNavigation from 'web-app-files/src/components/AppBar/SharesNavigation.vue'
import { ShareResource, ShareTypes } from '@ownclouders/web-client/src/helpers'
import { OutgoingShareResource, ShareTypes } from '@ownclouders/web-client/src/helpers'
import { storeToRefs } from 'pinia'
const visibilityObserver = new VisibilityObserver()
Expand Down Expand Up @@ -140,7 +140,7 @@ export default defineComponent({
const { updateResourceField } = resourcesStore
const { totalResourcesCount } = storeToRefs(resourcesStore)
const resourcesViewDefaults = useResourcesViewDefaults<ShareResource, any, any[]>()
const resourcesViewDefaults = useResourcesViewDefaults<OutgoingShareResource, any, any[]>()
const { sortBy, sortDir, loadResourcesTask, selectedResourcesIds, paginatedResources } =
resourcesViewDefaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { defaultStubs, RouteLocation } from 'web-test-helpers'
import { useSortMock } from 'web-app-files/tests/mocks/useSortMock'
import { mock } from 'vitest-mock-extended'
import { defaultPlugins, mount, defaultComponentMocks } from 'web-test-helpers'
import { ShareTypes, ShareResource } from '@ownclouders/web-client/src/helpers'
import { ShareTypes, IncomingShareResource } from '@ownclouders/web-client/src/helpers'

vi.mock('web-app-files/src/composables/resourcesViewDefaults')
vi.mock('@ownclouders/web-pkg', async (importOriginal) => ({
Expand Down Expand Up @@ -84,8 +84,8 @@ describe('SharedWithMe view', () => {
const shareType2 = ShareTypes.group
const { wrapper } = getMountedWrapper({
files: [
mock<ShareResource>({ shareTypes: [shareType1.value] }),
mock<ShareResource>({ shareTypes: [shareType2.value] })
mock<IncomingShareResource>({ shareTypes: [shareType1.value] }),
mock<IncomingShareResource>({ shareTypes: [shareType2.value] })
]
})
const filterItems = wrapper.findComponent<any>('.share-type-filter').props('items')
Expand All @@ -99,11 +99,11 @@ describe('SharedWithMe view', () => {
const collaborator2 = { id: 'user2', displayName: 'user2' }
const { wrapper } = getMountedWrapper({
files: [
mock<ShareResource>({
mock<IncomingShareResource>({
sharedBy: collaborator1,
shareTypes: [ShareTypes.user.value]
}),
mock<ShareResource>({
mock<IncomingShareResource>({
sharedBy: collaborator2,
shareTypes: [ShareTypes.user.value]
})
Expand All @@ -122,12 +122,12 @@ describe('SharedWithMe view', () => {
it('filters shares accordingly by name', async () => {
const { wrapper } = getMountedWrapper({
files: [
mock<ShareResource>({
mock<IncomingShareResource>({
name: 'share1',
hidden: false,
shareTypes: [ShareTypes.user.value]
}),
mock<ShareResource>({
mock<IncomingShareResource>({
name: 'share2',
hidden: false,
shareTypes: [ShareTypes.user.value]
Expand Down
25 changes: 16 additions & 9 deletions packages/web-client/src/helpers/share/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ import {
import { ShareTypes } from './type'
import path from 'path'
import { SHARE_JAIL_ID, SpaceResource, buildWebDavSpacesPath } from '../space'
import { ShareStatus } from './status'
import { SharePermissions } from './permission'
import { buildSpaceShare } from './space'
import { LinkShareRoles, PeopleShareRoles } from './role'
import { ShareResource, Share } from './types'
import { ShareResource, Share, OutgoingShareResource, IncomingShareResource } from './types'

export const isShareResource = (resource: Resource): resource is ShareResource => {
return Object.hasOwn(resource, 'sharedWith')
}

export const isOutgoingShareResource = (resource: Resource): resource is OutgoingShareResource => {
return isShareResource(resource) && resource.outgoing
}

export const isIncomingShareResource = (resource: Resource): resource is IncomingShareResource => {
return isShareResource(resource) && !resource.outgoing
}

/**
* Transforms given shares into a resource format and returns only their unique occurences
*
Expand Down Expand Up @@ -160,12 +167,13 @@ export function buildSharedResource(
shareTypes: [parseInt(share.share_type)],
owner: { id: share.uid_owner, displayName: share.displayname_owner },
sharedBy: { id: share.uid_owner, displayName: share.displayname_owner },
sharedWith: share.sharedWith || []
sharedWith: share.sharedWith || [],
outgoing: !incomingShares
}

if (incomingShares) {
resource.status = parseInt(share.state)
resource.hidden = share.hidden === 'true' || share.hidden === true
;(resource as IncomingShareResource).syncEnabled = parseInt(share.state) === 0
;(resource as IncomingShareResource).hidden = share.hidden === 'true' || share.hidden === true
resource.name = isRemoteShare ? share.name : path.basename(share.file_target)
if (isRemoteShare) {
resource.path = '/'
Expand All @@ -179,13 +187,12 @@ export function buildSharedResource(
resource.path = share.file_target
resource.webDavPath = buildWebDavFilesPath(share.share_with, share.file_target)
}
resource.canDownload = () => parseInt(share.state) === ShareStatus.accepted
resource.canDownload = () => parseInt(share.state) === 0
resource.canShare = () => SharePermissions.share.enabled(share.permissions)
resource.canRename = () => parseInt(share.state) === ShareStatus.accepted
resource.canRename = () => parseInt(share.state) === 0
resource.canBeDeleted = () => SharePermissions.delete.enabled(share.permissions)
resource.canEditTags = () =>
parseInt(share.state) === ShareStatus.accepted &&
SharePermissions.update.enabled(share.permissions)
parseInt(share.state) === 0 && SharePermissions.update.enabled(share.permissions)
} else {
resource.name = isRemoteShare ? share.name : path.basename(share.path)
resource.path = share.path
Expand Down
14 changes: 7 additions & 7 deletions packages/web-client/src/helpers/share/functionsNG.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { extractDomSelector, extractExtensionFromFile, extractStorageId } from '../resource'
import { ShareTypes } from './type'
import { SHARE_JAIL_ID, buildWebDavSpacesPath } from '../space'
import { ShareStatus } from './status'
import { DriveItem, UnifiedRoleDefinition, User } from '../../generated'
import { GraphSharePermission, ShareResource } from './types'
import { GraphSharePermission, IncomingShareResource, OutgoingShareResource } from './types'
import { urlJoin } from '../../utils'

export const getShareResourceRoles = ({
Expand Down Expand Up @@ -64,7 +63,7 @@ export function buildIncomingShareResource({
}: {
driveItem: DriveItem
graphRoles: UnifiedRoleDefinition[]
}): ShareResource {
}): IncomingShareResource {
const resourceName = driveItem.name || driveItem.remoteItem.name
const storageId = extractStorageId(driveItem.remoteItem.id)
const permission = driveItem.remoteItem?.permissions[0]
Expand All @@ -74,7 +73,7 @@ export function buildIncomingShareResource({
const shareRoles = getShareResourceRoles({ driveItem, graphRoles })
const sharePermissions = getShareResourcePermissions({ driveItem, shareRoles })

const resource: ShareResource = {
const resource: IncomingShareResource = {
id,
shareId: id,
path: '/',
Expand All @@ -98,11 +97,11 @@ export function buildIncomingShareResource({
isFolder: !!driveItem.remoteItem.folder,
type: !!driveItem.remoteItem.folder ? 'folder' : 'file',
mimeType: driveItem.remoteItem.file?.mimeType || 'httpd/unix-directory',
status: permission?.['@client.synchronize'] ? ShareStatus.accepted : ShareStatus.declined,
syncEnabled: permission?.['@client.synchronize'],
hidden: permission?.['@ui.hidden'],
shareRoles,
sharePermissions,
outgoing: false,
canRename: () => !!permission?.['@client.synchronize'],
canDownload: () => sharePermissions.includes(GraphSharePermission.readBasic),
canUpload: () => sharePermissions.includes(GraphSharePermission.createUpload),
Expand All @@ -127,11 +126,11 @@ export function buildOutgoingShareResource({
}: {
driveItem: DriveItem
user: User
}): ShareResource {
}): OutgoingShareResource {
const storageId = extractStorageId(driveItem.id)
const path = urlJoin(driveItem.parentReference.path, driveItem.name)

const resource: ShareResource = {
const resource: OutgoingShareResource = {
id: driveItem.permissions[0].id,
shareId: driveItem.permissions[0].id,
path,
Expand Down Expand Up @@ -171,6 +170,7 @@ export function buildOutgoingShareResource({
isFolder: !!driveItem.folder,
type: !!driveItem.folder ? 'folder' : 'file',
mimeType: driveItem.file?.mimeType || 'httpd/unix-directory',
outgoing: true,
canRename: () => true,
canDownload: () => true,
canUpload: () => true,
Expand Down
1 change: 0 additions & 1 deletion packages/web-client/src/helpers/share/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export * from './functions'
export * from './permission'
export * from './role'
export * from './space'
export * from './status'
export * from './type'
export * from './types'
5 changes: 0 additions & 5 deletions packages/web-client/src/helpers/share/status.ts

This file was deleted.

15 changes: 9 additions & 6 deletions packages/web-client/src/helpers/share/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ export enum GraphSharePermission {
export interface ShareResource extends Resource {
sharedWith: Array<{ shareType: number } & Identity>
sharedBy: Identity
outgoing: boolean

syncEnabled?: boolean
shareRoles?: UnifiedRoleDefinition[]
sharePermissions?: GraphSharePermission[]
hidden?: boolean

status?: number // FIXME: remove in favour of syncEnabled
share?: any // FIXME: type DriveItem OR remove? do we want to expose the share on each resource?
}
export interface OutgoingShareResource extends ShareResource {}

export interface IncomingShareResource extends ShareResource {
hidden: boolean
syncEnabled: boolean
shareRoles: UnifiedRoleDefinition[]
sharePermissions: GraphSharePermission[]
}

/** @deprecated */
export interface Share {
Expand Down
12 changes: 6 additions & 6 deletions packages/web-pkg/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ import ViewOptions from '../ViewOptions.vue'
import { isLocationCommonActive, isLocationTrashActive } from '../../router'
import { FolderView } from '../../ui/types'
import {
useFileActionsAcceptShare,
useFileActionsEnableSync,
useFileActionsCopy,
useFileActionsDeclineShare,
useFileActionsDisableSync,
useFileActionsDelete,
useFileActionsDownloadArchive,
useFileActionsDownloadFile,
Expand Down Expand Up @@ -155,11 +155,11 @@ export default defineComponent({
const resourcesStore = useResourcesStore()
const { selectedResources } = storeToRefs(resourcesStore)
const { actions: acceptShareActions } = useFileActionsAcceptShare()
const { actions: enableSyncActions } = useFileActionsEnableSync()
const { actions: hideShareActions } = useFileActionsToggleHideShare()
const { actions: copyActions } = useFileActionsCopy()
const { actions: duplicateActions } = useSpaceActionsDuplicate()
const { actions: declineShareActions } = useFileActionsDeclineShare()
const { actions: disableSyncActions } = useFileActionsDisableSync()
const { actions: deleteActions } = useFileActionsDelete()
const { actions: downloadArchiveActions } = useFileActionsDownloadArchive()
const { actions: downloadFileActions } = useFileActionsDownloadFile()
Expand All @@ -181,8 +181,8 @@ export default defineComponent({
const batchActions = computed(() => {
let actions = [
...unref(hideShareActions),
...unref(acceptShareActions),
...unref(declineShareActions),
...unref(enableSyncActions),
...unref(disableSyncActions),
...unref(downloadArchiveActions),
...unref(downloadFileActions),
...unref(moveActions),
Expand Down
Loading

0 comments on commit 634c0f8

Please sign in to comment.