diff --git a/app/controllers/activity_controller.rb b/app/controllers/activity_controller.rb index 1e80f7d6d..fb74badc1 100644 --- a/app/controllers/activity_controller.rb +++ b/app/controllers/activity_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class ActivityController < ApplicationController before_filter :authentication_check @@ -9,4 +11,4 @@ class ActivityController < ApplicationController render :json => activity_stream end -end \ No newline at end of file +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7ba669f47..254e2fa9a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,16 +1,18 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class ApplicationController < ActionController::Base -# http_basic_authenticate_with :name => "test", :password => "ttt" + # http_basic_authenticate_with :name => "test", :password => "ttt" helper_method :current_user, - :authentication_check, - :config_frontend, - :user_data_full, - :is_role, - :model_create_render, - :model_update_render, - :model_restory_render, - :mode_show_rendeder, - :model_index_render + :authentication_check, + :config_frontend, + :user_data_full, + :is_role, + :model_create_render, + :model_update_render, + :model_restory_render, + :mode_show_rendeder, + :model_index_render before_filter :set_user before_filter :cors_preflight_check @@ -19,7 +21,7 @@ class ApplicationController < ActionController::Base after_filter :trigger_events # For all responses in this controller, return the CORS access control headers. - def set_access_control_headers + def set_access_control_headers headers['Access-Control-Allow-Origin'] = '*' headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS' headers['Access-Control-Max-Age'] = '1728000' @@ -45,7 +47,7 @@ class ApplicationController < ActionController::Base private - # execute events + # execute events def trigger_events Observer::Ticket::Notification.transaction end @@ -73,7 +75,7 @@ class ApplicationController < ActionController::Base def authentication_check_only puts 'authentication_check' -# puts params.inspect + # puts params.inspect # check http basic auth authenticate_with_http_basic do |username, password| @@ -107,7 +109,7 @@ class ApplicationController < ActionController::Base end # check logon session - if params['logon_session'] + if params['logon_session'] logon_session = ActiveRecord::SessionStore::Session.where( :session_id => params['logon_session'] ).first if logon_session userdata = User.find( logon_session.data[:user_id] ) @@ -207,15 +209,15 @@ class ApplicationController < ActionController::Base config['timezones'] = {} TZInfo::Timezone.all.each { |t| - # ignore the following time zones - next if t.name =~ /^GMT/ - next if t.name =~ /^Etc/ - next if t.name =~ /^MET/ - next if t.name =~ /^MST/ - next if t.name =~ /^ROC/ - next if t.name =~ /^ROK/ - diff = t.current_period.utc_total_offset / 60 /60 - config['timezones'][ t.name ] = diff + # ignore the following time zones + next if t.name =~ /^GMT/ + next if t.name =~ /^Etc/ + next if t.name =~ /^MET/ + next if t.name =~ /^MST/ + next if t.name =~ /^ROC/ + next if t.name =~ /^ROK/ + diff = t.current_period.utc_total_offset / 60 /60 + config['timezones'][ t.name ] = diff } return config @@ -251,7 +253,7 @@ class ApplicationController < ActionController::Base # save object generic_object.update_attributes!( object.param_cleanup(params) ) model_update_render_item(generic_object) - rescue Exception => e + rescue Exception => e logger.error e.message render :json => { :error => e.message }, :status => :unprocessable_entity end diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index d9c9aec7e..486337c65 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class ChannelsController < ApplicationController before_filter :authentication_check @@ -111,7 +113,7 @@ Response: Test: curl http://localhost/api/channels/#{id}.json -v -u #{login}:#{password} - + =end def show diff --git a/app/controllers/email_addresses_controller.rb b/app/controllers/email_addresses_controller.rb index 4acc40b70..621502678 100644 --- a/app/controllers/email_addresses_controller.rb +++ b/app/controllers/email_addresses_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class EmailAddressesController < ApplicationController before_filter :authentication_check @@ -61,7 +63,7 @@ Response: Test: curl http://localhost/api/email_addresses/#{id}.json -v -u #{login}:#{password} - + =end def show @@ -137,7 +139,7 @@ Resource: Response: Test: - + =end def destroy diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index be3579ed1..e0ece73b3 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class GettingStartedController < ApplicationController =begin @@ -22,7 +24,7 @@ Response: Test: curl http://localhost/api/getting_started.json -v -u #{login}:#{password} - + =end def index @@ -48,4 +50,4 @@ curl http://localhost/api/getting_started.json -v -u #{login}:#{password} :groups => groups, } end -end \ No newline at end of file +end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index fed1656fb..5f51141c8 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class GroupsController < ApplicationController before_filter :authentication_check @@ -19,7 +21,7 @@ Example: "created_at":"2012-09-14T17:51:53Z", "created_by_id":2, } - + =end =begin @@ -64,7 +66,7 @@ Response: Test: curl http://localhost/api/groups/#{id}.json -v -u #{login}:#{password} - + =end def show @@ -142,7 +144,7 @@ Resource: Response: Test: - + =end def destroy diff --git a/app/controllers/init_controller.rb b/app/controllers/init_controller.rb index 836b73853..bce59e7a5 100644 --- a/app/controllers/init_controller.rb +++ b/app/controllers/init_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class InitController < ApplicationController # GET /init diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index c82179d5d..e9e53900d 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class LinksController < ApplicationController before_filter :authentication_check diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index b5d6061a1..9b63d4c4a 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class LongPollingController < ApplicationController # GET /api/message_send @@ -58,7 +60,7 @@ class LongPollingController < ApplicationController log 'notice', "send auth login (user_id #{user_id})", client_id Session.create( client_id, user, { :type => 'ajax' } ) - # broadcast + # broadcast elsif params['data']['action'] == 'broadcast' # list all current clients @@ -74,7 +76,7 @@ class LongPollingController < ApplicationController Session.send( local_client_id, params['data'] ) end } - # broadcast every client + # broadcast every client else log 'notice', "send broadcast from (#{client_id.to_s})", local_client_id Session.send( local_client_id, params['data'] ) @@ -115,7 +117,7 @@ class LongPollingController < ApplicationController count = count - 1 queue = Session.queue( client_id ) if queue && queue[0] -# puts "send " + queue.inspect + client_id.to_s + # puts "send " + queue.inspect + client_id.to_s render :json => queue return end @@ -134,25 +136,25 @@ class LongPollingController < ApplicationController end private - def client_id_check - return params[:client_id] if params[:client_id] - return - end - def client_id_gen - rand(99999999) - end - def client_id_verify - return if !params[:client_id] - sessions = Session.sessions - return if !sessions.include?( params[:client_id].to_s ) - return true - end + def client_id_check + return params[:client_id] if params[:client_id] + return + end + def client_id_gen + rand(99999999) + end + def client_id_verify + return if !params[:client_id] + sessions = Session.sessions + return if !sessions.include?( params[:client_id].to_s ) + return true + end - def log( level, data, client_id = '-' ) - if false - return if level == 'debug' - end - puts "#{Time.now}:client(#{ client_id }) #{ data }" -# puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }" + def log( level, data, client_id = '-' ) + if false + return if level == 'debug' end + puts "#{Time.now}:client(#{ client_id }) #{ data }" + # puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }" + end end diff --git a/app/controllers/network_controller.rb b/app/controllers/network_controller.rb index 50f75f5a5..775f5e041 100644 --- a/app/controllers/network_controller.rb +++ b/app/controllers/network_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class NetworksController < ApplicationController before_filter :authentication_check diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 8acfe9235..3825fc5be 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class OrganizationsController < ApplicationController before_filter :authentication_check @@ -17,7 +19,7 @@ Example: "created_at":"2012-09-14T17:51:53Z", "created_by_id":2, } - + =end =begin @@ -62,7 +64,7 @@ Response: Test: curl http://localhost/api/organizations/#{id}.json -v -u #{login}:#{password} - + =end def show @@ -137,10 +139,10 @@ Resource: Response: Test: - + =end -def destroy + def destroy return if is_not_role('Agent') model_destory_render(Organization, params) end diff --git a/app/controllers/overviews_controller.rb b/app/controllers/overviews_controller.rb index ae71c321a..ea1cb6f42 100644 --- a/app/controllers/overviews_controller.rb +++ b/app/controllers/overviews_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class OverviewsController < ApplicationController before_filter :authentication_check @@ -22,7 +24,7 @@ Example: "updated_by_id":2. "created_by_id":2, } - + =end =begin @@ -68,7 +70,7 @@ Response: Test: curl http://localhost/api/overviews/#{id}.json -v -u #{login}:#{password} - + =end def show diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 890ea4357..535cd9bfa 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class PackagesController < ApplicationController before_filter :authentication_check @@ -32,4 +34,4 @@ class PackagesController < ApplicationController } end -end \ No newline at end of file +end diff --git a/app/controllers/postmaster_filters_controller.rb b/app/controllers/postmaster_filters_controller.rb index 621085937..25c2e2fa8 100644 --- a/app/controllers/postmaster_filters_controller.rb +++ b/app/controllers/postmaster_filters_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class PostmasterFiltersController < ApplicationController before_filter :authentication_check @@ -70,7 +72,7 @@ Response: Test: curl http://localhost/api/postmaster_filters/#{id}.json -v -u #{login}:#{password} - + =end def show @@ -173,7 +175,7 @@ Resource: Response: Test: - + =end def destroy diff --git a/app/controllers/recent_viewed_controller.rb b/app/controllers/recent_viewed_controller.rb index d1d7c3dfc..97c443ac1 100644 --- a/app/controllers/recent_viewed_controller.rb +++ b/app/controllers/recent_viewed_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class RecentViewedController < ApplicationController before_filter :authentication_check @@ -23,4 +25,4 @@ curl http://localhost/api/recent_viewed.json -v -u #{login}:#{password} -H "Cont render :json => recent_viewed end -end \ No newline at end of file +end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 232f0d682..f19ee2a1c 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class RolesController < ApplicationController before_filter :authentication_check @@ -16,7 +18,7 @@ Example: "updated_by_id":2, "created_by_id":2, } - + =end =begin @@ -61,7 +63,7 @@ Response: Test: curl http://localhost/api/roles/#{id}.json -v -u #{login}:#{password} - + =end def show @@ -133,7 +135,7 @@ Resource: Response: Test: - + =end def destroy diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb index e4e8de697..c64f06138 100644 --- a/app/controllers/rss_controller.rb +++ b/app/controllers/rss_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class RssController < ApplicationController before_filter :authentication_check @@ -25,4 +27,4 @@ curl http://localhost/api/rss_fetch.json -v -u #{login}:#{password} -H "Content- render :json => { :items => items } end -end \ No newline at end of file +end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 1e9b7b1f3..92daaddd5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,9 +1,11 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class SearchController < ApplicationController before_filter :authentication_check # GET /api/search def search - + # build result list tickets = Ticket.search( :limit => params[:limit], diff --git a/app/controllers/sessions/collection_base.rb b/app/controllers/sessions/collection_base.rb index 235833414..a9d8f9408 100644 --- a/app/controllers/sessions/collection_base.rb +++ b/app/controllers/sessions/collection_base.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + module ExtraCollection def session( collections, user ) diff --git a/app/controllers/sessions/collection_network.rb b/app/controllers/sessions/collection_network.rb index 31d92c552..ff2a7d109 100644 --- a/app/controllers/sessions/collection_network.rb +++ b/app/controllers/sessions/collection_network.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + module ExtraCollection def session( collections, user ) @@ -16,4 +18,4 @@ module ExtraCollection end module_function :session, :push -end \ No newline at end of file +end diff --git a/app/controllers/sessions/collection_ticket.rb b/app/controllers/sessions/collection_ticket.rb index dcb8be10c..40461cb20 100644 --- a/app/controllers/sessions/collection_ticket.rb +++ b/app/controllers/sessions/collection_ticket.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + module ExtraCollection def session( collections, user ) @@ -9,10 +11,10 @@ module ExtraCollection collections['TicketArticleSender'] = Ticket::Article::Sender.all if !user.is_role('Customer') - + # all signatures collections['Signature'] = Signature.all - + # all email addresses collections['EmailAddress'] = EmailAddress.all end @@ -30,17 +32,17 @@ module ExtraCollection # all signatures collections['Signature'] = Signature.all - + # all email addresses collections['EmailAddress'] = EmailAddress.all - + # all templates collections['Template'] = Template.all - + # all text modules collections['TextModule'] = TextModule.all end end module_function :session, :push -end \ No newline at end of file +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 523edc148..8d55bdfd9 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,7 +1,9 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class SessionsController < ApplicationController -# def create -# render :text => request.env['rack.auth'].inspect -# end + # def create + # render :text => request.env['rack.auth'].inspect + # end # "Create" a login, aka "log the user in" def create @@ -143,4 +145,4 @@ class SessionsController < ApplicationController redirect_to '/#' end -end \ No newline at end of file +end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 6ad1e2f29..4f8f7d3e3 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class SettingsController < ApplicationController before_filter :authentication_check diff --git a/app/controllers/signatures_controller.rb b/app/controllers/signatures_controller.rb index 72fad0b15..b79482e26 100644 --- a/app/controllers/signatures_controller.rb +++ b/app/controllers/signatures_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class SignaturesController < ApplicationController before_filter :authentication_check @@ -17,7 +19,7 @@ Example: "updated_by_id":2, "created_by_id":2, } - + =end =begin @@ -62,7 +64,7 @@ Response: Test: curl http://localhost/api/signatures/#{id}.json -v -u #{login}:#{password} - + =end def show @@ -134,7 +136,7 @@ Resource: Response: Test: - + =end def destroy diff --git a/app/controllers/slas_controller.rb b/app/controllers/slas_controller.rb index c1fea7447..c6d961938 100644 --- a/app/controllers/slas_controller.rb +++ b/app/controllers/slas_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class SlasController < ApplicationController before_filter :authentication_check @@ -17,7 +19,7 @@ Example: "updated_by_id":2. "created_by_id":2, } - + =end =begin @@ -63,7 +65,7 @@ Response: Test: curl http://localhost/api/slas/#{id}.json -v -u #{login}:#{password} - + =end def show diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index efe2407e9..487b62777 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TagsController < ApplicationController before_filter :authentication_check diff --git a/app/controllers/taskbar_controller.rb b/app/controllers/taskbar_controller.rb index f16b1c1ed..8b0f1cee7 100644 --- a/app/controllers/taskbar_controller.rb +++ b/app/controllers/taskbar_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TaskbarController < ApplicationController before_filter :authentication_check @@ -38,11 +40,11 @@ class TaskbarController < ApplicationController end private - def access(taskbar) - if taskbar.user_id != current_user.id - render :json => { :error => 'Not allowed to access this task.' }, :status => :unprocessable_entity - return false - end - return true + def access(taskbar) + if taskbar.user_id != current_user.id + render :json => { :error => 'Not allowed to access this task.' }, :status => :unprocessable_entity + return false end + return true + end end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 4e0317484..01e169a02 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TemplatesController < ApplicationController before_filter :authentication_check @@ -17,7 +19,7 @@ Example: "updated_by_id":2. "created_by_id":2, } - + =end =begin @@ -62,7 +64,7 @@ Response: Test: curl http://localhost/api/templates/#{id}.json -v -u #{login}:#{password} - + =end def show diff --git a/app/controllers/tests_controller.rb b/app/controllers/tests_controller.rb index 2a1559c11..8af1ab501 100644 --- a/app/controllers/tests_controller.rb +++ b/app/controllers/tests_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TestsController < ApplicationController # GET /test diff --git a/app/controllers/text_modules_controller.rb b/app/controllers/text_modules_controller.rb index 0ceba6709..3c717e66f 100644 --- a/app/controllers/text_modules_controller.rb +++ b/app/controllers/text_modules_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TextModulesController < ApplicationController before_filter :authentication_check @@ -19,7 +21,7 @@ Example: "updated_by_id":2. "created_by_id":2, } - + =end =begin @@ -64,7 +66,7 @@ Response: Test: curl http://localhost/api/text_modules/#{id}.json -v -u #{login}:#{password} - + =end def show diff --git a/app/controllers/ticket_articles_controller.rb b/app/controllers/ticket_articles_controller.rb index 8b8e96498..14b1938eb 100644 --- a/app/controllers/ticket_articles_controller.rb +++ b/app/controllers/ticket_articles_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TicketArticlesController < ApplicationController before_filter :authentication_check @@ -66,7 +68,7 @@ class TicketArticlesController < ApplicationController def attachment_new # store file -# content_type = request.content_type + # content_type = request.content_type content_type = request[:content_type] puts 'content_type: ' + content_type.inspect if !content_type || content_type == 'application/octet-stream' diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index da4660c93..28628364b 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -1,9 +1,10 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TicketOverviewsController < ApplicationController before_filter :authentication_check # GET /api/tickets def show -#sleep 2 # get navbar overview data if !params[:view] @@ -20,7 +21,7 @@ class TicketOverviewsController < ApplicationController :view => params[:view], :current_user => current_user, :array => true, - ) + ) tickets = [] overview[:tickets].each {|ticket_id| data = { :id => ticket_id } @@ -37,7 +38,7 @@ class TicketOverviewsController < ApplicationController end overview = Ticket.overview( :view => params[:view], -# :view_mode => params[:view_mode], + # :view_mode => params[:view_mode], :current_user => User.find( current_user.id ), :array => true, ) @@ -74,14 +75,14 @@ class TicketOverviewsController < ApplicationController } groups_users = {} group_ids.each {|group_id| - groups_users[ group_id ] = [] - 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) - end - } + groups_users[ group_id ] = [] + 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) + end + } } # return result @@ -99,4 +100,4 @@ class TicketOverviewsController < ApplicationController } end -end \ No newline at end of file +end diff --git a/app/controllers/ticket_priorities_controller.rb b/app/controllers/ticket_priorities_controller.rb index 2abf84327..9e064cd53 100644 --- a/app/controllers/ticket_priorities_controller.rb +++ b/app/controllers/ticket_priorities_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TicketPrioritiesController < ApplicationController before_filter :authentication_check diff --git a/app/controllers/ticket_states_controller.rb b/app/controllers/ticket_states_controller.rb index e3d968811..9af36f0ef 100644 --- a/app/controllers/ticket_states_controller.rb +++ b/app/controllers/ticket_states_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TicketStatesController < ApplicationController before_filter :authentication_check diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 0843c62ea..3dd5d6aec 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TicketsController < ApplicationController before_filter :authentication_check @@ -133,7 +135,7 @@ class TicketsController < ApplicationController :open => tickets_open, :closed => tickets_closed } -# :users => users, + # :users => users, } end @@ -187,9 +189,9 @@ class TicketsController < ApplicationController ) ticket = Ticket.find( params[:ticket_id] ) ticket_list = Ticket.where( :customer_id => ticket.customer_id, :ticket_state_id => ticket_states ) - .where( 'id != ?', [ ticket.id ] ) - .order('created_at DESC') - .limit(6) + .where( 'id != ?', [ ticket.id ] ) + .order('created_at DESC') + .limit(6) # get related users users = {} @@ -257,14 +259,14 @@ class TicketsController < ApplicationController } return end - + # merge ticket success = ticket_slave.merge_to( { :ticket_id => ticket_master.id, :created_by_id => current_user.id, - } - ) + } + ) # return result render :json => { @@ -346,7 +348,7 @@ class TicketsController < ApplicationController # load article ids ticket[:article_ids].push article_tmp['id'] - + # add attachment list to article article_tmp['attachments'] = Store.list( :object => 'Ticket::Article', :o_id => article.id ) @@ -375,8 +377,8 @@ class TicketsController < ApplicationController # get attributes to update attributes_to_change = Ticket.attributes_to_change( :user => current_user, -# :ticket_id => params[:ticket_id], -# :article_id => params[:article_id] + # :ticket_id => params[:ticket_id], + # :article_id => params[:article_id] ) users = {} @@ -444,7 +446,7 @@ class TicketsController < ApplicationController # GET /api/tickets/search def search - + # build result list tickets = Ticket.search( :limit => params[:limit], diff --git a/app/controllers/translations_controller.rb b/app/controllers/translations_controller.rb index 32a0d8022..9f72640a5 100644 --- a/app/controllers/translations_controller.rb +++ b/app/controllers/translations_controller.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TranslationsController < ApplicationController before_filter :authentication_check, :except => [:load] diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c1c7d3216..37a24d660 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,8 +1,10 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class UsersController < ApplicationController before_filter :authentication_check, :except => [:create, :password_reset_send, :password_reset_verify] =begin - + Format: JSON @@ -36,7 +38,7 @@ Example: =begin -Resource: +Resource: GET /api/users.json Response: @@ -55,7 +57,7 @@ Response: Test: curl http://localhost/api/users.json -v -u #{login}:#{password} - + =end def index @@ -69,7 +71,7 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} =begin -Resource: +Resource: GET /api/users/1.json Response: @@ -143,14 +145,14 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type group_ids.push group.id } - # everybody else will go as customer per default + # everybody else will go as customer per default else role_ids.push Role.where( :name => 'Customer' ).first.id end user.role_ids = role_ids user.group_ids = group_ids - # else do assignment as defined + # else do assignment as defined else if params[:role_ids] user.role_ids = params[:role_ids] @@ -195,19 +197,19 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type data[:subject] = 'Invitation to #{config.product_name} at #{config.fqdn}' data[:body] = 'Hi #{user.firstname}, -I (#{current_user.firstname} #{current_user.lastname}) invite you to #{config.product_name} - a customer support / ticket system platform. + I (#{current_user.firstname} #{current_user.lastname}) invite you to #{config.product_name} - a customer support / ticket system platform. -Click on the following link and set your password: + Click on the following link and set your password: -#{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name} + #{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name} -Enjoy, + Enjoy, - #{current_user.firstname} #{current_user.lastname} + #{current_user.firstname} #{current_user.lastname} + + Your #{config.product_name} Team + ' - Your #{config.product_name} Team -' - # prepare subject & body [:subject, :body].each { |key| data[key.to_sym] = NotificationFactory.build( @@ -220,7 +222,7 @@ Enjoy, } ) } - + # send notification NotificationFactory.send( :recipient => user, @@ -271,7 +273,7 @@ curl http://localhost/api/users/2.json -v -u #{login}:#{password} -H "Content-Ty user = User.find( params[:id] ) begin - + user.update_attributes( User.param_cleanup(params) ) # only allow Admin's and Agent's @@ -424,18 +426,18 @@ curl http://localhost/api/users/password_change.json -v -u #{login}:#{password} # check old password if !params[:password_old] render :json => { :message => 'Old password needed!' }, :status => :unprocessable_entity - return + return end user = User.authenticate( current_user.login, params[:password_old] ) if !user render :json => { :message => 'Old password is wrong!' }, :status => :unprocessable_entity - return + return end # set new password if !params[:password_new] render :json => { :message => 'New password needed!' }, :status => :unprocessable_entity - return + return end user.update_attributes( :password => params[:password_new] ) render :json => { :message => 'ok', :user_login => user.login }, :status => :ok @@ -465,7 +467,7 @@ curl http://localhost/api/users/preferences.json -v -u #{login}:#{password} -H " def preferences if !current_user render :json => { :message => 'No current user!' }, :status => :unprocessable_entity - return + return end if params[:user] params[:user].each {|key, value| @@ -500,17 +502,17 @@ curl http://localhost/api/users/account.json -v -u #{login}:#{password} -H "Cont def account_remove if !current_user render :json => { :message => 'No current user!' }, :status => :unprocessable_entity - return + return end # provider + uid to remove if !params[:provider] render :json => { :message => 'provider needed!' }, :status => :unprocessable_entity - return + return end if !params[:uid] render :json => { :message => 'uid needed!' }, :status => :unprocessable_entity - return + return end # remove from database @@ -521,7 +523,7 @@ curl http://localhost/api/users/account.json -v -u #{login}:#{password} -H "Cont ) if !record.first render :json => { :message => 'No record found!' }, :status => :unprocessable_entity - return + return end record.destroy_all render :json => { :message => 'ok' }, :status => :ok diff --git a/app/models/application_model.rb b/app/models/application_model.rb index a9c8e314d..3308219f3 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'cache' require 'user_info' @@ -26,7 +28,7 @@ class ApplicationModel < ActiveRecord::Base data = {} self.new.attributes.each {|item| if params.has_key?(item[0]) -# puts 'use ' + item[0].to_s + '-' + params[item[0]].to_s + # puts 'use ' + item[0].to_s + '-' + params[item[0]].to_s data[item[0].to_sym] = params[item[0]] end } @@ -69,9 +71,9 @@ class ApplicationModel < ActiveRecord::Base end def cache_update(o) -# puts 'u ' + self.class.to_s + # puts 'u ' + self.class.to_s if self.respond_to?('cache_delete') then self.cache_delete end -# puts 'g ' + group.class.to_s + # puts 'g ' + group.class.to_s if o.respond_to?('cache_delete') then o.cache_delete end end def cache_delete_before @@ -120,11 +122,11 @@ class ApplicationModel < ActiveRecord::Base def self.lookup(data) if data[:id] -# puts "GET- + #{self.to_s}.#{data[:id].to_s}" + # puts "GET- + #{self.to_s}.#{data[:id].to_s}" cache = self.cache_get( data[:id] ) return cache if cache -# puts "Fillup- + #{self.to_s}.#{data[:id].to_s}" + # puts "Fillup- + #{self.to_s}.#{data[:id].to_s}" record = self.where( :id => data[:id] ).first self.cache_set( data[:id], record ) return record diff --git a/app/models/authorization.rb b/app/models/authorization.rb index 2885f222a..e1abebba3 100644 --- a/app/models/authorization.rb +++ b/app/models/authorization.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Authorization < ApplicationModel belongs_to :user after_create :delete_user_cache @@ -33,19 +35,19 @@ class Authorization < ApplicationModel end return auth end - + def self.create_from_hash(hash, user = nil) if user then user.update_attributes( -# :username => hash['username'], + # :username => hash['username'], :image => hash['info']['image'] ) # fillup empty attributes # TODO - + else - user = User.create_from_hash!(hash) + user = User.create_from_hash!(hash) end auth = Authorization.create( @@ -60,8 +62,8 @@ class Authorization < ApplicationModel end private - def delete_user_cache - self.user.cache_delete - end + def delete_user_cache + self.user.cache_delete + end -end \ No newline at end of file +end diff --git a/app/models/channel.rb b/app/models/channel.rb index 3bb64b25b..b7d23bde9 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Channel < ApplicationModel store :options @@ -14,4 +16,4 @@ class Channel < ApplicationModel end } end -end \ No newline at end of file +end diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 32afe8922..9c74a9b3f 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'mail' class Channel::EmailBuild @@ -28,7 +30,7 @@ class Channel::EmailBuild end end - # add body + # add body mail.text_part = Mail::Part.new do body attr[:body] end @@ -45,4 +47,4 @@ class Channel::EmailBuild end return mail end -end \ No newline at end of file +end diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index a7486cd98..f68ce0dba 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + # encoding: utf-8 require 'mail' @@ -72,7 +74,7 @@ class Channel::EmailParser data[:from_local] = Mail::Address.new( mail[:from].value ).local data[:from_domain] = Mail::Address.new( mail[:from].value ).domain data[:from_display_name] = Mail::Address.new( mail[:from].value ).display_name || - ( Mail::Address.new( mail[:from].value ).comments && Mail::Address.new( mail[:from].value ).comments[0] ) + ( Mail::Address.new( mail[:from].value ).comments && Mail::Address.new( mail[:from].value ).comments[0] ) # do extra decoding because we needed to use field.value data[:from_display_name] = Mail::Field.new( 'X-From', data[:from_display_name] ).to_s @@ -81,8 +83,8 @@ class Channel::EmailParser data[:message_id] = data['message-id'.to_sym] # body -# plain_part = mail.multipart? ? (mail.text_part ? mail.text_part.body.decoded : nil) : mail.body.decoded -# html_part = message.html_part ? message.html_part.body.decoded : nil + # plain_part = mail.multipart? ? (mail.text_part ? mail.text_part.body.decoded : nil) : mail.body.decoded + # html_part = message.html_part ? message.html_part.body.decoded : nil data[:attachments] = [] # multi part email @@ -93,7 +95,7 @@ class Channel::EmailParser data[:body] = mail.text_part.body.decoded data[:body] = Encode.conv( mail.text_part.charset, data[:body] ) - # html attachment/body may exists and will be converted to text + # html attachment/body may exists and will be converted to text else filename = '-no name-' if mail.html_part.body @@ -102,7 +104,7 @@ class Channel::EmailParser data[:body] = Encode.conv( mail.html_part.charset.to_s, data[:body] ) data[:body] = html2ascii( data[:body] ) - # any other attachments + # any other attachments else data[:body] = 'no visible content' end @@ -144,7 +146,7 @@ class Channel::EmailParser } end - # not multipart email + # not multipart email else # text part @@ -152,7 +154,7 @@ class Channel::EmailParser data[:body] = mail.body.decoded data[:body] = Encode.conv( mail.charset, data[:body] ) - # html part + # html part else filename = '-no name-' if mail.mime_type.to_s.downcase == 'text/html' @@ -161,7 +163,7 @@ class Channel::EmailParser data[:body] = Encode.conv( mail.charset, data[:body] ) data[:body] = html2ascii( data[:body] ) - # any other attachments + # any other attachments else data[:body] = 'no visible content' end @@ -375,10 +377,10 @@ class Channel::EmailParser internal = true end article_attributes = { - :ticket_id => ticket.id, + :ticket_id => ticket.id, :ticket_article_type_id => Ticket::Article::Type.where( :name => 'email' ).first.id, :ticket_article_sender_id => Ticket::Article::Sender.where( :name => 'Customer' ).first.id, - :body => mail[:body], + :body => mail[:body], :from => mail[:from], :to => mail[:to], :cc => mail[:cc], @@ -425,7 +427,7 @@ class Channel::EmailParser # run postmaster post filter filters = { -# '0010' => Channel::Filter::Trusted, + # '0010' => Channel::Filter::Trusted, } # filter( channel, mail ) @@ -525,14 +527,14 @@ module Mail text else # Join QP encoded-words that are adjacent to avoid decoding partial chars -# text.gsub!(/\?\=\=\?.+?\?[Qq]\?/m, '') if text =~ /\?==\?/ + # text.gsub!(/\?\=\=\?.+?\?[Qq]\?/m, '') if text =~ /\?==\?/ # Search for occurences of quoted strings or plain strings text.scan(/( # Group around entire regex to include it in matches - \=\?[^?]+\?([QB])\?[^?]+?\?\= # Quoted String with subgroup for encoding method - | # or - .+?(?=\=\?|$) # Plain String - )/xmi).map do |matches| + \=\?[^?]+\?([QB])\?[^?]+?\?\= # Quoted String with subgroup for encoding method + | # or + .+?(?=\=\?|$) # Plain String + )/xmi).map do |matches| string, method = *matches if method == 'b' || method == 'B' b_value_decode(string) @@ -546,4 +548,4 @@ module Mail end.join("") end end -end \ No newline at end of file +end diff --git a/app/models/channel/facebook.rb b/app/models/channel/facebook.rb index 6d16ac9d0..2dcbb9d03 100644 --- a/app/models/channel/facebook.rb +++ b/app/models/channel/facebook.rb @@ -1,14 +1,16 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + #require 'rubygems' #require 'twitter' class Channel::Facebook -# def fetch(:oauth_token, :oauth_token_secret) + # def fetch(:oauth_token, :oauth_token_secret) def fetch end def send - + logger.debug('face!!!!!!!!!!!!!!') graph_api = Koala::Facebook::API.new( 'AAACqTciZAPsQBAHO9DbM333y2DcL5kccHyIObZB7WhaZBVUXUIeBNChkshvShCgiN6uwZC3r3l4cDvAZAPTArNIkemEraojzN1veNPZBADQAZDZD' @@ -20,10 +22,10 @@ class Channel::Facebook :message => self.body } ) -# client.direct_message_create( -# 'medenhofer', -# self.body, -# options = {} -# ) + # client.direct_message_create( + # 'medenhofer', + # self.body, + # options = {} + # ) end -end \ No newline at end of file +end diff --git a/app/models/channel/filter/database.rb b/app/models/channel/filter/database.rb index 4b15be30a..3334900af 100644 --- a/app/models/channel/filter/database.rb +++ b/app/models/channel/filter/database.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + # process all database filter module Channel::Filter::Database @@ -38,4 +40,4 @@ module Channel::Filter::Database } end -end \ No newline at end of file +end diff --git a/app/models/channel/filter/trusted.rb b/app/models/channel/filter/trusted.rb index c0e5114cc..ced56b611 100644 --- a/app/models/channel/filter/trusted.rb +++ b/app/models/channel/filter/trusted.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + # delete all X-Zammad header if channel is not trusted module Channel::Filter::Trusted @@ -13,4 +15,4 @@ module Channel::Filter::Trusted end end -end \ No newline at end of file +end diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index 0387fe009..62c3f6cc0 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'net/imap' class Channel::IMAP < Channel::EmailParser @@ -34,9 +36,9 @@ class Channel::IMAP < Channel::EmailParser count += 1 puts " - message #{count.to_s}/#{count_all.to_s}" msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822'] -# puts msg.to_s + # puts msg.to_s - # delete email from server after article was created + # delete email from server after article was created if process(channel, msg) imap.store(message_id, "+FLAGS", [:Deleted]) end @@ -58,4 +60,4 @@ class Channel::IMAP < Channel::EmailParser puts e.inspect end end -end \ No newline at end of file +end diff --git a/app/models/channel/mail_stdin.rb b/app/models/channel/mail_stdin.rb index ec087ff9e..20e722f2d 100644 --- a/app/models/channel/mail_stdin.rb +++ b/app/models/channel/mail_stdin.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Channel::MailStdin < Channel::EmailParser def initialize puts "read main from STDIN" @@ -6,4 +8,4 @@ class Channel::MailStdin < Channel::EmailParser process( {}, msg ) end -end \ No newline at end of file +end diff --git a/app/models/channel/pop3.rb b/app/models/channel/pop3.rb index a084fa5d4..6648381fc 100644 --- a/app/models/channel/pop3.rb +++ b/app/models/channel/pop3.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'net/pop' class Channel::POP3 < Channel::EmailParser @@ -16,7 +18,7 @@ class Channel::POP3 < Channel::EmailParser if ssl pop.enable_ssl end - pop.start( channel[:options][:user], channel[:options][:password] ) + pop.start( channel[:options][:user], channel[:options][:password] ) count = 0 count_all = pop.mails.size pop.each_mail do |m| @@ -44,4 +46,4 @@ class Channel::POP3 < Channel::EmailParser puts e.inspect end end -end \ No newline at end of file +end diff --git a/app/models/channel/sendmail.rb b/app/models/channel/sendmail.rb index 84b7afdeb..808e72d51 100644 --- a/app/models/channel/sendmail.rb +++ b/app/models/channel/sendmail.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Channel::Sendmail < Channel::EmailBuild def send(attr, channel, notification = false) @@ -6,6 +8,6 @@ class Channel::Sendmail < Channel::EmailBuild mail = build(attr, notification) mail.delivery_method :sendmail - mail.deliver + mail.deliver end -end \ No newline at end of file +end diff --git a/app/models/channel/smtp.rb b/app/models/channel/smtp.rb index 8617dc405..d4952613f 100644 --- a/app/models/channel/smtp.rb +++ b/app/models/channel/smtp.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Channel::SMTP < Channel::EmailBuild def send(attr, channel, notification = false) @@ -12,9 +14,9 @@ class Channel::SMTP < Channel::EmailBuild :domain => channel[:options][:host], :user_name => channel[:options][:user], :password => channel[:options][:password], - # :authentication => 'plain', + # :authentication => 'plain', :enable_starttls_auto => true } - mail.deliver + mail.deliver end -end \ No newline at end of file +end diff --git a/app/models/channel/twitter2.rb b/app/models/channel/twitter2.rb index 50e96f3ec..75bb307e0 100644 --- a/app/models/channel/twitter2.rb +++ b/app/models/channel/twitter2.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'twitter' class Channel::Twitter2 @@ -32,7 +34,7 @@ class Channel::Twitter2 @article_type = 'twitter status' fetch_loop(tweets, channel, channel[:options][:mentions][:group]) end - + # direct messages if channel[:options][:direct_messages] puts " - searching for direct_messages" @@ -49,13 +51,13 @@ class Channel::Twitter2 all_tweets = [] result_class = tweets.class if result_class.to_s == 'Array' - all_tweets = tweets + all_tweets = tweets elsif result_class.to_s == 'Twitter::SearchResults' - tweets.results.map do |tweet| - all_tweets.push tweet - end + tweets.results.map do |tweet| + all_tweets.push tweet + end else - puts 'UNKNOWN: ' + result_class.to_s + puts 'UNKNOWN: ' + result_class.to_s end # find tweets @@ -77,7 +79,7 @@ class Channel::Twitter2 fetch_import( tweet, channel, group ) end - # execute ticket events + # execute ticket events Observer::Ticket::Notification.transaction end end @@ -91,16 +93,16 @@ class Channel::Twitter2 if tweet['user'] sender = tweet['user'] - # direct message (full user data is included) + # direct message (full user data is included) elsif tweet['sender'] sender = tweet['sender'] - # search (no user data is included, do extra lookup) + # search (no user data is included, do extra lookup) elsif tweet['from_user_id'] begin # reconnect for # workaround -# @client = connect(channel) + # @client = connect(channel) sender = @client.user(tweet.from_user_id) rescue Exception => e puts "Exception: twitter: " + e.inspect @@ -113,10 +115,10 @@ class Channel::Twitter2 if tweet['in_reply_to_status_id'] puts 'import in_reply_tweet ' + tweet.in_reply_to_status_id.to_s tweet_sub = @client.status(tweet.in_reply_to_status_id) -# puts tweet_sub.inspect + # puts tweet_sub.inspect (user, ticket, article) = fetch_import(tweet_sub, channel, group) end - + # create stuff user = fetch_user_create(tweet, sender) if !ticket @@ -126,11 +128,11 @@ class Channel::Twitter2 article = fetch_article_create(user, ticket, tweet, sender) return user, ticket, article end - + def fetch_user_create(tweet, sender) # create sender in db -# puts tweet.inspect -# user = User.where( :login => tweet.sender.screen_name ).first + # puts tweet.inspect + # user = User.where( :login => tweet.sender.screen_name ).first auth = Authorization.where( :uid => sender.id, :provider => 'twitter' ).first user = nil if auth @@ -151,7 +153,7 @@ class Channel::Twitter2 :active => true, :roles => roles, :updated_by_id => 1, - :created_by_id => 1 + :created_by_id => 1 ) puts 'autentication create...' authentication = Authorization.create( @@ -167,12 +169,12 @@ class Channel::Twitter2 # set current user UserInfo.current_user_id = user.id - return user + return user end - + def fetch_ticket_create(user, tweet, sender, channel, group) -# puts '+++++++++++++++++++++++++++' + tweet.inspect + # puts '+++++++++++++++++++++++++++' + tweet.inspect # check if ticket exists if tweet['in_reply_to_status_id'] puts 'tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id @@ -260,7 +262,7 @@ class Channel::Twitter2 end def send(attr, notification = false) -# logger.debug('tweeeeettttt!!!!!!') + # logger.debug('tweeeeettttt!!!!!!') channel = Channel.where( :area => 'Twitter::Inbound', :active => true ).first client = Twitter::Client.new( @@ -276,8 +278,8 @@ class Channel::Twitter2 attr[:body].to_s, {} ) -# puts dm.inspect - return dm + # puts dm.inspect + return dm end if attr[:type] == 'twitter status' @@ -287,9 +289,9 @@ class Channel::Twitter2 :in_reply_to_status_id => attr[:in_reply_to] } ) -# puts message.inspect + # puts message.inspect return message end end -end \ No newline at end of file +end diff --git a/app/models/email_address.rb b/app/models/email_address.rb index 848131f0b..de59f72a8 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class EmailAddress < ApplicationModel has_many :groups, :after_add => :cache_update, :after_remove => :cache_update validates :realname, :presence => true diff --git a/app/models/group.rb b/app/models/group.rb index 08b688dad..707f55197 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Group < ApplicationModel has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update belongs_to :email_address diff --git a/app/models/history.rb b/app/models/history.rb index 497c7801b..20eb657a0 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -1,10 +1,12 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class History < ApplicationModel self.table_name = 'histories' belongs_to :history_type, :class_name => 'History::Type' belongs_to :history_object, :class_name => 'History::Object' belongs_to :history_attribute, :class_name => 'History::Attribute' -# before_validation :check_type, :check_object -# attr_writer :history_type, :history_object + # before_validation :check_type, :check_object + # attr_writer :history_type, :history_object @@cache_type = {} @@cache_object = {} @@ -63,29 +65,29 @@ class History < ApplicationModel def self.history_destroy( requested_object, requested_object_id ) History.where( :history_object_id => History::Object.where( :name => requested_object ) ). - where( :o_id => requested_object_id ). - destroy_all + where( :o_id => requested_object_id ). + destroy_all end def self.history_list( requested_object, requested_object_id, related_history_object = nil ) if !related_history_object history_object = self.history_object_lookup( requested_object ) history = History.where( :history_object_id => history_object.id ). - where( :o_id => requested_object_id ). - where( :history_type_id => History::Type.where( :name => ['created', 'updated', 'notification', 'email', 'added', 'removed'] ) ). - order('created_at ASC, id ASC') + where( :o_id => requested_object_id ). + where( :history_type_id => History::Type.where( :name => ['created', 'updated', 'notification', 'email', 'added', 'removed'] ) ). + order('created_at ASC, id ASC') else history_object_requested = self.history_object_lookup( requested_object ) history_object_related = self.history_object_lookup( related_history_object ) history = History.where( - '((history_object_id = ? AND o_id = ?) OR (history_object_id = ? AND related_o_id = ? )) AND history_type_id IN (?)', - history_object_requested.id, - requested_object_id, - history_object_related.id, - requested_object_id, - History::Type.where( :name => ['created', 'updated', 'notification', 'email', 'added', 'removed'] ) - ). - order('created_at ASC, id ASC') + '((history_object_id = ? AND o_id = ?) OR (history_object_id = ? AND related_o_id = ? )) AND history_type_id IN (?)', + history_object_requested.id, + requested_object_id, + history_object_related.id, + requested_object_id, + History::Type.where( :name => ['created', 'updated', 'notification', 'email', 'added', 'removed'] ) + ). + order('created_at ASC, id ASC') end list = [] @@ -94,7 +96,7 @@ class History < ApplicationModel item_tmp['history_type'] = item.history_type.name item_tmp['history_object'] = item.history_object.name if item.history_attribute - item_tmp['history_attribute'] = item.history_attribute.name + item_tmp['history_attribute'] = item.history_attribute.name end item_tmp.delete( 'history_attribute_id' ) item_tmp.delete( 'history_object_id' ) @@ -121,14 +123,14 @@ class History < ApplicationModel end def self.activity_stream( user, limit = 10 ) -# g = Group.where( :active => true ).joins(:users).where( 'users.id' => user.id ) -# stream = History.select("distinct(histories.o_id), created_by_id, history_attribute_id, history_type_id, history_object_id, value_from, value_to"). -# where( :history_type_id => History::Type.where( :name => ['created', 'updated']) ). + # g = Group.where( :active => true ).joins(:users).where( 'users.id' => user.id ) + # stream = History.select("distinct(histories.o_id), created_by_id, history_attribute_id, history_type_id, history_object_id, value_from, value_to"). + # where( :history_type_id => History::Type.where( :name => ['created', 'updated']) ). stream = History.select("distinct(histories.o_id), created_by_id, history_type_id, history_object_id"). - where( :history_object_id => History::Object.where( :name => [ 'Ticket', 'Ticket::Article' ] ) ). - where( :history_type_id => History::Type.where( :name => [ 'created', 'updated' ]) ). - order('created_at DESC, id DESC'). - limit(limit) + where( :history_object_id => History::Object.where( :name => [ 'Ticket', 'Ticket::Article' ] ) ). + where( :history_type_id => History::Type.where( :name => [ 'created', 'updated' ]) ). + order('created_at DESC, id DESC'). + limit(limit) datas = [] stream.each do |item| data = item.attributes @@ -137,7 +139,7 @@ class History < ApplicationModel data.delete('history_object_id') data.delete('history_type_id') datas.push data -# item['history_attribute'] = item.history_attribute + # item['history_attribute'] = item.history_attribute end return datas end @@ -196,88 +198,88 @@ class History < ApplicationModel private - def self.history_type_lookup_id( id ) + def self.history_type_lookup_id( id ) - # use cache - return @@cache_type[ id ] if @@cache_type[ id ] + # use cache + return @@cache_type[ id ] if @@cache_type[ id ] - # lookup - history_type = History::Type.find(id) - @@cache_type[ id ] = history_type - return history_type - end + # lookup + history_type = History::Type.find(id) + @@cache_type[ id ] = history_type + return history_type + end - def self.history_type_lookup( name ) + def self.history_type_lookup( name ) - # use cache - return @@cache_type[ name ] if @@cache_type[ name ] + # use cache + return @@cache_type[ name ] if @@cache_type[ name ] - # lookup - history_type = History::Type.where( :name => name ).first - if history_type - @@cache_type[ name ] = history_type - return history_type - end - - # create - history_type = History::Type.create( - :name => name - ) + # lookup + history_type = History::Type.where( :name => name ).first + if history_type @@cache_type[ name ] = history_type return history_type end - def self.history_object_lookup_id( id ) + # create + history_type = History::Type.create( + :name => name + ) + @@cache_type[ name ] = history_type + return history_type + end - # use cache - return @@cache_object[ id ] if @@cache_object[ id ] + def self.history_object_lookup_id( id ) - # lookup - history_object = History::Object.find(id) - @@cache_object[ id ] = history_object - return history_object - end + # use cache + return @@cache_object[ id ] if @@cache_object[ id ] - def self.history_object_lookup( name ) + # lookup + history_object = History::Object.find(id) + @@cache_object[ id ] = history_object + return history_object + end - # use cache - return @@cache_object[ name ] if @@cache_object[ name ] + def self.history_object_lookup( name ) - # lookup - history_object = History::Object.where( :name => name ).first - if history_object - @@cache_object[ name ] = history_object - return history_object - end + # use cache + return @@cache_object[ name ] if @@cache_object[ name ] - # create - history_object = History::Object.create( - :name => name - ) + # lookup + history_object = History::Object.where( :name => name ).first + if history_object @@cache_object[ name ] = history_object return history_object end - def self.history_attribute_lookup( name ) + # create + history_object = History::Object.create( + :name => name + ) + @@cache_object[ name ] = history_object + return history_object + end - # use cache - return @@cache_attribute[ name ] if @@cache_attribute[ name ] + def self.history_attribute_lookup( name ) - # lookup - history_attribute = History::Attribute.where( :name => name ).first - if history_attribute - @@cache_attribute[ name ] = history_attribute - return history_attribute - end + # use cache + return @@cache_attribute[ name ] if @@cache_attribute[ name ] - # create - history_attribute = History::Attribute.create( - :name => name - ) + # lookup + history_attribute = History::Attribute.where( :name => name ).first + if history_attribute @@cache_attribute[ name ] = history_attribute return history_attribute end + # create + history_attribute = History::Attribute.create( + :name => name + ) + @@cache_attribute[ name ] = history_attribute + return history_attribute + end + class Object < ApplicationModel end diff --git a/app/models/link.rb b/app/models/link.rb index 6dfcbe607..adf9cc3ab 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Link < ApplicationModel belongs_to :link_type, :class_name => 'Link::Type' belongs_to :link_object, :class_name => 'Link::Object' @@ -14,7 +16,7 @@ class Link < ApplicationModel :link_object => 'Ticket', :link_object_value => 1 ) - + =end def self.list(data) @@ -66,7 +68,7 @@ class Link < ApplicationModel :link_object_source_value => 1, :link_object_target_id => 1, :link_object_target_value => 1 - ) + ) =end @@ -101,7 +103,7 @@ class Link < ApplicationModel :link_object_source_value => 6, :link_object_target => 'Ticket', :link_object_target_value => 31 - ) + ) =end @@ -150,25 +152,25 @@ class Link < ApplicationModel end private - def self.link_type_get(data) - linktype = Link::Type.where( :name => data[:name] ).first - if !linktype - linktype = Link::Type.create( - :name => data[:name] - ) - end - return linktype + def self.link_type_get(data) + linktype = Link::Type.where( :name => data[:name] ).first + if !linktype + linktype = Link::Type.create( + :name => data[:name] + ) end + return linktype + end - def self.link_object_get(data) - linkobject = Link::Object.where( :name => data[:name] ).first - if !linkobject - linkobject = Link::Object.create( - :name => data[:name] - ) - end - return linkobject + def self.link_object_get(data) + linkobject = Link::Object.where( :name => data[:name] ).first + if !linkobject + linkobject = Link::Object.create( + :name => data[:name] + ) end + return linkobject + end end @@ -178,4 +180,4 @@ end class Link::Object < ApplicationModel validates :name, :presence => true -end \ No newline at end of file +end diff --git a/app/models/network.rb b/app/models/network.rb index 439079872..2940ac975 100644 --- a/app/models/network.rb +++ b/app/models/network.rb @@ -1,7 +1,9 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Network < ApplicationModel -# belongs_to :group -# belongs_to :ticket_state, :class_name => 'Ticket::State' -# belongs_to :ticket_priority, :class_name => 'Ticket::Priority' + # belongs_to :group + # belongs_to :ticket_state, :class_name => 'Ticket::State' + # belongs_to :ticket_priority, :class_name => 'Ticket::Priority' class Category < ApplicationModel self.table_name = 'network_categories' @@ -12,7 +14,7 @@ class Network < ApplicationModel class Subscription < ApplicationModel end end - + class Item < ApplicationModel class Comment < ApplicationModel end diff --git a/app/models/notification.rb b/app/models/notification.rb index 199a1961f..5672bab02 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,2 +1,4 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Notifications < ActiveRecord::Base end diff --git a/app/models/observer/history.rb b/app/models/observer/history.rb index 5775cb789..5cdffb7df 100644 --- a/app/models/observer/history.rb +++ b/app/models/observer/history.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'history' class Observer::History < ActiveRecord::Observer @@ -9,7 +11,7 @@ class Observer::History < ActiveRecord::Observer return if Setting.get('import_mode') puts "HISTORY OBSERVER, object created #{ record.class.name }.find(#{ record.id })" -# puts record.inspect + # puts record.inspect # if Ticket::Article has changed, remember ticket to be able # to show article changes in ticket history @@ -34,17 +36,17 @@ class Observer::History < ActiveRecord::Observer # return if we run import mode return if Setting.get('import_mode') -# puts 'before_update' + # puts 'before_update' current = record.class.find(record.id) # do not send anything if nothing has changed return if current.attributes == record.attributes puts "HISTORY OBSERVER, object will be updated #{ record.class.name.to_s}.find(#{ current.id.to_s })" -# puts 'current' -# puts current.inspect -# puts 'record' -# puts record.inspect + # puts 'current' + # puts current.inspect + # puts 'record' + # puts record.inspect diff = differences_from?(current, record) puts ' DIFF' @@ -123,7 +125,7 @@ class Observer::History < ActiveRecord::Observer value[1] = map[key.to_sym][:lookup_object].find( value_ids[1] ).send( map[key.to_sym][:lookup_method] ) end - # if not, fill diff data to value, empty value_ids + # if not, fill diff data to value, empty value_ids else value = value_ids value_ids = [] diff --git a/app/models/observer/tag/ticket_history.rb b/app/models/observer/tag/ticket_history.rb index 39647c42a..4da0afdf4 100644 --- a/app/models/observer/tag/ticket_history.rb +++ b/app/models/observer/tag/ticket_history.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'history' class Observer::Tag::TicketHistory < ActiveRecord::Observer @@ -33,4 +35,4 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer :created_by_id => record.created_by_id || UserInfo.current_user_id || 1 ) end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article/communicate_email.rb b/app/models/observer/ticket/article/communicate_email.rb index 1023b2d77..8bd0e45bb 100644 --- a/app/models/observer/ticket/article/communicate_email.rb +++ b/app/models/observer/ticket/article/communicate_email.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer observe 'ticket::_article' @@ -67,4 +69,4 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer ) end end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article/communicate_facebook.rb b/app/models/observer/ticket/article/communicate_facebook.rb index 84cc0305d..c9c5ea893 100644 --- a/app/models/observer/ticket/article/communicate_facebook.rb +++ b/app/models/observer/ticket/article/communicate_facebook.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer observe 'ticket::_article' @@ -24,4 +26,4 @@ class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer } ) end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article/communicate_twitter.rb b/app/models/observer/ticket/article/communicate_twitter.rb index 8120e6f5c..b30d61da6 100644 --- a/app/models/observer/ticket/article/communicate_twitter.rb +++ b/app/models/observer/ticket/article/communicate_twitter.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer observe 'ticket::_article' @@ -23,9 +25,9 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer :body => record.body, :in_reply_to => record.in_reply_to }, -# Rails.application.config.channel_twitter + # Rails.application.config.channel_twitter ) record.message_id = message.id record.save end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article/fillup_from_email.rb b/app/models/observer/ticket/article/fillup_from_email.rb index ba9196c62..de7aca61c 100644 --- a/app/models/observer/ticket/article/fillup_from_email.rb +++ b/app/models/observer/ticket/article/fillup_from_email.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer observe 'ticket::_article' @@ -39,4 +41,4 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer record.from = system_sender end end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article/fillup_from_general.rb b/app/models/observer/ticket/article/fillup_from_general.rb index f4a3580c4..06e590e1e 100644 --- a/app/models/observer/ticket/article/fillup_from_general.rb +++ b/app/models/observer/ticket/article/fillup_from_general.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer observe 'ticket::_article' @@ -17,4 +19,4 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer record.from = "#{user.firstname} #{user.lastname}" end end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article_counter.rb b/app/models/observer/ticket/article_counter.rb index 5d8b27ed5..f21420eff 100644 --- a/app/models/observer/ticket/article_counter.rb +++ b/app/models/observer/ticket/article_counter.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::ArticleCounter < ActiveRecord::Observer observe 'ticket::_article' @@ -9,4 +11,4 @@ class Observer::Ticket::ArticleCounter < ActiveRecord::Observer # save ticket record.ticket.save end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/article_sender_type.rb b/app/models/observer/ticket/article_sender_type.rb index 68b0a387d..adea94459 100644 --- a/app/models/observer/ticket/article_sender_type.rb +++ b/app/models/observer/ticket/article_sender_type.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::ArticleSenderType < ActiveRecord::Observer observe 'ticket::_article' @@ -13,4 +15,4 @@ class Observer::Ticket::ArticleSenderType < ActiveRecord::Observer # save ticket record.ticket.save end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/close_time.rb b/app/models/observer/ticket/close_time.rb index 3938dbbcb..eaf2182e5 100644 --- a/app/models/observer/ticket/close_time.rb +++ b/app/models/observer/ticket/close_time.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::CloseTime < ActiveRecord::Observer observe 'ticket' @@ -10,24 +12,24 @@ class Observer::Ticket::CloseTime < ActiveRecord::Observer end private - def _check(record) -# puts 'check close time' + def _check(record) + # puts 'check close time' - # return if we run import mode - return if Setting.get('import_mode') + # return if we run import mode + return if Setting.get('import_mode') - # check if close_time is already set - return true if record.close_time + # check if close_time is already set + return true if record.close_time - # check if ticket is closed now - ticket_state = Ticket::State.lookup( :id => record.ticket_state_id ) - ticket_state_type = Ticket::StateType.lookup( :id => ticket_state.state_type_id ) - return true if ticket_state_type.name != 'closed' + # check if ticket is closed now + ticket_state = Ticket::State.lookup( :id => record.ticket_state_id ) + ticket_state_type = Ticket::StateType.lookup( :id => ticket_state.state_type_id ) + return true if ticket_state_type.name != 'closed' - # set close_time - record.close_time = Time.now + # set close_time + record.close_time = Time.now - # save ticket - record.save - end -end \ No newline at end of file + # save ticket + record.save + end +end diff --git a/app/models/observer/ticket/escalation_calculation.rb b/app/models/observer/ticket/escalation_calculation.rb index e2fd24791..62fc167a8 100644 --- a/app/models/observer/ticket/escalation_calculation.rb +++ b/app/models/observer/ticket/escalation_calculation.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::EscalationCalculation < ActiveRecord::Observer observe 'ticket', 'ticket::_article' @@ -37,4 +39,4 @@ class Observer::Ticket::EscalationCalculation < ActiveRecord::Observer record.callback_loop = false end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/first_response.rb b/app/models/observer/ticket/first_response.rb index 8e291273b..220158797 100644 --- a/app/models/observer/ticket/first_response.rb +++ b/app/models/observer/ticket/first_response.rb @@ -1,8 +1,10 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::FirstResponse < ActiveRecord::Observer observe 'ticket::_article' def after_create(record) -# puts 'check first response' + # puts 'check first response' # return if we run import mode return if Setting.get('import_mode') @@ -29,4 +31,4 @@ class Observer::Ticket::FirstResponse < ActiveRecord::Observer # save ticket record.ticket.save end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/last_contact.rb b/app/models/observer/ticket/last_contact.rb index 244d79da2..596b94794 100644 --- a/app/models/observer/ticket/last_contact.rb +++ b/app/models/observer/ticket/last_contact.rb @@ -1,8 +1,10 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::LastContact < ActiveRecord::Observer observe 'ticket::_article' def after_create(record) -# puts 'check last contact' + # puts 'check last contact' # if article in internal return true if record.internal @@ -41,4 +43,4 @@ class Observer::Ticket::LastContact < ActiveRecord::Observer record.ticket.save end end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index f07afc9da..8a309bb2f 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'notification_factory' class Observer::Ticket::Notification < ActiveRecord::Observer @@ -10,8 +12,8 @@ class Observer::Ticket::Notification < ActiveRecord::Observer # return if we run import mode return if Setting.get('import_mode') -# puts '@@event_buffer' -# puts @@event_buffer.inspect + # puts '@@event_buffer' + # puts @@event_buffer.inspect @@event_buffer.each { |event| # get current state of objects @@ -24,7 +26,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer ticket = article.ticket elsif event[:name] == 'Ticket' ticket = Ticket.lookup( :id => event[:id] ) - + # next if ticket is already deleted next if !ticket @@ -44,19 +46,19 @@ class Observer::Ticket::Notification < ActiveRecord::Observer :subject => 'New Ticket (#{ticket.title})', :body => 'Hi #{recipient.firstname}, -a new Ticket (#{ticket.title}) via i18n(#{article.ticket_article_type.name}). + a new Ticket (#{ticket.title}) via i18n(#{article.ticket_article_type.name}). -Group: #{ticket.group.name} -Owner: #{ticket.owner.firstname} #{ticket.owner.lastname} -State: i18n(#{ticket.ticket_state.name}) + Group: #{ticket.group.name} + Owner: #{ticket.owner.firstname} #{ticket.owner.lastname} + State: i18n(#{ticket.ticket_state.name}) -From: #{article.from} - -#{article.body} - + From: #{article.from} + + #{article.body} + -#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}/#{article.id} -' + #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}/#{article.id} + ' }, ticket, article @@ -77,17 +79,17 @@ From: #{article.from} :subject => 'New Ticket has been created! (#{ticket.title})', :body => 'Thanks for your email. A new ticket has been created. -You wrote: - -#{article.body} - + You wrote: + + #{article.body} + -Your email will be answered by a human ASAP + Your email will be answered by a human ASAP -Have fun with Zammad! :-) + Have fun with Zammad! :-) -Your Zammad Team -' + Your Zammad Team + ' }, ticket, article @@ -110,25 +112,25 @@ Your Zammad Team :subject => 'Follow Up (#{ticket.title})', :body => 'Hi #{recipient.firstname}, -a follow Up (#{ticket.title}) via i18n(#{article.ticket_article_type.name}). + a follow Up (#{ticket.title}) via i18n(#{article.ticket_article_type.name}). -Group: #{ticket.group.name} -Owner: #{ticket.owner.firstname} #{ticket.owner.lastname} -State: i18n(#{ticket.ticket_state.name}) + Group: #{ticket.group.name} + Owner: #{ticket.owner.firstname} #{ticket.owner.lastname} + State: i18n(#{ticket.ticket_state.name}) -From: #{article.from} - -#{article.body} - + From: #{article.from} + + #{article.body} + -#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}/#{article.id} -' + #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}/#{article.id} + ' }, ticket, article ) end - + # send new note notification to owner # if agent == created.id if article.ticket_article_sender.name == 'Agent' && article.created_by_id != article.ticket.owner_id @@ -138,20 +140,20 @@ From: #{article.from} :recipient => 'owner', # group|owner|to_work_on :subject => 'Updated (#{ticket.title})', :body => 'Hi #{recipient.firstname}, - -updated (#{ticket.title}) via i18n(#{article.ticket_article_type.name}). -Group: #{ticket.group.name} -Owner: #{ticket.owner.firstname} #{ticket.owner.lastname} -State: i18n(#{ticket.ticket_state.name}) + updated (#{ticket.title}) via i18n(#{article.ticket_article_type.name}). -From: #{article.from} - -#{article.body} - + Group: #{ticket.group.name} + Owner: #{ticket.owner.firstname} #{ticket.owner.lastname} + State: i18n(#{ticket.ticket_state.name}) -#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}/#{article.id} -' + From: #{article.from} + + #{article.body} + + + #{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}/#{article.id} + ' }, ticket, article @@ -159,7 +161,7 @@ From: #{article.from} end end } - + # reset buffer @@event_buffer = [] end @@ -173,20 +175,20 @@ From: #{article.from} if data[:recipient] == 'group' recipients = ticket.agent_of_group() - # owner + # owner elsif data[:recipient] == 'owner' if ticket.owner_id != 1 recipients.push ticket.owner end - # customer + # customer elsif data[:recipient] == 'customer' if ticket.customer_id != 1 -# temporarily disabled -# recipients.push ticket.customer + # temporarily disabled + # recipients.push ticket.customer end - # owner or group of agents to work on + # owner or group of agents to work on elsif data[:recipient] == 'to_work_on' if ticket.owner_id != 1 recipients.push ticket.owner @@ -251,8 +253,8 @@ From: #{article.from} # return if we run import mode return if Setting.get('import_mode') -# puts 'CREATED!!!!' -# puts record.inspect + # puts 'CREATED!!!!' + # puts record.inspect e = { :name => record.class.name, :type => 'create', @@ -272,12 +274,12 @@ From: #{article.from} # do not send anything if nothing has changed return if current.attributes == record.attributes - -# puts 'UPDATE!!!!!!!!' -# puts 'current' -# puts current.inspect -# puts 'record' -# puts record.inspect + + # puts 'UPDATE!!!!!!!!' + # puts 'current' + # puts current.inspect + # puts 'record' + # puts record.inspect e = { :name => record.class.name, @@ -293,10 +295,10 @@ From: #{article.from} # return if we run import mode return if Setting.get('import_mode') -# puts 'after_update' -# puts record.inspect -# puts '-----' -# puts @a.inspect -# AuditTrail.new(record, "UPDATED") + # puts 'after_update' + # puts record.inspect + # puts '-----' + # puts @a.inspect + # AuditTrail.new(record, "UPDATED") end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/reset_new_state.rb b/app/models/observer/ticket/reset_new_state.rb index a21c91dc7..fe9c1bf25 100644 --- a/app/models/observer/ticket/reset_new_state.rb +++ b/app/models/observer/ticket/reset_new_state.rb @@ -1,8 +1,10 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::ResetNewState < ActiveRecord::Observer observe 'ticket::_article' def after_create(record) -# puts 'check reset new state' + # puts 'check reset new state' # return if we run import mode return if Setting.get('import_mode') @@ -30,4 +32,4 @@ class Observer::Ticket::ResetNewState < ActiveRecord::Observer # save ticket ticket.save end -end \ No newline at end of file +end diff --git a/app/models/observer/ticket/user_ticket_counter.rb b/app/models/observer/ticket/user_ticket_counter.rb index 8b83c6059..3f6017e37 100644 --- a/app/models/observer/ticket/user_ticket_counter.rb +++ b/app/models/observer/ticket/user_ticket_counter.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Observer::Ticket::UserTicketCounter < ActiveRecord::Observer observe 'ticket' @@ -30,4 +32,4 @@ class Observer::Ticket::UserTicketCounter < ActiveRecord::Observer customer[:preferences][:tickets_closed] = tickets_closed customer.save end -end \ No newline at end of file +end diff --git a/app/models/organization.rb b/app/models/organization.rb index dc5f26451..615e2ef4c 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Organization < ApplicationModel has_and_belongs_to_many :users validates :name, :presence => true @@ -27,7 +29,7 @@ class Organization < ApplicationModel :limit => limit, :conditions => ['users.firstname LIKE ? or users.lastname LIKE ? or users.email LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%"], :order => 'organizations.name' - ) + ) end return organizations end diff --git a/app/models/overview.rb b/app/models/overview.rb index ffbffb51f..fc0911954 100644 --- a/app/models/overview.rb +++ b/app/models/overview.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Overview < ApplicationModel store :condition store :order @@ -5,4 +7,4 @@ class Overview < ApplicationModel validates :name, :presence => true validates :prio, :presence => true validates :link, :presence => true -end \ No newline at end of file +end diff --git a/app/models/package.rb b/app/models/package.rb index b86d402a0..1100912d5 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'rexml/document' class Package < ApplicationModel @@root = Rails.root.to_s @@ -34,7 +36,7 @@ class Package < ApplicationModel location = data[:output] + '/' + package.elements["zpm/name"].text + '-' + package.elements["zpm/version"].text + '.zpm' puts "NOTICE: writting package to '#{location}'" file = File.new( location, 'wb' ) - file.write( package.to_s ) + file.write( package.to_s ) file.close return true end @@ -76,7 +78,7 @@ class Package < ApplicationModel end end - # check if zpm is a package source repo + # check if zpm is a package source repo def self._package_base_dir?(package_base_dir) package = false Dir.glob( package_base_dir + '/*.szpm') do |entry| @@ -93,7 +95,7 @@ class Package < ApplicationModel # execute migration down + unlink files def self.unlink(package_base_dir) - # check if zpm is a package source repo + # check if zpm is a package source repo package = self._package_base_dir?(package_base_dir) # migration down @@ -105,7 +107,7 @@ class Package < ApplicationModel file = entry file = file.sub( /#{package_base_dir.to_s}/, '' ) dest = @@root + '/' + file - + if File.symlink?( dest.to_s ) puts "Unlink file: #{dest.to_s}" File.delete( dest.to_s ) @@ -123,7 +125,7 @@ class Package < ApplicationModel # link files + execute migration up def self.link(package_base_dir) - # check if zpm is a package source repo + # check if zpm is a package source repo package = self._package_base_dir?(package_base_dir) # link files @@ -322,14 +324,14 @@ class Package < ApplicationModel end def self._parse(xml) -# puts xml.inspect + # puts xml.inspect begin package = REXML::Document.new( xml ) rescue => e puts 'ERROR: ' + e.inspect return end -# puts package.inspect + # puts package.inspect return package end @@ -403,7 +405,7 @@ class Package < ApplicationModel begin puts "NOTICE: install '#{location}' (#{permission})" file = File.new( location, 'wb' ) - file.write( data ) + file.write( data ) file.close File.chmod( permission.to_i(8), location ) rescue => e @@ -481,7 +483,7 @@ class Package < ApplicationModel record.destroy end - # up + # up else done = Package::Migration.where( :name => package.underscore, :version => version ).first next if done @@ -497,4 +499,4 @@ class Package < ApplicationModel } end end -end \ No newline at end of file +end diff --git a/app/models/postmaster_filter.rb b/app/models/postmaster_filter.rb index b484fa45f..62ea286e2 100644 --- a/app/models/postmaster_filter.rb +++ b/app/models/postmaster_filter.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class PostmasterFilter < ApplicationModel store :perform store :match diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 5e7e75209..614f2ee4f 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -1,9 +1,11 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class RecentView < ApplicationModel belongs_to :recent_view_object, :class_name => 'RecentView::Object' @@cache_object = {} - def self.log( object, user ) + def self.log( object, user ) # lookups recent_view_object = self.recent_view_object_lookup( object.class.to_s ) @@ -19,14 +21,14 @@ class RecentView < ApplicationModel def self.log_destroy( requested_object, requested_object_id ) RecentView.where( :recent_view_object_id => RecentView::Object.where( :name => requested_object ) ). - where( :o_id => requested_object_id ). - destroy_all + where( :o_id => requested_object_id ). + destroy_all end def self.list( user, limit = 10 ) recent_views = RecentView.where( :created_by_id => user.id ). - order('created_at DESC, id DESC'). - limit(limit) + order('created_at DESC, id DESC'). + limit(limit) list = [] recent_views.each { |item| @@ -47,17 +49,17 @@ class RecentView < ApplicationModel recent_viewed.each {|item| # load article ids -# if item.recent_view_object == 'Ticket' - ticket = Ticket.find( item['o_id'] ).attributes - tickets.push ticket -# end -# if item.recent_view_object 'Ticket::Article' -# tickets.push Ticket::Article.find(item.o_id) -# end -# if item.recent_view_object 'User' -# tickets.push User.find(item.o_id) -# end - + # if item.recent_view_object == 'Ticket' + ticket = Ticket.find( item['o_id'] ).attributes + tickets.push ticket + # end + # if item.recent_view_object 'Ticket::Article' + # tickets.push Ticket::Article.find(item.o_id) + # end + # if item.recent_view_object 'User' + # 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'] ) @@ -78,37 +80,37 @@ class RecentView < ApplicationModel private - def self.recent_view_object_lookup_id( id ) + def self.recent_view_object_lookup_id( id ) - # use cache - return @@cache_object[ id ] if @@cache_object[ id ] + # use cache + return @@cache_object[ id ] if @@cache_object[ id ] - # lookup - history_object = RecentView::Object.find(id) - @@cache_object[ id ] = history_object - return history_object - end + # lookup + history_object = RecentView::Object.find(id) + @@cache_object[ id ] = history_object + return history_object + end - def self.recent_view_object_lookup( name ) + def self.recent_view_object_lookup( name ) - # use cache - return @@cache_object[ name ] if @@cache_object[ name ] + # use cache + return @@cache_object[ name ] if @@cache_object[ name ] - # lookup - recent_view_object = RecentView::Object.where( :name => name ).first - if recent_view_object - @@cache_object[ name ] = recent_view_object - return recent_view_object - end - - # create - recent_view_object = RecentView::Object.create( - :name => name - ) + # lookup + recent_view_object = RecentView::Object.where( :name => name ).first + if recent_view_object @@cache_object[ name ] = recent_view_object return recent_view_object end + # create + recent_view_object = RecentView::Object.create( + :name => name + ) + @@cache_object[ name ] = recent_view_object + return recent_view_object + end + class Object < ApplicationModel end diff --git a/app/models/role.rb b/app/models/role.rb index a565ff56d..bd9580925 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Role < ApplicationModel has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update validates :name, :presence => true diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index 0d90bfe0e..1eeb1e05b 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -1,9 +1,11 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Scheduler < ApplicationModel def self.run( worker, worker_count ) Thread.abort_on_exception = true - + jobs_started = {} while true puts "Scheduler running (worker #{worker} of #{worker_count})..." @@ -44,7 +46,7 @@ class Scheduler < ApplicationModel else self._start_job( job, worker, worker_count ) end -# raise "Exception from thread" + # raise "Exception from thread" job.pid = '' job.save puts " ...stopped thread for '#{job.method}'" @@ -58,4 +60,4 @@ class Scheduler < ApplicationModel job.save eval job.method() end -end \ No newline at end of file +end diff --git a/app/models/setting.rb b/app/models/setting.rb index 08e147f23..2a0db2f8e 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Setting < ApplicationModel store :options store :state @@ -48,17 +50,17 @@ class Setting < ApplicationModel end private - def delete_cache - @@current[:settings_config] = nil - end - def set_initial - self.state_initial = self.state - end - def state_check - if self.state || self.state == false - if !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) - self.state = { :value => self.state } - end + def delete_cache + @@current[:settings_config] = nil + end + def set_initial + self.state_initial = self.state + end + def state_check + if self.state || self.state == false + if !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) + self.state = { :value => self.state } end end + end end diff --git a/app/models/signature.rb b/app/models/signature.rb index 54b2dc01b..1abb91d86 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Signature < ApplicationModel has_many :groups, :after_add => :cache_update, :after_remove => :cache_update validates :name, :presence => true diff --git a/app/models/sla.rb b/app/models/sla.rb index 7f6911674..a73ed4ff6 100644 --- a/app/models/sla.rb +++ b/app/models/sla.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'cache' class Sla < ApplicationModel @@ -10,8 +12,8 @@ class Sla < ApplicationModel after_destroy :escalation_calculation_rebuild private - def escalation_calculation_rebuild - Cache.delete( 'SLA::List::Active' ) - Ticket.escalation_calculation_rebuild - end -end \ No newline at end of file + def escalation_calculation_rebuild + Cache.delete( 'SLA::List::Active' ) + Ticket.escalation_calculation_rebuild + end +end diff --git a/app/models/store.rb b/app/models/store.rb index 9075e8f4e..e127163c4 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'digest/md5' class Store < ApplicationModel @@ -14,10 +16,10 @@ class Store < ApplicationModel data['store_object_id'] = store_object.id # check if record already exists -# store = Store.where( :store_object_id => store_object.id, :o_id => data['o_id'], ).first -# if store != nil -# return store -# end + # store = Store.where( :store_object_id => store_object.id, :o_id => data['o_id'], ).first + # if store != nil + # return store + # end # check real store md5 = Digest::MD5.hexdigest( data['data'] ) @@ -49,7 +51,7 @@ class Store < ApplicationModel # search store_object_id = Store::Object.lookup( :name => data[:object] ) stores = Store.where( :store_object_id => store_object_id, :o_id => data[:o_id].to_i ). - order('created_at ASC, id ASC') + order('created_at ASC, id ASC') return stores end @@ -57,8 +59,8 @@ class Store < ApplicationModel # search store_object_id = Store::Object.lookup( :name => data[:object] ) stores = Store.where( :store_object_id => store_object_id ). - where( :o_id => data[:o_id] ). - order('created_at ASC, id ASC') + where( :o_id => data[:o_id] ). + order('created_at ASC, id ASC') stores.each do |store| store.destroy end @@ -73,9 +75,9 @@ class Store < ApplicationModel before_validation :add_md5 private - def add_md5 - self.md5 = Digest::MD5.hexdigest( self.data ) - end + def add_md5 + self.md5 = Digest::MD5.hexdigest( self.data ) + end end end diff --git a/app/models/tag.rb b/app/models/tag.rb index 8830214a3..03079e402 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Tag < ApplicationModel belongs_to :tag_object, :class_name => 'Tag::Object' belongs_to :tag_item, :class_name => 'Tag::Item' @@ -5,7 +7,7 @@ class Tag < ApplicationModel @@cache_item = {} @@cache_object = {} - def self.tag_add(data) + def self.tag_add(data) # lookups if data[:object] @@ -25,7 +27,7 @@ class Tag < ApplicationModel return true end - def self.tag_remove(data) + def self.tag_remove(data) # lookups if data[:object] @@ -50,82 +52,82 @@ class Tag < ApplicationModel def self.tag_list( data ) tag_object_id_requested = self.tag_object_lookup( data[:object] ) tag_search = Tag.where( - :tag_object_id => tag_object_id_requested, - :o_id => data[:o_id], + :tag_object_id => tag_object_id_requested, + :o_id => data[:o_id], ) tags = [] tag_search.each {|tag| - tags.push self.tag_item_lookup_id( tag.tag_item_id ) + tags.push self.tag_item_lookup_id( tag.tag_item_id ) } return tags end private - def self.tag_item_lookup_id( id ) + def self.tag_item_lookup_id( id ) - # use cache - return @@cache_item[ id ] if @@cache_item[ id ] + # use cache + return @@cache_item[ id ] if @@cache_item[ id ] - # lookup - tag_item = Tag::Item.find(id) - @@cache_item[ id ] = tag_item.name - return tag_item.name - end + # lookup + tag_item = Tag::Item.find(id) + @@cache_item[ id ] = tag_item.name + return tag_item.name + end - def self.tag_item_lookup( name ) + def self.tag_item_lookup( name ) - name = name.downcase + name = name.downcase - # use cache - return @@cache_item[ name ] if @@cache_item[ name ] + # use cache + return @@cache_item[ name ] if @@cache_item[ name ] - # lookup - tag_item = Tag::Item.where( :name => name ).first - if tag_item - @@cache_item[ name ] = tag_item.id - return tag_item.id - end - - # create - tag_item = Tag::Item.create( - :name => name - ) + # lookup + tag_item = Tag::Item.where( :name => name ).first + if tag_item @@cache_item[ name ] = tag_item.id return tag_item.id end - def self.tag_object_lookup_id( id ) + # create + tag_item = Tag::Item.create( + :name => name + ) + @@cache_item[ name ] = tag_item.id + return tag_item.id + end - # use cache - return @@cache_object[ id ] if @@cache_object[ id ] + def self.tag_object_lookup_id( id ) - # lookup - tag_object = Tag::Object.find(id) - @@cache_object[ id ] = tag_object.name - return tag_object.name - end + # use cache + return @@cache_object[ id ] if @@cache_object[ id ] - def self.tag_object_lookup( name ) + # lookup + tag_object = Tag::Object.find(id) + @@cache_object[ id ] = tag_object.name + return tag_object.name + end - # use cache - return @@cache_object[ name ] if @@cache_object[ name ] + def self.tag_object_lookup( name ) - # lookup - tag_object = Tag::Object.where( :name => name ).first - if tag_object - @@cache_object[ name ] = tag_object.id - return tag_object.id - end + # use cache + return @@cache_object[ name ] if @@cache_object[ name ] - # create - tag_object = Tag::Object.create( - :name => name - ) + # lookup + tag_object = Tag::Object.where( :name => name ).first + if tag_object @@cache_object[ name ] = tag_object.id return tag_object.id end + # create + tag_object = Tag::Object.create( + :name => name + ) + @@cache_object[ name ] = tag_object.id + return tag_object.id + end + class Object < ActiveRecord::Base end diff --git a/app/models/taskbar.rb b/app/models/taskbar.rb index 48a41813e..c9cab98c4 100644 --- a/app/models/taskbar.rb +++ b/app/models/taskbar.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Taskbar < ApplicationModel store :state store :params @@ -5,7 +7,7 @@ class Taskbar < ApplicationModel before_update :update_last_contact private - def update_last_contact - self.last_contact = Time.now - end + def update_last_contact + self.last_contact = Time.now + end end diff --git a/app/models/template.rb b/app/models/template.rb index 36a7ebbad..d0ab235f3 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -1,4 +1,6 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Template < ApplicationModel store :options validates :name, :presence => true -end \ No newline at end of file +end diff --git a/app/models/text_module.rb b/app/models/text_module.rb index d9bf52d95..be494b70e 100644 --- a/app/models/text_module.rb +++ b/app/models/text_module.rb @@ -1,4 +1,6 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TextModule < ApplicationModel validates :name, :presence => true validates :content, :presence => true -end \ No newline at end of file +end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index b35b545da..79af2869f 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'time_calculation' require 'sla' @@ -64,7 +66,7 @@ class Ticket < ApplicationModel owner_ids.push user.id } end - + # get group group_ids = [] Group.where( :active => true ).each { |group| @@ -78,11 +80,11 @@ class Ticket < ApplicationModel } groups_users = {} group_ids.each {|group_id| - groups_users[ group_id ] = [] - Group.find( group_id ).users.each {|user| - next if !agents[ user.id ] - groups_users[ group_id ].push user.id - } + groups_users[ group_id ] = [] + Group.find( group_id ).users.each {|user| + next if !agents[ user.id ] + groups_users[ group_id ].push user.id + } } # get priorities @@ -124,7 +126,7 @@ class Ticket < ApplicationModel # create new merge article Ticket::Article.create( - :ticket_id => self.id, + :ticket_id => self.id, :ticket_article_type_id => Ticket::Article::Type.lookup( :name => 'note' ).id, :ticket_article_sender_id => Ticket::Article::Sender.lookup( :name => 'Agent' ).id, :body => 'merged', @@ -152,9 +154,9 @@ class Ticket < ApplicationModel self.save end -# def self.agent -# Role.where( :name => ['Agent'], :active => true ).first.users.where( :active => true ).uniq() -# end + # def self.agent + # Role.where( :name => ['Agent'], :active => true ).first.users.where( :active => true ).uniq() + # end def subject_build (subject) @@ -204,9 +206,9 @@ class Ticket < ApplicationModel return subject end -# ticket.permission( -# :current_user => 123 -# ) + # ticket.permission( + # :current_user => 123 + # ) def permission (data) # check customer @@ -236,11 +238,11 @@ class Ticket < ApplicationModel return false end -# Ticket.search( -# :current_user => 123, -# :query => 'search something', -# :limit => 15, -# ) + # Ticket.search( + # :current_user => 123, + # :query => 'search something', + # :limit => 15, + # ) def self.search (params) # get params @@ -251,9 +253,9 @@ class Ticket < ApplicationModel conditions = [] if current_user.is_role('Agent') group_ids = Group.select( 'groups.id' ).joins(:users). - where( 'groups_users.user_id = ?', current_user.id ). - where( 'groups.active = ?', true ). - map( &:id ) + where( 'groups_users.user_id = ?', current_user.id ). + where( 'groups.active = ?', true ). + map( &:id ) conditions = [ 'group_id IN (?)', group_ids ] else if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) @@ -265,11 +267,11 @@ class Ticket < ApplicationModel # do query tickets_all = Ticket.select('DISTINCT(tickets.id)'). - where(conditions). - where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ). - joins(:articles). - limit(limit). - order('`tickets`.`created_at` DESC') + where(conditions). + where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ). + joins(:articles). + limit(limit). + order('`tickets`.`created_at` DESC') # build result list tickets = [] @@ -281,9 +283,9 @@ class Ticket < ApplicationModel return tickets end -# Ticket.overview_list( -# :current_user => 123, -# ) + # Ticket.overview_list( + # :current_user => 123, + # ) def self.overview_list (data) # get customer overviews @@ -303,10 +305,10 @@ class Ticket < ApplicationModel return overviews end -# Ticket.overview( -# :view => 'some_view_url', -# :current_user => OBJECT, -# ) + # Ticket.overview( + # :view => 'some_view_url', + # :current_user => OBJECT, + # ) def self.overview (data) overviews = self.overview_list(data) @@ -339,35 +341,35 @@ class Ticket < ApplicationModel end # sortby - # prio - # state - # group - # customer + # prio + # state + # group + # customer # order - # asc - # desc + # asc + # desc # groupby - # prio - # state - # group - # customer + # prio + # state + # group + # customer -# all = attributes[:myopenassigned] -# all.merge( { :group_id => groups } ) + # all = attributes[:myopenassigned] + # all.merge( { :group_id => groups } ) -# @tickets = Ticket.where(:group_id => groups, attributes[:myopenassigned] ).limit(params[:limit]) + # @tickets = Ticket.where(:group_id => groups, attributes[:myopenassigned] ).limit(params[:limit]) # get only tickets with permissions if data[:current_user].is_role('Customer') group_ids = Group.select( 'groups.id' ). - where( 'groups.active = ?', true ). - map( &:id ) + where( 'groups.active = ?', true ). + map( &:id ) else group_ids = Group.select( 'groups.id' ).joins(:users). - where( 'groups_users.user_id = ?', [ data[:current_user].id ] ). - where( 'groups.active = ?', true ). - map( &:id ) + where( 'groups_users.user_id = ?', [ data[:current_user].id ] ). + where( 'groups.active = ?', true ). + map( &:id ) end # overview meta for navbar @@ -400,10 +402,10 @@ class Ticket < ApplicationModel order_by = overview_selected.group_by + '_id, ' + order_by end tickets = Ticket.select( 'id' ). - where( :group_id => group_ids ). - where( self._condition( overview_selected.condition ) ). - order( order_by ). - limit( 500 ) + where( :group_id => group_ids ). + where( self._condition( overview_selected.condition ) ). + order( order_by ). + limit( 500 ) ticket_ids = [] tickets.each { |ticket| @@ -411,8 +413,8 @@ class Ticket < ApplicationModel } tickets_count = Ticket.where( :group_id => group_ids ). - where( self._condition( overview_selected.condition ) ). - count() + where( self._condition( overview_selected.condition ) ). + count() return { :ticket_list => ticket_ids, @@ -424,14 +426,14 @@ class Ticket < ApplicationModel # get tickets for overview data[:start_page] ||= 1 tickets = Ticket.where( :group_id => group_ids ). - where( self._condition( overview_selected.condition ) ). - order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )#. -# limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ). -# offset( overview_selected.view[ data[:view_mode].to_sym ][:per_page].to_i * ( data[:start_page].to_i - 1 ) ) + where( self._condition( overview_selected.condition ) ). + order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )#. + # limit( overview_selected.view[ data[:view_mode].to_sym ][:per_page] ). + # offset( overview_selected.view[ data[:view_mode].to_sym ][:per_page].to_i * ( data[:start_page].to_i - 1 ) ) tickets_count = Ticket.where( :group_id => group_ids ). - where( self._condition( overview_selected.condition ) ). - count() + where( self._condition( overview_selected.condition ) ). + count() return { :tickets => tickets, @@ -580,8 +582,8 @@ class Ticket < ApplicationModel ignore_escalation = ['removed', 'closed', 'merged', 'pending action'] if ignore_escalation.include?( ticket_state_type.name ) self.escalation_time = nil -# self.first_response_escal_date = nil -# self.close_time_escal_date = nil + # self.first_response_escal_date = nil + # self.close_time_escal_date = nil self.callback_loop = true self.save return true @@ -593,15 +595,15 @@ class Ticket < ApplicationModel # reset escalation if no sla is set if !sla_selected self.escalation_time = nil -# self.first_response_escal_date = nil -# self.close_time_escal_date = nil + # self.first_response_escal_date = nil + # self.close_time_escal_date = nil self.callback_loop = true self.save return true end -# puts sla_selected.inspect -# puts days.inspect + # puts sla_selected.inspect + # puts days.inspect self.escalation_time = nil self.first_response_escal_date = nil self.update_time_escal_date = nil @@ -664,43 +666,43 @@ class Ticket < ApplicationModel private - def number_generate - return if self.number + def number_generate + return if self.number - # generate number - (1..25_000).each do |i| + # generate number + (1..25_000).each do |i| + number = Ticket.number_adapter.number_generate_item() + ticket = Ticket.where( :number => number ).first + if ticket != nil number = Ticket.number_adapter.number_generate_item() - ticket = Ticket.where( :number => number ).first - if ticket != nil - number = Ticket.number_adapter.number_generate_item() - else - self.number = number - return number - end + else + self.number = number + return number end end - def check_defaults - if !self.owner_id - self.owner_id = 1 - end -# if self.customer_id && ( !self.organization_id || self.organization_id.empty? ) - if self.customer_id - customer = User.find( self.customer_id ) - if self.organization_id != customer.organization_id - self.organization_id = customer.organization_id - end - end - + end + def check_defaults + if !self.owner_id + self.owner_id = 1 end - def destroy_dependencies - - # delete history - History.history_destroy( 'Ticket', self.id ) - - # delete articles - self.articles.destroy_all + # if self.customer_id && ( !self.organization_id || self.organization_id.empty? ) + if self.customer_id + customer = User.find( self.customer_id ) + if self.organization_id != customer.organization_id + self.organization_id = customer.organization_id + end end + end + def destroy_dependencies + + # delete history + History.history_destroy( 'Ticket', self.id ) + + # delete articles + self.articles.destroy_all + end + class Number end diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index eecbf362c..c51884aab 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Ticket::Article < ApplicationModel after_create :attachment_check belongs_to :ticket @@ -9,25 +11,25 @@ class Ticket::Article < ApplicationModel private - def attachment_check + def attachment_check - # do nothing if no attachment exists - return 1 if self.attachments == nil + # do nothing if no attachment exists + return 1 if self.attachments == nil - # store attachments - article_store = [] - self.attachments.each do |attachment| - article_store.push Store.add( - :object => 'Ticket::Article', - :o_id => self.id, - :data => attachment.store_file.data, - :filename => attachment.filename, - :preferences => attachment.preferences, - :created_by_id => self.created_by_id, - ) - end - self.attachments = article_store + # store attachments + article_store = [] + self.attachments.each do |attachment| + article_store.push Store.add( + :object => 'Ticket::Article', + :o_id => self.id, + :data => attachment.store_file.data, + :filename => attachment.filename, + :preferences => attachment.preferences, + :created_by_id => self.created_by_id, + ) end + self.attachments = article_store + end class Flag < ApplicationModel end diff --git a/app/models/ticket/counter.rb b/app/models/ticket/counter.rb index a5ae6bca6..922a5b2e7 100644 --- a/app/models/ticket/counter.rb +++ b/app/models/ticket/counter.rb @@ -1,2 +1,4 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Ticket::Counter < ApplicationModel -end \ No newline at end of file +end diff --git a/app/models/ticket/flag.rb b/app/models/ticket/flag.rb index 8b71b0740..a3e6df147 100644 --- a/app/models/ticket/flag.rb +++ b/app/models/ticket/flag.rb @@ -1,2 +1,4 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Ticket::Flag < ApplicationModel end diff --git a/app/models/ticket/number/date.rb b/app/models/ticket/number/date.rb index 2d3328e46..57869822e 100644 --- a/app/models/ticket/number/date.rb +++ b/app/models/ticket/number/date.rb @@ -1,5 +1,7 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + module Ticket::Number::Date - extend self + extend self def number_generate_item @@ -78,4 +80,4 @@ module Ticket::Number::Date end return ticket end -end \ No newline at end of file +end diff --git a/app/models/ticket/number/increment.rb b/app/models/ticket/number/increment.rb index e0ea1d6b7..8a9706c5f 100644 --- a/app/models/ticket/number/increment.rb +++ b/app/models/ticket/number/increment.rb @@ -1,5 +1,7 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + module Ticket::Number::Increment - extend self + extend self def number_generate_item @@ -82,4 +84,4 @@ module Ticket::Number::Increment end return ticket end -end \ No newline at end of file +end diff --git a/app/models/ticket/priority.rb b/app/models/ticket/priority.rb index 37340366f..ded6210dc 100644 --- a/app/models/ticket/priority.rb +++ b/app/models/ticket/priority.rb @@ -1,4 +1,6 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Ticket::Priority < ApplicationModel self.table_name = 'ticket_priorities' validates :name, :presence => true -end \ No newline at end of file +end diff --git a/app/models/ticket/state.rb b/app/models/ticket/state.rb index 34c1cb09f..6ab1aef3d 100644 --- a/app/models/ticket/state.rb +++ b/app/models/ticket/state.rb @@ -1,4 +1,6 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Ticket::State < ApplicationModel belongs_to :state_type, :class_name => 'Ticket::StateType' validates :name, :presence => true -end \ No newline at end of file +end diff --git a/app/models/ticket/state_type.rb b/app/models/ticket/state_type.rb index 6fea7b174..5b3a2830b 100644 --- a/app/models/ticket/state_type.rb +++ b/app/models/ticket/state_type.rb @@ -1,4 +1,6 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Ticket::StateType < ApplicationModel has_many :states, :class_name => 'Ticket::State' validates :name, :presence => true -end \ No newline at end of file +end diff --git a/app/models/time_accounting.rb b/app/models/time_accounting.rb index 6c0b8c27d..a78c3090f 100644 --- a/app/models/time_accounting.rb +++ b/app/models/time_accounting.rb @@ -1,2 +1,4 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class TimeAccounting < ActiveRecord::Base end diff --git a/app/models/token.rb b/app/models/token.rb index 2b1a80728..fd2e39189 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Token < ActiveRecord::Base before_create :generate_token @@ -8,7 +10,7 @@ class Token < ActiveRecord::Base # fetch token token = Token.where( :action => data[:action], :name => data[:name] ).first return if !token - + # check if token is still valid if token.created_at < 1.day.ago @@ -23,9 +25,9 @@ class Token < ActiveRecord::Base end private - def generate_token - begin - self.name = SecureRandom.hex(20) - end while Token.exists?( :name => self.name ) - end -end \ No newline at end of file + def generate_token + begin + self.name = SecureRandom.hex(20) + end while Token.exists?( :name => self.name ) + end +end diff --git a/app/models/translation.rb b/app/models/translation.rb index e581c7984..b62a195bd 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Translation < ApplicationModel before_create :set_initial @@ -19,7 +21,7 @@ class Translation < ApplicationModel end private - def set_initial - self.target_initial = self.target - end + def set_initial + self.target_initial = self.target + end end diff --git a/app/models/trigger.rb b/app/models/trigger.rb index 9172928c9..b5e3f487b 100644 --- a/app/models/trigger.rb +++ b/app/models/trigger.rb @@ -1,2 +1,4 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + class Triggers < ActiveRecord::Base end diff --git a/app/models/user.rb b/app/models/user.rb index e70a887a1..b5744595d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ + require 'digest/sha2' require 'organization' @@ -41,7 +43,7 @@ class User < ApplicationModel # do not authenticate with nothing return if !username || username == '' - return if !password || password == '' + return if !password || password == '' # try to find user based on login user = User.where( :login => username.downcase, :active => true ).first @@ -117,11 +119,11 @@ class User < ApplicationModel :adapter => 'otrs', }, ] -# Setting.where( :area => 'Security::Authentication' ).each {|setting| -# if setting.state[:value] -# config.push setting.state[:value] -# end -# } + # Setting.where( :area => 'Security::Authentication' ).each {|setting| + # if setting.state[:value] + # config.push setting.state[:value] + # end + # } # try to login against configure auth backends user_auth = nil @@ -160,7 +162,7 @@ class User < ApplicationModel :firstname => hash['info']['name'], :email => hash['info']['email'], :image => hash['info']['image'], -# :url => url.to_s, + # :url => url.to_s, :note => hash['info']['description'], :source => hash['provider'], :roles => roles, @@ -193,18 +195,18 @@ class User < ApplicationModel data[:subject] = 'Reset your #{config.product_name} password' data[:body] = 'Forgot your password? -We received a request to reset the password for your #{config.product_name} account (#{user.login}). + We received a request to reset the password for your #{config.product_name} account (#{user.login}). -If you want to reset your password, click on the link below (or copy and paste the URL into your browser): + If you want to reset your password, click on the link below (or copy and paste the URL into your browser): -#{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name} + #{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name} -This link takes you to a page where you can change your password. + This link takes you to a page where you can change your password. -If you don\'t want to reset your password, please ignore this message. Your password will not be reset. + If you don\'t want to reset your password, please ignore this message. Your password will not be reset. -Your #{config.product_name} Team -' + Your #{config.product_name} Team + ' # prepare subject & body [:subject, :body].each { |key| @@ -320,7 +322,7 @@ Your #{config.product_name} Team return data end - + def self.user_data_full (user_id) # get user @@ -404,124 +406,124 @@ Your #{config.product_name} Team end private - def check_geo + def check_geo - # geo update if no user exists - if !self.id - self.geo_update + # geo update if no user exists + if !self.id + self.geo_update + return + end + + location = ['street', 'zip', 'city', 'country'] + + # get current user data + current = User.where( :id => self.id ).first + return if !current + + # check if geo update is needed + current_location = {} + location.each { |item| + current_location[item] = current[item] + } + + # get full address + next_location = {} + location.each { |item| + next_location[item] = self[item] + } + + # return if address hasn't changed and geo data is already available + return if ( current_location == next_location ) && ( self.preferences['lat'] && self.preferences['lng'] ) + + # geo update + self.geo_update + end + + def check_name + + if ( self.firstname && !self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? ) + + # Lastname, Firstname + scan = self.firstname.scan(/, /) + if scan[0] + name = self.firstname.split(', ', 2) + self.lastname = name[0] + self.firstname = name[1] return end - location = ['street', 'zip', 'city', 'country'] - - # get current user data - current = User.where( :id => self.id ).first - return if !current - - # check if geo update is needed - current_location = {} - location.each { |item| - current_location[item] = current[item] - } - - # get full address - next_location = {} - location.each { |item| - next_location[item] = self[item] - } - - # return if address hasn't changed and geo data is already available - return if ( current_location == next_location ) && ( self.preferences['lat'] && self.preferences['lng'] ) - - # geo update - self.geo_update - end - - def check_name - - if ( self.firstname && !self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? ) - - # Lastname, Firstname - scan = self.firstname.scan(/, /) - if scan[0] - name = self.firstname.split(', ', 2) - self.lastname = name[0] - self.firstname = name[1] - return - end - - # Firstname Lastname - name = self.firstname.split(' ', 2) - self.firstname = name[0] - self.lastname = name[1] - return + # Firstname Lastname + name = self.firstname.split(' ', 2) + self.firstname = name[0] + self.lastname = name[1] + return # -no name- firstname.lastname@example.com - elsif ( !self.firstname || self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? ) && ( self.email && !self.email.empty? ) - scan = self.email.scan(/^(.+?)\.(.+?)\@.+?$/) - if scan[0] - self.firstname = scan[0][0].capitalize - self.lastname = scan[0][1].capitalize - end + elsif ( !self.firstname || self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? ) && ( self.email && !self.email.empty? ) + scan = self.email.scan(/^(.+?)\.(.+?)\@.+?$/) + if scan[0] + self.firstname = scan[0][0].capitalize + self.lastname = scan[0][1].capitalize + end + end + end + + def check_email + if self.email + self.email = self.email.downcase + end + end + + def check_login + if self.login + self.login = self.login.downcase + check = true + while check + exists = User.where( :login => self.login ).first + if exists + self.login = self.login + rand(99).to_s + else + check = false + end end end + end - def check_email + # FIXME: Remove me later + def check_login_update + if self.login + self.login = self.login.downcase + end + end + + def check_image + require 'digest/md5' + if !self.image || self.image == '' if self.email - self.email = self.email.downcase + hash = Digest::MD5.hexdigest(self.email) + self.image = "http://www.gravatar.com/avatar/#{hash}?s=48" end end + end - def check_login - if self.login - self.login = self.login.downcase - check = true - while check - exists = User.where( :login => self.login ).first - if exists - self.login = self.login + rand(99).to_s - else - check = false - end - end + def check_password + + # set old password again if not given + if self.password == '' || !self.password + + # get current record + if self.id + current = User.find(self.id) + self.password = current.password end - end - - # FIXME: Remove me later - def check_login_update - if self.login - self.login = self.login.downcase - end - end - - def check_image - require 'digest/md5' - if !self.image || self.image == '' - if self.email - hash = Digest::MD5.hexdigest(self.email) - self.image = "http://www.gravatar.com/avatar/#{hash}?s=48" - end - end - end - - def check_password - - # set old password again if not given - if self.password == '' || !self.password - - # get current record - if self.id - current = User.find(self.id) - self.password = current.password - end # create crypted password if not already crypted - else - if self.password !~ /^\{sha2\}/ - crypted = Digest::SHA2.hexdigest( self.password ) - self.password = "{sha2}#{crypted}" - end + else + if self.password !~ /^\{sha2\}/ + crypted = Digest::SHA2.hexdigest( self.password ) + self.password = "{sha2}#{crypted}" end end + end end