diff --git a/apps/files_sharing/src/components/SharingEntryLink.vue b/apps/files_sharing/src/components/SharingEntryLink.vue
index 63091dcf986d1..57bf1467ff445 100644
--- a/apps/files_sharing/src/components/SharingEntryLink.vue
+++ b/apps/files_sharing/src/components/SharingEntryLink.vue
@@ -334,6 +334,7 @@ import Actions from '@nextcloud/vue/dist/Components/Actions'
import Avatar from '@nextcloud/vue/dist/Components/Avatar'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
+import GeneratePassword from '../utils/GeneratePassword'
import Share from '../models/Share'
import SharesMixin from '../mixins/SharesMixin'
@@ -460,7 +461,7 @@ export default {
},
async set(enabled) {
// TODO: directly save after generation to make sure the share is always protected
- Vue.set(this.share, 'password', enabled ? await this.generatePassword() : '')
+ Vue.set(this.share, 'password', enabled ? await GeneratePassword() : '')
Vue.set(this.share, 'newPassword', this.share.password)
},
},
@@ -618,7 +619,7 @@ export default {
shareDefaults.expiration = this.config.defaultExpirationDateString
}
if (this.config.enableLinkPasswordByDefault) {
- shareDefaults.password = await this.generatePassword()
+ shareDefaults.password = await GeneratePassword()
}
// do not push yet if we need a password or an expiration date
@@ -639,7 +640,7 @@ export default {
// ELSE, show the pending popovermenu
// if password enforced, pre-fill with random one
if (this.config.enforcePasswordForPublicLink) {
- shareDefaults.password = await this.generatePassword()
+ shareDefaults.password = await GeneratePassword()
}
// create share & close menu
diff --git a/apps/files_sharing/src/components/SharingInput.vue b/apps/files_sharing/src/components/SharingInput.vue
index 588ed63416636..beffcde6a997b 100644
--- a/apps/files_sharing/src/components/SharingInput.vue
+++ b/apps/files_sharing/src/components/SharingInput.vue
@@ -53,6 +53,7 @@ import debounce from 'debounce'
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
import Config from '../services/ConfigService'
+import GeneratePassword from '../utils/GeneratePassword'
import Share from '../models/Share'
import ShareRequests from '../mixins/ShareRequests'
import ShareTypes from '../mixins/ShareTypes'
@@ -412,9 +413,6 @@ export default {
return true
}
- // TODO: reset the search string when done
- // https://github.com/shentao/vue-multiselect/issues/633
-
// handle externalResults from OCA.Sharing.ShareSearch
if (value.handler) {
const share = await value.handler(this)
@@ -423,25 +421,55 @@ export default {
}
this.loading = true
+ console.debug('Adding a new share from the input for', value)
try {
+ let password = null
+
+ if (this.config.enforcePasswordForPublicLink
+ && value.shareType === this.SHARE_TYPES.SHARE_TYPE_EMAIL) {
+ password = await GeneratePassword()
+ }
+
const path = (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
const share = await this.createShare({
path,
shareType: value.shareType,
shareWith: value.shareWith,
+ password,
permissions: this.fileInfo.sharePermissions & OC.getCapabilities().files_sharing.default_permissions,
})
- this.$emit('add:share', share)
- this.getRecommendations()
+ // If we had a password, we need to show it to the user as it was generated
+ if (password) {
+ share.newPassword = password
+ // Wait for the newly added share
+ const component = await new Promise(resolve => {
+ this.$emit('add:share', share, resolve)
+ })
+
+ // open the menu on the
+ // freshly created share component
+ component.open = true
+ } else {
+ // Else we just add it normally
+ this.$emit('add:share', share)
+ }
+
+ // reset the search string when done
+ // FIXME: https://github.com/shentao/vue-multiselect/issues/633
+ if (this.$refs.multiselect?.$refs?.VueMultiselect?.search) {
+ this.$refs.multiselect.$refs.VueMultiselect.search = ''
+ }
- } catch (response) {
+ await this.getRecommendations()
+ } catch (error) {
// focus back if any error
const input = this.$refs.multiselect.$el.querySelector('input')
if (input) {
input.focus()
}
this.query = value.shareWith
+ console.error('Error while adding new share', error)
} finally {
this.loading = false
}
diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js
index 7aa6ce7d89770..b35ebd8359e57 100644
--- a/apps/files_sharing/src/mixins/SharesMixin.js
+++ b/apps/files_sharing/src/mixins/SharesMixin.js
@@ -20,7 +20,6 @@
*
*/
-import axios from '@nextcloud/axios'
import PQueue from 'p-queue'
import debounce from 'debounce'
@@ -30,8 +29,6 @@ import ShareTypes from './ShareTypes'
import Config from '../services/ConfigService'
import { getCurrentUser } from '@nextcloud/auth'
-const passwordSet = 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789'
-
export default {
mixins: [SharesRequests, ShareTypes],
@@ -326,33 +323,5 @@ export default {
return (this.dateTomorrow && dateMoment.isBefore(this.dateTomorrow, 'day'))
|| (this.dateMaxEnforced && dateMoment.isSameOrAfter(this.dateMaxEnforced, 'day'))
},
-
- /**
- * Generate a valid policy password or
- * request a valid password if password_policy
- * is enabled
- *
- * @returns {string} a valid password
- */
- async generatePassword() {
- // password policy is enabled, let's request a pass
- if (this.config.passwordPolicy.api && this.config.passwordPolicy.api.generate) {
- try {
- const request = await axios.get(this.config.passwordPolicy.api.generate)
- if (request.data.ocs.data.password) {
- return request.data.ocs.data.password
- }
- } catch (error) {
- console.info('Error generating password from password_policy', error)
- }
- }
-
- // generate password of 10 length based on passwordSet
- return Array(10).fill(0)
- .reduce((prev, curr) => {
- prev += passwordSet.charAt(Math.floor(Math.random() * passwordSet.length))
- return prev
- }, '')
- },
},
}
diff --git a/apps/files_sharing/src/utils/GeneratePassword.js b/apps/files_sharing/src/utils/GeneratePassword.js
new file mode 100644
index 0000000000000..6e1a79f3f51b6
--- /dev/null
+++ b/apps/files_sharing/src/utils/GeneratePassword.js
@@ -0,0 +1,56 @@
+
+/**
+ * @copyright Copyright (c) 2020 John Molakvoæ
+
/>
-
+