From a2e3d8c7b489f4a926e9089f675a26ca61507a0d Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Mon, 7 Dec 2020 09:29:54 +0100 Subject: [PATCH] Fixes #3007 - Customer invitation doesn't work if "customer" role is name wise missing. --- .../controllers/_dashboard/first_steps.coffee | 2 +- .../app/controllers/widget/invite_user.coffee | 12 +++++++----- spec/system/dashboard_spec.rb | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee b/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee index 9014da9d2..d589b6f8c 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/first_steps.coffee @@ -48,7 +48,7 @@ class App.DashboardFirstSteps extends App.Controller #container: @el.closest('.content') head: 'Invite Customer' screen: 'invite_customer' - role: 'Customer' + signup: true ) testTicketLoading: => diff --git a/app/assets/javascripts/app/controllers/widget/invite_user.coffee b/app/assets/javascripts/app/controllers/widget/invite_user.coffee index 3d6ebb686..6b10fd9bd 100644 --- a/app/assets/javascripts/app/controllers/widget/invite_user.coffee +++ b/app/assets/javascripts/app/controllers/widget/invite_user.coffee @@ -48,11 +48,13 @@ class App.InviteUser extends App.WizardModal # set invite flag @params.invite = true - # find agent role - if @role - role = App.Role.findByAttribute('name', @role) - if role - @params.role_ids = role.id + # find signup roles + if @signup + @params.role_ids = App.Role.search( + filter: + active: true + default_at_signup: true + ).map((role) -> role.id) user = new App.User user.load(@params) diff --git a/spec/system/dashboard_spec.rb b/spec/system/dashboard_spec.rb index c4a3ae697..e6f03dcb3 100644 --- a/spec/system/dashboard_spec.rb +++ b/spec/system/dashboard_spec.rb @@ -13,4 +13,23 @@ RSpec.describe 'Dashboard', type: :system, authenticated_as: true do expect(page).to have_css('.ticket_in_process > div > div.stat-title', text: /Your tickets in process/i) expect(page).to have_css('.ticket_reopen > div > div.stat-title', text: /Reopening rate/i) end + + context 'when customer role is named different', authenticated_as: :authenticate do + def authenticate + Role.find_by(name: 'Customer').update(name: 'Public') + true + end + + it 'invites a customer user' do + visit 'dashboard' + find('div.tab[data-area=first-steps-widgets]').click + find('.js-inviteCustomer').click + fill_in 'Firstname', with: 'Nick' + fill_in 'Lastname', with: 'Braun' + fill_in 'Email', with: 'nick.braun@zammad.org' + click_on 'Invite' + await_empty_ajax_queue + expect(User.find_by(firstname: 'Nick').roles).to eq([Role.find_by(name: 'Public')]) + end + end end