Skip to content

Commit ee97330

Browse files
committed
fix(files_sharing): use newPassword always for the unsaved password
`newPassword` is the unsaved password, while `share.password` is the current saved password. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent cc2ed08 commit ee97330

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export default {
501501
return true
502502
}
503503
// Check if either password or expiration date is missing and enforced
504-
const isPasswordMissing = this.config.enforcePasswordForPublicLink && !this.share.password
504+
const isPasswordMissing = this.config.enforcePasswordForPublicLink && !this.share.newPassword
505505
const isExpireDateMissing = this.config.isDefaultExpireDateEnforced && !this.share.expireDate
506506
507507
return isPasswordMissing || isExpireDateMissing
@@ -631,15 +631,12 @@ export default {
631631
632632
logger.info('Share policy requires a review or has mandated properties (password, expirationDate)...')
633633
634-
// ELSE, show the pending popovermenu
634+
const share = new Share(shareDefaults)
635635
// if password default or enforced, pre-fill with random one
636636
if (this.config.enableLinkPasswordByDefault || this.config.enforcePasswordForPublicLink) {
637-
shareDefaults.password = await GeneratePassword(true)
637+
this.$set(share, 'newPassword', await GeneratePassword(true))
638638
}
639639
640-
// create share & close menu
641-
const share = new Share(shareDefaults)
642-
share.newPassword = share.password
643640
const component = await new Promise(resolve => {
644641
this.$emit('add:share', share, resolve)
645642
})
@@ -703,7 +700,7 @@ export default {
703700
const options = {
704701
path,
705702
shareType: ShareType.Link,
706-
password: share.password,
703+
password: share.newPassword,
707704
expireDate: share.expireDate ?? '',
708705
attributes: JSON.stringify(this.fileInfo.shareAttributes),
709706
// we do not allow setting the publicUpload
@@ -810,10 +807,8 @@ export default {
810807
* cannot ensure data is up-to-date
811808
*/
812809
onPasswordDisable() {
813-
this.share.password = ''
814-
815810
// reset password state after sync
816-
this.$delete(this.share, 'newPassword')
811+
this.$set(this.share, 'newPassword', '')
817812
818813
// only update if valid share.
819814
if (this.share.id) {

apps/files_sharing/src/mixins/SharesMixin.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export default {
5555
saving: false,
5656
open: false,
5757

58+
/** @type {boolean | undefined} */
59+
passwordProtectedState: undefined,
60+
5861
// concurrency management queue
5962
// we want one queue per share
6063
updateQueue: new PQueue({ concurrency: 1 }),
@@ -164,15 +167,22 @@ export default {
164167
*/
165168
isPasswordProtected: {
166169
get() {
167-
return this.config.enforcePasswordForPublicLink
168-
|| this.share.password !== undefined
169-
|| this.share.newPassword !== undefined
170+
if (this.config.enforcePasswordForPublicLink) {
171+
return true
172+
}
173+
if (this.passwordProtectedState !== undefined) {
174+
return this.passwordProtectedState
175+
}
176+
return this.share.newPassword !== undefined
177+
|| this.share.password !== undefined
178+
170179
},
171180
async set(enabled) {
172181
if (enabled) {
182+
this.passwordProtectedState = true
173183
this.$set(this.share, 'newPassword', await GeneratePassword(true))
174184
} else {
175-
this.share.password = ''
185+
this.passwordProtectedState = false
176186
this.$delete(this.share, 'newPassword')
177187
}
178188
},
@@ -208,6 +218,11 @@ export default {
208218
return false
209219
}
210220
}
221+
if (share.newPassword) {
222+
if (typeof share.newPassword !== 'string') {
223+
return false
224+
}
225+
}
211226
if (share.expirationDate) {
212227
const date = share.expirationDate
213228
if (!date.isValid()) {
@@ -394,7 +409,7 @@ export default {
394409
* @param {string} message the error message
395410
*/
396411
onSyncError(property, message) {
397-
if (property === 'password' && this.share.newPassword) {
412+
if (property === 'password' && this.share.newPassword !== undefined) {
398413
if (this.share.newPassword === this.share.password) {
399414
this.share.password = ''
400415
}

0 commit comments

Comments
 (0)