Skip to content

Commit

Permalink
feat: rename hide to hidden, use PUT for the request to set it
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Oct 26, 2023
1 parent 4ad2e1f commit dfabb67
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/web-client/src/helpers/share/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function buildSharedResource(
]
resource.sharedWith = share.sharedWith || []
resource.status = parseInt(share.state)
resource.hidden = share.hide === 'true' || share.hide === true
resource.hidden = share.hidden === 'true' || share.hidden === true
resource.name = path.basename(share.file_target)
if (hasShareJail) {
// FIXME, HACK 1: path needs to be '/' because the share has it's own webdav endpoint (we access it's root). should ideally be removed backend side.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const useFileActionsAcceptShare = ({ store }: { store?: Store<any> } = {}
const share = await triggerShareAction({
resource,
status: ShareStatus.accepted,
// Set hidden false here?
hasResharing: unref(hasResharing),
hasShareJail: unref(hasShareJail),
client: clientService.owncloudSdk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const useFileActionsDeclineShare = ({ store }: { store?: Store<any> } = {
const share = await triggerShareAction({
resource,
status: ShareStatus.declined,
// TODO: Hidden implications here?
hasResharing: unref(hasResharing),
hasShareJail: unref(hasShareJail),
client: clientService.owncloudSdk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useStore } from '../../store'
import { computed, unref } from 'vue'
import { useGettext } from 'vue3-gettext'
import { FileAction, FileActionOptions } from '../../actions'
import { Resource } from '@ownclouders/web-client'

export const useFileActionsToggleHideShare = ({ store }: { store?: Store<any> } = {}) => {
store = store || useStore()
Expand All @@ -25,13 +24,11 @@ export const useFileActionsToggleHideShare = ({ store }: { store?: Store<any> }
const loadingService = useLoadingService()
const configurationManager = useConfigurationManager()

const highlightedFile = computed<Resource>(() => store.getters['Files/highlightedFile'])

const handler = async ({ resources }: FileActionOptions) => {
const errors = []
const triggerPromises = []
const triggerQueue = new PQueue({ concurrency: 4 })
const hide = !resources[0].hidden
const hidden = !resources[0].hidden

resources.forEach((resource) => {
triggerPromises.push(
Expand All @@ -40,7 +37,7 @@ export const useFileActionsToggleHideShare = ({ store }: { store?: Store<any> }
const share = await triggerShareAction({
resource,
status: resource.status,
hide,
hidden,
hasResharing: unref(hasResharing),
hasShareJail: unref(hasShareJail),
client: clientService.owncloudSdk,
Expand All @@ -63,7 +60,7 @@ export const useFileActionsToggleHideShare = ({ store }: { store?: Store<any> }
if (errors.length === 0) {
store.dispatch('Files/resetFileSelection')
store.dispatch('showMessage', {
title: hide
title: hidden
? $gettext('The share was hidden successfully')
: $gettext('The share was unhidden successfully')
})
Expand All @@ -72,7 +69,9 @@ export const useFileActionsToggleHideShare = ({ store }: { store?: Store<any> }
}

store.dispatch('showErrorMessage', {
title: hide ? $gettext('Failed to hide the share') : $gettext('Failed to unhide share share'),
title: hidden
? $gettext('Failed to hide the share')
: $gettext('Failed to unhide share share'),
errors
})
}
Expand Down
14 changes: 9 additions & 5 deletions packages/web-pkg/src/helpers/share/triggerShareAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import { OwnCloudSdk } from '@ownclouders/web-client/src/types'
export async function triggerShareAction({
resource,
status,
hide = false,
hasResharing,
hasShareJail,
client,
hidden = undefined,
spaces = [],
fullShareOwnerPaths = false
}: {
resource: Resource
status: ShareStatus
hide?: boolean
hasResharing: boolean
hasShareJail: boolean
client: OwnCloudSdk
hidden?: boolean
spaces?: SpaceResource[]
fullShareOwnerPaths?: boolean
}) {
const method = _getRequestMethod(status)
const method = _getRequestMethod(status, hidden)
if (!method) {
throw new Error('invalid new share status')
}

// exec share action
let response = await client.requests.ocs({
service: 'apps/files_sharing',
action: `api/v1/shares/pending/${resource.share.id}?hide=${hide ? 'true' : 'false'}`,
action: `api/v1/shares/pending/${resource.share.id}?hidden=${hidden ? 'true' : 'false'}`,
method
})

Expand Down Expand Up @@ -58,7 +58,11 @@ export async function triggerShareAction({
return null
}

function _getRequestMethod(status) {
function _getRequestMethod(status: ShareStatus, hidden: boolean) {
if (hidden !== undefined) {
// setting the hidden state is always done via PUT
return 'PUT'
}
switch (status) {
case ShareStatus.accepted:
return 'POST'
Expand Down

0 comments on commit dfabb67

Please sign in to comment.