Skip to content

Commit 5fafe28

Browse files
committed
fix(files_sharing): Improve recursion in onNewLinShare
These changes fixes the issue of having the refresh the UI after share creation, as the share is not immediately removed from the UI list. Important changes - The basis of checking wether a password/expire date is no longer based on config values alone because the config is not expected in a share creation circle. Hence we check the configs and check if the share object (this.share) has the expected values set. This way, once the required properties are set, code control does not enter the block meant to handle the setting of required properties unneccessarily. Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
1 parent 98b9dbc commit 5fafe28

4 files changed

Lines changed: 82 additions & 38 deletions

File tree

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export default {
238238
239239
data() {
240240
return {
241+
shareCreationComplete: false,
241242
showDropdown: false,
242243
copySuccess: true,
243244
copied: false,
@@ -296,7 +297,7 @@ export default {
296297
* @return {string}
297298
*/
298299
subtitle() {
299-
if (this.isEmailShareType
300+
if (this.isEmailShareTypef
300301
&& this.title !== this.share.shareWith) {
301302
return this.share.shareWith
302303
}
@@ -407,6 +408,29 @@ export default {
407408
return this.config.isDefaultExpireDateEnforced && this.share && !this.share.id
408409
},
409410
411+
sharePolicyHasRequiredProperties() {
412+
return this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced
413+
},
414+
415+
requiredPropertiesMissing() {
416+
// Destructure share and config from this
417+
const { share, config } = this
418+
// Ensure share exist and the share policy has required properties
419+
if (!this.sharePolicyHasRequiredProperties) return false
420+
421+
if (share) {
422+
// If share has ID, then this is an incoming link share created from the existing link share
423+
// Hence assume required properties
424+
if (share.id) return true
425+
// Check if either password or expiration date is missing and enforced
426+
const isPasswordMissing = config.enforcePasswordForPublicLink && (share.password === null || share.password === undefined)
427+
const isExpireDateMissing = config.isDefaultExpireDateEnforced && (share.expireDate === null || share.expireDate === undefined)
428+
429+
return isPasswordMissing || isExpireDateMissing
430+
}
431+
// if no share, we can't tell if properties are missing or not so we assume they are
432+
return true
433+
},
410434
// if newPassword exists, but is empty, it means
411435
// the user deleted the original password
412436
hasUnsavedPassword() {
@@ -483,6 +507,7 @@ export default {
483507
* Create a new share link and append it to the list
484508
*/
485509
async onNewLinkShare() {
510+
console.debug('onNewLinkShare called (this.share status)', this.share)
486511
// do not run again if already loading
487512
if (this.loading) {
488513
return
@@ -497,28 +522,13 @@ export default {
497522
shareDefaults.expiration = this.formatDateToString(this.config.defaultExpirationDate)
498523
}
499524
525+
console.debug('Missing required properties?', this.requiredPropertiesMissing)
500526
// do not push yet if we need a password or an expiration date: show pending menu
501-
if (this.config.enableLinkPasswordByDefault || this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced) {
527+
if (this.sharePolicyHasRequiredProperties && this.requiredPropertiesMissing) {
502528
this.pending = true
529+
this.shareCreationComplete = false
503530
504-
// if a share already exists, pushing it
505-
if (this.share && !this.share.id) {
506-
// if the share is valid, create it on the server
507-
if (this.checkShare(this.share)) {
508-
try {
509-
await this.pushNewLinkShare(this.share, true)
510-
} catch (e) {
511-
this.pending = false
512-
console.error(e)
513-
return false
514-
}
515-
return true
516-
} else {
517-
this.open = true
518-
OC.Notification.showTemporary(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
519-
return false
520-
}
521-
}
531+
this.logger.info('Share policy requires mandated properties (password)...')
522532
523533
// ELSE, show the pending popovermenu
524534
// if password default or enforced, pre-fill with random one
@@ -540,8 +550,33 @@ export default {
540550
541551
// Nothing is enforced, creating share directly
542552
} else {
553+
554+
// if a share already exists, pushing it
555+
if (this.share && !this.share.id) {
556+
// if the share is valid, create it on the server
557+
if (this.checkShare(this.share)) {
558+
try {
559+
this.logger.info('Sending existing share to server', this.share)
560+
await this.pushNewLinkShare(this.share, true)
561+
this.shareCreationComplete = true
562+
this.logger.info('Share created on server', this.share)
563+
} catch (e) {
564+
this.pending = false
565+
console.error(e)
566+
this.logger.error('Error creating share', e)
567+
return false
568+
}
569+
return true
570+
} else {
571+
this.open = true
572+
OC.Notification.showTemporary(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
573+
return false
574+
}
575+
}
576+
543577
const share = new Share(shareDefaults)
544578
await this.pushNewLinkShare(share)
579+
this.shareCreationComplete = true
545580
}
546581
},
547582
@@ -581,8 +616,8 @@ export default {
581616
const newShare = await this.createShare(options)
582617
583618
this.open = false
619+
this.shareCreationComplete = true
584620
console.debug('Link share created', newShare)
585-
586621
// if share already exists, copy link directly on next tick
587622
let component
588623
if (update) {
@@ -624,8 +659,10 @@ export default {
624659
this.onSyncError('pending', message)
625660
}
626661
throw data
662+
627663
} finally {
628664
this.loading = false
665+
this.shareCreationComplete = true
629666
}
630667
},
631668
async copyLink() {
@@ -728,7 +765,9 @@ export default {
728765
// this.share already exists at this point,
729766
// but is incomplete as not pushed to server
730767
// YET. We can safely delete the share :)
731-
this.$emit('remove:share', this.share)
768+
if (!this.shareCreationComplete) {
769+
this.$emit('remove:share', this.share)
770+
}
732771
},
733772
734773
toggleQuickShareSelect() {
@@ -752,25 +791,23 @@ export default {
752791
width: 80%;
753792
min-width: 80%;
754793
755-
&__desc {
756-
display: flex;
757-
flex-direction: column;
758-
line-height: 1.2em;
794+
&__desc {
795+
display: flex;
796+
flex-direction: column;
797+
line-height: 1.2em;
759798
760-
p {
761-
color: var(--color-text-maxcontrast);
762-
}
799+
p {
800+
color: var(--color-text-maxcontrast);
801+
}
763802
764-
&__title {
765-
text-overflow: ellipsis;
766-
overflow: hidden;
767-
white-space: nowrap;
803+
&__title {
804+
text-overflow: ellipsis;
805+
overflow: hidden;
806+
white-space: nowrap;
807+
}
768808
}
769-
}
770-
771-
&__copy {
772809
773-
}
810+
&__copy {}
774811
}
775812
776813
&:not(.sharing-entry--share) &__actions {

apps/files_sharing/src/mixins/SharesMixin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import SharesRequests from './ShareRequests.js'
3636
import ShareTypes from './ShareTypes.js'
3737
import Config from '../services/ConfigService.js'
3838

39+
import { getLoggerBuilder } from '@nextcloud/logger'
40+
3941
import {
4042
BUNDLED_PERMISSIONS,
4143
} from '../lib/SharePermissionsToolBox.js'
@@ -80,6 +82,10 @@ export default {
8082
* ! do not remove it ot you'll lose all reactivity here
8183
*/
8284
reactiveState: this.share?.state,
85+
logger: getLoggerBuilder()
86+
.setApp('files_sharing')
87+
.detectUser()
88+
.build(),
8389
}
8490
},
8591

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ export default {
806806
this.share = share
807807
this.$emit('add:share', this.share)
808808
} else {
809+
this.$emit('update:share', this.share)
809810
this.queueUpdate(...permissionsAndAttributes)
810811
}
811812

apps/files_sharing/src/views/SharingLinkList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default {
116116
*/
117117
addShare(share, resolve) {
118118
// eslint-disable-next-line vue/no-mutating-props
119-
this.shares.unshift(share)
119+
this.shares = [share, ...this.shares]
120120
this.awaitForShare(share, resolve)
121121
},
122122

0 commit comments

Comments
 (0)