diff options
Diffstat (limited to 'apps/files_sharing/src/mixins/SharesMixin.js')
-rw-r--r-- | apps/files_sharing/src/mixins/SharesMixin.js | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js index ab84a6f0e19..a461da56d85 100644 --- a/apps/files_sharing/src/mixins/SharesMixin.js +++ b/apps/files_sharing/src/mixins/SharesMixin.js @@ -7,11 +7,11 @@ import { getCurrentUser } from '@nextcloud/auth' import { showError, showSuccess } from '@nextcloud/dialogs' import { ShareType } from '@nextcloud/sharing' import { emit } from '@nextcloud/event-bus' -import { fetchNode } from '../services/WebdavClient.ts' import PQueue from 'p-queue' import debounce from 'debounce' +import GeneratePassword from '../utils/GeneratePassword.ts' import Share from '../models/Share.ts' import SharesRequests from './ShareRequests.js' import Config from '../services/ConfigService.ts' @@ -20,6 +20,7 @@ import logger from '../services/logger.ts' import { BUNDLED_PERMISSIONS, } from '../lib/SharePermissionsToolBox.js' +import { fetchNode } from '../../../files/src/services/WebdavClient.ts' export default { mixins: [SharesRequests], @@ -110,6 +111,9 @@ export default { monthFormat: 'MMM', } }, + isNewShare() { + return !this.share.id + }, isFolder() { return this.fileInfo.type === 'dir' }, @@ -153,6 +157,26 @@ export default { } return null }, + /** + * Is the current share password protected ? + * + * @return {boolean} + */ + isPasswordProtected: { + get() { + return this.config.enforcePasswordForPublicLink + || this.share.password !== '' + || this.share.newPassword !== undefined + }, + async set(enabled) { + if (enabled) { + this.$set(this.share, 'newPassword', await GeneratePassword(true)) + } else { + this.share.password = '' + this.$delete(this.share, 'newPassword') + } + }, + }, }, methods: { @@ -164,7 +188,7 @@ export default { async getNode() { const node = { path: this.path } try { - this.node = await fetchNode(node) + this.node = await fetchNode(node.path) logger.info('Fetched node:', { node: this.node }) } catch (error) { logger.error('Error:', error) @@ -210,17 +234,13 @@ export default { * @param {Date} date */ onExpirationChange(date) { - this.share.expireDate = this.formatDateToString(new Date(date)) - }, - - /** - * Uncheck expire date - * We need this method because @update:checked - * is ran simultaneously as @uncheck, so - * so we cannot ensure data is up-to-date - */ - onExpirationDisable() { - this.share.expireDate = '' + if (!date) { + this.share.expireDate = null + this.$set(this.share, 'expireDate', null) + return + } + const parsedDate = (date instanceof Date) ? date : new Date(date) + this.share.expireDate = this.formatDateToString(parsedDate) }, /** @@ -252,7 +272,7 @@ export default { this.loading = true this.open = false await this.deleteShare(this.share.id) - console.debug('Share deleted', this.share.id) + logger.debug('Share deleted', { shareId: this.share.id }) const message = this.share.itemType === 'file' ? t('files_sharing', 'File "{path}" has been unshared', { path: this.share.path }) : t('files_sharing', 'Folder "{path}" has been unshared', { path: this.share.path }) @@ -283,22 +303,30 @@ export default { const properties = {} // force value to string because that is what our // share api controller accepts - propertyNames.forEach(name => { - if ((typeof this.share[name]) === 'object') { + for (const name of propertyNames) { + if (name === 'password') { + properties[name] = this.share.newPassword ?? this.share.password + continue + } + + if (this.share[name] === null || this.share[name] === undefined) { + properties[name] = '' + } else if ((typeof this.share[name]) === 'object') { properties[name] = JSON.stringify(this.share[name]) } else { properties[name] = this.share[name].toString() } - }) + } - this.updateQueue.add(async () => { + return this.updateQueue.add(async () => { this.saving = true this.errors = {} try { const updatedShare = await this.updateShare(this.share.id, properties) - if (propertyNames.indexOf('password') >= 0) { + if (propertyNames.includes('password')) { // reset password state after sync + this.share.password = this.share.newPassword ?? '' this.$delete(this.share, 'newPassword') // updates password expiration time after sync @@ -306,14 +334,18 @@ export default { } // clear any previous errors - this.$delete(this.errors, propertyNames[0]) + for (const property of propertyNames) { + this.$delete(this.errors, property) + } showSuccess(this.updateSuccessMessage(propertyNames)) } catch (error) { logger.error('Could not update share', { error, share: this.share, propertyNames }) const { message } = error if (message && message !== '') { - this.onSyncError(propertyNames[0], message) + for (const property of propertyNames) { + this.onSyncError(property, message) + } showError(message) } else { // We do not have information what happened, but we should still inform the user @@ -323,7 +355,6 @@ export default { this.saving = false } }) - return } // This share does not exists on the server yet @@ -363,6 +394,13 @@ export default { * @param {string} message the error message */ onSyncError(property, message) { + if (property === 'password' && this.share.newPassword) { + if (this.share.newPassword === this.share.password) { + this.share.password = '' + } + this.$delete(this.share, 'newPassword') + } + // re-open menu if closed this.open = true switch (property) { |