@@ -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 {
0 commit comments