Skip to content

Commit

Permalink
fix(files_sharing): Improve recursion in onNewLinShare
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nfebe committed Apr 29, 2024
1 parent 98b9dbc commit 5fafe28
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 38 deletions.
111 changes: 74 additions & 37 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default {

data() {
return {
shareCreationComplete: false,
showDropdown: false,
copySuccess: true,
copied: false,
Expand Down Expand Up @@ -296,7 +297,7 @@ export default {
* @return {string}
*/
subtitle() {
if (this.isEmailShareType
if (this.isEmailShareTypef
&& this.title !== this.share.shareWith) {
return this.share.shareWith
}
Expand Down Expand Up @@ -407,6 +408,29 @@ export default {
return this.config.isDefaultExpireDateEnforced && this.share && !this.share.id
},

sharePolicyHasRequiredProperties() {
return this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced
},

requiredPropertiesMissing() {
// Destructure share and config from this
const { share, config } = this
// Ensure share exist and the share policy has required properties
if (!this.sharePolicyHasRequiredProperties) return false

if (share) {
// If share has ID, then this is an incoming link share created from the existing link share
// Hence assume required properties
if (share.id) return true
// Check if either password or expiration date is missing and enforced
const isPasswordMissing = config.enforcePasswordForPublicLink && (share.password === null || share.password === undefined)
const isExpireDateMissing = config.isDefaultExpireDateEnforced && (share.expireDate === null || share.expireDate === undefined)

return isPasswordMissing || isExpireDateMissing
}
// if no share, we can't tell if properties are missing or not so we assume they are
return true
},
// if newPassword exists, but is empty, it means
// the user deleted the original password
hasUnsavedPassword() {
Expand Down Expand Up @@ -483,6 +507,7 @@ export default {
* Create a new share link and append it to the list
*/
async onNewLinkShare() {
console.debug('onNewLinkShare called (this.share status)', this.share)
// do not run again if already loading
if (this.loading) {
return
Expand All @@ -497,28 +522,13 @@ export default {
shareDefaults.expiration = this.formatDateToString(this.config.defaultExpirationDate)
}

console.debug('Missing required properties?', this.requiredPropertiesMissing)
// do not push yet if we need a password or an expiration date: show pending menu
if (this.config.enableLinkPasswordByDefault || this.config.enforcePasswordForPublicLink || this.config.isDefaultExpireDateEnforced) {
if (this.sharePolicyHasRequiredProperties && this.requiredPropertiesMissing) {
this.pending = true
this.shareCreationComplete = false

// if a share already exists, pushing it
if (this.share && !this.share.id) {
// if the share is valid, create it on the server
if (this.checkShare(this.share)) {
try {
await this.pushNewLinkShare(this.share, true)
} catch (e) {
this.pending = false
console.error(e)
return false
}
return true
} else {
this.open = true
OC.Notification.showTemporary(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
return false
}
}
this.logger.info('Share policy requires mandated properties (password)...')

// ELSE, show the pending popovermenu
// if password default or enforced, pre-fill with random one
Expand All @@ -540,8 +550,33 @@ export default {

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

// if a share already exists, pushing it
if (this.share && !this.share.id) {
// if the share is valid, create it on the server
if (this.checkShare(this.share)) {
try {
this.logger.info('Sending existing share to server', this.share)
await this.pushNewLinkShare(this.share, true)
this.shareCreationComplete = true
this.logger.info('Share created on server', this.share)
} catch (e) {
this.pending = false
console.error(e)
this.logger.error('Error creating share', e)
return false
}
return true
} else {
this.open = true
OC.Notification.showTemporary(t('files_sharing', 'Error, please enter proper password and/or expiration date'))
return false
}
}

const share = new Share(shareDefaults)
await this.pushNewLinkShare(share)
this.shareCreationComplete = true
}
},

Expand Down Expand Up @@ -581,8 +616,8 @@ export default {
const newShare = await this.createShare(options)

this.open = false
this.shareCreationComplete = true
console.debug('Link share created', newShare)

// if share already exists, copy link directly on next tick
let component
if (update) {
Expand Down Expand Up @@ -624,8 +659,10 @@ export default {
this.onSyncError('pending', message)
}
throw data

} finally {
this.loading = false
this.shareCreationComplete = true
}
},
async copyLink() {
Expand Down Expand Up @@ -728,7 +765,9 @@ export default {
// this.share already exists at this point,
// but is incomplete as not pushed to server
// YET. We can safely delete the share :)
this.$emit('remove:share', this.share)
if (!this.shareCreationComplete) {
this.$emit('remove:share', this.share)
}
},

toggleQuickShareSelect() {
Expand All @@ -752,25 +791,23 @@ export default {
width: 80%;
min-width: 80%;

&__desc {
display: flex;
flex-direction: column;
line-height: 1.2em;
&__desc {
display: flex;
flex-direction: column;
line-height: 1.2em;

p {
color: var(--color-text-maxcontrast);
}
p {
color: var(--color-text-maxcontrast);
}

&__title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
&__title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
}
}

&__copy {

}
&__copy {}
}

&:not(.sharing-entry--share) &__actions {
Expand Down
6 changes: 6 additions & 0 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import SharesRequests from './ShareRequests.js'
import ShareTypes from './ShareTypes.js'
import Config from '../services/ConfigService.js'

import { getLoggerBuilder } from '@nextcloud/logger'

import {
BUNDLED_PERMISSIONS,
} from '../lib/SharePermissionsToolBox.js'
Expand Down Expand Up @@ -80,6 +82,10 @@ export default {
* ! do not remove it ot you'll lose all reactivity here
*/
reactiveState: this.share?.state,
logger: getLoggerBuilder()
.setApp('files_sharing')
.detectUser()
.build(),
}
},

Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ export default {
this.share = share
this.$emit('add:share', this.share)
} else {
this.$emit('update:share', this.share)
this.queueUpdate(...permissionsAndAttributes)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/views/SharingLinkList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default {
*/
addShare(share, resolve) {
// eslint-disable-next-line vue/no-mutating-props
this.shares.unshift(share)
this.shares = [share, ...this.shares]
this.awaitForShare(share, resolve)
},

Expand Down

0 comments on commit 5fafe28

Please sign in to comment.