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

[full-ci] Batch actions for accepting and declining shares #5374

Merged
merged 26 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2bfbe61
batch actions for Accept and Decline in Shared with me
elizavetaRa Jun 8, 2021
f13eab5
Move share action trigger into helper and create file action mixins
kulmann Jun 24, 2021
0fbd6ed
Merge remote-tracking branch 'origin/master' into batch-actions-accep…
kulmann Jun 24, 2021
da7ecf5
Remove unnecessary params
kulmann Jun 24, 2021
3ff7e9d
Move unit test from SharedWithMe view to helper
kulmann Jun 25, 2021
e10c0f2
Fix tests for declining a share
kulmann Jun 25, 2021
27a774d
Changelog item
kulmann Jun 25, 2021
dd65fca
Remove unneeded mutation mappings
kulmann Jun 25, 2021
8e6e97c
Fix e2e test about declining share
kulmann Jun 28, 2021
5b889e6
Use decline share action in all files view sidebar
kulmann Jun 28, 2021
cc63a9e
Make highlighted file reactive
kulmann Jun 28, 2021
7ebf005
Introduce mixins for data mod when mounting and destroying sidebar
kulmann Jun 28, 2021
dc2e4c3
Adjust tests about accepting shares
kulmann Jun 29, 2021
745a28d
Remove resource after declining share when in personal route
kulmann Jun 29, 2021
1371e88
Merge remote-tracking branch 'origin/master' into batch-actions-accep…
kulmann Jun 29, 2021
695c7be
Make linter happy
kulmann Jun 29, 2021
8c9bb37
Revert "decline share" action on "all files" page back to "delete" ac…
kulmann Jun 30, 2021
df7a6ac
Use delete step in tests where delete button is expected
kulmann Jun 30, 2021
f352330
Merge remote-tracking branch 'origin/master' into batch-actions-accep…
kulmann Jun 30, 2021
fee2fb5
Revert share loading when sidebar opens as it's not needed, yet
kulmann Jul 1, 2021
e72172f
Fix loading highlighted file in search mode
kulmann Jul 1, 2021
953e6d9
Merge remote-tracking branch 'origin/master' into batch-actions-accep…
kulmann Jul 1, 2021
168c78d
Fix e2e test for batch declining shares
kulmann Jul 1, 2021
9caf39c
Add expected test failure about declining shares
kulmann Jul 2, 2021
05404eb
Add more issue links to changelog
kulmann Jul 2, 2021
1e72e12
Correctly await share action batches with a p-queue
kulmann Jul 2, 2021
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-share-batch-actions
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Batch actions for accepting and declining shares

We've added batch actions for accepting and declining multiple selected incoming shares at once.

