@@ -53,6 +53,7 @@ import debounce from 'debounce'
5353import Multiselect from ' @nextcloud/vue/dist/Components/Multiselect'
5454
5555import Config from ' ../services/ConfigService'
56+ import GeneratePassword from ' ../utils/GeneratePassword'
5657import Share from ' ../models/Share'
5758import ShareRequests from ' ../mixins/ShareRequests'
5859import ShareTypes from ' ../mixins/ShareTypes'
@@ -412,9 +413,6 @@ export default {
412413 return true
413414 }
414415
415- // TODO: reset the search string when done
416- // https://github.com/shentao/vue-multiselect/issues/633
417-
418416 // handle externalResults from OCA.Sharing.ShareSearch
419417 if (value .handler ) {
420418 const share = await value .handler (this )
@@ -423,25 +421,55 @@ export default {
423421 }
424422
425423 this .loading = true
424+ console .debug (' Adding a new share from the input for' , value)
426425 try {
426+ let password = null
427+
428+ if (this .config .enforcePasswordForPublicLink
429+ && value .shareType === this .SHARE_TYPES .SHARE_TYPE_EMAIL ) {
430+ password = await GeneratePassword ()
431+ }
432+
427433 const path = (this .fileInfo .path + ' /' + this .fileInfo .name ).replace (' //' , ' /' )
428434 const share = await this .createShare ({
429435 path,
430436 shareType: value .shareType ,
431437 shareWith: value .shareWith ,
438+ password,
432439 permissions: this .fileInfo .sharePermissions & OC .getCapabilities ().files_sharing .default_permissions ,
433440 })
434- this .$emit (' add:share' , share)
435441
436- this .getRecommendations ()
442+ // If we had a password, we need to show it to the user as it was generated
443+ if (password) {
444+ share .newPassword = password
445+ // Wait for the newly added share
446+ const component = await new Promise (resolve => {
447+ this .$emit (' add:share' , share, resolve)
448+ })
449+
450+ // open the menu on the
451+ // freshly created share component
452+ component .open = true
453+ } else {
454+ // Else we just add it normally
455+ this .$emit (' add:share' , share)
456+ }
457+
458+ // reset the search string when done
459+ // FIXME: https://github.com/shentao/vue-multiselect/issues/633
460+ if (this .$refs .multiselect ? .$refs ? .VueMultiselect ? .search ) {
461+ this .$refs .multiselect .$refs .VueMultiselect .search = ' '
462+ }
437463
438- } catch (response) {
464+ await this .getRecommendations ()
465+ } catch (error) {
439466 // focus back if any error
440467 const input = this .$refs .multiselect .$el .querySelector (' input' )
441468 if (input) {
442469 input .focus ()
443470 }
444471 this .query = value .shareWith
472+ console .error (' Error while adding new share' , error)
445473 } finally {
446474 this .loading = false
447475 }
0 commit comments