Skip to content

Commit f032df6

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 2863ad5 commit f032df6

2 files changed

Lines changed: 76 additions & 27 deletions

File tree

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ import GeneratePassword from '../utils/GeneratePassword.js'
241241
import Share from '../models/Share.js'
242242
import SharesMixin from '../mixins/SharesMixin.js'
243243
import ShareDetails from '../mixins/ShareDetails.js'
244+
import { getLoggerBuilder } from '@nextcloud/logger'
244245
245246
export default {
246247
name: 'SharingEntryLink',
@@ -453,6 +454,32 @@ export default {
453454
return this.config.isDefaultExpireDateEnforced && this.share && !this.share.id
454455
},
455456
457+
sharePolicyHasRequiredProperties() {
458+
return this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced
459+
},
460+
461+
requiredPropertiesMissing() {
462+
// Ensure share exist and the share policy has required properties
463+
if (!this.sharePolicyHasRequiredProperties) {
464+
return false
465+
}
466+
467+
if (!this.share) {
468+
// if no share, we can't tell if properties are missing or not so we assume properties are missing
469+
return true
470+
}
471+
472+
// If share has ID, then this is an incoming link share created from the existing link share
473+
// Hence assume required properties
474+
if (this.share.id) {
475+
return true
476+
}
477+
// Check if either password or expiration date is missing and enforced
478+
const isPasswordMissing = this.config.enforcePasswordForPublicLink && !this.share.password
479+
const isExpireDateMissing = this.config.isDefaultExpireDateEnforced && !this.share.expireDate
480+
481+
return isPasswordMissing || isExpireDateMissing
482+
},
456483
// if newPassword exists, but is empty, it means
457484
// the user deleted the original password
458485
hasUnsavedPassword() {
@@ -529,6 +556,7 @@ export default {
529556
* Create a new share link and append it to the list
530557
*/
531558
async onNewLinkShare() {
559+
this.logger.debug('onNewLinkShare called (with this.share)', this.share)
532560
// do not run again if already loading
533561
if (this.loading) {
534562
return
@@ -543,28 +571,13 @@ export default {
543571
shareDefaults.expiration = this.formatDateToString(this.config.defaultExpirationDate)
544572
}
545573
574+
this.logger.debug('Missing required properties?', this.requiredPropertiesMissing)
546575
// do not push yet if we need a password or an expiration date: show pending menu
547-
if (this.config.enableLinkPasswordByDefault || this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced) {
576+
if (this.sharePolicyHasRequiredProperties && this.requiredPropertiesMissing) {
548577
this.pending = true
578+
this.shareCreationComplete = false
549579
550-
// if a share already exists, pushing it
551-
if (this.share && !this.share.id) {
552-
// if the share is valid, create it on the server
553-
if (this.checkShare(this.share)) {
554-
try {
555-
await this.pushNewLinkShare(this.share, true)
556-
} catch (e) {
557-
this.pending = false
558-
console.error(e)
559-
return false
560-
}
561-
return true
562-
} else {
563-
this.open = true
564-
OC.Notification.showTemporary(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
565-
return false
566-
}
567-
}
580+
this.logger.info('Share policy requires mandated properties (password)...')
568581
569582
// ELSE, show the pending popovermenu
570583
// if password default or enforced, pre-fill with random one
@@ -586,8 +599,32 @@ export default {
586599
587600
// Nothing is enforced, creating share directly
588601
} else {
602+
603+
// if a share already exists, pushing it
604+
if (this.share && !this.share.id) {
605+
// if the share is valid, create it on the server
606+
if (this.checkShare(this.share)) {
607+
try {
608+
this.logger.info('Sending existing share to server', this.share)
609+
await this.pushNewLinkShare(this.share, true)
610+
this.shareCreationComplete = true
611+
this.logger.info('Share created on server', this.share)
612+
} catch (e) {
613+
this.pending = false
614+
this.logger.error('Error creating share', e)
615+
return false
616+
}
617+
return true
618+
} else {
619+
this.open = true
620+
showError(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
621+
return false
622+
}
623+
}
624+
589625
const share = new Share(shareDefaults)
590626
await this.pushNewLinkShare(share)
627+
this.shareCreationComplete = true
591628
}
592629
},
593630
@@ -627,8 +664,8 @@ export default {
627664
const newShare = await this.createShare(options)
628665
629666
this.open = false
667+
this.shareCreationComplete = true
630668
console.debug('Link share created', newShare)
631-
632669
// if share already exists, copy link directly on next tick
633670
let component
634671
if (update) {
@@ -670,8 +707,10 @@ export default {
670707
this.onSyncError('pending', message)
671708
}
672709
throw data
710+
673711
} finally {
674712
this.loading = false
713+
this.shareCreationComplete = true
675714
}
676715
},
677716
async copyLink() {
@@ -774,7 +813,9 @@ export default {
774813
// this.share already exists at this point,
775814
// but is incomplete as not pushed to server
776815
// YET. We can safely delete the share :)
777-
this.$emit('remove:share', this.share)
816+
if (!this.shareCreationComplete) {
817+
this.$emit('remove:share', this.share)
818+
}
778819
},
779820
},
780821
}
@@ -795,13 +836,20 @@ export default {
795836
min-width: 0;
796837
}
797838
798-
&__desc {
799-
display: flex;
800-
flex-direction: column;
801-
line-height: 1.2em;
839+
&__desc {
840+
display: flex;
841+
flex-direction: column;
842+
line-height: 1.2em;
802843
803-
p {
804-
color: var(--color-text-maxcontrast);
844+
p {
845+
color: var(--color-text-maxcontrast);
846+
}
847+
848+
&__title {
849+
text-overflow: ellipsis;
850+
overflow: hidden;
851+
white-space: nowrap;
852+
}
805853
}
806854
807855
&__title {

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ export default {
892892
this.share = share
893893
this.$emit('add:share', this.share)
894894
} else {
895+
this.$emit('update:share', this.share)
895896
this.queueUpdate(...permissionsAndAttributes)
896897
}
897898

0 commit comments

Comments
 (0)