diff options
Diffstat (limited to 'apps/files_sharing/src/mixins')
-rw-r--r-- | apps/files_sharing/src/mixins/ShareDetails.js | 14 | ||||
-rw-r--r-- | apps/files_sharing/src/mixins/ShareRequests.js | 6 | ||||
-rw-r--r-- | apps/files_sharing/src/mixins/SharesMixin.js | 59 |
3 files changed, 69 insertions, 10 deletions
diff --git a/apps/files_sharing/src/mixins/ShareDetails.js b/apps/files_sharing/src/mixins/ShareDetails.js index 61cffab86f2..6ccdf8d63d0 100644 --- a/apps/files_sharing/src/mixins/ShareDetails.js +++ b/apps/files_sharing/src/mixins/ShareDetails.js @@ -5,6 +5,8 @@ import Share from '../models/Share.ts' import Config from '../services/ConfigService.ts' +import { ATOMIC_PERMISSIONS } from '../lib/SharePermissionsToolBox.js' +import logger from '../services/logger.ts' export default { methods: { @@ -26,6 +28,18 @@ export default { share = this.mapShareRequestToShareObject(shareRequestObject) } + if (this.fileInfo.type !== 'dir') { + const originalPermissions = share.permissions + const strippedPermissions = originalPermissions + & ~ATOMIC_PERMISSIONS.CREATE + & ~ATOMIC_PERMISSIONS.DELETE + + if (originalPermissions !== strippedPermissions) { + logger.debug('Removed create/delete permissions from file share (only valid for folders)') + share.permissions = strippedPermissions + } + } + const shareDetails = { fileInfo: this.fileInfo, share, diff --git a/apps/files_sharing/src/mixins/ShareRequests.js b/apps/files_sharing/src/mixins/ShareRequests.js index 24b4b12061e..2c33fa3b0c7 100644 --- a/apps/files_sharing/src/mixins/ShareRequests.js +++ b/apps/files_sharing/src/mixins/ShareRequests.js @@ -6,10 +6,12 @@ // TODO: remove when ie not supported import 'url-search-params-polyfill' +import { emit } from '@nextcloud/event-bus' +import { showError } from '@nextcloud/dialogs' import { generateOcsUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' + import Share from '../models/Share.ts' -import { emit } from '@nextcloud/event-bus' const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares') @@ -45,7 +47,7 @@ export default { } catch (error) { console.error('Error while creating share', error) const errorMessage = error?.response?.data?.ocs?.meta?.message - OC.Notification.showTemporary( + showError( errorMessage ? t('files_sharing', 'Error creating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error creating the share'), { type: 'error' }, ) diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js index 588b0bf4bc6..a461da56d85 100644 --- a/apps/files_sharing/src/mixins/SharesMixin.js +++ b/apps/files_sharing/src/mixins/SharesMixin.js @@ -11,6 +11,7 @@ import { emit } from '@nextcloud/event-bus' 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' @@ -156,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: { @@ -213,8 +234,13 @@ export default { * @param {Date} date */ onExpirationChange(date) { - const formattedDate = date ? this.formatDateToString(new Date(date)) : '' - this.share.expireDate = formattedDate + 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) }, /** @@ -246,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 }) @@ -277,7 +303,12 @@ export default { const properties = {} // force value to string because that is what our // share api controller accepts - propertyNames.forEach(name => { + 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') { @@ -285,7 +316,7 @@ export default { } else { properties[name] = this.share[name].toString() } - }) + } return this.updateQueue.add(async () => { this.saving = true @@ -293,8 +324,9 @@ export default { 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 @@ -302,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 @@ -358,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) { |