Skip to content

Commit 34bd23d

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 9578f89 commit 34bd23d

2 files changed

Lines changed: 82 additions & 39 deletions

File tree

apps/files_sharing/src/components/SharingEntryLink.vue

Lines changed: 81 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
{{ t('files_sharing', 'Customize link') }}
152152
</NcActionButton>
153153
</template>
154-
154+
155155
<NcActionButton :close-after-click="true"
156156
@click.prevent="showQRCode = true">
157157
<template #icon>
@@ -231,7 +231,7 @@ import { generateUrl } from '@nextcloud/router'
231231
import { showError, showSuccess } from '@nextcloud/dialogs'
232232
import { Type as ShareTypes } from '@nextcloud/sharing'
233233
import Vue from 'vue'
234-
import VueQrcode from '@chenfengyuan/vue-qrcode';
234+
import VueQrcode from '@chenfengyuan/vue-qrcode'
235235
236236
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
237237
import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
@@ -258,6 +258,7 @@ import GeneratePassword from '../utils/GeneratePassword.js'
258258
import Share from '../models/Share.js'
259259
import SharesMixin from '../mixins/SharesMixin.js'
260260
import ShareDetails from '../mixins/ShareDetails.js'
261+
import { getLoggerBuilder } from '@nextcloud/logger'
261262
262263
export default {
263264
name: 'SharingEntryLink',
@@ -299,6 +300,7 @@ export default {
299300
300301
data() {
301302
return {
303+
shareCreationComplete: false,
302304
copySuccess: true,
303305
copied: false,
304306
@@ -307,6 +309,10 @@ export default {
307309
308310
ExternalLegacyLinkActions: OCA.Sharing.ExternalLinkActions.state,
309311
ExternalShareActions: OCA.Sharing.ExternalShareActions.state,
312+
logger: getLoggerBuilder()
313+
.setApp('files_sharing')
314+
.detectUser()
315+
.build(),
310316
311317
// tracks whether modal should be opened or not
312318
showQRCode: false,
@@ -470,6 +476,32 @@ export default {
470476
return this.config.isDefaultExpireDateEnforced && this.share && !this.share.id
471477
},
472478
479+
sharePolicyHasRequiredProperties() {
480+
return this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced
481+
},
482+
483+
requiredPropertiesMissing() {
484+
// Ensure share exist and the share policy has required properties
485+
if (!this.sharePolicyHasRequiredProperties) {
486+
return false
487+
}
488+
489+
if (!this.share) {
490+
// if no share, we can't tell if properties are missing or not so we assume properties are missing
491+
return true
492+
}
493+
494+
// If share has ID, then this is an incoming link share created from the existing link share
495+
// Hence assume required properties
496+
if (this.share.id) {
497+
return true
498+
}
499+
// Check if either password or expiration date is missing and enforced
500+
const isPasswordMissing = this.config.enforcePasswordForPublicLink && !this.share.password
501+
const isExpireDateMissing = this.config.isDefaultExpireDateEnforced && !this.share.expireDate
502+
503+
return isPasswordMissing || isExpireDateMissing
504+
},
473505
// if newPassword exists, but is empty, it means
474506
// the user deleted the original password
475507
hasUnsavedPassword() {
@@ -546,6 +578,7 @@ export default {
546578
* Create a new share link and append it to the list
547579
*/
548580
async onNewLinkShare() {
581+
this.logger.debug('onNewLinkShare called (with this.share)', this.share)
549582
// do not run again if already loading
550583
if (this.loading) {
551584
return
@@ -560,28 +593,13 @@ export default {
560593
shareDefaults.expiration = this.formatDateToString(this.config.defaultExpirationDate)
561594
}
562595
596+
this.logger.debug('Missing required properties?', this.requiredPropertiesMissing)
563597
// do not push yet if we need a password or an expiration date: show pending menu
564-
if (this.config.enableLinkPasswordByDefault || this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced) {
598+
if (this.sharePolicyHasRequiredProperties && this.requiredPropertiesMissing) {
565599
this.pending = true
600+
this.shareCreationComplete = false
566601
567-
// if a share already exists, pushing it
568-
if (this.share && !this.share.id) {
569-
// if the share is valid, create it on the server
570-
if (this.checkShare(this.share)) {
571-
try {
572-
await this.pushNewLinkShare(this.share, true)
573-
} catch (e) {
574-
this.pending = false
575-
console.error(e)
576-
return false
577-
}
578-
return true
579-
} else {
580-
this.open = true
581-
OC.Notification.showTemporary(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
582-
return false
583-
}
584-
}
602+
this.logger.info('Share policy requires mandated properties (password)...')
585603
586604
// ELSE, show the pending popovermenu
587605
// if password default or enforced, pre-fill with random one
@@ -603,8 +621,32 @@ export default {
603621
604622
// Nothing is enforced, creating share directly
605623
} else {
624+
625+
// if a share already exists, pushing it
626+
if (this.share && !this.share.id) {
627+
// if the share is valid, create it on the server
628+
if (this.checkShare(this.share)) {
629+
try {
630+
this.logger.info('Sending existing share to server', this.share)
631+
await this.pushNewLinkShare(this.share, true)
632+
this.shareCreationComplete = true
633+
this.logger.info('Share created on server', this.share)
634+
} catch (e) {
635+
this.pending = false
636+
this.logger.error('Error creating share', e)
637+
return false
638+
}
639+
return true
640+
} else {
641+
this.open = true
642+
showError(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
643+
return false
644+
}
645+
}
646+
606647
const share = new Share(shareDefaults)
607648
await this.pushNewLinkShare(share)
649+
this.shareCreationComplete = true
608650
}
609651
},
610652
@@ -644,8 +686,8 @@ export default {
644686
const newShare = await this.createShare(options)
645687
646688
this.open = false
689+
this.shareCreationComplete = true
647690
console.debug('Link share created', newShare)
648-
649691
// if share already exists, copy link directly on next tick
650692
let component
651693
if (update) {
@@ -687,8 +729,10 @@ export default {
687729
this.onSyncError('pending', message)
688730
}
689731
throw data
732+
690733
} finally {
691734
this.loading = false
735+
this.shareCreationComplete = true
692736
}
693737
},
694738
async copyLink() {
@@ -791,7 +835,9 @@ export default {
791835
// this.share already exists at this point,
792836
// but is incomplete as not pushed to server
793837
// YET. We can safely delete the share :)
794-
this.$emit('remove:share', this.share)
838+
if (!this.shareCreationComplete) {
839+
this.$emit('remove:share', this.share)
840+
}
795841
},
796842
},
797843
}
@@ -812,25 +858,21 @@ export default {
812858
min-width: 0;
813859
}
814860
815-
&__desc {
816-
display: flex;
817-
flex-direction: column;
818-
line-height: 1.2em;
861+
&__desc {
862+
display: flex;
863+
flex-direction: column;
864+
line-height: 1.2em;
819865
820-
p {
821-
color: var(--color-text-maxcontrast);
822-
}
866+
p {
867+
color: var(--color-text-maxcontrast);
868+
}
823869
824-
&__title {
825-
text-overflow: ellipsis;
826-
overflow: hidden;
827-
white-space: nowrap;
870+
&__title {
871+
text-overflow: ellipsis;
872+
overflow: hidden;
873+
white-space: nowrap;
874+
}
828875
}
829-
}
830-
831-
&__copy {
832-
833-
}
834876
835877
&:not(.sharing-entry--share) &__actions {
836878
.new-share-link {

apps/files_sharing/src/views/SharingDetailsTab.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ export default {
888888
this.share = share
889889
this.$emit('add:share', this.share)
890890
} else {
891+
this.$emit('update:share', this.share)
891892
this.queueUpdate(...permissionsAndAttributes)
892893
}
893894

0 commit comments

Comments
 (0)