From a52a74a915a281c41dd81f5ea47a16046266029d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 21 Feb 2013 22:09:36 +0100 Subject: [PATCH] Added possibility to set create groups via setting/channels/web. Added browser tests. --- .../controllers/agent_ticket_zoom.js.coffee | 8 +-- .../controllers/customer_ticket_new.js.coffee | 19 +++++-- db/seeds.rb | 24 +++++++++ test/browser/ticket_create.rb | 50 ++++++++++++++++++- test/browser_test_helper.rb | 12 +++++ 5 files changed, 105 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee index b967e75c2..1f09bf11e 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_zoom.js.coffee @@ -279,9 +279,9 @@ class Index extends App.Controller reply: (e) => e.preventDefault() article_id = $(e.target).parents('[data-id]').data('id') - article = App.TicketArticle.find( article_id ) - article_type = App.TicketArticleType.find( article.ticket_article_type_id ) - customer = App.User.find( article.created_by_id ) + article = App.Collection.find( 'TicketArticle', article_id ) + article_type = App.Collection.find( 'TicketArticleType', article.ticket_article_type_id ) + customer = App.Collection.find( 'User', article.created_by_id ) # update form @form_update_execute(article_type) @@ -347,7 +347,7 @@ class Index extends App.Controller e.preventDefault() params = @formParam(e.target) @log 'TicketZoom', 'notice', 'update', params, @ticket - article_type = App.TicketArticleType.find( params['ticket_article_type_id'] ) + article_type = App.Collection.find( 'TicketArticleType', params['ticket_article_type_id'] ) # update ticket ticket_update = {} diff --git a/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee index 743883970..618d5fe2a 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_new.js.coffee @@ -85,12 +85,25 @@ class Index extends App.Controller if !( 'ticket_priority_id' of defaults ) defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ) - groupFilter = (collection) => + groupFilter = (collection, type) => + + # only filter on collections + return collection if type isnt 'collection' + + # get configured ids + group_ids = App.Config.get('customer_ticket_create_group_ids') + + # return all groups if no one is selected + if !_.isArray( group_ids ) + group_ids = [group_ids] + + # filter selected groups + if _.isEmpty( group_ids ) + return collection _.filter( collection (item) -> - return item if item.name is 'Support' - return item if item.name is 'Sales' + return item if item && _.contains( group_ids, item.id.toString() ) ) # generate form diff --git a/db/seeds.rb b/db/seeds.rb index e21f59e02..de30d687a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -779,6 +779,30 @@ Setting.create_if_not_exists( :frontend => true ) +Setting.create_if_not_exists( + :title => 'Group selection for Ticket creation', + :name => 'customer_ticket_create_group_ids', + :area => 'CustomerWeb::Base', + :description => 'Defines groups where customer can create tickets via web interface. "-" means all groups are available.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'group_ids', + :tag => 'select', + :multiple => true, + :null => false, + :nulloption => true, + :relation => 'Group', + }, + ], + }, + :state => '', + :frontend => true +) + + Setting.create_if_not_exists( :title => 'Enable Ticket View/Update', :name => 'customer_ticket_view', diff --git a/test/browser/ticket_create.rb b/test/browser/ticket_create.rb index 00c7e29bf..8d84eab79 100644 --- a/test/browser/ticket_create.rb +++ b/test/browser/ticket_create.rb @@ -22,6 +22,16 @@ class TicketCreate < ActiveSupport::TestCase :id => 'form_create', :result => true, }, + { + :execute => 'wait', + :value => 2, + }, + { + :execute => 'select', + :element => :select_list, + :name => 'group_id', + :value => 'Users', + }, { :execute => 'set', :element => :text_field, @@ -41,7 +51,7 @@ class TicketCreate < ActiveSupport::TestCase }, { :execute => 'wait', - :value => 3, + :value => 5, }, { :execute => 'check', @@ -54,6 +64,44 @@ class TicketCreate < ActiveSupport::TestCase :element => :url, :result => '#ticket/zoom/', }, + + # check ticket + { + :execute => 'match', + :element => :div, + :class => 'article', + :value => 'some body 123äöü', + :match_result => true, + }, + + # update ticket + { + :execute => 'check', + :element => :text_field, + :name => 'body', + :result => true, + }, + { + :execute => 'set', + :element => :text_field, + :name => 'body', + :value => 'some body 1234 äöüß', + }, + { + :execute => 'click', + :element => :button, + :type => 'submit', + }, + { + :execute => 'wait', + :value => 5, + }, + { + :execute => 'match', + :element => :body, + :value => 'some body 1234 äöüß', + :match_result => true, + }, ], }, ] diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 852426f9d..3c7ffff5a 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -138,6 +138,14 @@ class ActiveSupport::TestCase element = instance.send( action[:element], { :type => action[:type] } ) assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with type #{action[:type]} doesn't exist" ) end + elsif action[:class] + if action[:result] == false + element = instance.send( action[:element], { :class => action[:class] } ) + assert( !element.exists?, "(#{test[:name]}) Element #{action[:element]} with class #{action[:class]} exists" ) + else + element = instance.send( action[:element], { :class => action[:class] } ) + assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with class #{action[:class]} doesn't exist" ) + end elsif action[:name] if action[:result] == false element = instance.send( action[:element], { :name => action[:name] } ) @@ -160,11 +168,15 @@ class ActiveSupport::TestCase else assert( false, "(#{test[:name]}) url #{instance.url} is not matching #{action[:result]}" ) end + elsif action[:element] == :body + element = instance.send( action[:element] ) else assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" ) end if action[:execute] == 'set' element.set( action[:value] ) + elsif action[:execute] == 'select' + element.select( action[:value] ) elsif action[:execute] == 'click' element.click elsif action[:execute] == 'send_key'