Merge pull request #21210 from nextcloud/backport/20938/stable19

[stable19] Fix the Talk verification
This commit is contained in:
Roeland Jago Douma 2020-06-06 09:31:16 +02:00 committed by GitHub
commit 513446cafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 40 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -198,9 +198,9 @@
<!-- password protected by Talk --> <!-- password protected by Talk -->
<ActionCheckbox v-if="isPasswordProtectedByTalkAvailable" <ActionCheckbox v-if="isPasswordProtectedByTalkAvailable"
:checked.sync="isPasswordProtectedByTalk" :checked.sync="isPasswordProtectedByTalk"
:disabled="saving" :disabled="!canTogglePasswordProtectedByTalkAvailable || saving"
class="share-link-password-talk-checkbox" class="share-link-password-talk-checkbox"
@change="queueUpdate('sendPasswordByTalk')"> @change="onPasswordProtectedByTalkChange">
{{ t('files_sharing', 'Video verification') }} {{ t('files_sharing', 'Video verification') }}
</ActionCheckbox> </ActionCheckbox>
@ -481,6 +481,20 @@ export default {
: false : false
}, },
canTogglePasswordProtectedByTalkAvailable() {
if (!this.isPasswordProtected) {
// Makes no sense
return false
} else if (this.isEmailShareType && !this.hasUnsavedPassword) {
// For email shares we need a new password in order to enable or
// disable
return false
}
// Anything else should be fine
return true
},
/** /**
* Pending data. * Pending data.
* If the share still doesn't have an id, it is not synced * If the share still doesn't have an id, it is not synced
@ -792,6 +806,22 @@ export default {
} }
}, },
/**
* Update the password along with "sendPasswordByTalk".
*
* If the password was modified the new password is sent; otherwise
* updating a mail share would fail, as in that case it is required that
* a new password is set when enabling or disabling
* "sendPasswordByTalk".
*/
onPasswordProtectedByTalkChange() {
if (this.hasUnsavedPassword) {
this.share.password = this.share.newPassword.trim()
}
this.queueUpdate('sendPasswordByTalk', 'password')
},
/** /**
* Save potential changed data on menu close * Save potential changed data on menu close
*/ */

View File

@ -88,17 +88,11 @@ export default {
* Update a share * Update a share
* *
* @param {number} id share id * @param {number} id share id
* @param {Object} data destructuring object * @param {Object} properties key-value object of the properties to update
* @param {string} data.property property to update
* @param {any} data.value value to set
*/ */
async updateShare(id, { property, value }) { async updateShare(id, properties) {
try { try {
// ocs api requires x-www-form-urlencoded const request = await axios.put(shareUrl + `/${id}`, properties, headers)
const data = new URLSearchParams()
data.append(property, value)
const request = await axios.put(shareUrl + `/${id}`, { [property]: value }, headers)
if (!('ocs' in request.data)) { if (!('ocs' in request.data)) {
throw request throw request
} }
@ -107,7 +101,7 @@ export default {
console.error('Error while updating share', error) console.error('Error while updating share', error)
OC.Notification.showTemporary(t('files_sharing', 'Error updating the share'), { type: 'error' }) OC.Notification.showTemporary(t('files_sharing', 'Error updating the share'), { type: 'error' })
const message = error.response.data.ocs.meta.message const message = error.response.data.ocs.meta.message
throw new Error(`${property}, ${message}`) throw new Error(`${Object.keys(properties)}, ${message}`)
} }
}, },
}, },

View File

@ -224,31 +224,34 @@ export default {
/** /**
* Send an update of the share to the queue * Send an update of the share to the queue
* *
* @param {string} property the property to sync * @param {string} propertyNames the properties to sync
*/ */
queueUpdate(property) { queueUpdate(...propertyNames) {
if (propertyNames.length === 0) {
// Nothing to update
return
}
if (this.share.id) { if (this.share.id) {
const properties = {}
// force value to string because that is what our // force value to string because that is what our
// share api controller accepts // share api controller accepts
const value = this.share[property].toString() propertyNames.map(p => (properties[p] = this.share[p].toString()))
this.updateQueue.add(async() => { this.updateQueue.add(async() => {
this.saving = true this.saving = true
this.errors = {} this.errors = {}
try { try {
await this.updateShare(this.share.id, { await this.updateShare(this.share.id, properties)
property,
value,
})
// clear any previous errors // clear any previous errors
this.$delete(this.errors, property) this.$delete(this.errors, propertyNames[0])
// reset password state after sync // reset password state after sync
this.$delete(this.share, 'newPassword') this.$delete(this.share, 'newPassword')
} catch ({ message }) { } catch ({ message }) {
if (message && message !== '') { if (message && message !== '') {
this.onSyncError(property, message) this.onSyncError(propertyNames[0], message)
} }
} finally { } finally {
this.saving = false this.saving = false
@ -288,6 +291,14 @@ export default {
} }
break break
} }
case 'sendPasswordByTalk': {
// show error
this.$set(this.errors, property, message)
// Restore previous state
this.share.sendPasswordByTalk = !this.share.sendPasswordByTalk
break
}
} }
}, },