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 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,32 @@
<translate>Delete</translate>
</oc-button>
</div>
<div v-if="canAccept">
<oc-button id="accept-shares-btn" key="accept-shares-btn" @click="acceptShares()">
<oc-icon name="check" />
<translate>Accept</translate>
</oc-button>
</div>
<div v-if="canDecline">
<oc-button id="decline-shares-btn" key="decline-shares-btn" @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 +124,42 @@ export default {
},

canDelete() {
if (checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}

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

return true
},

canAccept() {
if (!checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}
let canAccept = true
this.selectedFiles.forEach(file => {
if (file.status === shareStatus.accepted) {
canAccept = false
}
})

return canAccept
},

canDecline() {
if (!checkRoute(['files-shared-with-me'], this.$route.name)) {
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 +172,12 @@ export default {
methods: {
...mapActions('Files', ['removeFilesFromTrashbin', 'resetFileSelection', 'setHighlightedFile']),
...mapActions(['showMessage']),
...mapMutations('Files', [
kulmann marked this conversation as resolved.
Show resolved Hide resolved
'LOAD_FILES',
'SELECT_RESOURCES',
'CLEAR_CURRENT_FILES_LIST',
'UPDATE_RESOURCE'
]),

restoreFiles(resources = this.selectedFiles) {
for (const resource of resources) {
Expand Down Expand Up @@ -189,6 +238,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
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
}
}
50 changes: 50 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,50 @@
import { triggerShareAction } from '../../helpers/share/triggerShareAction'

import { checkRoute } from '../../helpers/route'
import MixinRoutes from '../routes'
import { shareStatus } from '../../helpers/shareStatus'
import { mapGetters } 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: {
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'
})
}
}
}
}
50 changes: 50 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,50 @@
import { triggerShareAction } from '../../helpers/share/triggerShareAction'

import { checkRoute } from '../../helpers/route'
import MixinRoutes from '../routes'
import { shareStatus } from '../../helpers/shareStatus'
import { mapGetters } 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: {
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'
})
}
}
}
}
7 changes: 3 additions & 4 deletions packages/web-app-files/src/mixins/actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ export default {
return [
{
icon: 'delete',
label: () => {
return this.$gettext('Delete')
},
label: () => this.$gettext('Delete'),
handler: this.$_delete_trigger,
isEnabled: ({ resource }) => {
if (checkRoute(['files-trashbin'], this.$route.name)) {
if (checkRoute(['files-shared-with-me', 'files-trashbin'], this.$route.name)) {
return false
}

Expand All @@ -23,6 +21,7 @@ export default {
class: 'oc-files-actions-sidebar-delete-trigger'
},
{
// this menu item is ONLY for the trashbin (permanently delete a file/folder)
icon: 'delete',
label: () => this.$gettext('Delete'),
handler: this.$_delete_trigger,
Expand Down
18 changes: 17 additions & 1 deletion packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { mapGetters, mapActions, mapState } from 'vuex'

import { checkRoute } from '../helpers/route'
import AcceptShare from './actions/acceptShare'
import Copy from './actions/copy'
import DeclineShare from './actions/declineShare'
import Delete from './actions/delete'
import Download from './actions/download'
import Favorite from './actions/favorite'
Expand All @@ -17,6 +19,8 @@ const actionsMixins = [
'navigate',
'download',
'favorite',
'acceptShare',
'declineShare',
'copy',
'move',
'rename',
Expand All @@ -28,7 +32,19 @@ export const EDITOR_MODE_EDIT = 'edit'
export const EDITOR_MODE_CREATE = 'create'

export default {
mixins: [Copy, Delete, Download, Favorite, Fetch, Move, Navigate, Rename, Restore],
mixins: [
AcceptShare,
Copy,
DeclineShare,
Delete,
Download,
Favorite,
Fetch,
Move,
Navigate,
Rename,
Restore
],
computed: {
...mapState(['apps']),
...mapGetters('Files', ['highlightedFile', 'currentFolder']),
Expand Down
Loading