Browse Source

Improved tests for out of office feature and related controllers.

Martin Edenhofer 7 years ago
parent
commit
003d60d6b1

+ 2 - 0
.gitlab-ci.yml

@@ -293,6 +293,7 @@ test:integration:es_mysql:
     - ruby -I test/ test/controllers/search_controller_test.rb
     - ruby -I test/ test/integration/report_test.rb
     - ruby -I test/ test/controllers/form_controller_test.rb
+    - ruby -I test/ test/controllers/user_organization_controller_test.rb
     - rake db:drop
 
 test:integration:es_postgresql:
@@ -310,6 +311,7 @@ test:integration:es_postgresql:
     - ruby -I test/ test/controllers/search_controller_test.rb
     - ruby -I test/ test/integration/report_test.rb
     - ruby -I test/ test/controllers/form_controller_test.rb
+    - ruby -I test/ test/controllers/user_organization_controller_test.rb
     - rake db:drop
 
 test:integration:zendesk_mysql:

+ 5 - 5
app/assets/javascripts/app/controllers/_ui_element/autocompletion.coffee

@@ -14,7 +14,7 @@ class App.UiElement.autocompletion
 
       # call calback on init
       if @callback && attribute.value && @params
-        @callback( @params )
+        @callback(@params)
 
       b = (event, item) =>
         # set html form attribute
@@ -24,7 +24,7 @@ class App.UiElement.autocompletion
         # call calback
         if @callback
           params = App.ControllerForm.params(form)
