Handle enforced password for mail shares in the WebUI
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
c8e0809d43
commit
c47e79fc67
|
@ -56,6 +56,7 @@ import debounce from 'debounce'
|
|||
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
|
||||
|
||||
import Config from '../services/ConfigService'
|
||||
import GeneratePassword from '../utils/GeneratePassword'
|
||||
import Share from '../models/Share'
|
||||
import ShareRequests from '../mixins/ShareRequests'
|
||||
import ShareTypes from '../mixins/ShareTypes'
|
||||
|
@ -459,25 +460,49 @@ export default {
|
|||
}
|
||||
|
||||
this.loading = true
|
||||
console.debug('Adding a new share from the input for', value)
|
||||
try {
|
||||
let password = null
|
||||
|
||||
if (this.config.isPasswordForMailSharesRequired
|
||||
&& value.shareType === this.SHARE_TYPES.SHARE_TYPE_EMAIL) {
|
||||
password = await GeneratePassword()
|
||||
}
|
||||
|
||||
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
|
||||
const share = await this.createShare({
|
||||
path,
|
||||
shareType: value.shareType,
|
||||
shareWith: value.shareWith,
|
||||
password,
|
||||
permissions: this.fileInfo.sharePermissions & OC.getCapabilities().files_sharing.default_permissions,
|
||||
})
|
||||
|
||||
// If we had a password, we need to show it to the user as it was generated
|
||||
if (password) {
|
||||
share.newPassword = password
|
||||
// Wait for the newly added share
|
||||
const component = await new Promise(resolve => {
|
||||
this.$emit('add:share', share, resolve)
|
||||
})
|
||||
|
||||
// open the menu on the
|
||||
// freshly created share component
|
||||
component.open = true
|
||||
} else {
|
||||
// Else we just add it normally
|
||||
this.$emit('add:share', share)
|
||||
}
|
||||
|
||||
this.getRecommendations()
|
||||
|
||||
} catch (response) {
|
||||
await this.getRecommendations()
|
||||
} catch (error) {
|
||||
// focus back if any error
|
||||
const input = this.$refs.multiselect.$el.querySelector('input')
|
||||
if (input) {
|
||||
input.focus()
|
||||
}
|
||||
this.query = value.shareWith
|
||||
console.error('Error while adding new share', error)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
|
|
|
@ -52,12 +52,14 @@
|
|||
|
||||
<!-- link shares list -->
|
||||
<SharingLinkList v-if="!loading"
|
||||
ref="linkShareList"
|
||||
:can-reshare="canReshare"
|
||||
:file-info="fileInfo"
|
||||
:shares="linkShares" />
|
||||
|
||||
<!-- other shares list -->
|
||||
<SharingList v-if="!loading"
|
||||
ref="shareList"
|
||||
:shares="shares"
|
||||
:file-info="fileInfo" />
|
||||
|
||||
|
@ -295,11 +297,13 @@ export default {
|
|||
},
|
||||
|
||||
/**
|
||||
* Insert share at top of arrays
|
||||
* Add a new share into the shares list
|
||||
* and return the newly created share component
|
||||
*
|
||||
* @param {Share} share the share to insert
|
||||
* @param {Share} share the share to add to the array
|
||||
* @param {Function} resolve a function to run after the share is added and its component initialized
|
||||
*/
|
||||
addShare(share) {
|
||||
addShare(share, resolve) {
|
||||
// only catching share type MAIL as link shares are added differently
|
||||
// meaning: not from the ShareInput
|
||||
if (share.type === this.SHARE_TYPES.SHARE_TYPE_EMAIL) {
|
||||
|
@ -307,6 +311,31 @@ export default {
|
|||
} else {
|
||||
this.shares.unshift(share)
|
||||
}
|
||||
this.awaitForShare(share, resolve)
|
||||
},
|
||||
|
||||
/**
|
||||
* Await for next tick and render after the list updated
|
||||
* Then resolve with the matched vue component of the
|
||||
* provided share object
|
||||
*
|
||||
* @param {Share} share newly created share
|
||||
* @param {Function} resolve a function to execute after
|
||||
*/
|
||||
awaitForShare(share, resolve) {
|
||||
let listComponent = this.$refs.shareList
|
||||
// Only mail shares comes from the input, link shares
|
||||
// are managed internally in the SharingLinkList component
|
||||
if (share.type === this.SHARE_TYPES.SHARE_TYPE_EMAIL) {
|
||||
listComponent = this.$refs.linkShareList
|
||||
}
|
||||
|
||||
this.$nextTick(() => {
|
||||
const newShare = listComponent.$children.find(component => component.share === share)
|
||||
if (newShare) {
|
||||
resolve(newShare)
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue