From d0689778dce28478cb6de9fbf96a15290e8ba826 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 25 Aug 2021 15:08:05 +0200 Subject: [PATCH] Fixes #2293 - Any user can be set as a replacement for out of office. --- .../controllers/_profile/out_of_office.coffee | 7 +++ ..._object_organization_autocompletion.coffee | 61 +++++++++++-------- app/controllers/users_controller.rb | 17 +++--- spec/system/profile/out_of_office_spec.rb | 20 ++++++ 4 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 spec/system/profile/out_of_office_spec.rb diff --git a/app/assets/javascripts/app/controllers/_profile/out_of_office.coffee b/app/assets/javascripts/app/controllers/_profile/out_of_office.coffee index 06a632e9d..c7958ffdc 100644 --- a/app/assets/javascripts/app/controllers/_profile/out_of_office.coffee +++ b/app/assets/javascripts/app/controllers/_profile/out_of_office.coffee @@ -75,6 +75,13 @@ class ProfileOutOfOffice extends App.ControllerSubContent translate: false disableCreateObject: true value: @localData + source: "#{@apiPath}/users/search?full=true" + sourceType: 'POST' + queryCallback: (query) -> + return JSON.stringify( + query: query + permissions: ['ticket.agent'] + ) ] noFieldset: true params: @localData diff --git a/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee b/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee index 58e941f65..5b558f8ed 100644 --- a/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee +++ b/app/assets/javascripts/app/lib/app_post/_object_organization_autocompletion.coffee @@ -39,6 +39,8 @@ class App.ObjectOrganizationAutocompletion extends App.Controller @key = Math.floor( Math.random() * 999999 ).toString() + if !@attribute.sourceType + @attribute.sourceType = 'GET' if !@attribute.source @attribute.source = "#{@apiPath}/search/user-organization" @build() @@ -345,38 +347,49 @@ class App.ObjectOrganizationAutocompletion extends App.Controller @lazySearch(query) searchObject: (query) => + data = + query: query + if @attribute.queryCallback + data = @attribute.queryCallback(query) + @ajax( - id: "searchObject#{@key}" - type: 'GET' - url: @attribute.source - data: - query: query + id: "searchObject#{@key}" + type: @attribute.sourceType + url: @attribute.source + data: data processData: true - success: (data, status, xhr) => + success: (data, status, xhr) => @emptyResultList() # load assets App.Collection.loadAssets(data.assets) - # build markup - for item in data.result - - # organization - if item.type is 'Organization' - organization = App.Organization.fullLocal(item.id) - @recipientList.append(@buildOrganizationItem(organization)) - - # objectss of organization - if organization[@referenceAttribute] - @$('.dropdown-menu').append(@buildOrganizationMembers(organization)) - - # objectss - if item.type is @objectSingle - object = App[@objectSingle].fullLocal(item.id) + # user search endpoint + if data.user_ids + for id in data.user_ids + object = App[@objectSingle].fullLocal(id) @recipientList.append(@buildObjectItem(object)) - if !@attribute.disableCreateObject - @recipientList.append(@buildObjectNew()) + # global search endpoint + else + for item in data.result + + # organization + if item.type is 'Organization' + organization = App.Organization.fullLocal(item.id) + @recipientList.append(@buildOrganizationItem(organization)) + + # objectss of organization + if organization[@referenceAttribute] + @$('.dropdown-menu').append(@buildOrganizationMembers(organization)) + + # objectss + else if item.type is @objectSingle + object = App[@objectSingle].fullLocal(item.id) + @recipientList.append(@buildObjectItem(object)) + + if !@attribute.disableCreateObject + @recipientList.append(@buildObjectNew()) @recipientList.find('.js-object').first().addClass('is-active') ) @@ -445,4 +458,4 @@ class App.ObjectOrganizationAutocompletion extends App.Controller newObject: (e) -> if e - e.preventDefault() \ No newline at end of file + e.preventDefault() diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d23bb2fb5..5ab176c9a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -208,14 +208,15 @@ class UsersController < ApplicationController # The requester has to be in the role 'Admin' or 'Agent' to # be able to search for User records. # - # @parameter query [String] The search query. - # @parameter limit [Integer] The limit of search results. - # @parameter ids(multi) [Array] A list of User IDs which should be returned - # @parameter role_ids(multi) [Array] A list of Role identifiers to which the Users have to be allocated to. - # @parameter group_ids(multi) [HashString,Array>] A list of Group identifiers to which the Users have to be allocated to. - # @parameter full [Boolean] Defines if the result should be - # true: { user_ids => [1,2,...], assets => {...} } - # or false: [{:id => user.id, :label => "firstname lastname ", :value => "firstname lastname "},...]. + # @parameter query [String] The search query. + # @parameter limit [Integer] The limit of search results. + # @parameter ids(multi) [Array] A list of User IDs which should be returned + # @parameter role_ids(multi) [Array] A list of Role identifiers to which the Users have to be allocated to. + # @parameter group_ids(multi) [HashInteger,Array>] A list of Group identifiers to which the Users have to be allocated to. + # @parameter permissions(multi) [Array] A list of Permission identifiers to which the Users have to be allocated to. + # @parameter full [Boolean] Defines if the result should be + # true: { user_ids => [1,2,...], assets => {...} } + # or false: [{:id => user.id, :label => "firstname lastname ", :value => "firstname lastname "},...]. # # @response_message 200 [Array] A list of User records matching the search term. # @response_message 403 Forbidden / Invalid session. diff --git a/spec/system/profile/out_of_office_spec.rb b/spec/system/profile/out_of_office_spec.rb new file mode 100644 index 000000000..4c0ff115f --- /dev/null +++ b/spec/system/profile/out_of_office_spec.rb @@ -0,0 +1,20 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'Profile > Out of Office', type: :system do + before do + visit 'profile/out_of_office' + sleep 3 # wait for popover killer to pass + end + + it 'does find agents' do + find(:css, '.js-objectSelect').send_keys('Agent') + expect(page).to have_text('Agent 1 Test', wait: 20) + end + + it 'does not find customers' do + find(:css, '.js-objectSelect').send_keys('Nicole') + expect(page).to have_no_text('Nicole Braun', wait: 20) + end +end