-          @callback( params )
+          @callback(params)
       ###
       $(@local_attribute_full).tagsInput(
         autocomplete_url: '/users/search',
@@ -33,7 +33,7 @@ class App.UiElement.autocompletion
         auto: {
           source: '/users/search',
           minLength: 2,
-          select: ( event, ui ) ->
+          select: (event, ui) ->
             #@log 'notice', 'selected', event, ui
             b(event, ui.item)
         }
@@ -45,8 +45,8 @@ class App.UiElement.autocompletion
       $(local_attribute_full).autocomplete(
         source: source,
         minLength: attribute.minLengt || 3,
-        select: ( event, ui ) ->
+        select: (event, ui) ->
           b(event, ui.item)
       )
-    App.Delay.set( a, 280, undefined, 'form_autocompletion' )
+    App.Delay.set(a, 280, undefined, 'form_autocompletion')
     item

+ 11 - 0
app/assets/javascripts/app/controllers/_ui_element/ticket_selector.coffee

@@ -80,6 +80,17 @@ class App.UiElement.ticket_selector
             if config.name && config.name.match(myRegExp)
               config.operator = operator
             elements["#{groupKey}.#{config.name}"] = config
+
+    if attribute.out_of_office
+      elements['ticket.out_of_office_replacement_id'] =
+        name: 'out_of_office_replacement_id'
+        display: 'Out of office replacement'
+        tag: 'autocompletion_ajax'
+        relation: 'User'
+        null: false
+        translate: true
+        operator: ['is', 'is not']
+
     [defaults, groups, elements]
 
   @rowContainer: (groups, elements, attribute) ->

+ 2 - 2
app/assets/javascripts/app/controllers/users.coffee

@@ -140,7 +140,7 @@ class Index extends App.ControllerSubContent
     App.Ajax.request(
       id: 'search'
       type: 'GET'
-      url: @apiPath + '/users/search'
+      url: "#{@apiPath}/users/search"
       data:
         query: @query
         limit: 140
@@ -165,7 +165,7 @@ class Index extends App.ControllerSubContent
       type: 'GET'
       url: "#{@apiPath}/users/recent"
       data:
-        limit: 40
+        limit: 50
         role_ids: role_ids
         full: 1
       processData: true

+ 1 - 1
app/assets/javascripts/app/models/overview.coffee

@@ -9,7 +9,7 @@ class App.Overview extends App.Model
     { name: 'user_ids',   display: 'Available for User',  tag: 'column_select', multiple: true, null: true,  relation: 'User', sortBy: 'firstname' },
     { name: 'organization_shared', display: 'Only available for Users with shared Organization', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true },
     { name: 'out_of_office', display: 'Only available for Users which are replacements for other users.', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true },
-    { name: 'condition',  display: 'Conditions for shown Tickets', tag: 'ticket_selector', null: false },
+    { name: 'condition',  display: 'Conditions for shown Tickets', tag: 'ticket_selector', null: false, out_of_office: true },
     { name: 'prio',       display: 'Prio',                readonly: 1 },
     {
       name:    'view::s'

+ 1 - 1
app/assets/javascripts/app/models/trigger.coffee

@@ -5,7 +5,7 @@ class App.Trigger extends App.Model
   @configure_attributes = [
     { name: 'name',       display: 'Name',          tag: 'input',     type: 'text', limit: 100, null: false },
     { name: 'condition',  display: 'Conditions for effected objects', tag: 'ticket_selector', null: false, preview: false, action: true, hasChanged: true },
-    { name: 'perform',    display: 'Execute changes on objects',      tag: 'ticket_perform_action', null: true, notification: true },
+    { name: 'perform',    display: 'Execute changes on objects',      tag: 'ticket_perform_action', null: true, notification: true, trigger: true },
     { name: 'active',     display: 'Active',        tag: 'active',    default: true },
     { name: 'updated_at', display: 'Updated',       tag: 'datetime',  readonly: 1 },
   ]

+ 3 - 3
app/controllers/search_controller.rb

@@ -57,7 +57,7 @@ class SearchController < ApplicationController
       }
 
       # do only one query to index search backend
-      if !objects_with_direct_search_index.empty?
+      if objects_with_direct_search_index.present?
         items = SearchIndexBackend.search(query, limit, objects_with_direct_search_index)
         items.each { |item|
           require item[:type].to_filename
@@ -71,7 +71,7 @@ class SearchController < ApplicationController
       # e. g. do ticket query by Ticket class to handle ticket permissions
       objects_without_direct_search_index.each { |object|
         object_result = search_generic_backend(object, query, limit, current_user, assets)
-        if !object_result.empty?
+        if object_result.present?
           result = result.concat(object_result)
         end
       }
@@ -92,7 +92,7 @@ class SearchController < ApplicationController
       # do query
       objects_in_order.each { |object|
         object_result = search_generic_backend(object, query, limit, current_user, assets)
-        if !object_result.empty?
+        if object_result.present?
           result = result.concat(object_result)
         end
       }

+ 3 - 2
app/controllers/users_controller.rb

@@ -368,8 +368,9 @@ class UsersController < ApplicationController
       limit: params[:limit],
       current_user: current_user,
     }
-    if params[:role_ids].present?
-      query_params[:role_ids] = params[:role_ids]
+    [:role_ids, :permissions].each do |key|
+      next if params[key].blank?
+      query_params[key] = params[key]
     end
 
     # do query

+ 6 - 6
app/models/concerns/has_search_index_backend.rb

@@ -19,10 +19,10 @@ update search index, if configured - will be executed automatically
 =end
 
   def search_index_update
-    return if ignore_search_indexing?(:update)
+    return true if ignore_search_indexing?(:update)
 
     # start background job to transfer data to search index
-    return if !SearchIndexBackend.enabled?
+    return true if !SearchIndexBackend.enabled?
     Delayed::Job.enqueue(BackgroundJobSearchIndex.new(self.class.to_s, id))
     true
   end
@@ -37,7 +37,7 @@ delete search index object, will be executed automatically
 =end
 
   def search_index_destroy
-    return if ignore_search_indexing?(:destroy)
+    return true if ignore_search_indexing?(:destroy)
     SearchIndexBackend.remove(self.class.to_s, id)
     true
   end
@@ -58,7 +58,7 @@ returns
   def search_index_update_backend
     # fill up with search data
     attributes = search_index_attribute_lookup
-    return if !attributes
+    return true if !attributes
 
     # update backend
     SearchIndexBackend.add(self.class.to_s, attributes)
@@ -86,10 +86,10 @@ returns
     attributes = {}
     %w(name note).each { |key|
       next if !self[key]
-      next if self[key].respond_to?('empty?') && self[key].empty?
+      next if self[key].respond_to?('blank?') && self[key].blank?
       attributes[key] = self[key]
     }
-    return if attributes.empty?
+    return true if attributes.blank?
     attributes
   end
 

+ 34 - 8
app/models/ticket.rb

@@ -549,6 +549,12 @@ condition example
       # get attributes
       attributes = attribute.split(/\./)
       attribute = "#{attributes[0]}s.#{attributes[1]}"
+
+      # magic selectors
+      if attributes[0] == 'ticket' && attributes[1] == 'out_of_office_replacement_id'
+        attribute = "#{attributes[0]}s.owner_id"
+      end
+
       if attributes[0] == 'ticket' && attributes[1] == 'tags'
         selector['value'] = selector['value'].split(/,/).collect(&:strip)
       end
@@ -567,8 +573,13 @@ condition example
           end
         elsif selector['pre_condition'] == 'current_user.id'
           raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
-          query += "#{attribute} IN (?)"
-          bind_params.push current_user_id
+          if attributes[1] == 'out_of_office_replacement_id'
+            query += "#{attribute} IN (?)"
+            bind_params.push User.find(current_user_id).out_of_office_agent_of.pluck(:id)
+          else
+            query += "#{attribute} IN (?)"
+            bind_params.push current_user_id
+          end
         elsif selector['pre_condition'] == 'current_user.organization_id'
           raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
           query += "#{attribute} IN (?)"
@@ -579,8 +590,13 @@ condition example
           if selector['value'].nil?
             query += "#{attribute} IS NULL"
           else
-            query += "#{attribute} IN (?)"
-            bind_params.push selector['value']
+            if attributes[1] == 'out_of_office_replacement_id'
+              query += "#{attribute} IN (?)"
+              bind_params.push User.find(selector['value']).out_of_office_agent_of.pluck(:id)
+            else
+              query += "#{attribute} IN (?)"
+              bind_params.push selector['value']
+            end
           end
           # rubocop:enable Style/IfInsideElse
         end
@@ -593,8 +609,13 @@ condition example
             query += "#{attribute} IS NOT NULL"
           end
         elsif selector['pre_condition'] == 'current_user.id'
-          query += "#{attribute} NOT IN (?)"
-          bind_params.push current_user_id
+          if attributes[1] == 'out_of_office_replacement_id'
+            query += "#{attribute} NOT IN (?)"
+            bind_params.push User.find(current_user_id).out_of_office_agent_of.pluck(:id)
+          else
+            query += "#{attribute} NOT IN (?)"
+            bind_params.push current_user_id
+          end
         elsif selector['pre_condition'] == 'current_user.organization_id'
           query += "#{attribute} NOT IN (?)"
           user = User.lookup(id: current_user_id)
@@ -604,8 +625,13 @@ condition example
           if selector['value'].nil?
             query += "#{attribute} IS NOT NULL"
           else
-            query += "#{attribute} NOT IN (?)"
-            bind_params.push selector['value']
+            if attributes[1] == 'out_of_office_replacement_id'
+              query += "#{attribute} NOT IN (?)"
+              bind_params.push User.find(selector['value']).out_of_office_agent_of.pluck(:id)
+            else
+              query += "#{attribute} NOT IN (?)"
+              bind_params.push selector['value']
+            end
           end
           # rubocop:enable Style/IfInsideElse
         end

Some files were not shown because too many files changed in this diff