Skip to content

Commit

Permalink
fix(files_sharing): Resolve race condition blocking link share requests
Browse files Browse the repository at this point in the history
Fixed a race condition in the frontend that prevented share link creation requests
from being sent to the backend. Instead of communicating with the server,
the share links were incorrectly added to the frontend list, and a new menu
to create another link appeared.

This fix ensures the correct sequence of actions, allowing share links to be
properly created and synchronized with the backend.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Dec 5, 2024
1 parent bca864d commit 1894862
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ export default {
copySuccess: true,
copied: false,
defaultExpirationDateEnabled: false,
shareReviewComplete: false,
calls: 0,

// Are we waiting for password/expiration date
pending: false,
Expand Down Expand Up @@ -472,7 +474,7 @@ export default {
* @return {boolean}
*/
pendingDataIsMissing() {
return this.pendingPassword || this.pendingEnforcedPassword || this.pendingEnforcedExpirationDate
return this.pendingPassword || this.pendingEnforcedPassword || this.pendingEnforcedExpirationDate || this.shareRequiresReview
},
pendingPassword() {
return this.config.enableLinkPasswordByDefault && this.isPendingShare
Expand All @@ -492,6 +494,10 @@ export default {
},

shareRequiresReview() {
console.debug('Share requires review?', this.shareReviewComplete)
if (this.shareReviewComplete) {
return false
}
return this.defaultExpirationDateEnabled || this.config.enableLinkPasswordByDefault
},

Expand Down Expand Up @@ -596,8 +602,8 @@ export default {
},
},
mounted() {
this.defaultExpirationDateEnabled = this.config.defaultExpirationDate instanceof Date
if (this.share) {
this.defaultExpirationDateEnabled = this.config.defaultExpirationDate instanceof Date
this.share.expireDate = this.defaultExpirationDateEnabled ? this.formatDateToString(this.config.defaultExpirationDate) : ''
}
},
Expand Down Expand Up @@ -627,10 +633,15 @@ export default {
// A share would require a review for example is default expiration date is set but not enforced, this allows
// the user to review the share and remove the expiration date if they don't want it
if ((this.sharePolicyHasRequiredProperties && this.requiredPropertiesMissing) || this.shareRequiresReview) {
console.debug('Share requires review', {
sharePolicyHasRequiredProperties: this.sharePolicyHasRequiredProperties,
requiredPropertiesMissing: this.requiredPropertiesMissing,
shareRequiresReview: this.shareRequiresReview
})
this.pending = true
this.shareCreationComplete = false

this.logger.info('Share policy requires mandated properties (password)...')
//debugger

Check failure on line 643 in apps/files_sharing/src/components/SharingEntryLink.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected space or tab after '//' in comment
this.logger.info('Share policy requires a review or has mandated properties (password, expirationDate)...')

// ELSE, show the pending popovermenu
// if password default or enforced, pre-fill with random one
Expand All @@ -648,11 +659,18 @@ export default {
// freshly created share component
this.open = false
this.pending = false
this.shareReviewComplete = true
component.open = true

// Nothing is enforced, creating share directly
} else {

console.debug('Share does not require review', {
sharePolicyHasRequiredProperties: this.sharePolicyHasRequiredProperties,
requiredPropertiesMissing: this.requiredPropertiesMissing,
shareRequiresReview: this.shareRequiresReview
})

// if a share already exists, pushing it
if (this.share && !this.share.id) {
// if the share is valid, create it on the server
Expand All @@ -678,6 +696,7 @@ export default {
const share = new Share(shareDefaults)
await this.pushNewLinkShare(share)
this.shareCreationComplete = true
this.shareReviewComplete = false
}
},

Expand Down

0 comments on commit 1894862

Please sign in to comment.