https://github.com/owncloud/web/issues/5204
https://github.com/owncloud/web/pull/5374
13 changes: 5 additions & 8 deletions packages/web-app-files/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ref="filesSidebar"
tabindex="-1"
class="uk-width-1-1 uk-width-1-2@m uk-width-1-3@xl"
@reset="setHighlightedFile(null)"
@reset="$_destroySideBar_hideDetails"
@beforeDestroy="focusSideBar"
@mounted="focusSideBar"
@fileChanged="focusSideBar"
Expand All @@ -27,6 +27,7 @@
<script>
import Mixins from './mixins'
import MixinRoutes from './mixins/routes'
import MixinDestroySideBar from './mixins/sidebar/destroySideBar'
import { mapActions, mapGetters, mapMutations } from 'vuex'
import AppBar from './components/AppBar/AppBar.vue'
import ProgressBar from './components/Upload/ProgressBar.vue'
Expand All @@ -38,7 +39,7 @@ export default {
ProgressBar,
SideBar
},
mixins: [Mixins, MixinRoutes],
mixins: [Mixins, MixinRoutes, MixinDestroySideBar],
data() {
return {
createFolder: false,
Expand All @@ -63,7 +64,7 @@ export default {
},
watch: {
$route() {
this.setHighlightedFile(null)
this.$_destroySideBar_hideDetails()
this.resetFileSelection()
}
},
Expand All @@ -78,7 +79,7 @@ export default {
},

methods: {
...mapActions('Files', ['dragOver', 'setHighlightedFile', 'resetFileSelection']),
...mapActions('Files', ['dragOver', 'resetFileSelection']),
...mapActions(['showMessage']),
...mapMutations('Files', ['SET_APP_SIDEBAR_EXPANDED_ACCORDION']),
...mapMutations(['SET_SIDEBAR_FOOTER_CONTENT_COMPONENT']),
Expand All @@ -87,10 +88,6 @@ export default {
console.info('trace', arguments)
},

openSideBar(file, sideBarName) {
this.setHighlightedFile(file)
this.SET_APP_SIDEBAR_EXPANDED_ACCORDION(sideBarName)
},
focusSideBar(component, event) {
this.focus({
from: document.activeElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<template v-if="isTrashbinRoute">
<oc-button
v-if="selectedFiles.length > 0"
id="restore-selected-btn"
key="restore-btn"
variation="primary"
class="oc-mr-s"
Expand Down Expand Up @@ -56,18 +57,42 @@
<translate>Delete</translate>
</oc-button>
</div>
<div v-if="canAccept">
<oc-button
id="accept-selected-shares-btn"
key="accept-shares-btn"
variation="primary"
@click="acceptShares()"
>
<oc-icon name="check" />
<translate>Accept</translate>
</oc-button>
</div>
<div v-if="canDecline">
<oc-button
id="decline-selected-shares-btn"
key="decline-shares-btn"
variation="primary"
@click="declineShares()"
>
<oc-icon name="not_interested" />
<translate>Decline</translate>
</oc-button>
</div>
</oc-grid>
</div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import { mapGetters, mapActions, mapMutations } from 'vuex'

import MixinRoutes from '../../../mixins/routes'
import MixinDeleteResources from '../../../mixins/deleteResources'
import { cloneStateObject } from '../../../helpers/store'
import { canBeMoved } from '../../../helpers/permissions'
import { checkRoute } from '../../../helpers/route'
import { shareStatus } from '../../../helpers/shareStatus'
import { triggerShareAction } from '../../../helpers/share/triggerShareAction'

export default {
mixins: [MixinRoutes, MixinDeleteResources],
Expand Down Expand Up @@ -110,13 +135,42 @@ export default {
},

canDelete() {
if (this.isSharedWithMeRoute) {
return false
}

if (this.isPublicFilesRoute) {
return this.currentFolder.canBeDeleted()
}

return true
},

canAccept() {
if (!this.isSharedWithMeRoute) {
return false
}
let canAccept = true
this.selectedFiles.forEach(file => {
if (file.status === shareStatus.accepted) {
canAccept = false
}
})

return canAccept
},

canDecline() {
if (!this.isSharedWithMeRoute) {
return false
}
let canDecline = true
this.selectedFiles.forEach(file => {
if (file.status === shareStatus.declined) canDecline = false
})
return canDecline
},

displayBulkActions() {
return this.$route.meta.hasBulkActions && this.selectedFiles.length > 0
},
Expand All @@ -129,6 +183,7 @@ export default {
methods: {
...mapActions('Files', ['removeFilesFromTrashbin', 'resetFileSelection', 'setHighlightedFile']),
...mapActions(['showMessage']),
...mapMutations('Files', ['SELECT_RESOURCES', 'UPDATE_RESOURCE']),

restoreFiles(resources = this.selectedFiles) {
for (const resource of resources) {
Expand Down Expand Up @@ -189,6 +244,61 @@ export default {
})
}
})
},

acceptShares() {
this.triggerShareActions(shareStatus.accepted)
},

declineShares() {
this.triggerShareActions(shareStatus.declined)
},

triggerShareActions(newShareStatus) {
const errors = []
this.selectedFiles.forEach(async resource => {
kulmann marked this conversation as resolved.
Show resolved Hide resolved
try {
const share = await triggerShareAction(
resource,
newShareStatus,
!this.isOcis,
this.$client
)
if (share) {
this.UPDATE_RESOURCE(share)
}
} catch (error) {
errors.push(error)
}
})

if (errors.length === 0) {
this.SELECT_RESOURCES([])
return
}

console.log(errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev leftover or on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional, because I don't want to swallow errors. Eventually we should come up with a proper logging solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC ;)

if (newShareStatus === shareStatus.accepted) {
this.showMessage({
title: this.$ngettext(
'Error while accepting the selected share.',
'Error while accepting selected shares.',
this.selectedFiles.length
),
status: 'danger'
})
return
}
if (newShareStatus === shareStatus.declined) {
this.showMessage({
title: this.$ngettext(
'Error while declining the selected share.',
'Error while declining selected shares.',
this.selectedFiles.length
),
status: 'danger'
})
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app-files/src/helpers/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function _getFileExtension(name) {
export function buildResource(resource) {
const isFolder = resource.type === 'dir'
const extension = _getFileExtension(resource.name)
return {
const result = {
id: resource.fileInfo['{http://owncloud.org/ns}fileid'],
fileId: resource.fileInfo['{http://owncloud.org/ns}fileid'],
icon: isFolder ? 'folder' : getFileIcon(extension),
Expand Down Expand Up @@ -83,6 +83,7 @@ export function buildResource(resource) {
return this.permissions.indexOf('S') >= 0
}
}
return result
}

export function attachIndicators(resource, sharesTree) {
Expand Down
43 changes: 43 additions & 0 deletions packages/web-app-files/src/helpers/share/triggerShareAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { buildSharedResource } from '../resources'
import { shareStatus } from '../shareStatus'

export async function triggerShareAction(resource, status, allowReSharing, $client) {
const method = _getRequestMethod(status)
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}`,
method
})

// exit on failure
if (response.status !== 200) {
throw new Error(response.statusText)
}

// get updated share from response and transform & return it
if (parseInt(response.headers.get('content-length')) > 0) {
response = await response.json()
if (response.ocs.data.length > 0) {
const share = response.ocs.data[0]
return buildSharedResource(share, true, allowReSharing)
}
}

return null
}

function _getRequestMethod(status) {
switch (status) {
case shareStatus.accepted:
return 'POST'
case shareStatus.declined:
return 'DELETE'
default:
return null
}
}
51 changes: 51 additions & 0 deletions packages/web-app-files/src/mixins/actions/acceptShare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { triggerShareAction } from '../../helpers/share/triggerShareAction'

import { checkRoute } from '../../helpers/route'
import MixinRoutes from '../routes'
import { shareStatus } from '../../helpers/shareStatus'
import { mapGetters, mapMutations } from 'vuex'

export default {
mixins: [MixinRoutes],
computed: {
...mapGetters(['isOcis']),
$_acceptShare_items() {
return [
{
icon: 'check',
handler: this.$_acceptShare_trigger,
label: () => this.$gettext('Accept share'),
isEnabled: ({ resource }) => {
if (!checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}

return [shareStatus.pending, shareStatus.declined].includes(resource.status)
},
componentType: 'oc-button',
class: 'oc-files-actions-sidebar-accept-share-trigger'
}
]
}
},
methods: {
...mapMutations('Files', ['UPDATE_RESOURCE']),
async $_acceptShare_trigger(resource) {
try {
const share = await triggerShareAction(
resource,
shareStatus.accepted,
!this.isOcis,
this.$client
)
this.UPDATE_RESOURCE(share)
} catch (error) {
console.log(error)
this.showMessage({
title: this.$gettext('Error while accepting the selected share.'),
status: 'danger'
})
}
}
}
}
51 changes: 51 additions & 0 deletions packages/web-app-files/src/mixins/actions/declineShare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { triggerShareAction } from '../../helpers/share/triggerShareAction'

import { checkRoute } from '../../helpers/route'
import MixinRoutes from '../routes'
import { shareStatus } from '../../helpers/shareStatus'
import { mapGetters, mapMutations } from 'vuex'

export default {
mixins: [MixinRoutes],
computed: {
...mapGetters(['isOcis']),
$_declineShare_items() {
return [
{
icon: 'not_interested',
handler: this.$_declineShare_trigger,
label: () => this.$gettext('Decline share'),
isEnabled: ({ resource }) => {
if (!checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}

return [shareStatus.pending, shareStatus.accepted].includes(resource.status)
},
componentType: 'oc-button',
class: 'oc-files-actions-sidebar-decline-share-trigger'
}
]
}
},
methods: {
...mapMutations('Files', ['UPDATE_RESOURCE']),
async $_declineShare_trigger(resource) {
try {
const share = await triggerShareAction(
resource,
shareStatus.declined,
!this.isOcis,
this.$client
)
this.UPDATE_RESOURCE(share)
} catch (error) {
console.log(error)
this.showMessage({
title: this.$gettext('Error while declining the selected share.'),
status: 'danger'
})
}
}
}
}
Loading