diff --git a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee index 70a74d844..c495ca7d2 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/activity_stream.js.coffee @@ -1,10 +1,6 @@ class App.DashboardActivityStream extends App.Controller - events: - 'click [data-type=edit]': 'zoom' - constructor: -> super - @items = [] @fetch() @@ -36,34 +32,29 @@ class App.DashboardActivityStream extends App.Controller load: (data) => items = data.activity_stream - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.tickets ) - - # load article collection - App.Collection.load( type: 'TicketArticle', data: data.articles ) + # load collections + App.Event.trigger 'loadAssets', data.assets @render(items) render: (items) -> - # load user data for item in items - item.created_by = App.User.find( item.created_by_id ) - - # load ticket data - for item in items - item.data = {} if item.history_object is 'Ticket' - item.data.title = App.Ticket.find( item.o_id ).title - if item.history_object is 'Ticket::Article' + ticket = App.Ticket.find( item.o_id ) + item.link = '#ticket_zoom/' + ticket.id + item.title = ticket.title + item.type = item.history_object + item.updated_by_id = ticket.updated_by_id + item.updated_by = App.User.find( ticket.updated_by_id ) + else if item.history_object is 'Ticket::Article' article = App.TicketArticle.find( item.o_id ) - item.history_object = 'Article' - item.sub_o_id = article.id - item.o_id = article.ticket_id - item.data.title = article.subject + ticket = App.Ticket.find( article.ticket_id ) + item.link = '#ticket_zoom/' + ticket.id + '/' + article.od + item.title = article.subject || ticket.title + item.type = item.history_object + item.updated_by_id = article.updated_by_id + item.updated_by = App.User.find( article.updated_by_id ) html = App.view('dashboard/activity_stream')( head: 'Activity Stream', @@ -76,11 +67,3 @@ class App.DashboardActivityStream extends App.Controller # start user popups @userPopups('left') - zoom: (e) => - e.preventDefault() - id = $(e.target).parents('[data-id]').data('id') - subid = $(e.target).parents('[data-subid]').data('subid') - if subid - @navigate 'ticket/zoom/' + id + '/' + subid - else - @navigate 'ticket/zoom/' + id diff --git a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee index 56cbde3e5..23496b794 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/recent_viewed.js.coffee @@ -1,7 +1,4 @@ class App.DashboardRecentViewed extends App.Controller - events: - 'click [data-type=edit]': 'zoom' - constructor: -> super @@ -16,28 +13,21 @@ class App.DashboardRecentViewed extends App.Controller limit: 5, } processData: true, -# data: JSON.stringify( view: @view ), success: (data, status, xhr) => @items = data.recent_viewed - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets @render() ) render: -> - # load user data for item in @items - item.created_by = App.User.find( item.created_by_id ) - - # load ticket data - for item in @items - item.ticket = App.User.find( item.o_id ) + item.link = '#ticket_zoom/' + item.o_id + item.title = App.Ticket.find( item.o_id ).title + item.type = item.recent_view_object html = App.view('dashboard/recent_viewed')( head: 'Recent Viewed', @@ -49,9 +39,3 @@ class App.DashboardRecentViewed extends App.Controller # start user popups @userPopups('left') - - zoom: (e) => - e.preventDefault() - id = $(e.target).parents('[data-id]').data('id') - - @navigate 'ticket/zoom/' + id diff --git a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee index 03678756a..9a37a27a4 100644 --- a/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee +++ b/app/assets/javascripts/app/controllers/_dashboard/ticket.js.coffee @@ -48,11 +48,8 @@ class App.DashboardTicket extends App.Controller data.ajax = false App.Store.write( @key, data ) - # load user collection - App.Collection.load( type: 'User', data: data.collections.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.collections.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets # get meta data App.Overview.refresh( data.overview, options: { clear: true } ) @@ -71,12 +68,12 @@ class App.DashboardTicket extends App.Controller render: (data) -> return if !data - return if !data.ticket_list + return if !data.ticket_ids return if !data.overview @overview = data.overview @tickets_count = data.tickets_count - @ticket_list = data.ticket_list + @ticket_ids = data.ticket_ids # FIXME 10 pages_total = parseInt( ( @tickets_count / 10 ) + 0.99999 ) || 1 html = App.view('dashboard/ticket')( @@ -94,8 +91,8 @@ class App.DashboardTicket extends App.Controller i = start while i < end i = i + 1 - if @ticket_list[ i - 1 ] - @tickets_in_table.push App.Ticket.retrieve( @ticket_list[ i - 1 ] ) + if @ticket_ids[ i - 1 ] + @tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i - 1 ] ) shown_all_attributes = @ticketTableAttributes( App.Overview.find(@overview.id).view.d ) new App.ControllerTable( diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index a8cd95db7..1acc0b452 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -35,12 +35,18 @@ class App.TicketCreate extends App.Controller title: 'Email' @article_attributes = article_sender_type_map[@type] + # remember split info if exists + split = '' + if @ticket_id && @article_id + split = "/#{@ticket_id}/#{@article_id}" + # if no map entry exists, route to default if !@article_attributes - @navigate '#ticket_create/' + default_type + @navigate '#ticket_create/' + default_type + split + return # update navbar highlighting - @navupdate '#ticket_create/' + @type + '/id/' + @id + @navupdate '#ticket_create/' + @type + '/id/' + @id + split @fetch(params) @@ -97,8 +103,8 @@ class App.TicketCreate extends App.Controller # get edit form attributes @edit_form = cache.edit_form - # load user collection - App.Collection.load( type: 'User', data: cache.users ) + # load collections + App.Event.trigger 'loadAssets', cache.assets @render() else @@ -118,17 +124,11 @@ class App.TicketCreate extends App.Controller # get edit form attributes @edit_form = data.edit_form - # load user collection - App.Collection.load( type: 'User', data: data.users ) + # load collections + App.Event.trigger 'loadAssets', data.assets - # load ticket collection - if data.ticket && data.articles - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load article collections - App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) - - # render page + # split ticket + if data.split && data.split.ticket_id && data.split.article_id t = App.Ticket.find( params.ticket_id ).attributes() a = App.TicketArticle.find( params.article_id ) @@ -137,6 +137,8 @@ class App.TicketCreate extends App.Controller t.customer_id_autocompletion = a.from t.subject = a.subject || t.title t.body = a.body + + # render page @render( options: t ) ) @@ -386,8 +388,13 @@ class TicketCreateRouter extends App.ControllerPermanent # create new uniq form id if !params['id'] + # remember split info if exists + split = '' + if params['ticket_id'] && params['article_id'] + split = "/#{params['ticket_id']}/#{params['article_id']}" + id = Math.floor( Math.random() * 99999 ) - @navigate "#ticket_create/#{params['type']}/id/#{id}" + @navigate "#ticket_create/#{params['type']}/id/#{id}#{split}" return # cleanup params @@ -399,14 +406,16 @@ class TicketCreateRouter extends App.ControllerPermanent App.TaskManager.add( 'TicketCreateScreen-' + params['type'] + '-' + params['id'], 'TicketCreate', clean_params ) -# split ticket -App.Config.set( 'ticket_create/:ticket_id/:article_id', TicketCreateRouter, 'Routes' ) - # create new ticket routs/controller App.Config.set( 'ticket_create', TicketCreateRouter, 'Routes' ) App.Config.set( 'ticket_create/:type', TicketCreateRouter, 'Routes' ) App.Config.set( 'ticket_create/:type/id/:id', TicketCreateRouter, 'Routes' ) + +# split ticket +App.Config.set( 'ticket_create/:type/:ticket_id/:article_id', TicketCreateRouter, 'Routes' ) +App.Config.set( 'ticket_create/:type/id/:id/:ticket_id/:article_id', TicketCreateRouter, 'Routes' ) + # set new task actions App.Config.set( 'TicketNewCallOutbound', { prio: 8001, name: 'Call Outbound', target: '#ticket_create/call_outbound', role: ['Agent'] }, 'TaskActions' ) App.Config.set( 'TicketNewCallInbound', { prio: 8002, name: 'Call Inbound', target: '#ticket_create/call_inbound', role: ['Agent'] }, 'TaskActions' ) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee index 2c89a6ad8..6309a5e92 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_history.js.coffee @@ -15,23 +15,9 @@ class App.TicketHistory extends App.ControllerModal type: 'GET', url: @apiPath + '/ticket_history/' + ticket_id, success: (data, status, xhr) => - # remember ticket - @ticket = data.ticket - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load history_type collections - App.Collection.load( type: 'HistoryType', data: data.history_types ) - - # load history_object collections - App.Collection.load( type: 'HistoryObject', data: data.history_objects ) - - # load history_attributes collections - App.Collection.load( type: 'HistoryAttribute', data: data.history_attributes ) + # load collections + App.Event.trigger 'loadAssets', data.assets # load history collections App.History.deleteAll() @@ -53,7 +39,7 @@ class App.TicketHistory extends App.ControllerModal @userPopups() # show frontend times - @delay( @frontendTimeUpdate, 200, 'ui-time-update' ) + @delay( @frontendTimeUpdate, 300, 'ui-time-update' ) sortorder: (e) -> e.preventDefault() @@ -72,7 +58,6 @@ class App.TicketHistory extends App.ControllerModal state: @sortstate ) - @modalShow() # enable user popups diff --git a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee index a3af61b45..01e4e40d8 100644 --- a/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/customer_ticket_create.js.coffee @@ -24,13 +24,13 @@ class Index extends App.ControllerContent # use cache cache = App.Store.get( 'ticket_create_attributes' ) - if cache && !params.ticket_id && !params.article_id + if cache # get edit form attributes @edit_form = cache.edit_form - # load user collection - App.Collection.load( type: 'User', data: cache.users ) + # load collections + App.Event.trigger 'loadAssets', cache.assets @render() else @@ -38,10 +38,6 @@ class Index extends App.ControllerContent id: 'ticket_create', type: 'GET', url: @apiPath + '/ticket_create', - data: { - ticket_id: params.ticket_id, - article_id: params.article_id, - }, processData: true, success: (data, status, xhr) => @@ -51,27 +47,10 @@ class Index extends App.ControllerContent # get edit form attributes @edit_form = data.edit_form - # load user collection - App.Collection.load( type: 'User', data: data.users ) + # load collections + App.Event.trigger 'loadAssets', data.assets - # load ticket collection - if data.ticket && data.articles - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load article collections - App.Collection.load( type: 'TicketArticle', data: data.articles || [] ) - - # render page - t = App.Ticket.find( params.ticket_id ).attributes() - a = App.TicketArticle.find( params.article_id ) - - # reset owner - t.owner_id = 0 - t.customer_id_autocompletion = a.from - t.subject = a.subject || t.title - t.body = a.body - @log 'CustomerTicketCreate', 'notice', 'created', t - @render( options: t ) + @render() ) render: (template = {}) -> diff --git a/app/assets/javascripts/app/controllers/dashboard.js.coffee b/app/assets/javascripts/app/controllers/dashboard.js.coffee index abd74d4b3..f797d232e 100644 --- a/app/assets/javascripts/app/controllers/dashboard.js.coffee +++ b/app/assets/javascripts/app/controllers/dashboard.js.coffee @@ -53,9 +53,9 @@ class Index extends App.ControllerContent # }, # }, -# recent_viewed: { -# controller: App.DashboardRecentViewed, -# } + recent_viewed: { + controller: App.DashboardRecentViewed, + } } } diff --git a/app/assets/javascripts/app/controllers/link_info_widget.js.coffee b/app/assets/javascripts/app/controllers/link_info_widget.js.coffee index 9bf17db04..1a07420b6 100644 --- a/app/assets/javascripts/app/controllers/link_info_widget.js.coffee +++ b/app/assets/javascripts/app/controllers/link_info_widget.js.coffee @@ -23,11 +23,8 @@ class App.LinkInfo extends App.Controller success: (data, status, xhr) => @links = data.links - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: data.tickets ) + # load collections + App.Event.trigger 'loadAssets', data.assets @render() ) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index eea3c67da..745ebfe70 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -82,7 +82,7 @@ class App.TicketZoom extends App.Controller @log 'diff', diff # notify if ticket changed not by my self - if !_.isEmpty(diff) && data.ticket.updated_by_id isnt @Session.all().id + if !_.isEmpty(diff) && data.asset.ticket[0].updated_by_id isnt @Session.all().id App.TaskManager.notify( @task_key ) # rerender edit box @@ -112,20 +112,19 @@ class App.TicketZoom extends App.Controller # reset old indexes @ticket = undefined + + # remember article ids + @ticket_article_ids = data.ticket_article_ids + + # get edit form attributes @edit_form = data.edit_form # get signature @signature = data.signature - # load user collection - App.Collection.load( type: 'User', data: data.users ) - - # load ticket collection - App.Collection.load( type: 'Ticket', data: [data.ticket] ) - - # load article collections - App.Collection.load( type: 'TicketArticle', data: data.articles ) + # load collections + App.Event.trigger 'loadAssets', data.assets # render page @render(force) @@ -196,9 +195,10 @@ class App.TicketZoom extends App.Controller ArticleView: => # show article new ArticleView( - ticket: @ticket - el: @el.find('.article-view') - ui: @ + ticket: @ticket + ticket_article_ids: @ticket_article_ids + el: @el.find('.article-view') + ui: @ ) Edit: => @@ -570,7 +570,7 @@ class ArticleView extends App.Controller # get all articles @articles = [] - for article_id in @ticket.article_ids + for article_id in @ticket_article_ids article = App.TicketArticle.retrieve( article_id ) @articles.push article @@ -620,16 +620,16 @@ class ArticleView extends App.Controller checkIfSignatureIsNeeded: (article_type) => - # add signature - if @ui.signature && @ui.signature.body && article_type.name is 'email' - body = @ui.el.find('[name="body"]').val() || '' - regexp = new RegExp( escapeRegExp( @ui.signature.body ) , 'i') - if !body.match(regexp) - body = body + "\n" + @ui.signature.body - @ui.el.find('[name="body"]').val( body ) + # add signature + if @ui.signature && @ui.signature.body && article_type.name is 'email' + body = @ui.el.find('[name="body"]').val() || '' + regexp = new RegExp( escapeRegExp( @ui.signature.body ) , 'i') + if !body.match(regexp) + body = body + "\n" + @ui.signature.body + @ui.el.find('[name="body"]').val( body ) - # update textarea size - @ui.el.find('[name="body"]').trigger('change') + # update textarea size + @ui.el.find('[name="body"]').trigger('change') reply: (e) => e.preventDefault() @@ -774,7 +774,7 @@ class Article extends App.Controller actions.push { name: 'split' type: 'split' - href: '#ticket_create/' + @article.ticket_id + '/' + @article.id + href: '#ticket_create/call_inbound/' + @article.ticket_id + '/' + @article.id } @article.actions = actions diff --git a/app/assets/javascripts/app/lib/app_post/collection.js.coffee b/app/assets/javascripts/app/lib/app_post/collection.js.coffee index 63476a2cc..df2c55413 100644 --- a/app/assets/javascripts/app/lib/app_post/collection.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/collection.js.coffee @@ -19,6 +19,28 @@ class _collectionSingleton extends Spine.Module constructor: (@args) -> + # add trigger - bind new events + App.Event.bind 'loadAssets', (data) => + if data + for type, collections of data + if type is 'users' + type = 'User' + if type is 'tickets' + type = 'Ticket' + if type is 'ticket_article' + type = 'TicketArticle' + if type is 'organization' + type = 'Organization' + if type is 'history_object' + type = 'HistoryObject' + if type is 'history_type' + type = 'HistoryType' + if type is 'history_attribute' + type = 'HistoryAttribute' + + @log 'debug', 'loadCollection:trigger', type, collections + @load( localStorage: data.localStorage, type: type, data: collections ) + # add trigger - bind new events App.Event.bind 'loadCollection', (data) => diff --git a/app/assets/javascripts/app/models/organization.js.coffee b/app/assets/javascripts/app/models/organization.js.coffee index 3dbae098f..0f4e15bd5 100644 --- a/app/assets/javascripts/app/models/organization.js.coffee +++ b/app/assets/javascripts/app/models/organization.js.coffee @@ -13,3 +13,14 @@ class App.Organization extends App.Model 'name', 'shared', ] + + @_fillUp: (data) -> + + # addd users of organization + if data['user_ids'] + data['user_ids'] = [] + for user_id in data['user_ids'] + if App.User.exists( user_id ) + user = App.User.find( user_id ) + data['user_ids'].push user + data \ No newline at end of file diff --git a/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco b/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco index 53c4bf10f..2f7134571 100644 --- a/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco +++ b/app/assets/javascripts/app/views/dashboard/activity_stream.jst.eco @@ -3,8 +3,8 @@

