Skip to content

Commit

Permalink
Add unshare dialog (#6795)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan authored Apr 21, 2022
1 parent 6260166 commit eabb7f3
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add un-share confirmation dialog

We have implemented a confirmation dialog which pops up if the user clicks the "remove share" button

https://github.com/owncloud/web/pull/6795
https://github.com/owncloud/web/issues/6728
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
:share="collaborator"
:modifiable="!collaborator.indirect"
:shared-parent-route="getSharedParentRoute(collaborator)"
@onDelete="$_ocCollaborators_deleteShare"
@onDelete="$_ocCollaborators_deleteShare_trigger"
/>
</li>
</ul>
Expand Down Expand Up @@ -306,6 +306,7 @@ export default {
'deleteShare',
'loadIncomingShares'
]),
...mapActions(['createModal', 'hideModal', 'showMessage']),
$_isCollaboratorShare(collaborator) {
return ShareTypes.containsAnyValue(ShareTypes.authenticated, [collaborator.shareType])
},
Expand Down Expand Up @@ -337,13 +338,43 @@ export default {
toggleShareeList() {
this.showShareesList = !this.showShareesList
},
$_ocCollaborators_deleteShare_trigger(share) {
const modal = {
variation: 'danger',
title: this.$gettext('Remove share'),
cancelText: this.$gettext('Cancel'),
confirmText: this.$gettext('Remove'),
icon: 'alarm-warning',
message: this.$gettext('Are you sure you want to remove this share?'),
hasInput: false,
onCancel: this.hideModal,
onConfirm: () => this.$_ocCollaborators_deleteShare(share)
}
this.createModal(modal)
},
$_ocCollaborators_deleteShare(share) {
this.deleteShare({
client: this.$client,
share: share,
resource: this.highlightedFile,
storageId: this.$route.params.storageId
})
.then(() => {
this.hideModal()
this.showMessage({
title: this.$gettext('Share was removed successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to remove share'),
status: 'danger'
})
})
},
$_reloadShares() {
this.loadCurrentFileOutgoingShares({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<collaborator-list-item
:share="collaborator"
:modifiable="isModifiable(collaborator)"
@onDelete="$_ocCollaborators_deleteShare(collaborator)"
@onDelete="$_ocCollaborators_deleteShare_trigger(collaborator)"
/>
</li>
</ul>
Expand Down Expand Up @@ -104,6 +104,7 @@ export default defineComponent({
},
methods: {
...mapActions('Files', ['loadCurrentFileOutgoingShares', 'deleteShare']),
...mapActions(['createModal', 'hideModal', 'showMessage']),
isModifiable(share) {
if (!this.currentUserIsManager) {
Expand All @@ -120,21 +121,50 @@ export default defineComponent({
)
return managers.length > 1
},
$_ocCollaborators_deleteShare_trigger(share) {
const modal = {
variation: 'danger',
title: this.$gettext('Remove share'),
cancelText: this.$gettext('Cancel'),
confirmText: this.$gettext('Remove'),
icon: 'alarm-warning',
message: this.$gettext('Are you sure you want to remove this share?'),
hasInput: false,
onCancel: this.hideModal,
onConfirm: () => this.$_ocCollaborators_deleteShare(share)
}
this.createModal(modal)
},
$_ocCollaborators_deleteShare(share) {
this.deleteShare({
client: this.$client,
graphClient: this.graphClient,
share: share,
resource: this.highlightedFile
}).then(() => {
// current user was removed from the share.
if (share.collaborator.name === this.user.id) {
if (isLocationSpacesActive(this.$router, 'files-spaces-projects')) {
return this.$router.go()
}
return this.$router.push(createLocationSpaces('files-spaces-projects'))
}
})
.then(() => {
this.hideModal()
this.showMessage({
title: this.$gettext('Share was removed successfully')
})
// current user was removed from the share.
if (share.collaborator.name === this.user.id) {
if (isLocationSpacesActive(this.$router, 'files-spaces-projects')) {
return this.$router.go()
}
return this.$router.push(createLocationSpaces('files-spaces-projects'))
}
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to remove share'),
status: 'danger'
})
})
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ describe('FileShares', () => {
})

it('reacts on delete events by collaborator list items', async () => {
const spyOnCollaboratorDelete = jest
.spyOn(FileShares.methods, '$_ocCollaborators_deleteShare')
const spyOnCollaboratorDeleteTrigger = jest
.spyOn(FileShares.methods, '$_ocCollaborators_deleteShare_trigger')
.mockImplementation()
const wrapper = getMountedWrapper({
user,
outgoingCollaborators: collaborators
})
wrapper.find(selectors.firstCollaboratorListItem).vm.$emit('onDelete')
await wrapper.vm.$nextTick()
expect(spyOnCollaboratorDelete).toHaveBeenCalledTimes(1)
expect(spyOnCollaboratorDeleteTrigger).toHaveBeenCalledTimes(1)
})
it('reloads shares if highlighted file is changed', async () => {
const spyOnReloadShares = jest
Expand Down Expand Up @@ -207,6 +207,11 @@ const storeOptions = (data) => {
}

return {
actions: {
createModal: jest.fn(),
hideModal: jest.fn(),
showMessage: jest.fn()
},
state: {
user
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,15 @@ describe('SpaceMembers', () => {
outgoingCollaborators: outgoingShares
})

const spyOnCollaboratorDelete = jest.spyOn(wrapper.vm, 'deleteShare')
const spyOnCollaboratorDeleteTrigger = jest.spyOn(
wrapper.vm,
'$_ocCollaborators_deleteShare_trigger'
)
wrapper
.find(`div[data-testid="collaborator-user-item-${outgoingShares[0].collaborator.name}"]`)
.vm.$emit('onDelete')
await wrapper.vm.$nextTick()
expect(spyOnCollaboratorDelete).toHaveBeenCalledTimes(1)
expect(spyOnCollaboratorDeleteTrigger).toHaveBeenCalledTimes(1)
})
})
})
Expand All @@ -132,6 +135,11 @@ const storeOptions = (data, isInLoadingState) => {
const { user, outgoingCollaborators = [] } = data

return {
actions: {
createModal: jest.fn(),
hideModal: jest.fn(),
showMessage: jest.fn()
},
state: {
user
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ module.exports = {
deleteShareWithUserGroup: function (collaborator) {
this.expandShareEditDropdown(collaborator)
const deleteSelector = this.elements.deleteShareButton.selector
const dialogSelector = this.elements.dialog.selector
const dialogConfirmSelector = this.elements.dialogConfirmBtn.selector

return this.useXpath()
.waitForElementVisible(deleteSelector)
.waitForAnimationToFinish() // wait for animation of share sliding out
.click(deleteSelector)
.waitForElementVisible(dialogSelector)
.waitForAnimationToFinish() // wait for transition on the modal to finish
.click(dialogConfirmSelector)
.waitForAjaxCallsToStartAndFinish()
},
/**
Expand Down Expand Up @@ -207,6 +213,14 @@ module.exports = {
selector: '//button[contains(@class, "remove-share")]',
locateStrategy: 'xpath'
},
dialog: {
selector: '//div[contains(@class, "oc-modal")]',
locateStrategy: 'xpath'
},
dialogConfirmBtn: {
selector: '//button[contains(@class, "oc-modal-body-actions-confirm")]',
locateStrategy: 'xpath'
},
createShareDialog: {
selector: '#new-collaborators-form'
},
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/support/objects/app-files/share/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export const removeSharee = async (args: removeShareeArgs): Promise<void> => {
.locator(
`${userColumn}//ul[contains(@class,"collaborator-edit-dropdown-options-list")]//button[contains(@class,"remove-share")]`
)
.click()
.click(),
page.locator('.oc-modal-body-actions-confirm').click()
])
}
}

0 comments on commit eabb7f3

Please sign in to comment.