aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/mixins/ShareRequests.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/src/mixins/ShareRequests.js')
-rw-r--r--apps/files_sharing/src/mixins/ShareRequests.js60
1 files changed, 24 insertions, 36 deletions
diff --git a/apps/files_sharing/src/mixins/ShareRequests.js b/apps/files_sharing/src/mixins/ShareRequests.js
index 9eaad8c4161..2c33fa3b0c7 100644
--- a/apps/files_sharing/src/mixins/ShareRequests.js
+++ b/apps/files_sharing/src/mixins/ShareRequests.js
@@ -1,34 +1,17 @@
/**
- * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license AGPL-3.0-or-later
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
// 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'
+
+import Share from '../models/Share.ts'
const shareUrl = generateOcsUrl('apps/files_sharing/api/v1/shares')
@@ -41,29 +24,32 @@ export default {
* @param {string} data.path path to the file/folder which should be shared
* @param {number} data.shareType 0 = user; 1 = group; 3 = public link; 6 = federated cloud share
* @param {string} data.shareWith user/group id with which the file should be shared (optional for shareType > 1)
- * @param {boolean} [data.publicUpload=false] allow public upload to a public shared folder
+ * @param {boolean} [data.publicUpload] allow public upload to a public shared folder
* @param {string} [data.password] password to protect public link Share with
- * @param {number} [data.permissions=31] 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1)
- * @param {boolean} [data.sendPasswordByTalk=false] send the password via a talk conversation
- * @param {string} [data.expireDate=''] expire the shareautomatically after
- * @param {string} [data.label=''] custom label
- * @param {string} [data.attributes=null] Share attributes encoded as json
+ * @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 share automatically after
+ * @param {string} [data.label] custom label
+ * @param {string} [data.attributes] Share attributes encoded as json
+ * @param {string} data.note custom note to recipient
* @return {Share} the new share
* @throws {Error}
*/
- async createShare({ path, permissions, shareType, shareWith, publicUpload, password, sendPasswordByTalk, expireDate, label, attributes }) {
+ async createShare({ path, permissions, shareType, shareWith, publicUpload, password, sendPasswordByTalk, expireDate, label, note, attributes }) {
try {
- const request = await axios.post(shareUrl, { path, permissions, shareType, shareWith, publicUpload, password, sendPasswordByTalk, expireDate, label, attributes })
+ const request = await axios.post(shareUrl, { path, permissions, shareType, shareWith, publicUpload, password, sendPasswordByTalk, expireDate, label, note, attributes })
if (!request?.data?.ocs) {
throw request
}
- return new Share(request.data.ocs.data)
+ const share = new Share(request.data.ocs.data)
+ emit('files_sharing:share:created', { share })
+ return share
} 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' }
+ { type: 'error' },
)
throw error
}
@@ -81,13 +67,14 @@ export default {
if (!request?.data?.ocs) {
throw request
}
+ emit('files_sharing:share:deleted', { id })
return true
} catch (error) {
console.error('Error while deleting share', error)
const errorMessage = error?.response?.data?.ocs?.meta?.message
OC.Notification.showTemporary(
errorMessage ? t('files_sharing', 'Error deleting the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error deleting the share'),
- { type: 'error' }
+ { type: 'error' },
)
throw error
}
@@ -102,6 +89,7 @@ export default {
async updateShare(id, properties) {
try {
const request = await axios.put(shareUrl + `/${id}`, properties)
+ emit('files_sharing:share:updated', { id })
if (!request?.data?.ocs) {
throw request
} else {
@@ -113,7 +101,7 @@ export default {
const errorMessage = error?.response?.data?.ocs?.meta?.message
OC.Notification.showTemporary(
errorMessage ? t('files_sharing', 'Error updating the share: {errorMessage}', { errorMessage }) : t('files_sharing', 'Error updating the share'),
- { type: 'error' }
+ { type: 'error' },
)
}
const message = error.response.data.ocs.meta.message