<%- @T( @head ) %>

<% for item in @items: %> -
"<%= item.created_by.displayName() %>"
-
<%- @T( item.history_type ) %> <%= item.history_object %><% if item.data.title: %> (<%= item.data.title %>)<% end %>.
+
"<%= item.updated_by.displayName() %>"
+
<%- @T( item.history_type ) %> <%= item.type %><% if item.title: %> (<%= item.title %>)<% end %>.
<% end %>
diff --git a/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco b/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco index ff161319f..bf342e815 100644 --- a/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco +++ b/app/assets/javascripts/app/views/dashboard/recent_viewed.jst.eco @@ -3,7 +3,7 @@

<%- @T( @head ) %>

diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index 001c0d7f2..b73a8fc61 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -10,32 +10,20 @@ class LinksController < ApplicationController :link_object_value => params[:link_object_value], ) - # - tickets = [] - users = {} + assets = {} link_list = [] links.each { |item| link_list.push item if item['link_object'] == 'Ticket' - data = Ticket.lookup( :id => item['link_object_value'] ) - tickets.push data - if !users[ data['owner_id'] ] - users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) - end - if !users[ data['customer_id'] ] - users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) - end - if !users[ data['created_by_id'] ] - users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) - end + ticket = Ticket.lookup( :id => item['link_object_value'] ) + assets = ticket.assets(assets) end } # return result render :json => { - :links => link_list, - :tickets => tickets, - :users => users, + :links => link_list, + :assets => assets, } end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 31ca3133b..cec5dcc40 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -12,13 +12,11 @@ class SearchController < ApplicationController :query => params[:term], :current_user => current_user, ) - users_data = {} + assets = {} ticket_result = [] tickets.each do |ticket| + assets = ticket.assets(assets) ticket_result.push ticket.id - users_data[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - users_data[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - users_data[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) end # do query @@ -30,7 +28,7 @@ class SearchController < ApplicationController user_result = [] users.each do |user| user_result.push user.id - users_data[ user.id ] = User.user_data_full( user.id ) + assets = user.assets(assets) end organizations = Organization.search( @@ -39,17 +37,10 @@ class SearchController < ApplicationController :current_user => current_user, ) - organizations_data = {} organization_result = [] organizations.each do |organization| organization_result.push organization.id - organizations_data[ organization.id ] = Organization.find( organization.id ).attributes - organizations_data[ organization.id ][:user_ids] = [] - users = User.where( :organization_id => organization.id ).limit(10) - users.each {|user| - users_data[ user.id ] = User.user_data_full( user.id ) - organizations_data[ organization.id ][:user_ids].push user.id - } + assets = organization.assets(assets) end result = [] @@ -77,11 +68,7 @@ class SearchController < ApplicationController # return result render :json => { - :load => { - :tickets => tickets, - :users => users_data, - :organizations => organizations_data, - }, + :load => assets, :result => result, } end diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index 63b2e1c77..b985a23eb 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -3,7 +3,7 @@ class TicketOverviewsController < ApplicationController before_filter :authentication_check - # GET /api/v1/tickets + # GET /api/v1/ticket_overviews def show # get navbar overview data @@ -38,8 +38,7 @@ class TicketOverviewsController < ApplicationController end overview = Ticket::Overview.list( :view => params[:view], - # :view_mode => params[:view_mode], - :current_user => User.find( current_user.id ), + :current_user => current_user, :array => true, ) if !overview @@ -48,20 +47,10 @@ class TicketOverviewsController < ApplicationController end # get related users - users = {} - tickets = [] - overview[:ticket_list].each {|ticket_id| - data = Ticket.lookup( :id => ticket_id ) - tickets.push data - if !users[ data['owner_id'] ] - users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) - end - if !users[ data['customer_id'] ] - users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) - end - if !users[ data['created_by_id'] ] - users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) - end + assets = { :users => {} } + overview[:ticket_ids].each {|ticket_id| + ticket = Ticket.lookup( :id => ticket_id ) + assets = ticket.assets(assets) } # get groups @@ -79,8 +68,8 @@ class TicketOverviewsController < ApplicationController Group.find(group_id).users.each {|user| next if !agents[ user.id ] groups_users[ group_id ].push user.id - if !users[user.id] - users[user.id] = User.user_data_full(user.id) + if !assets[:users][user.id] + assets[:users][user.id] = User.user_data_full(user.id) end } } @@ -88,15 +77,12 @@ class TicketOverviewsController < ApplicationController # return result render :json => { :overview => overview[:overview], - :ticket_list => overview[:ticket_list], + :ticket_ids => overview[:ticket_ids], :tickets_count => overview[:tickets_count], :bulk => { :group_id__owner_id => groups_users, }, - :collections => { - :users => users, - :tickets => tickets, - }, + :assets => assets, } end diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 860579b1a..d8f991ee4 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -132,14 +132,13 @@ class TicketsController < ApplicationController # get history of ticket history = History.list( 'Ticket', params[:id], 'Ticket::Article' ) - # get related users - users = {} - users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id ) - users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id ) + # get related assets + assets = ticket.assets({}) history_list = [] history.each do |item| - users[ item[:created_by_id] ] = User.user_data_full( item[:created_by_id] ) + assets = item.assets(assets) + item_tmp = item.attributes if item['history_object'] == 'Ticket::Article' item_temp['type'] = 'Article ' + item['type'].to_s @@ -171,22 +170,12 @@ class TicketsController < ApplicationController item_tmp.delete( 'related_o_id' ) end history_list.push item_tmp - end - # fetch meta relations - history_objects = History::Object.all() - history_types = History::Type.all() - history_attributes = History::Attribute.all() - # return result render :json => { - :ticket => ticket, - :users => users, - :history => history_list, - :history_objects => history_objects, - :history_types => history_types, - :history_attributes => history_attributes + :assets => assets, + :history => history_list, } end @@ -203,34 +192,18 @@ class TicketsController < ApplicationController .limit(6) # get related users - users = {} - tickets = [] + assets = {} ticket_list.each {|ticket| - data = Ticket.lookup( :id => ticket.id ) - tickets.push data - if !users[ data['owner_id'] ] - users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] ) - end - if !users[ data['customer_id'] ] - users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] ) - end - if !users[ data['created_by_id'] ] - users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] ) - end - if !users[ data['updated_by_id'] ] - users[ data['updated_by_id'] ] = User.user_data_full( data['updated_by_id'] ) - end + ticket = Ticket.lookup( :id => ticket.id ) + assets = ticket.assets(assets) } recent_viewed = RecentView.list_fulldata( current_user, 8 ) # return result render :json => { - :customer => { - :tickets => tickets, - :users => users, - }, - :recent => recent_viewed + :customer => assets, + :recent => recent_viewed } end @@ -295,18 +268,6 @@ class TicketsController < ApplicationController ticket = Ticket.find( params[:id] ) return if !ticket_permission( ticket ) - # get related users - users = {} - if !users[ticket.owner_id] - users[ticket.owner_id] = User.user_data_full( ticket.owner_id ) - end - if !users[ticket.customer_id] - users[ticket.customer_id] = User.user_data_full( ticket.customer_id ) - end - if !users[ticket.created_by_id] - users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id ) - end - # log object as viewed if !params[:do_not_log] || params[:do_not_log].to_i == 0 log_view( ticket ) @@ -328,58 +289,52 @@ class TicketsController < ApplicationController ) end + # get related users + assets = {} + assets[:users] = {} + assets = ticket.assets(assets) + # get attributes to update attributes_to_change = Ticket::ScreenOptions.attributes_to_change( :user => current_user, :ticket => ticket ) attributes_to_change[:owner_id].each { |user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } attributes_to_change[:group_id__owner_id].each {|group_id, user_ids| user_ids.each {|user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } } # get related articles - ticket = ticket.attributes - ticket[:article_ids] = [] articles = Ticket::Article.where( :ticket_id => params[:id] ) # get related users - articles_used = [] + article_ids = [] articles.each {|article| # ignore internal article if customer is requesting next if article.internal == true && is_role('Customer') - article_tmp = article.attributes # load article ids - ticket[:article_ids].push article_tmp['id'] + article_ids.push article.id - # add attachment list to article - article_tmp['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => article.id ) - - # remember article - articles_used.push article_tmp - - # load users - if !users[article.created_by_id] - users[article.created_by_id] = User.user_data_full( article.created_by_id ) - end + # load assets + assets = article.assets(assets) } # return result render :json => { - :ticket => ticket, - :articles => articles_used, - :signature => signature, - :users => users, - :edit_form => attributes_to_change, + :ticket_id => ticket.id, + :ticket_article_ids => article_ids, + :signature => signature, + :assets => assets, + :edit_form => attributes_to_change, } end @@ -393,65 +348,47 @@ class TicketsController < ApplicationController # :article_id => params[:article_id] ) - users = {} + assets = {} + assets[:users] = {} attributes_to_change[:owner_id].each { |user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } attributes_to_change[:group_id__owner_id].each {|group_id, user_ids| user_ids.each {|user_id| - if !users[user_id] - users[user_id] = User.user_data_full( user_id ) + if !assets[:users][user_id] + assets[:users][user_id] = User.user_data_full( user_id ) end } } # split data - ticket = nil - articles = nil + split = {} if params[:ticket_id] && params[:article_id] ticket = Ticket.find( params[:ticket_id] ) - - # get related users - if !users[ticket.owner_id] - users[ticket.owner_id] = User.user_data_full( ticket.owner_id ) - end - if !users[ticket.customer_id] - users[ticket.customer_id] = User.user_data_full( ticket.customer_id ) - end - if !users[ticket.created_by_id] - users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id ) - end + split[:ticket_id] = ticket.id + assets = ticket.assets(assets) owner_ids = [] ticket.agent_of_group.each { |user| owner_ids.push user.id - if !users[user.id] - users[user.id] = User.user_data_full( user.id ) + if !assets[:users][user.id] + assets[:users][user.id] = User.user_data_full( user.id ) end } # get related articles - ticket[:article_ids] = [ params[:article_id] ] - article = Ticket::Article.find( params[:article_id] ) - - # add attachment list to article - article['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => article.id ) - - # load users - if !users[article.created_by_id] - users[article.created_by_id] = User.user_data_full( article.created_by_id ) - end + split[:article_id] = article.id + assets = article.assets(assets) end # return result render :json => { - :ticket => ticket, - :articles => [ article ], - :users => users, + :split => split, + :assets => assets, :edit_form => attributes_to_change, } end @@ -465,19 +402,17 @@ class TicketsController < ApplicationController :query => params[:term], :current_user => current_user, ) - users_data = {} + assets = {} ticket_result = [] tickets.each do |ticket| ticket_result.push ticket.id - users_data[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - users_data[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - users_data[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) + assets = ticket.assets(assets) end # return result render :json => { :tickets => ticket_result, - :users => users_data, + :assets => assets, } end diff --git a/app/models/history.rb b/app/models/history.rb index 358c4a0e8..0ff89fe6d 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -1,6 +1,8 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ class History < ApplicationModel + include History::Assets + self.table_name = 'histories' belongs_to :history_type, :class_name => 'History::Type' belongs_to :history_object, :class_name => 'History::Object' @@ -157,51 +159,27 @@ return all histoy entries of an object activity_stream = History.activity_stream( user, limit ) # get related users - users = {} - tickets = [] - articles = [] + assets = {} activity_stream.each {|item| # load article ids if item['history_object'] == 'Ticket' - ticket = Ticket.find( item['o_id'] ).attributes - tickets.push ticket - - # load users - if !users[ ticket['owner_id'] ] - users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - end - if !users[ ticket['customer_id'] ] - users[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - end + ticket = Ticket.find( item['o_id'] ) + assets = ticket.assets(assets) end if item['history_object'] == 'Ticket::Article' - article = Ticket::Article.find( item['o_id'] ).attributes - if !article['subject'] || article['subject'] == '' - article['subject'] = Ticket.find( article['ticket_id'] ).title - end - articles.push article - - # load users - if !users[ article['created_by_id'] ] - users[ article['created_by_id'] ] = User.user_data_full( article['created_by_id'] ) - end + article = Ticket::Article.find( item['o_id'] ) + assets = article.assets(assets) end if item['history_object'] == 'User' - users[ item['o_id'] ] = User.user_data_full( item['o_id'] ) - end - - # load users - if !users[ item['created_by_id'] ] - users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] ) + user = User.find( item['o_id'] ) + assets = user.assets(assets) end } return { :activity_stream => activity_stream, - :tickets => tickets, - :articles => articles, - :users => users, + :assets => assets, } end diff --git a/app/models/history/assets.rb b/app/models/history/assets.rb new file mode 100644 index 000000000..b81d94ef4 --- /dev/null +++ b/app/models/history/assets.rb @@ -0,0 +1,46 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module History::Assets + +=begin + +get all assets / related models for this history entry + + history = History.find(123) + result = history.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + } + +=end + + def assets (data) + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self['created_by_id'] ] + data[:users][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) + end + + # fetch meta relations + if !data[:history_object] + data[:history_object] = History::Object.all() + end + if !data[:history_type] + data[:history_type] = History::Type.all() + end + if !data[:history_attribute] + data[:history_attribute] = History::Attribute.all() + end + + data + end + +end \ No newline at end of file diff --git a/app/models/organization.rb b/app/models/organization.rb index 615e2ef4c..4fba65cc5 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,37 +1,10 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ class Organization < ApplicationModel + include Organization::Assets + extend Organization::Search + has_and_belongs_to_many :users validates :name, :presence => true - def self.search(params) - - # get params - query = params[:query] - limit = params[:limit] || 10 - current_user = params[:current_user] - - # enable search only for agents and admins - return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') - - # do query - organizations = Organization.find( - :all, - :limit => limit, - :conditions => ['name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"], - :order => 'name' - ) - - # if only a few organizations are found, search for names of users - if organizations.length <= 3 - organizations = Organization.select('DISTINCT(organizations.id)').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').find( - :all, - :limit => limit, - :conditions => ['users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"], - :order => 'organizations.name' - ) - end - return organizations - end - -end +end \ No newline at end of file diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb new file mode 100644 index 000000000..c3818915c --- /dev/null +++ b/app/models/organization/assets.rb @@ -0,0 +1,43 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Organization::Assets + +=begin + +get all assets / related models for this organization + + organization = Organization.find(123) + result = organization.assets( assets_if_exists ) + +returns + + result = { + :organizations => { + 123 => organization_model_123, + 1234 => organization_model_1234, + } + } + +=end + + def assets (data) + + if !data[:organizations] + data[:organizations] = {} + end + if !data[:users] + data[:users] = {} + end + if !data[:organizations][ self.id ] + data[:organizations][ self.id ] = self.attributes + data[:organizations][ self.id ][:user_ids] = [] + users = User.where( :organization_id => self.id ).limit(10) + users.each {|user| + data[:users][ user.id ] = User.user_data_full( user.id ) + data[:organizations][ self.id ][:user_ids].push user.id + } + end + data + end + +end \ No newline at end of file diff --git a/app/models/organization/search.rb b/app/models/organization/search.rb new file mode 100644 index 000000000..9d048bb0d --- /dev/null +++ b/app/models/organization/search.rb @@ -0,0 +1,62 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Organization::Search + +=begin + +search organizations + + result = Organization.search( + :current_user => User.find(123), + :query => 'search something', + :limit => 15, + ) + +returns + + result = [organization_model1, organization_model2] + +=end + + def search(params) + + # get params + query = params[:query] + limit = params[:limit] || 10 + current_user = params[:current_user] + + # enable search only for agents and admins + return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') + + # do query + organizations = Organization.find( + :all, + :limit => limit, + :conditions => ['name LIKE ? OR note LIKE ?', "%#{query}%", "%#{query}%"], + :order => 'name' + ) + + # if only a few organizations are found, search for names of users + if organizations.length <= 3 + organizations_by_user = Organization.select('DISTINCT(organizations.id)').joins('LEFT OUTER JOIN users ON users.organization_id = organizations.id').find( + :all, + :limit => limit, + :conditions => ['users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"], + :order => 'organizations.name' + ) + organizations_by_user.each {|organization_by_user| + puts 'OOO ' + organization_by_user.inspect + organization_exists = false + organizations.each {|organization| + if organization.id == organization_by_user.id + organization_exists = true + end + } + if !organization_exists + organizations.push organization + end + } + end + organizations + end +end \ No newline at end of file diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 614f2ee4f..7ac9ed16e 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -44,14 +44,14 @@ class RecentView < ApplicationModel recent_viewed = self.list( user, limit ) # get related users - users = {} - tickets = [] + assets = {} + ticket_ids = [] recent_viewed.each {|item| # load article ids # if item.recent_view_object == 'Ticket' - ticket = Ticket.find( item['o_id'] ).attributes - tickets.push ticket + ticket = Ticket.find( item['o_id'] ) + ticket_ids.push ticket.id # end # if item.recent_view_object 'Ticket::Article' # tickets.push Ticket::Article.find(item.o_id) @@ -60,21 +60,12 @@ class RecentView < ApplicationModel # tickets.push User.find(item.o_id) # end - # load users - if !users[ ticket['owner_id'] ] - users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - end - if !users[ ticket['created_by_id'] ] - users[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) - end - if !users[ item['created_by_id'] ] - users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] ) - end + assets = ticket.assets(assets) } return { :recent_viewed => recent_viewed, - :tickets => tickets, - :users => users, + :ticket_ids => ticket_ids, + :assets => assets, } end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 84c01b645..3669c13ac 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -25,6 +25,7 @@ class Ticket < ApplicationModel include Ticket::Escalation include Ticket::Subject include Ticket::Permission + include Ticket::Assets extend Ticket::Search attr_accessor :callback_loop diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index dd4c97855..c1bf19b4a 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -1,6 +1,8 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ class Ticket::Article < ApplicationModel + include Ticket::Article::Assets + after_create :attachment_check belongs_to :ticket belongs_to :ticket_article_type, :class_name => 'Ticket::Article::Type' diff --git a/app/models/ticket/article/assets.rb b/app/models/ticket/article/assets.rb new file mode 100644 index 000000000..6b8d0e117 --- /dev/null +++ b/app/models/ticket/article/assets.rb @@ -0,0 +1,48 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Ticket::Article::Assets + +=begin + +get all assets / related models for this article + + article = Ticket::Article.find(123) + result = article.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + :article => [ article_model1 ], + } + +=end + + def assets (data) + + if !data[:ticket_article] + data[:ticket_article] = {} + end + if !data[:ticket_article][ self.id ] + data[:ticket_article][ self.id ] = self.attributes + + # add attachment list to article + data[:ticket_article][ self.id ]['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => self.id ) + end + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self['created_by_id'] ] + data[:users][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) + end + if !data[:users][ self['updated_by_id'] ] + data[:users][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] ) + end + data + end + +end \ No newline at end of file diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb new file mode 100644 index 000000000..7b96346ec --- /dev/null +++ b/app/models/ticket/assets.rb @@ -0,0 +1,51 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module Ticket::Assets + +=begin + +get all assets / related models for this ticket + + ticket = Ticket.find(123) + result = ticket.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + :tickets => [ ticket_model1 ] + } + +=end + + def assets (data) + + if !data[:tickets] + data[:tickets] = {} + end + if !data[:tickets][ self.id ] + data[:tickets][ self.id ] = self.attributes + end + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self['owner_id'] ] + data[:users][ self['owner_id'] ] = User.user_data_full( self['owner_id'] ) + end + if !data[:users][ self['customer_id'] ] + data[:users][ self['customer_id'] ] = User.user_data_full( self['customer_id'] ) + end + if !data[:users][ self['created_by_id'] ] + data[:users][ self['created_by_id'] ] = User.user_data_full( self['created_by_id'] ) + end + if !data[:users][ self['updated_by_id'] ] + data[:users][ self['updated_by_id'] ] = User.user_data_full( self['updated_by_id'] ) + end + data + end + +end \ No newline at end of file diff --git a/app/models/ticket/overview.rb b/app/models/ticket/overview.rb index 6a900a464..d707a38da 100644 --- a/app/models/ticket/overview.rb +++ b/app/models/ticket/overview.rb @@ -164,7 +164,7 @@ returns count() return { - :ticket_list => ticket_ids, + :ticket_ids => ticket_ids, :tickets_count => tickets_count, :overview => overview_selected_raw, } diff --git a/app/models/user.rb b/app/models/user.rb index 4f4fcf8a8..5fa2bfb92 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,9 @@ require 'digest/sha2' require 'organization' class User < ApplicationModel + include User::Assets + extend User::Search + before_create :check_name, :check_email, :check_login, :check_image, :check_password before_update :check_password, :check_image, :check_email, :check_login_update after_create :notify_clients_after_create @@ -283,42 +286,6 @@ returns return user end -=begin - -search user - - result = User.search( - :query => 'some search term' - :limit => 15, - :current_user => user_model, - ) - -returns - - result = [user_model1, user_model2, ...] - -=end - - def self.search(params) - - # get params - query = params[:query] - limit = params[:limit] || 10 - current_user = params[:current_user] - - # enable search only for agents and admins - return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') - - # do query - users = User.find( - :all, - :limit => limit, - :conditions => ['(firstname LIKE ? or lastname LIKE ? or email LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%"], - :order => 'firstname' - ) - return users - end - def self.find_fulldata(user_id) cache = self.cache_get(user_id, true) diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb new file mode 100644 index 000000000..202303355 --- /dev/null +++ b/app/models/user/assets.rb @@ -0,0 +1,34 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module User::Assets + +=begin + +get all assets / related models for this user + + user = User.find(123) + result = user.assets( assets_if_exists ) + +returns + + result = { + :users => { + 123 => user_model_123, + 1234 => user_model_1234, + } + } + +=end + + def assets (data) + + if !data[:users] + data[:users] = {} + end + if !data[:users][ self.id ] + data[:users][ self.id ] = User.user_data_full( self.id ) + end + data + end + +end \ No newline at end of file diff --git a/app/models/user/search.rb b/app/models/user/search.rb new file mode 100644 index 000000000..705b0cee5 --- /dev/null +++ b/app/models/user/search.rb @@ -0,0 +1,57 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + +module User::Search + +=begin + +search tickets + + result = Ticket.search( + :current_user => User.find(123), + :query => 'search something', + :limit => 15, + ) + +returns + + result = [ticket_model1, ticket_model2] + +=end + +=begin + +search user + + result = User.search( + :query => 'some search term' + :limit => 15, + :current_user => user_model, + ) + +returns + + result = [user_model1, user_model2, ...] + +=end + + def search(params) + + # get params + query = params[:query] + limit = params[:limit] || 10 + current_user = params[:current_user] + + # enable search only for agents and admins + return [] if !current_user.is_role('Agent') && !current_user.is_role('Admin') + + # do query + users = User.find( + :all, + :limit => limit, + :conditions => ['(firstname LIKE ? or lastname LIKE ? or email LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%"], + :order => 'firstname' + ) + return users + end + +end \ No newline at end of file diff --git a/db/migrate/20130817000001_update_auth.rb b/db/migrate/20130817000001_update_auth.rb new file mode 100644 index 000000000..449334f11 --- /dev/null +++ b/db/migrate/20130817000001_update_auth.rb @@ -0,0 +1,52 @@ +class UpdateAuth < ActiveRecord::Migration + def up + Setting.create_or_update( + :title => 'Authentication via OTRS', + :name => 'auth_otrs', + :area => 'Security::Authentication', + :description => 'Enables user authentication via OTRS.', + :state => { + :adapter => 'Auth::Otrs', + :required_group_ro => 'stats', + :group_rw_role_map => { + 'admin' => 'Admin', + 'stats' => 'Report', + }, + :group_ro_role_map => { + 'stats' => 'Report', + }, + :always_role => { + 'Agent' => true, + }, + }, + :frontend => false + ) + Setting.create_or_update( + :title => 'Authentication via LDAP', + :name => 'auth_ldap', + :area => 'Security::Authentication', + :description => 'Enables user authentication via LDAP.', + :state => { + :adapter => 'Auth::Ldap', + :host => 'localhost', + :port => 389, + :bind_dn => 'cn=Manager,dc=example,dc=org', + :bind_pw => 'example', + :uid => 'mail', + :base => 'dc=example,dc=org', + :always_filter => '', + :always_roles => ['Admin', 'Agent'], + :always_groups => ['Users'], + :sync_params => { + :firstname => 'sn', + :lastname => 'givenName', + :email => 'mail', + :login => 'mail', + }, + }, + :frontend => false + ) + end + def down + end +end \ No newline at end of file