Skip to content

Commit 0d07542

Browse files
authored
Merge pull request #54055 from nextcloud/fix/sharing-restore-on-failure
fix(files_sharing): restore state when updating share failed
2 parents cf29ebb + 1fbce91 commit 0d07542

12 files changed

+44
-34
lines changed

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@
7474
{{ config.enforcePasswordForPublicLink ? t('files_sharing', 'Password protection (enforced)') : t('files_sharing', 'Password protection') }}
7575
</NcActionCheckbox>
7676

77-
<NcActionInput v-if="pendingEnforcedPassword || share.password"
77+
<NcActionInput v-if="pendingEnforcedPassword || isPasswordProtected"
7878
class="share-link-password"
7979
:label="t('files_sharing', 'Enter a password')"
80-
:value.sync="share.password"
80+
:value.sync="share.newPassword"
8181
:disabled="saving"
8282
:required="config.enableLinkPasswordByDefault || config.enforcePasswordForPublicLink"
8383
:minlength="isPasswordPolicyEnabled && config.passwordPolicy.minLength"
@@ -115,7 +115,8 @@
115115
</template>
116116
</NcActionInput>
117117

118-
<NcActionButton @click.prevent.stop="onNewLinkShare(true)">
118+
<NcActionButton :disabled="pendingEnforcedPassword && !share.newPassword"
119+
@click.prevent.stop="onNewLinkShare(true)">
119120
<template #icon>
120121
<CheckIcon :size="20" />
121122
</template>
@@ -646,6 +647,7 @@ export default {
646647
647648
// create share & close menu
648649
const share = new Share(shareDefaults)
650+
share.newPassword = share.password
649651
const component = await new Promise(resolve => {
650652
this.$emit('add:share', share, resolve)
651653
})
@@ -838,7 +840,7 @@ export default {
838840
*/
839841
onPasswordSubmit() {
840842
if (this.hasUnsavedPassword) {
841-
this.share.password = this.share.newPassword.trim()
843+
this.share.newPassword = this.share.newPassword.trim()
842844
this.queueUpdate('password')
843845
}
844846
},
@@ -853,7 +855,7 @@ export default {
853855
*/
854856
onPasswordProtectedByTalkChange() {
855857
if (this.hasUnsavedPassword) {
856-
this.share.password = this.share.newPassword.trim()
858+
this.share.newPassword = this.share.newPassword.trim()
857859
}
858860
859861
this.queueUpdate('sendPasswordByTalk', 'password')

apps/files_sharing/src/mixins/SharesMixin.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ export default {
165165
isPasswordProtected: {
166166
get() {
167167
return this.config.enforcePasswordForPublicLink
168-
|| !!this.share.password
168+
|| this.share.password !== ''
169+
|| this.share.newPassword !== undefined
169170
},
170171
async set(enabled) {
171172
if (enabled) {
172-
this.share.password = await GeneratePassword(true)
173-
this.$set(this.share, 'newPassword', this.share.password)
173+
this.$set(this.share, 'newPassword', await GeneratePassword(true))
174174
} else {
175175
this.share.password = ''
176176
this.$delete(this.share, 'newPassword')
@@ -272,7 +272,7 @@ export default {
272272
this.loading = true
273273
this.open = false
274274
await this.deleteShare(this.share.id)
275-
console.debug('Share deleted', this.share.id)
275+
logger.debug('Share deleted', { shareId: this.share.id })
276276
const message = this.share.itemType === 'file'
277277
? t('files_sharing', 'File "{path}" has been unshared', { path: this.share.path })
278278
: t('files_sharing', 'Folder "{path}" has been unshared', { path: this.share.path })
@@ -303,39 +303,49 @@ export default {
303303
const properties = {}
304304
// force value to string because that is what our
305305
// share api controller accepts
306-
propertyNames.forEach(name => {
306+
for (const name of propertyNames) {
307+
if (name === 'password') {
308+
properties[name] = this.share.newPassword ?? this.share.password
309+
continue
310+
}
311+
307312
if (this.share[name] === null || this.share[name] === undefined) {
308313
properties[name] = ''
309314
} else if ((typeof this.share[name]) === 'object') {
310315
properties[name] = JSON.stringify(this.share[name])
311316
} else {
312317
properties[name] = this.share[name].toString()
313318
}
314-
})
319+
}
315320

316321
return this.updateQueue.add(async () => {
317322
this.saving = true
318323
this.errors = {}
319324
try {
320325
const updatedShare = await this.updateShare(this.share.id, properties)
321326

322-
if (propertyNames.indexOf('password') >= 0) {
327+
if (propertyNames.includes('password')) {
323328
// reset password state after sync
329+
this.share.password = this.share.newPassword ?? ''
324330
this.$delete(this.share, 'newPassword')
325331

326332
// updates password expiration time after sync
327333
this.share.passwordExpirationTime = updatedShare.password_expiration_time
328334
}
329335

330336
// clear any previous errors
331-
this.$delete(this.errors, propertyNames[0])
337+
for (const property of propertyNames) {
338+
this.$delete(this.errors, property)
339+
}
332340
showSuccess(this.updateSuccessMessage(propertyNames))
333341
} catch (error) {
334342
logger.error('Could not update share', { error, share: this.share, propertyNames })
335343

336344
const { message } = error
337345
if (message && message !== '') {
338-
this.onSyncError(propertyNames[0], message)
346+
for (const property of propertyNames) {
347+
this.onSyncError(property, message)
348+
}
339349
showError(message)
340350
} else {
341351
// We do not have information what happened, but we should still inform the user
@@ -384,6 +394,13 @@ export default {
384394
* @param {string} message the error message
385395
*/
386396
onSyncError(property, message) {
397+
if (property === 'password' && this.share.newPassword) {
398+
if (this.share.newPassword === this.share.password) {
399+
this.share.password = ''
400+
}
401+
this.$delete(this.share, 'newPassword')
402+
}
403+
387404
// re-open menu if closed
388405
this.open = true
389406
switch (property) {

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</NcCheckboxRadioSwitch>
129129
<NcPasswordField v-if="isPasswordProtected"
130130
autocomplete="new-password"
131-
:value="hasUnsavedPassword ? share.newPassword : ''"
131+
:value="share.newPassword ?? ''"
132132
:error="passwordError"
133133
:helper-text="errorPasswordLabel || passwordHint"
134134
:required="isPasswordEnforced && isNewShare"
@@ -872,7 +872,6 @@ export default {
872872
if (this.isNewShare) {
873873
if ((this.config.enableLinkPasswordByDefault || this.isPasswordEnforced) && this.isPublicShare) {
874874
this.$set(this.share, 'newPassword', await GeneratePassword(true))
875-
this.$set(this.share, 'password', this.share.newPassword)
876875
this.advancedSectionAccordionExpanded = true
877876
}
878877
/* Set default expiration dates if configured */
@@ -973,10 +972,7 @@ export default {
973972
this.share.note = ''
974973
}
975974
if (this.isPasswordProtected) {
976-
if (this.hasUnsavedPassword && this.isValidShareAttribute(this.share.newPassword)) {
977-
this.share.password = this.share.newPassword
978-
this.$delete(this.share, 'newPassword')
979-
} else if (this.isPasswordEnforced && this.isNewShare && !this.isValidShareAttribute(this.share.password)) {
975+
if (this.isPasswordEnforced && this.isNewShare && !this.isValidShareAttribute(this.share.password)) {
980976
this.passwordError = true
981977
}
982978
} else {
@@ -1000,7 +996,7 @@ export default {
1000996
incomingShare.expireDate = this.hasExpirationDate ? this.share.expireDate : ''
1001997
1002998
if (this.isPasswordProtected) {
1003-
incomingShare.password = this.share.password
999+
incomingShare.password = this.share.newPassword
10041000
}
10051001
10061002
let share
@@ -1032,9 +1028,8 @@ export default {
10321028
this.$emit('add:share', this.share)
10331029
} else {
10341030
// Let's update after creation as some attrs are only available after creation
1031+
await this.queueUpdate(...permissionsAndAttributes)
10351032
this.$emit('update:share', this.share)
1036-
emit('update:share', this.share)
1037-
this.queueUpdate(...permissionsAndAttributes)
10381033
}
10391034
10401035
await this.getNode()
@@ -1111,10 +1106,6 @@ export default {
11111106
* "sendPasswordByTalk".
11121107
*/
11131108
onPasswordProtectedByTalkChange() {
1114-
if (this.hasUnsavedPassword) {
1115-
this.share.password = this.share.newPassword.trim()
1116-
}
1117-
11181109
this.queueUpdate('sendPasswordByTalk', 'password')
11191110
},
11201111
isValidShareAttribute(value) {

dist/2210-2210.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/2210-2210.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/2210-2210.js.map.license

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/9780-9780.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

dist/9780-9780.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/9780-9780.js.map.license

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9780-9780.js.license

0 commit comments

Comments
 (0)