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 3, 2024
1 parent 5ee4c9e commit ea48600
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 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.log("share requires review according to this.shareReviewComplete", this.shareReviewComplete)

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

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
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.log("Share requires review", {

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

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
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,13 +659,17 @@ 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.log("Gets here to non review share creation")

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

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote

// if a share already exists, pushing it
if (this.share && !this.share.id) {
console.log("Does not get blocked by share.id")

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

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement

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

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
// if the share is valid, create it on the server
if (this.checkShare(this.share)) {
try {
Expand All @@ -678,6 +693,7 @@ export default {
const share = new Share(shareDefaults)
await this.pushNewLinkShare(share)
this.shareCreationComplete = true
this.shareReviewComplete = false
}
},

Expand Down

0 comments on commit ea48600

Please sign in to comment.