aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/mixins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/src/mixins')
-rw-r--r--apps/files_sharing/src/mixins/ShareDetails.js33
-rw-r--r--apps/files_sharing/src/mixins/ShareRequests.js12
-rw-r--r--apps/files_sharing/src/mixins/ShareTypes.js14
-rw-r--r--apps/files_sharing/src/mixins/SharesMixin.js179
4 files changed, 162 insertions, 76 deletions
diff --git a/apps/files_sharing/src/mixins/ShareDetails.js b/apps/files_sharing/src/mixins/ShareDetails.js
index 6c50440ff24..6ccdf8d63d0 100644
--- a/apps/files_sharing/src/mixins/ShareDetails.js
+++ b/apps/files_sharing/src/mixins/ShareDetails.js
@@ -3,9 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
-import Share from '../models/Share.js'
-import Config from '../services/ConfigService.js'
+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: {
@@ -15,17 +16,30 @@ export default {
// TODO : Better name/interface for handler required
// For example `externalAppCreateShareHook` with proper documentation
if (shareRequestObject.handler) {
+ const handlerInput = {}
if (this.suggestions) {
- shareRequestObject.suggestions = this.suggestions
- shareRequestObject.fileInfo = this.fileInfo
- shareRequestObject.query = this.query
+ handlerInput.suggestions = this.suggestions
+ handlerInput.fileInfo = this.fileInfo
+ handlerInput.query = this.query
}
- share = await shareRequestObject.handler(shareRequestObject)
- share = new Share(share)
+ const externalShareRequestObject = await shareRequestObject.handler(handlerInput)
+ share = this.mapShareRequestToShareObject(externalShareRequestObject)
} else {
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,
@@ -46,11 +60,12 @@ export default {
const share = {
attributes: [
{
- enabled: true,
+ value: true,
key: 'download',
scope: 'permissions',
},
],
+ hideDownload: false,
share_type: shareRequestObject.shareType,
share_with: shareRequestObject.shareWith,
is_no_user: shareRequestObject.isNoUser,
diff --git a/apps/files_sharing/src/mixins/ShareRequests.js b/apps/files_sharing/src/mixins/ShareRequests.js
index f8bd4083d20..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.js'
-import { emit } from '@nextcloud/event-bus'
+
+import Share from '../models/Share.ts'
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
@@ -26,10 +28,10 @@ export default {
* @param {string} [data.password] password to protect public link Share with
* @param {number} [data.permissions] 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1)
* @param {boolean} [data.sendPasswordByTalk] send the password via a talk conversation
- * @param {string} [data.expireDate] expire the shareautomatically after
+ * @param {string} [data.expireDate] expire the share automatically after
* @param {string} [data.label] custom label
* @param {string} [data.attributes] Share attributes encoded as json
- * @param data.note
+ * @param {string} data.note custom note to recipient
* @return {Share} the new share
* @throws {Error}
*/
@@ -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/ShareTypes.js b/apps/files_sharing/src/mixins/ShareTypes.js
deleted file mode 100644
index 4b0746a4849..00000000000
--- a/apps/files_sharing/src/mixins/ShareTypes.js
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-import { Type as ShareTypes } from '@nextcloud/sharing'
-
-export default {
- data() {
- return {
- SHARE_TYPES: ShareTypes,
- }
- },
-}
diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js
index 23cc4fd343e..a461da56d85 100644
--- a/apps/files_sharing/src/mixins/SharesMixin.js
+++ b/apps/files_sharing/src/mixins/SharesMixin.js
@@ -3,23 +3,27 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import { showError, showSuccess } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
-// eslint-disable-next-line import/no-unresolved, n/no-missing-import
+import { showError, showSuccess } from '@nextcloud/dialogs'
+import { ShareType } from '@nextcloud/sharing'
+import { emit } from '@nextcloud/event-bus'
+
import PQueue from 'p-queue'
import debounce from 'debounce'
-import Share from '../models/Share.js'
+import GeneratePassword from '../utils/GeneratePassword.ts'
+import Share from '../models/Share.ts'
import SharesRequests from './ShareRequests.js'
-import ShareTypes from './ShareTypes.js'
-import Config from '../services/ConfigService.js'
+import Config from '../services/ConfigService.ts'
+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, ShareTypes],
+ mixins: [SharesRequests],
props: {
fileInfo: {
@@ -40,6 +44,8 @@ export default {
data() {
return {
config: new Config(),
+ node: null,
+ ShareType,
// errors helpers
errors: {},
@@ -62,7 +68,9 @@ export default {
},
computed: {
-
+ path() {
+ return (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
+ },
/**
* Does the current share have a note
*
@@ -86,10 +94,10 @@ export default {
// Datepicker language
lang() {
const weekdaysShort = window.dayNamesShort
- ? window.dayNamesShort // provided by nextcloud
+ ? window.dayNamesShort // provided by Nextcloud
: ['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.']
const monthsShort = window.monthNamesShort
- ? window.monthNamesShort // provided by nextcloud
+ ? window.monthNamesShort // provided by Nextcloud
: ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.']
const firstDayOfWeek = window.firstDay ? window.firstDay : 0
@@ -103,15 +111,18 @@ export default {
monthFormat: 'MMM',
}
},
+ isNewShare() {
+ return !this.share.id
+ },
isFolder() {
return this.fileInfo.type === 'dir'
},
isPublicShare() {
const shareType = this.share.shareType ?? this.share.type
- return [this.SHARE_TYPES.SHARE_TYPE_LINK, this.SHARE_TYPES.SHARE_TYPE_EMAIL].includes(shareType)
+ return [ShareType.Link, ShareType.Email].includes(shareType)
},
isRemoteShare() {
- return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP || this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
+ return this.share.type === ShareType.RemoteGroup || this.share.type === ShareType.Remote
},
isShareOwner() {
return this.share && this.share.owner === getCurrentUser().uid
@@ -121,7 +132,7 @@ export default {
return this.config.isDefaultExpireDateEnforced
}
if (this.isRemoteShare) {
- return this.config.isDefaultRemoteExpireDateEnforced
+ return this.config.isDefaultRemoteExpireDateEnforced
}
return this.config.isDefaultInternalExpireDateEnforced
},
@@ -146,10 +157,45 @@ 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: {
/**
+ * Fetch WebDAV node
+ *
+ * @return {Node}
+ */
+ async getNode() {
+ const node = { path: this.path }
+ try {
+ this.node = await fetchNode(node.path)
+ logger.info('Fetched node:', { node: this.node })
+ } catch (error) {
+ logger.error('Error:', error)
+ }
+ },
+
+ /**
* Check if a share is valid before
* firing the request
*
@@ -172,19 +218,7 @@ export default {
},
/**
- * @param {string} date a date with YYYY-MM-DD format
- * @return {Date} date
- */
- parseDateString(date) {
- if (!date) {
- return
- }
- const regex = /([0-9]{4}-[0-9]{2}-[0-9]{2})/i
- return new Date(date.match(regex)?.pop())
- },
-
- /**
- * @param {Date} date
+ * @param {Date} date the date to format
* @return {string} date a date with YYYY-MM-DD format
*/
formatDateToString(date) {
@@ -199,17 +233,14 @@ export default {
*
* @param {Date} date
*/
- onExpirationChange: debounce(function(date) {
- this.share.expireDate = this.formatDateToString(new Date(date))
- }, 500),
- /**
- * 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 = ''
+ onExpirationChange(date) {
+ 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)
},
/**
@@ -241,12 +272,14 @@ 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 })
showSuccess(message)
this.$emit('remove:share', this.share)
+ await this.getNode()
+ emit('files:node:updated', this.node)
} catch (error) {
// re-open menu if error
this.open = true
@@ -270,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
@@ -293,18 +334,27 @@ export default {
}
// clear any previous errors
- this.$delete(this.errors, propertyNames[0])
- showSuccess(t('files_sharing', 'Share {propertyName} saved', { propertyName: propertyNames[0] }))
- } catch ({ message }) {
+ 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)
- showError(t('files_sharing', 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
+ showError(t('files_sharing', 'Could not update share'))
}
} finally {
this.saving = false
}
})
- return
}
// This share does not exists on the server yet
@@ -312,12 +362,45 @@ export default {
},
/**
+ * @param {string[]} names Properties changed
+ */
+ updateSuccessMessage(names) {
+ if (names.length !== 1) {
+ return t('files_sharing', 'Share saved')
+ }
+
+ switch (names[0]) {
+ case 'expireDate':
+ return t('files_sharing', 'Share expiry date saved')
+ case 'hideDownload':
+ return t('files_sharing', 'Share hide-download state saved')
+ case 'label':
+ return t('files_sharing', 'Share label saved')
+ case 'note':
+ return t('files_sharing', 'Share note for recipient saved')
+ case 'password':
+ return t('files_sharing', 'Share password saved')
+ case 'permissions':
+ return t('files_sharing', 'Share permissions saved')
+ default:
+ return t('files_sharing', 'Share saved')
+ }
+ },
+
+ /**
* Manage sync errors
*
* @param {string} property the errored property, e.g. 'password'
* @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) {