Corrected with rubocop cop 'Style/HashSyntax'.

This commit is contained in:
Thorsten Eckel 2015-04-27 15:42:53 +02:00
parent 540c99fcaf
commit ce58d465c0
284 changed files with 10121 additions and 10128 deletions

View file

@ -167,13 +167,6 @@ Style/SymbolProc:
Description: 'Use symbols as procs instead of blocks when possible.' Description: 'Use symbols as procs instead of blocks when possible.'
Enabled: false Enabled: false
Style/HashSyntax:
Description: >-
Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
{ :a => 1, :b => 2 }.
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals'
Enabled: false
Style/RedundantBegin: Style/RedundantBegin:
Description: "Don't use begin blocks when they are not needed." Description: "Don't use begin blocks when they are not needed."
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit'

View file

@ -74,10 +74,10 @@ group :development, :test do
gem 'selenium-webdriver' gem 'selenium-webdriver'
# livereload on template changes (html, js, css) # livereload on template changes (html, js, css)
gem 'guard', '>= 2.2.2', :require => false gem 'guard', '>= 2.2.2', require: false
gem 'guard-livereload', :require => false gem 'guard-livereload', require: false
gem 'rack-livereload' gem 'rack-livereload'
gem 'rb-fsevent', :require => false gem 'rb-fsevent', require: false
# code QA # code QA
gem 'rubocop' gem 'rubocop'

View file

@ -1,7 +1,7 @@
# A sample Guardfile # A sample Guardfile
# More info at https://github.com/guard/guard#readme # More info at https://github.com/guard/guard#readme
guard 'livereload', :port => '35738' do guard 'livereload', port: '35738' do
watch(%r{app/views/.+\.(erb|haml|slim)$}) watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb}) watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)}) watch(%r{public/.+\.(css|js|html)})

View file

@ -8,7 +8,7 @@ class ActivityStreamController < ApplicationController
activity_stream = current_user.activity_stream( params[:limit], true ) activity_stream = current_user.activity_stream( params[:limit], true )
# return result # return result
render :json => activity_stream render json: activity_stream
end end
end end

View file

@ -41,7 +41,7 @@ class ApplicationController < ActionController::Base
headers['Access-Control-Allow-Headers'] = 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Accept-Language' headers['Access-Control-Allow-Headers'] = 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Accept-Language'
headers['Access-Control-Max-Age'] = '1728000' headers['Access-Control-Max-Age'] = '1728000'
headers['Access-Control-Allow-Credentials'] = 'true' headers['Access-Control-Allow-Credentials'] = 'true'
render :text => '', :content_type => 'text/plain' render text: '', content_type: 'text/plain'
return false return false
end end
end end
@ -123,20 +123,20 @@ class ApplicationController < ActionController::Base
# set basic auth user to current user # set basic auth user to current user
current_user_set(userdata) current_user_set(userdata)
return { return {
:auth => true auth: true
} }
end end
# return auth not ok # return auth not ok
return { return {
:auth => false, auth: false,
:message => message, message: message,
} }
end end
# check logon session # check logon session
if params['logon_session'] if params['logon_session']
logon_session = ActiveRecord::SessionStore::Session.where( :session_id => params['logon_session'] ).first logon_session = ActiveRecord::SessionStore::Session.where( session_id: params['logon_session'] ).first
if logon_session if logon_session
userdata = User.find( logon_session.data[:user_id] ) userdata = User.find( logon_session.data[:user_id] )
end end
@ -146,7 +146,7 @@ class ApplicationController < ActionController::Base
# set logon session user to current user # set logon session user to current user
current_user_set(userdata) current_user_set(userdata)
return { return {
:auth => true auth: true
} }
end end
@ -166,13 +166,13 @@ class ApplicationController < ActionController::Base
puts 'no valid session, user_id' puts 'no valid session, user_id'
message = 'no valid session, user_id' message = 'no valid session, user_id'
return { return {
:auth => false, auth: false,
:message => message, message: message,
} }
end end
return { return {
:auth => true auth: true
} }
end end
@ -182,10 +182,10 @@ class ApplicationController < ActionController::Base
# return auth not ok # return auth not ok
if result[:auth] == false if result[:auth] == false
render( render(
:json => { json: {
:error => result[:message], error: result[:message],
}, },
:status => :unauthorized status: :unauthorized
) )
return false return false
end end
@ -197,8 +197,8 @@ class ApplicationController < ActionController::Base
def authentication_check_action_token(action) def authentication_check_action_token(action)
user = Token.check( user = Token.check(
:action => action, action: action,
:name => params[:action_token], name: params[:action_token],
) )
if !user if !user
@ -219,7 +219,7 @@ class ApplicationController < ActionController::Base
end end
def ticket_permission(ticket) def ticket_permission(ticket)
return true if ticket.permission( :current_user => current_user ) return true if ticket.permission( current_user: current_user )
response_access_deny response_access_deny
false false
end end
@ -236,14 +236,14 @@ class ApplicationController < ActionController::Base
def valid_session_with_user def valid_session_with_user
return true if current_user return true if current_user
render :json => { :message => 'No session user!' }, :status => :unprocessable_entity render json: { message: 'No session user!' }, status: :unprocessable_entity
false false
end end
def response_access_deny def response_access_deny
render( render(
:json => {}, json: {},
:status => :unauthorized status: :unauthorized
) )
false false
end end
@ -252,7 +252,7 @@ class ApplicationController < ActionController::Base
# config # config
config = {} config = {}
Setting.select('name').where( :frontend => true ).each { |setting| Setting.select('name').where( frontend: true ).each { |setting|
config[setting.name] = Setting.get(setting.name) config[setting.name] = Setting.get(setting.name)
} }
@ -296,11 +296,11 @@ class ApplicationController < ActionController::Base
puts e.message.inspect puts e.message.inspect
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
def model_create_render_item (generic_object) def model_create_render_item (generic_object)
render :json => generic_object.attributes_with_associations, :status => :created render json: generic_object.attributes_with_associations, status: :created
end end
def model_update_render (object, params) def model_update_render (object, params)
@ -319,11 +319,11 @@ class ApplicationController < ActionController::Base
rescue Exception => e rescue Exception => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
def model_update_render_item (generic_object) def model_update_render_item (generic_object)
render :json => generic_object.attributes_with_associations, :status => :ok render json: generic_object.attributes_with_associations, status: :ok
end end
def model_destory_render (object, params) def model_destory_render (object, params)
@ -334,11 +334,11 @@ class ApplicationController < ActionController::Base
rescue Exception => e rescue Exception => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
def model_destory_render_item () def model_destory_render_item ()
render :json => {}, :status => :ok render json: {}, status: :ok
end end
def model_show_render (object, params) def model_show_render (object, params)
@ -346,7 +346,7 @@ class ApplicationController < ActionController::Base
if params[:full] if params[:full]
generic_object_full = object.full( params[:id] ) generic_object_full = object.full( params[:id] )
render :json => generic_object_full, :status => :ok render json: generic_object_full, status: :ok
return return
end end
@ -355,11 +355,11 @@ class ApplicationController < ActionController::Base
rescue Exception => e rescue Exception => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
def model_show_render_item (generic_object) def model_show_render_item (generic_object)
render :json => generic_object.attributes_with_associations, :status => :ok render json: generic_object.attributes_with_associations, status: :ok
end end
def model_index_render (object, params) def model_index_render (object, params)
@ -369,11 +369,11 @@ class ApplicationController < ActionController::Base
rescue Exception => e rescue Exception => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
def model_index_render_result (generic_objects) def model_index_render_result (generic_objects)
render :json => generic_objects, :status => :ok render json: generic_objects, status: :ok
end end
end end

View file

@ -44,12 +44,12 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# set system init to done # set system init to done
Setting.set( 'system_init_done', true ) Setting.set( 'system_init_done', true )
render :json => { render json: {
:auto_wizard => true, auto_wizard: true,
:setup_done => setup_done, setup_done: setup_done,
:import_mode => Setting.get('import_mode'), import_mode: Setting.get('import_mode'),
:import_backend => Setting.get('import_backend'), import_backend: Setting.get('import_backend'),
:system_online_service => Setting.get('system_online_service'), system_online_service: Setting.get('system_online_service'),
} }
return return
end end
@ -60,11 +60,11 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
# return result # return result
render :json => { render json: {
:setup_done => setup_done, setup_done: setup_done,
:import_mode => Setting.get('import_mode'), import_mode: Setting.get('import_mode'),
:import_backend => Setting.get('import_backend'), import_backend: Setting.get('import_backend'),
:system_online_service => Setting.get('system_online_service'), system_online_service: Setting.get('system_online_service'),
} }
end end
@ -97,9 +97,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
if !messages.empty? if !messages.empty?
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:messages => messages, messages: messages,
} }
return return
end end
@ -143,9 +143,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
Setting.set(key, value) Setting.set(key, value)
} }
render :json => { render json: {
:result => 'ok', result: 'ok',
:settings => settings, settings: settings,
} }
end end
@ -163,10 +163,10 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
if !user || !domain if !user || !domain
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:messages => { messages: {
:email => 'Invalid email.' email: 'Invalid email.'
}, },
} }
return return
@ -174,49 +174,49 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# check domain based attributes # check domain based attributes
providerMap = { providerMap = {
:google => { google: {
:domain => 'gmail.com|googlemail.com|gmail.de', domain: 'gmail.com|googlemail.com|gmail.de',
:inbound => { inbound: {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => 'imap.gmail.com', host: 'imap.gmail.com',
:port => '993', port: '993',
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
:outbound => { outbound: {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => 'smtp.gmail.com', host: 'smtp.gmail.com',
:port => '25', port: '25',
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
} }
}, },
}, },
:microsoft => { microsoft: {
:domain => 'outlook.com|hotmail.com', domain: 'outlook.com|hotmail.com',
:inbound => { inbound: {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => 'imap-mail.outlook.com', host: 'imap-mail.outlook.com',
:port => '993', port: '993',
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
:outbound => { outbound: {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => 'smtp-mail.outlook.com', host: 'smtp-mail.outlook.com',
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
} }
}, },
}, },
@ -238,20 +238,20 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# probe inbound # probe inbound
result = email_probe_inbound( settings[:inbound] ) result = email_probe_inbound( settings[:inbound] )
if result[:result] != 'ok' if result[:result] != 'ok'
render :json => result render json: result
return return
end end
# probe outbound # probe outbound
result = email_probe_outbound( settings[:outbound], params[:email] ) result = email_probe_outbound( settings[:outbound], params[:email] )
if result[:result] != 'ok' if result[:result] != 'ok'
render :json => result render json: result
return return
end end
render :json => { render json: {
:result => 'ok', result: 'ok',
:setting => settings, setting: settings,
} }
return return
end end
@ -263,23 +263,23 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0] if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
inboundMx = [ inboundMx = [
{ {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => mail_exchangers[0][0], host: mail_exchangers[0][0],
:port => 993, port: 993,
:ssl => true, ssl: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => mail_exchangers[0][0], host: mail_exchangers[0][0],
:port => 993, port: 993,
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
] ]
@ -287,103 +287,103 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
inboundAuto = [ inboundAuto = [
{ {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 993, port: 993,
:ssl => true, ssl: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 993, port: 993,
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => "imap.#{domain}", host: "imap.#{domain}",
:port => 993, port: 993,
:ssl => true, ssl: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'imap', adapter: 'imap',
:options => { options: {
:host => "imap.#{domain}", host: "imap.#{domain}",
:port => 993, port: 993,
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'pop3', adapter: 'pop3',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 995, port: 995,
:ssl => true, ssl: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'pop3', adapter: 'pop3',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 995, port: 995,
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'pop3', adapter: 'pop3',
:options => { options: {
:host => "pop.#{domain}", host: "pop.#{domain}",
:port => 995, port: 995,
:ssl => true, ssl: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'pop3', adapter: 'pop3',
:options => { options: {
:host => "pop.#{domain}", host: "pop.#{domain}",
:port => 995, port: 995,
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'pop3', adapter: 'pop3',
:options => { options: {
:host => "pop3.#{domain}", host: "pop3.#{domain}",
:port => 995, port: 995,
:ssl => true, ssl: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'pop3', adapter: 'pop3',
:options => { options: {
:host => "pop3.#{domain}", host: "pop3.#{domain}",
:port => 995, port: 995,
:ssl => true, ssl: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
] ]
@ -402,8 +402,8 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
} }
if !success if !success
render :json => { render json: {
:result => 'failed', result: 'failed',
} }
return return
end end
@ -413,43 +413,43 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0] if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
outboundMx = [ outboundMx = [
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => mail_exchangers[0][0], host: mail_exchangers[0][0],
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => mail_exchangers[0][0], host: mail_exchangers[0][0],
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => mail_exchangers[0][0], host: mail_exchangers[0][0],
:port => 465, port: 465,
:start_tls => true, start_tls: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => mail_exchangers[0][0], host: mail_exchangers[0][0],
:port => 465, port: 465,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
] ]
@ -457,83 +457,83 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
outboundAuto = [ outboundAuto = [
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 465, port: 465,
:start_tls => true, start_tls: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "mail.#{domain}", host: "mail.#{domain}",
:port => 465, port: 465,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "smtp.#{domain}", host: "smtp.#{domain}",
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "smtp.#{domain}", host: "smtp.#{domain}",
:port => 25, port: 25,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "smtp.#{domain}", host: "smtp.#{domain}",
:port => 465, port: 465,
:start_tls => true, start_tls: true,
:user => user, user: user,
:password => params[:password], password: params[:password],
}, },
}, },
{ {
:adapter => 'smtp', adapter: 'smtp',
:options => { options: {
:host => "smtp.#{domain}", host: "smtp.#{domain}",
:port => 465, port: 465,
:start_tls => true, start_tls: true,
:user => params[:email], user: params[:email],
:password => params[:password], password: params[:password],
}, },
}, },
] ]
@ -551,15 +551,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
} }
if !success if !success
render :json => { render json: {
:result => 'failed', result: 'failed',
} }
return return
end end
render :json => { render json: {
:result => 'ok', result: 'ok',
:setting => settings, setting: settings,
} }
end end
@ -570,8 +570,8 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# validate params # validate params
if !params[:adapter] if !params[:adapter]
render :json => { render json: {
:result => 'invalid', result: 'invalid',
} }
return return
end end
@ -579,7 +579,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# connection test # connection test
result = email_probe_outbound( params, params[:email] ) result = email_probe_outbound( params, params[:email] )
render :json => result render json: result
end end
def email_inbound def email_inbound
@ -589,8 +589,8 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# validate params # validate params
if !params[:adapter] if !params[:adapter]
render :json => { render json: {
:result => 'invalid', result: 'invalid',
} }
return return
end end
@ -598,7 +598,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# connection test # connection test
result = email_probe_inbound( params ) result = email_probe_inbound( params )
render :json => result render json: result
return return
end end
@ -623,15 +623,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
begin begin
if params[:inbound][:adapter] =~ /^imap$/i if params[:inbound][:adapter] =~ /^imap$/i
found = Channel::IMAP.new.fetch( { :options => params[:inbound][:options] }, 'verify', subject ) found = Channel::IMAP.new.fetch( { options: params[:inbound][:options] }, 'verify', subject )
else else
found = Channel::POP3.new.fetch( { :options => params[:inbound][:options] }, 'verify', subject ) found = Channel::POP3.new.fetch( { options: params[:inbound][:options] }, 'verify', subject )
end end
rescue Exception => e rescue Exception => e
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:message => e.to_s, message: e.to_s,
:subject => subject, subject: subject,
} }
return return
end end
@ -639,70 +639,70 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
if found && found == 'verify ok' if found && found == 'verify ok'
# remember address # remember address
address = EmailAddress.where( :email => params[:meta][:email] ).first address = EmailAddress.where( email: params[:meta][:email] ).first
if !address if !address
address = EmailAddress.first address = EmailAddress.first
end end
if address if address
address.update_attributes( address.update_attributes(
:realname => params[:meta][:realname], realname: params[:meta][:realname],
:email => params[:meta][:email], email: params[:meta][:email],
:active => 1, active: 1,
:updated_by_id => 1, updated_by_id: 1,
:created_by_id => 1, created_by_id: 1,
) )
else else
EmailAddress.create( EmailAddress.create(
:realname => params[:meta][:realname], realname: params[:meta][:realname],
:email => params[:meta][:email], email: params[:meta][:email],
:active => 1, active: 1,
:updated_by_id => 1, updated_by_id: 1,
:created_by_id => 1, created_by_id: 1,
) )
end end
# store mailbox # store mailbox
Channel.create( Channel.create(
:area => 'Email::Inbound', area: 'Email::Inbound',
:adapter => params[:inbound][:adapter], adapter: params[:inbound][:adapter],
:options => params[:inbound][:options], options: params[:inbound][:options],
:group_id => 1, group_id: 1,
:active => 1, active: 1,
:updated_by_id => 1, updated_by_id: 1,
:created_by_id => 1, created_by_id: 1,
) )
# save settings # save settings
if params[:outbound][:adapter] =~ /^smtp$/i if params[:outbound][:adapter] =~ /^smtp$/i
smtp = Channel.where( :adapter => 'SMTP', :area => 'Email::Outbound' ).first smtp = Channel.where( adapter: 'SMTP', area: 'Email::Outbound' ).first
smtp.options = params[:outbound][:options] smtp.options = params[:outbound][:options]
smtp.active = true smtp.active = true
smtp.save! smtp.save!
sendmail = Channel.where( :adapter => 'Sendmail' ).first sendmail = Channel.where( adapter: 'Sendmail' ).first
sendmail.active = false sendmail.active = false
sendmail.save! sendmail.save!
else else
sendmail = Channel.where( :adapter => 'Sendmail', :area => 'Email::Outbound' ).first sendmail = Channel.where( adapter: 'Sendmail', area: 'Email::Outbound' ).first
sendmail.options = {} sendmail.options = {}
sendmail.active = true sendmail.active = true
sendmail.save! sendmail.save!
smtp = Channel.where( :adapter => 'SMTP' ).first smtp = Channel.where( adapter: 'SMTP' ).first
smtp.active = false smtp.active = false
smtp.save smtp.save
end end
render :json => { render json: {
:result => 'ok', result: 'ok',
} }
return return
end end
} }
# check delivery for 30 sek. # check delivery for 30 sek.
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:message => 'Verification Email not found in mailbox.', message: 'Verification Email not found in mailbox.',
:subject => subject, subject: subject,
} }
end end
@ -713,8 +713,8 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# validate params # validate params
if !params[:adapter] if !params[:adapter]
result = { result = {
:result => 'invalid', result: 'invalid',
:message => 'Invalid, need adapter!', message: 'Invalid, need adapter!',
} }
return result return result
end end
@ -729,10 +729,10 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
} }
else else
mail = { mail = {
:from => email, from: email,
:to => 'emailtrytest@znuny.com', to: 'emailtrytest@znuny.com',
:subject => 'test', subject: 'test',
:body => 'test', body: 'test',
} }
end end
@ -758,7 +758,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
Channel::SMTP.new.send( Channel::SMTP.new.send(
mail, mail,
{ {
:options => params[:options] options: params[:options]
} }
) )
rescue Exception => e rescue Exception => e
@ -771,9 +771,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
whiteMap.each {|key, message| whiteMap.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
result = { result = {
:result => 'ok', result: 'ok',
:settings => params, settings: params,
:notice => e.message, notice: e.message,
} }
return result return result
end end
@ -786,15 +786,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
} }
result = { result = {
:result => 'invalid', result: 'invalid',
:settings => params, settings: params,
:message => e.message, message: e.message,
:message_human => message_human, message_human: message_human,
} }
return result return result
end end
result = { result = {
:result => 'ok', result: 'ok',
} }
return result return result
end end
@ -812,15 +812,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
} }
result = { result = {
:result => 'invalid', result: 'invalid',
:settings => params, settings: params,
:message => e.message, message: e.message,
:message_human => message_human, message_human: message_human,
} }
return result return result
end end
result = { result = {
:result => 'ok', result: 'ok',
} }
return result return result
end end
@ -843,7 +843,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
if params[:adapter] =~ /^imap$/i if params[:adapter] =~ /^imap$/i
begin begin
Channel::IMAP.new.fetch( { :options => params[:options] }, 'check' ) Channel::IMAP.new.fetch( { options: params[:options] }, 'check' )
rescue Exception => e rescue Exception => e
message_human = '' message_human = ''
translationMap.each {|key, message| translationMap.each {|key, message|
@ -852,21 +852,21 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
} }
result = { result = {
:result => 'invalid', result: 'invalid',
:settings => params, settings: params,
:message => e.message, message: e.message,
:message_human => message_human, message_human: message_human,
} }
return result return result
end end
result = { result = {
:result => 'ok', result: 'ok',
} }
return result return result
end end
begin begin
Channel::POP3.new.fetch( { :options => params[:options] }, 'check' ) Channel::POP3.new.fetch( { options: params[:options] }, 'check' )
rescue Exception => e rescue Exception => e
message_human = '' message_human = ''
translationMap.each {|key, message| translationMap.each {|key, message|
@ -875,15 +875,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
} }
result = { result = {
:result => 'invalid', result: 'invalid',
:settings => params, settings: params,
:message => e.message, message: e.message,
:message_human => message_human, message_human: message_human,
} }
return result return result
end end
result = { result = {
:result => 'ok', result: 'ok',
} }
return result return result
end end
@ -917,18 +917,18 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
# get all groups # get all groups
groups = Group.where( :active => true ) groups = Group.where( active: true )
# get email addresses # get email addresses
addresses = EmailAddress.where( :active => true ) addresses = EmailAddress.where( active: true )
render :json => { render json: {
:setup_done => true, setup_done: true,
:import_mode => Setting.get('import_mode'), import_mode: Setting.get('import_mode'),
:import_backend => Setting.get('import_backend'), import_backend: Setting.get('import_backend'),
:system_online_service => Setting.get('system_online_service'), system_online_service: Setting.get('system_online_service'),
:addresses => addresses, addresses: addresses,
:groups => groups, groups: groups,
} }
true true
end end

View file

@ -74,8 +74,8 @@ class IcalTicketsController < ApplicationController
condition = { condition = {
'tickets.owner_id' => current_user.id, 'tickets.owner_id' => current_user.id,
'tickets.state_id' => Ticket::State.where( 'tickets.state_id' => Ticket::State.where(
:state_type_id => Ticket::StateType.where( state_type_id: Ticket::StateType.where(
:name => [ name: [
'new', 'new',
'open', 'open',
], ],
@ -84,8 +84,8 @@ class IcalTicketsController < ApplicationController
} }
tickets = Ticket.search( tickets = Ticket.search(
:current_user => current_user, current_user: current_user,
:condition => condition, condition: condition,
) )
events_data = [] events_data = []
@ -109,8 +109,8 @@ class IcalTicketsController < ApplicationController
condition = { condition = {
'tickets.owner_id' => current_user.id, 'tickets.owner_id' => current_user.id,
'tickets.state_id' => Ticket::State.where( 'tickets.state_id' => Ticket::State.where(
:state_type_id => Ticket::StateType.where( state_type_id: Ticket::StateType.where(
:name => [ name: [
'pending reminder', 'pending reminder',
'pending action', 'pending action',
], ],
@ -119,8 +119,8 @@ class IcalTicketsController < ApplicationController
} }
tickets = Ticket.search( tickets = Ticket.search(
:current_user => current_user, current_user: current_user,
:condition => condition, condition: condition,
) )
events_data = [] events_data = []
@ -148,8 +148,8 @@ class IcalTicketsController < ApplicationController
] ]
tickets = Ticket.search( tickets = Ticket.search(
:current_user => current_user, current_user: current_user,
:condition => condition, condition: condition,
) )
events_data = [] events_data = []
@ -186,9 +186,9 @@ class IcalTicketsController < ApplicationController
send_data( send_data(
cal.to_ical, cal.to_ical,
:filename => 'zammad.ical', filename: 'zammad.ical',
:type => 'text/plain', type: 'text/plain',
:disposition => 'inline' disposition: 'inline'
) )
end end

View file

@ -8,9 +8,9 @@ class ImportOtrsController < ApplicationController
# validate # validate
if !params[:url] ||params[:url] !~ /^(http|https):\/\/.+?$/ if !params[:url] ||params[:url] !~ /^(http|https):\/\/.+?$/
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:message => 'Invalid!', message: 'Invalid!',
} }
return return
end end
@ -32,10 +32,10 @@ class ImportOtrsController < ApplicationController
message_human = message message_human = message
end end
} }
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:message_human => message_human, message_human: message_human,
:message => response.error.to_s, message: response.error.to_s,
} }
return return
end end
@ -53,9 +53,9 @@ class ImportOtrsController < ApplicationController
Setting.set('import_otrs_endpoint', url) Setting.set('import_otrs_endpoint', url)
Setting.set('import_otrs_endpoint_key', '01234567899876543210') Setting.set('import_otrs_endpoint_key', '01234567899876543210')
if response.body =~ /zammad migrator/ if response.body =~ /zammad migrator/
render :json => { render json: {
:url => url, url: url,
:result => 'ok', result: 'ok',
} }
return return
elsif response.body =~ /(otrs\sag|otrs.com|otrs.org)/i elsif response.body =~ /(otrs\sag|otrs.com|otrs.org)/i
@ -65,9 +65,9 @@ class ImportOtrsController < ApplicationController
# return result # return result
render :json => { render json: {
:result => 'invalid', result: 'invalid',
:message_human => message_human, message_human: message_human,
} }
end end
@ -77,9 +77,9 @@ class ImportOtrsController < ApplicationController
Setting.set('import_mode', true) Setting.set('import_mode', true)
welcome = Import::OTRS2.connection_test welcome = Import::OTRS2.connection_test
if !welcome if !welcome
render :json => { render json: {
:message => 'Migrator can\'t read OTRS output!', message: 'Migrator can\'t read OTRS output!',
:result => 'invalid', result: 'invalid',
} }
return return
end end
@ -87,8 +87,8 @@ class ImportOtrsController < ApplicationController
# start migration # start migration
Import::OTRS2.delay.start Import::OTRS2.delay.start
render :json => { render json: {
:result => 'ok', result: 'ok',
} }
end end
@ -97,9 +97,9 @@ class ImportOtrsController < ApplicationController
state = Import::OTRS2.get_current_state state = Import::OTRS2.get_current_state
render :json => { render json: {
:data => state, data: state,
:result => 'in_progress', result: 'in_progress',
} }
end end
@ -119,8 +119,8 @@ class ImportOtrsController < ApplicationController
if !setup_done if !setup_done
return false return false
end end
render :json => { render json: {
:setup_done => true, setup_done: true,
} }
true true
end end

View file

@ -6,8 +6,8 @@ class LinksController < ApplicationController
# GET /api/v1/links # GET /api/v1/links
def index def index
links = Link.list( links = Link.list(
:link_object => params[:link_object], link_object: params[:link_object],
:link_object_value => params[:link_object_value], link_object_value: params[:link_object_value],
) )
assets = {} assets = {}
@ -15,15 +15,15 @@ class LinksController < ApplicationController
links.each { |item| links.each { |item|
link_list.push item link_list.push item
if item['link_object'] == 'Ticket' if item['link_object'] == 'Ticket'
ticket = Ticket.lookup( :id => item['link_object_value'] ) ticket = Ticket.lookup( id: item['link_object_value'] )
assets = ticket.assets(assets) assets = ticket.assets(assets)
end end
} }
# return result # return result
render :json => { render json: {
:links => link_list, links: link_list,
:assets => assets, assets: assets,
} }
end end
@ -31,19 +31,19 @@ class LinksController < ApplicationController
def add def add
# lookup object id # lookup object id
object_id = Ticket.where( :number => params[:link_object_source_number] ).first.id object_id = Ticket.where( number: params[:link_object_source_number] ).first.id
link = Link.add( link = Link.add(
:link_type => params[:link_type], link_type: params[:link_type],
:link_object_target => params[:link_object_target], link_object_target: params[:link_object_target],
:link_object_target_value => params[:link_object_target_value], link_object_target_value: params[:link_object_target_value],
:link_object_source => params[:link_object_source], link_object_source: params[:link_object_source],
:link_object_source_value => object_id link_object_source_value: object_id
) )
if link if link
render :json => link, :status => :created render json: link, status: :created
else else
render :json => link.errors, :status => :unprocessable_entity render json: link.errors, status: :unprocessable_entity
end end
end end
@ -52,9 +52,9 @@ class LinksController < ApplicationController
link = Link.remove(params) link = Link.remove(params)
if link if link
render :json => link, :status => :created render json: link, status: :created
else else
render :json => link.errors, :status => :unprocessable_entity render json: link.errors, status: :unprocessable_entity
end end
end end

View file

@ -50,7 +50,7 @@ class LongPollingController < ApplicationController
# send spool:sent event to client # send spool:sent event to client
sleep 0.2 sleep 0.2
log 'notice', 'send spool:sent event', client_id log 'notice', 'send spool:sent event', client_id
Sessions.send( client_id, { :event => 'spool:sent', :data => { :timestamp => Time.now.utc.to_i } } ) Sessions.send( client_id, { event: 'spool:sent', data: { timestamp: Time.now.utc.to_i } } )
end end
@ -62,7 +62,7 @@ class LongPollingController < ApplicationController
user = User.find( user_id ).attributes user = User.find( user_id ).attributes
end end
log 'notice', "send auth login (user_id #{user_id})", client_id log 'notice', "send auth login (user_id #{user_id})", client_id
Sessions.create( client_id, user, { :type => 'ajax' } ) Sessions.create( client_id, user, { type: 'ajax' } )
# broadcast # broadcast
elsif params['data']['action'] == 'broadcast' elsif params['data']['action'] == 'broadcast'
@ -92,10 +92,10 @@ class LongPollingController < ApplicationController
end end
if new_connection if new_connection
result = { :client_id => client_id } result = { client_id: client_id }
render :json => result render json: result
else else
render :json => {} render json: {}
end end
end end
@ -105,7 +105,7 @@ class LongPollingController < ApplicationController
# check client id # check client id
client_id = client_id_verify client_id = client_id_verify
if !client_id if !client_id
render :json => { :error => 'Invalid client_id receive!' }, :status => :unprocessable_entity render json: { error: 'Invalid client_id receive!' }, status: :unprocessable_entity
return return
end end
@ -126,7 +126,7 @@ class LongPollingController < ApplicationController
queue = Sessions.queue( client_id ) queue = Sessions.queue( client_id )
if queue && queue[0] if queue && queue[0]
# puts "send " + queue.inspect + client_id.to_s # puts "send " + queue.inspect + client_id.to_s
render :json => queue render json: queue
return return
end end
8.times {|loop| 8.times {|loop|
@ -134,14 +134,14 @@ class LongPollingController < ApplicationController
} }
#sleep 2 #sleep 2
if count == 0 if count == 0
render :json => { :action => 'pong' } render json: { action: 'pong' }
return return
end end
end end
rescue Exception => e rescue Exception => e
puts e.inspect puts e.inspect
puts e.backtrace puts e.backtrace
render :json => { :error => 'Invalid client_id in receive loop!' }, :status => :unprocessable_entity render json: { error: 'Invalid client_id in receive loop!' }, status: :unprocessable_entity
return return
end end
end end

View file

@ -10,7 +10,7 @@ class NetworksController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render :json => @networks } format.json { render json: @networks }
end end
end end
@ -21,7 +21,7 @@ class NetworksController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.json { render :json => @network } format.json { render json: @network }
end end
end end
@ -32,7 +32,7 @@ class NetworksController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render :json => @network } format.json { render json: @network }
end end
end end
@ -48,11 +48,11 @@ class NetworksController < ApplicationController
respond_to do |format| respond_to do |format|
if @network.save if @network.save
format.html { redirect_to @network, :notice => 'Network was successfully created.' } format.html { redirect_to @network, notice: 'Network was successfully created.' }
format.json { render :json => @network, :status => :created } format.json { render json: @network, status: :created }
else else
format.html { render :action => 'new' } format.html { render action: 'new' }
format.json { render :json => @network.errors, :status => :unprocessable_entity } format.json { render json: @network.errors, status: :unprocessable_entity }
end end
end end
end end
@ -64,11 +64,11 @@ class NetworksController < ApplicationController
respond_to do |format| respond_to do |format|
if @network.update_attributes(params[:network]) if @network.update_attributes(params[:network])
format.html { redirect_to @network, :notice => 'Network was successfully updated.' } format.html { redirect_to @network, notice: 'Network was successfully updated.' }
format.json { render :json => @network, :status => :ok } format.json { render json: @network, status: :ok }
else else
format.html { render :action => 'edit' } format.html { render action: 'edit' }
format.json { render :json => @network.errors, :status => :unprocessable_entity } format.json { render json: @network.errors, status: :unprocessable_entity }
end end
end end
end end

View file

@ -7,8 +7,8 @@ class ObjectManagerAttributesController < ApplicationController
# GET /object_manager_attributes_list # GET /object_manager_attributes_list
def list def list
return if deny_if_not_role(Z_ROLENAME_ADMIN) return if deny_if_not_role(Z_ROLENAME_ADMIN)
render :json => { render json: {
:objects => ObjectManager.listFrontendObjects, objects: ObjectManager.listFrontendObjects,
} }
#model_index_render(ObjectManager::Attribute, params) #model_index_render(ObjectManager::Attribute, params)
end end
@ -16,7 +16,7 @@ class ObjectManagerAttributesController < ApplicationController
# GET /object_manager_attributes # GET /object_manager_attributes
def index def index
return if deny_if_not_role(Z_ROLENAME_ADMIN) return if deny_if_not_role(Z_ROLENAME_ADMIN)
render :json => ObjectManager::Attribute.list_full render json: ObjectManager::Attribute.list_full
#model_index_render(ObjectManager::Attribute, params) #model_index_render(ObjectManager::Attribute, params)
end end

View file

@ -48,7 +48,7 @@ curl http://localhost/api/v1/online_notifications.json -v -u #{login}:#{password
def index def index
if params[:full] if params[:full]
render :json => OnlineNotification.list_full(current_user, 50) render json: OnlineNotification.list_full(current_user, 50)
return return
end end
@ -108,10 +108,10 @@ curl http://localhost/api/v1/online_notifications/mark_all_as_read -v -u #{login
notifications = OnlineNotification.list(current_user,100) notifications = OnlineNotification.list(current_user,100)
notifications.each do |notification| notifications.each do |notification|
if !notification['seen'] if !notification['seen']
OnlineNotification.seen( :id => notification['id'] ) OnlineNotification.seen( id: notification['id'] )
end end
end end
render :json => {}, :status => :ok render json: {}, status: :ok
end end
end end

View file

@ -52,12 +52,12 @@ curl http://localhost/api/v1/organizations.json -v -u #{login}:#{password}
organizations = [] organizations = []
if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT) if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT)
if current_user.organization_id if current_user.organization_id
organizations = Organization.where( :id => current_user.organization_id ) organizations = Organization.where( id: current_user.organization_id )
end end
else else
organizations = Organization.all organizations = Organization.all
end end
render :json => organizations render json: organizations
end end
=begin =begin
@ -82,7 +82,7 @@ curl http://localhost/api/v1/organizations/#{id}.json -v -u #{login}:#{password}
# only allow customer to fetch his own organization # only allow customer to fetch his own organization
if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT) if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT)
if !current_user.organization_id if !current_user.organization_id
render :json => {} render json: {}
return return
end end
if params[:id].to_i != current_user.organization_id if params[:id].to_i != current_user.organization_id
@ -92,7 +92,7 @@ curl http://localhost/api/v1/organizations/#{id}.json -v -u #{login}:#{password}
end end
if params[:full] if params[:full]
full = Organization.full( params[:id] ) full = Organization.full( params[:id] )
render :json => full render json: full
return return
end end
model_show_render(Organization, params) model_show_render(Organization, params)
@ -190,7 +190,7 @@ Test:
history = organization.history_get(true) history = organization.history_get(true)
# return result # return result
render :json => history render json: history
end end
end end

View file

@ -7,8 +7,8 @@ class PackagesController < ApplicationController
def index def index
return if deny_if_not_role(Z_ROLENAME_ADMIN) return if deny_if_not_role(Z_ROLENAME_ADMIN)
packages = Package.all().order('name') packages = Package.all().order('name')
render :json => { render json: {
:packages => packages packages: packages
} }
end end
@ -16,7 +16,7 @@ class PackagesController < ApplicationController
def install def install
return if deny_if_not_role(Z_ROLENAME_ADMIN) return if deny_if_not_role(Z_ROLENAME_ADMIN)
Package.install( :string => params[:file_upload].read ) Package.install( string: params[:file_upload].read )
redirect_to '/#system/package' redirect_to '/#system/package'
end end
@ -27,10 +27,10 @@ class PackagesController < ApplicationController
package = Package.find( params[:id] ) package = Package.find( params[:id] )
Package.uninstall( :name => package.name, :version => package.version ) Package.uninstall( name: package.name, version: package.version )
render :json => { render json: {
:success => true success: true
} }
end end

View file

@ -22,7 +22,7 @@ curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-
recent_viewed = RecentView.list_full( current_user, 10 ) recent_viewed = RecentView.list_full( current_user, 10 )
# return result # return result
render :json => recent_viewed render json: recent_viewed
end end
=begin =begin
@ -49,7 +49,7 @@ curl http://localhost/api/v1/recent_view -v -u #{login}:#{password} -H "Content-
RecentView.log( params[:object], params[:o_id], current_user ) RecentView.log( params[:object], params[:o_id], current_user )
# return result # return result
render :json => { :message => 'ok' } render json: { message: 'ok' }
end end
end end

View file

@ -21,10 +21,10 @@ curl http://localhost/api/v1/rss_fetch.json -v -u #{login}:#{password} -H "Conte
def fetch def fetch
items = Rss.fetch(params[:url], params[:limit]) items = Rss.fetch(params[:url], params[:limit])
if items == nil if items == nil
render :json => { :message => "failed to fetch #{ params[:url] }", :status => :unprocessable_entity } render json: { message: "failed to fetch #{ params[:url] }", status: :unprocessable_entity }
return return
end end
render :json => { :items => items } render json: { items: items }
end end
end end

View file

@ -30,40 +30,40 @@ class SearchController < ApplicationController
else else
# do query # do query
users = User.search( users = User.search(
:query => query, query: query,
:limit => limit, limit: limit,
:current_user => current_user, current_user: current_user,
) )
user_result = [] user_result = []
users.each do |user| users.each do |user|
item = { item = {
:id => user.id, id: user.id,
:type => user.class.to_s type: user.class.to_s
} }
result.push item result.push item
assets = user.assets(assets) assets = user.assets(assets)
end end
organizations = Organization.search( organizations = Organization.search(
:query => query, query: query,
:limit => limit, limit: limit,
:current_user => current_user, current_user: current_user,
) )
organization_result = [] organization_result = []
organizations.each do |organization| organizations.each do |organization|
item = { item = {
:id => organization.id, id: organization.id,
:type => organization.class.to_s type: organization.class.to_s
} }
result.push item result.push item
assets = organization.assets(assets) assets = organization.assets(assets)
end end
end end
render :json => { render json: {
:assets => assets, assets: assets,
:result => result, result: result,
} }
end end
@ -72,9 +72,9 @@ class SearchController < ApplicationController
# build result list # build result list
tickets = Ticket.search( tickets = Ticket.search(
:limit => params[:limit], limit: params[:limit],
:query => params[:term], query: params[:term],
:current_user => current_user, current_user: current_user,
) )
assets = {} assets = {}
ticket_result = [] ticket_result = []
@ -85,9 +85,9 @@ class SearchController < ApplicationController
# do query # do query
users = User.search( users = User.search(
:query => params[:term], query: params[:term],
:limit => params[:limit], limit: params[:limit],
:current_user => current_user, current_user: current_user,
) )
user_result = [] user_result = []
users.each do |user| users.each do |user|
@ -96,9 +96,9 @@ class SearchController < ApplicationController
end end
organizations = Organization.search( organizations = Organization.search(
:query => params[:term], query: params[:term],
:limit => params[:limit], limit: params[:limit],
:current_user => current_user, current_user: current_user,
) )
organization_result = [] organization_result = []
@ -110,30 +110,30 @@ class SearchController < ApplicationController
result = [] result = []
if ticket_result[0] if ticket_result[0]
data = { data = {
:name => 'Ticket', name: 'Ticket',
:ids => ticket_result, ids: ticket_result,
} }
result.push data result.push data
end end
if user_result[0] if user_result[0]
data = { data = {
:name => 'User', name: 'User',
:ids => user_result, ids: user_result,
} }
result.push data result.push data
end end
if organization_result[0] if organization_result[0]
data = { data = {
:name => 'Organization', name: 'Organization',
:ids => organization_result, ids: organization_result,
} }
result.push data result.push data
end end
# return result # return result
render :json => { render json: {
:assets => assets, assets: assets,
:result => result, result: result,
} }
end end

View file

@ -4,9 +4,9 @@ module ExtraCollection
def session( collections, assets, user ) def session( collections, assets, user )
# all base stuff # all base stuff
collections[ Locale.to_app_model ] = Locale.where( :active => true ) collections[ Locale.to_app_model ] = Locale.where( active: true )
collections[ Taskbar.to_app_model ] = Taskbar.where( :user_id => user.id ) collections[ Taskbar.to_app_model ] = Taskbar.where( user_id: user.id )
collections[ Taskbar.to_app_model ].each {|item| collections[ Taskbar.to_app_model ].each {|item|
assets = item.assets(assets) assets = item.assets(assets)
} }
@ -34,7 +34,7 @@ module ExtraCollection
else else
if user.organization_id if user.organization_id
collections[ Organization.to_app_model ] = [] collections[ Organization.to_app_model ] = []
Organization.where( :id => user.organization_id ).each {|item| Organization.where( id: user.organization_id ).each {|item|
assets = item.assets(assets) assets = item.assets(assets)
} }
end end

View file

@ -13,7 +13,7 @@ class SessionsController < ApplicationController
# auth failed # auth failed
if !user if !user
render :json => { :error => 'login failed' }, :status => :unauthorized render json: { error: 'login failed' }, status: :unauthorized
return return
end end
@ -55,14 +55,14 @@ class SessionsController < ApplicationController
end end
# return new session data # return new session data
render :json => { render json: {
:session => user, session: user,
:models => models, models: models,
:collections => collections, collections: collections,
:assets => assets, assets: assets,
:logon_session => logon_session_key, logon_session: logon_session_key,
}, },
:status => :created status: :created
end end
def show def show
@ -86,10 +86,10 @@ class SessionsController < ApplicationController
# get models # get models
models = SessionHelper::models() models = SessionHelper::models()
render :json => { render json: {
:error => 'no valid session', error: 'no valid session',
:config => config_frontend, config: config_frontend,
:models => models, models: models,
} }
return return
end end
@ -108,12 +108,12 @@ class SessionsController < ApplicationController
models = SessionHelper::models(user) models = SessionHelper::models(user)
# return current session # return current session
render :json => { render json: {
:session => user, session: user,
:models => models, models: models,
:collections => collections, collections: collections,
:assets => assets, assets: assets,
:config => config_frontend, config: config_frontend,
} }
end end
@ -127,7 +127,7 @@ class SessionsController < ApplicationController
request.env['rack.session.options'][:expire_after] = -1.year request.env['rack.session.options'][:expire_after] = -1.year
request.env['rack.session.options'][:renew] = true request.env['rack.session.options'][:renew] = true
render :json => { } render json: { }
end end
def create_omniauth def create_omniauth
@ -195,17 +195,17 @@ class SessionsController < ApplicationController
# check user # check user
if !params[:id] if !params[:id]
render( render(
:json => { :message => 'no user given' }, json: { message: 'no user given' },
:status => :not_found status: :not_found
) )
return false return false
end end
user = User.lookup( :id => params[:id] ) user = User.lookup( id: params[:id] )
if !user if !user
render( render(
:json => {}, json: {},
:status => :not_found status: :not_found
) )
return false return false
end end
@ -231,11 +231,11 @@ class SessionsController < ApplicationController
return false return false
end end
user = User.lookup( :id => session[:switched_from_user_id] ) user = User.lookup( id: session[:switched_from_user_id] )
if !user if !user
render( render(
:json => {}, json: {},
:status => :not_found status: :not_found
) )
return false return false
end end
@ -263,20 +263,20 @@ class SessionsController < ApplicationController
next if !session.data['user_id'] next if !session.data['user_id']
sessions_clean.push session sessions_clean.push session
if session.data['user_id'] if session.data['user_id']
user = User.lookup( :id => session.data['user_id'] ) user = User.lookup( id: session.data['user_id'] )
assets = user.assets( assets ) assets = user.assets( assets )
end end
} }
render :json => { render json: {
:sessions => sessions_clean, sessions: sessions_clean,
:assets => assets, assets: assets,
} }
end end
def delete def delete
return if deny_if_not_role(Z_ROLENAME_ADMIN) return if deny_if_not_role(Z_ROLENAME_ADMIN)
SessionHelper::destroy( params[:id] ) SessionHelper::destroy( params[:id] )
render :json => {} render json: {}
end end
end end

View file

@ -8,49 +8,49 @@ class TagsController < ApplicationController
list = Tag.list() list = Tag.list()
# return result # return result
render :json => { render json: {
:tags => list, tags: list,
} }
end end
# GET /api/v1/tags # GET /api/v1/tags
def list def list
list = Tag.tag_list( list = Tag.tag_list(
:object => params[:object], object: params[:object],
:o_id => params[:o_id], o_id: params[:o_id],
) )
# return result # return result
render :json => { render json: {
:tags => list, tags: list,
} }
end end
# POST /api/v1/tag/add # POST /api/v1/tag/add
def add def add
success = Tag.tag_add( success = Tag.tag_add(
:object => params[:object], object: params[:object],
:o_id => params[:o_id], o_id: params[:o_id],
:item => params[:item], item: params[:item],
); );
if success if success
render :json => success, :status => :created render json: success, status: :created
else else
render :json => success.errors, :status => :unprocessable_entity render json: success.errors, status: :unprocessable_entity
end end
end end
# DELETE /api/v1/tag/remove # DELETE /api/v1/tag/remove
def remove def remove
success = Tag.tag_remove( success = Tag.tag_remove(
:object => params[:object], object: params[:object],
:o_id => params[:o_id], o_id: params[:o_id],
:item => params[:item], item: params[:item],
); );
if success if success
render :json => success, :status => :created render json: success, status: :created
else else
render :json => success.errors, :status => :unprocessable_entity render json: success.errors, status: :unprocessable_entity
end end
end end

View file

@ -5,7 +5,7 @@ class TaskbarController < ApplicationController
def index def index
current_user_tasks = Taskbar.where( :user_id => current_user.id ) current_user_tasks = Taskbar.where( user_id: current_user.id )
model_index_render_result(current_user_tasks) model_index_render_result(current_user_tasks)
end end
@ -40,7 +40,7 @@ class TaskbarController < ApplicationController
private private
def access(taskbar) def access(taskbar)
if taskbar.user_id != current_user.id if taskbar.user_id != current_user.id
render :json => { :error => 'Not allowed to access this task.' }, :status => :unprocessable_entity render json: { error: 'Not allowed to access this task.' }, status: :unprocessable_entity
return false return false
end end
return true return true

View file

@ -5,8 +5,8 @@ class TestsController < ApplicationController
# GET /test/wait # GET /test/wait
def wait def wait
sleep params[:sec].to_i sleep params[:sec].to_i
result = { :success => true } result = { success: true }
render :json => result render json: result
end end
end end

View file

@ -7,14 +7,14 @@ class TicketArticlesController < ApplicationController
def index def index
@articles = Ticket::Article.all @articles = Ticket::Article.all
render :json => @articles render json: @articles
end end
# GET /articles/1 # GET /articles/1
def show def show
@article = Ticket::Article.find( params[:id] ) @article = Ticket::Article.find( params[:id] )
render :json => @article render json: @article
end end
# POST /articles # POST /articles
@ -26,8 +26,8 @@ class TicketArticlesController < ApplicationController
# find attachments in upload cache # find attachments in upload cache
if form_id if form_id
@article.attachments = Store.list( @article.attachments = Store.list(
:object => 'UploadCache', object: 'UploadCache',
:o_id => form_id, o_id: form_id,
) )
end end
@ -35,13 +35,13 @@ class TicketArticlesController < ApplicationController
# remove attachments from upload cache # remove attachments from upload cache
Store.remove( Store.remove(
:object => 'UploadCache', object: 'UploadCache',
:o_id => form_id, o_id: form_id,
) )
render :json => @article, :status => :created render json: @article, status: :created
else else
render :json => @article.errors, :status => :unprocessable_entity render json: @article.errors, status: :unprocessable_entity
end end
end end
@ -50,9 +50,9 @@ class TicketArticlesController < ApplicationController
@article = Ticket::Article.find( params[:id] ) @article = Ticket::Article.find( params[:id] )
if @article.update_attributes( Ticket::Article.param_validation( params[:ticket_article] ) ) if @article.update_attributes( Ticket::Article.param_validation( params[:ticket_article] ) )
render :json => @article, :status => :ok render json: @article, status: :ok
else else
render :json => @article.errors, :status => :unprocessable_entity render json: @article.errors, status: :unprocessable_entity
end end
end end
@ -69,8 +69,8 @@ class TicketArticlesController < ApplicationController
Store.remove_item( params[:store_id] ) Store.remove_item( params[:store_id] )
# return result # return result
render :json => { render json: {
:success => true, success: true,
} }
end end
@ -91,20 +91,20 @@ class TicketArticlesController < ApplicationController
'Content-Type' => content_type 'Content-Type' => content_type
} }
store = Store.add( store = Store.add(
:object => 'UploadCache', object: 'UploadCache',
:o_id => params[:form_id], o_id: params[:form_id],
:data => file.read, data: file.read,
:filename => file.original_filename, filename: file.original_filename,
:preferences => headers_store preferences: headers_store
) )
# return result # return result
render :json => { render json: {
:success => true, success: true,
:data => { data: {
:store_id => store.id, store_id: store.id,
:filename => file.original_filename, filename: file.original_filename,
:size => store.size, size: store.size,
} }
} }
end end
@ -115,12 +115,12 @@ class TicketArticlesController < ApplicationController
# permissin check # permissin check
ticket = Ticket.find( params[:ticket_id] ) ticket = Ticket.find( params[:ticket_id] )
if !ticket_permission(ticket) if !ticket_permission(ticket)
render( :json => 'No such ticket.', :status => :unauthorized ) render( json: 'No such ticket.', status: :unauthorized )
return return
end end
article = Ticket::Article.find( params[:article_id] ) article = Ticket::Article.find( params[:article_id] )
if ticket.id != article.ticket_id if ticket.id != article.ticket_id
render( :json => 'No access, article_id/ticket_id is not matching.', :status => :unauthorized ) render( json: 'No access, article_id/ticket_id is not matching.', status: :unauthorized )
return return
end end
@ -132,7 +132,7 @@ class TicketArticlesController < ApplicationController
end end
} }
if !access if !access
render( :json => 'Requested file id is not linked with article_id.', :status => :unauthorized ) render( json: 'Requested file id is not linked with article_id.', status: :unauthorized )
return return
end end
@ -140,9 +140,9 @@ class TicketArticlesController < ApplicationController
file = Store.find(params[:id]) file = Store.find(params[:id])
send_data( send_data(
file.content, file.content,
:filename => file.filename, filename: file.filename,
:type => file.preferences['Content-Type'] || file.preferences['Mime-Type'], type: file.preferences['Content-Type'] || file.preferences['Mime-Type'],
:disposition => 'inline' disposition: 'inline'
) )
end end
@ -154,8 +154,8 @@ class TicketArticlesController < ApplicationController
return if !ticket_permission( article.ticket ) return if !ticket_permission( article.ticket )
list = Store.list( list = Store.list(
:object => 'Ticket::Article::Mail', object: 'Ticket::Article::Mail',
:o_id => params[:id], o_id: params[:id],
) )
# find file # find file
@ -163,9 +163,9 @@ class TicketArticlesController < ApplicationController
file = Store.find(list.first) file = Store.find(list.first)
send_data( send_data(
file.content, file.content,
:filename => file.filename, filename: file.filename,
:type => 'message/rfc822', type: 'message/rfc822',
:disposition => 'inline' disposition: 'inline'
) )
end end
end end

View file

@ -11,53 +11,53 @@ class TicketOverviewsController < ApplicationController
# get navbar overview data # get navbar overview data
if !params[:view] if !params[:view]
result = Ticket::Overviews.list( result = Ticket::Overviews.list(
:current_user => current_user, current_user: current_user,
) )
render :json => result render json: result
return return
end end
# get real overview data # get real overview data
if params[:array] if params[:array]
overview = Ticket::Overviews.list( overview = Ticket::Overviews.list(
:view => params[:view], view: params[:view],
:current_user => current_user, current_user: current_user,
:array => true, array: true,
) )
tickets = [] tickets = []
overview[:tickets].each {|ticket_id| overview[:tickets].each {|ticket_id|
data = { :id => ticket_id } data = { id: ticket_id }
tickets.push data tickets.push data
} }
# return result # return result
render :json => { render json: {
:overview => overview[:overview], overview: overview[:overview],
:tickets => tickets, tickets: tickets,
:tickets_count => overview[:tickets_count], tickets_count: overview[:tickets_count],
} }
return return
end end
overview = Ticket::Overviews.list( overview = Ticket::Overviews.list(
:view => params[:view], view: params[:view],
:current_user => current_user, current_user: current_user,
:array => true, array: true,
) )
if !overview if !overview
render :json => { :error => "No such view #{ params[:view] }!" }, :status => :unprocessable_entity render json: { error: "No such view #{ params[:view] }!" }, status: :unprocessable_entity
return return
end end
# get related users # get related users
assets = {} assets = {}
overview[:ticket_ids].each {|ticket_id| overview[:ticket_ids].each {|ticket_id|
ticket = Ticket.lookup( :id => ticket_id ) ticket = Ticket.lookup( id: ticket_id )
assets = ticket.assets(assets) assets = ticket.assets(assets)
} }
# get groups # get groups
group_ids = [] group_ids = []
Group.where( :active => true ).each { |group| Group.where( active: true ).each { |group|
group_ids.push group.id group_ids.push group.id
} }
agents = {} agents = {}
@ -75,15 +75,15 @@ class TicketOverviewsController < ApplicationController
} }
# return result # return result
render :json => { render json: {
:view => params[:view], view: params[:view],
:overview => overview[:overview], overview: overview[:overview],
:ticket_ids => overview[:ticket_ids], ticket_ids: overview[:ticket_ids],
:tickets_count => overview[:tickets_count], tickets_count: overview[:tickets_count],
:bulk => { bulk: {
:group_id__owner_id => groups_users, group_id__owner_id: groups_users,
}, },
:assets => assets, assets: assets,
} }
end end

View file

@ -7,7 +7,7 @@ class TicketsController < ApplicationController
def index def index
@tickets = Ticket.all @tickets = Ticket.all
render :json => @tickets render json: @tickets
end end
# GET /api/v1/tickets/1 # GET /api/v1/tickets/1
@ -17,7 +17,7 @@ class TicketsController < ApplicationController
# permissin check # permissin check
return if !ticket_permission(@ticket) return if !ticket_permission(@ticket)
render :json => @ticket render json: @ticket
end end
# POST /api/v1/tickets # POST /api/v1/tickets
@ -26,13 +26,13 @@ class TicketsController < ApplicationController
# check if article is given # check if article is given
if !params[:article] if !params[:article]
render :json => 'article hash is missing', :status => :unprocessable_entity render json: 'article hash is missing', status: :unprocessable_entity
return return
end end
# create ticket # create ticket
if !ticket.save if !ticket.save
render :json => ticket.errors, :status => :unprocessable_entity render json: ticket.errors, status: :unprocessable_entity
return return
end end
@ -41,10 +41,10 @@ class TicketsController < ApplicationController
tags = params[:tags].split /,/ tags = params[:tags].split /,/
tags.each {|tag| tags.each {|tag|
Tag.tag_add( Tag.tag_add(
:object => 'Ticket', object: 'Ticket',
:o_id => ticket.id, o_id: ticket.id,
:item => tag, item: tag,
:created_by_id => current_user.id, created_by_id: current_user.id,
) )
} }
end end
@ -54,7 +54,7 @@ class TicketsController < ApplicationController
article_create( ticket, params[:article] ) article_create( ticket, params[:article] )
end end
render :json => ticket, :status => :created render json: ticket, status: :created
end end
# PUT /api/v1/tickets/1 # PUT /api/v1/tickets/1
@ -70,9 +70,9 @@ class TicketsController < ApplicationController
article_create( ticket, params[:article] ) article_create( ticket, params[:article] )
end end
render :json => ticket, :status => :ok render json: ticket, status: :ok
else else
render :json => ticket.errors, :status => :unprocessable_entity render json: ticket.errors, status: :unprocessable_entity
end end
end end
@ -94,10 +94,10 @@ class TicketsController < ApplicationController
# return result # return result
result = Ticket::ScreenOptions.list_by_customer( result = Ticket::ScreenOptions.list_by_customer(
:customer_id => params[:customer_id], customer_id: params[:customer_id],
:limit => 15, limit: 15,
) )
render :json => result render json: result
end end
# GET /api/v1/ticket_history/1 # GET /api/v1/ticket_history/1
@ -114,7 +114,7 @@ class TicketsController < ApplicationController
# return result # return result
render :json => history render json: history
end end
# GET /api/v1/ticket_related/1 # GET /api/v1/ticket_related/1
@ -130,8 +130,8 @@ class TicketsController < ApplicationController
map( &:id ) map( &:id )
access_condition = [ 'group_id IN (?)', group_ids ] access_condition = [ 'group_id IN (?)', group_ids ]
ticket_list = Ticket.where( ticket_list = Ticket.where(
:customer_id => ticket.customer_id, customer_id: ticket.customer_id,
:state_id => Ticket::State.by_category( 'open' ) state_id: Ticket::State.by_category( 'open' )
) )
.where(access_condition) .where(access_condition)
@ -158,10 +158,10 @@ class TicketsController < ApplicationController
} }
# return result # return result
render :json => { render json: {
:assets => assets, assets: assets,
:ticket_ids_by_customer => ticket_ids_by_customer, ticket_ids_by_customer: ticket_ids_by_customer,
:ticket_ids_recent_viewed => ticket_ids_recent_viewed, ticket_ids_recent_viewed: ticket_ids_recent_viewed,
} }
end end
@ -169,11 +169,11 @@ class TicketsController < ApplicationController
def ticket_merge def ticket_merge
# check master ticket # check master ticket
ticket_master = Ticket.where( :number => params[:master_ticket_number] ).first ticket_master = Ticket.where( number: params[:master_ticket_number] ).first
if !ticket_master if !ticket_master
render :json => { render json: {
:result => 'faild', result: 'faild',
:message => 'No such master ticket number!', message: 'No such master ticket number!',
} }
return return
end end
@ -182,11 +182,11 @@ class TicketsController < ApplicationController
return if !ticket_permission(ticket_master) return if !ticket_permission(ticket_master)
# check slave ticket # check slave ticket
ticket_slave = Ticket.where( :id => params[:slave_ticket_id] ).first ticket_slave = Ticket.where( id: params[:slave_ticket_id] ).first
if !ticket_slave if !ticket_slave
render :json => { render json: {
:result => 'faild', result: 'faild',
:message => 'No such slave ticket!', message: 'No such slave ticket!',
} }
return return
end end
@ -196,9 +196,9 @@ class TicketsController < ApplicationController
# check diffetent ticket ids # check diffetent ticket ids
if ticket_slave.id == ticket_master.id if ticket_slave.id == ticket_master.id
render :json => { render json: {
:result => 'faild', result: 'faild',
:message => 'Can\'t merge ticket with it self!', message: 'Can\'t merge ticket with it self!',
} }
return return
end end
@ -206,16 +206,16 @@ class TicketsController < ApplicationController
# merge ticket # merge ticket
success = ticket_slave.merge_to( success = ticket_slave.merge_to(
{ {
:ticket_id => ticket_master.id, ticket_id: ticket_master.id,
:created_by_id => current_user.id, created_by_id: current_user.id,
} }
) )
# return result # return result
render :json => { render json: {
:result => 'success', result: 'success',
:master_ticket => ticket_master.attributes, master_ticket: ticket_master.attributes,
:slave_ticket => ticket_slave.attributes, slave_ticket: ticket_slave.attributes,
} }
end end
@ -227,14 +227,14 @@ class TicketsController < ApplicationController
return if !ticket_permission( ticket ) return if !ticket_permission( ticket )
# get attributes to update # get attributes to update
attributes_to_change = Ticket::ScreenOptions.attributes_to_change( :user => current_user, :ticket => ticket ) attributes_to_change = Ticket::ScreenOptions.attributes_to_change( user: current_user, ticket: ticket )
# get related users # get related users
assets = attributes_to_change[:assets] assets = attributes_to_change[:assets]
assets = ticket.assets(assets) assets = ticket.assets(assets)
# get related articles # get related articles
articles = Ticket::Article.where( :ticket_id => params[:id] ) articles = Ticket::Article.where( ticket_id: params[:id] )
# get related users # get related users
article_ids = [] article_ids = []
@ -252,34 +252,34 @@ class TicketsController < ApplicationController
# get links # get links
links = Link.list( links = Link.list(
:link_object => 'Ticket', link_object: 'Ticket',
:link_object_value => ticket.id, link_object_value: ticket.id,
) )
link_list = [] link_list = []
links.each { |item| links.each { |item|
link_list.push item link_list.push item
if item['link_object'] == 'Ticket' if item['link_object'] == 'Ticket'
linked_ticket = Ticket.lookup( :id => item['link_object_value'] ) linked_ticket = Ticket.lookup( id: item['link_object_value'] )
assets = linked_ticket.assets(assets) assets = linked_ticket.assets(assets)
end end
} }
# get tags # get tags
tags = Tag.tag_list( tags = Tag.tag_list(
:object => 'Ticket', object: 'Ticket',
:o_id => ticket.id, o_id: ticket.id,
) )
# return result # return result
render :json => { render json: {
:ticket_id => ticket.id, ticket_id: ticket.id,
:ticket_article_ids => article_ids, ticket_article_ids: article_ids,
:assets => assets, assets: assets,
:links => link_list, links: link_list,
:tags => tags, tags: tags,
:form_meta => { form_meta: {
:filter => attributes_to_change[:filter], filter: attributes_to_change[:filter],
:dependencies => attributes_to_change[:dependencies], dependencies: attributes_to_change[:dependencies],
} }
} }
end end
@ -289,9 +289,9 @@ class TicketsController < ApplicationController
# get attributes to update # get attributes to update
attributes_to_change = Ticket::ScreenOptions.attributes_to_change( attributes_to_change = Ticket::ScreenOptions.attributes_to_change(
:user => current_user, user: current_user,
:ticket_id => params[:ticket_id], ticket_id: params[:ticket_id],
:article_id => params[:article_id] article_id: params[:article_id]
) )
assets = attributes_to_change[:assets] assets = attributes_to_change[:assets]
@ -309,12 +309,12 @@ class TicketsController < ApplicationController
end end
# return result # return result
render :json => { render json: {
:split => split, split: split,
:assets => assets, assets: assets,
:form_meta => { form_meta: {
:filter => attributes_to_change[:filter], filter: attributes_to_change[:filter],
:dependencies => attributes_to_change[:dependencies], dependencies: attributes_to_change[:dependencies],
} }
} }
end end
@ -327,11 +327,11 @@ class TicketsController < ApplicationController
# build result list # build result list
tickets = Ticket.search( tickets = Ticket.search(
:limit => params[:limit], limit: params[:limit],
:query => params[:term], query: params[:term],
:condition => params[:condition], condition: params[:condition],
:current_user => current_user, current_user: current_user,
:detail => params[:detail] detail: params[:detail]
) )
assets = {} assets = {}
ticket_result = [] ticket_result = []
@ -341,10 +341,10 @@ class TicketsController < ApplicationController
end end
# return result # return result
render :json => { render json: {
:tickets => ticket_result, tickets: ticket_result,
:tickets_count => tickets.count, tickets_count: tickets.count,
:assets => assets, assets: assets,
} }
end end
@ -373,11 +373,11 @@ class TicketsController < ApplicationController
'tickets.customer_id' => user.id, 'tickets.customer_id' => user.id,
} }
user_tickets_open = Ticket.search( user_tickets_open = Ticket.search(
:limit => limit, limit: limit,
#:query => params[:term], #:query => params[:term],
:condition => condition, condition: condition,
:current_user => current_user, current_user: current_user,
:detail => true, detail: true,
) )
user_tickets_open_ids = assets_of_tickets(user_tickets_open, assets) user_tickets_open_ids = assets_of_tickets(user_tickets_open, assets)
@ -387,11 +387,11 @@ class TicketsController < ApplicationController
'tickets.customer_id' => user.id, 'tickets.customer_id' => user.id,
} }
user_tickets_closed = Ticket.search( user_tickets_closed = Ticket.search(
:limit => limit, limit: limit,
#:query => params[:term], #:query => params[:term],
:condition => condition, condition: condition,
:current_user => current_user, current_user: current_user,
:detail => true, detail: true,
) )
user_tickets_closed_ids = assets_of_tickets(user_tickets_closed, assets) user_tickets_closed_ids = assets_of_tickets(user_tickets_closed, assets)
@ -418,11 +418,11 @@ class TicketsController < ApplicationController
count count
data = { data = {
:month => date_to_check.month, month: date_to_check.month,
:year => date_to_check.year, year: date_to_check.year,
:text => Date::MONTHNAMES[date_to_check.month], text: Date::MONTHNAMES[date_to_check.month],
:created => created, created: created,
:closed => closed, closed: closed,
} }
user_ticket_volume_by_year.push data user_ticket_volume_by_year.push data
} }
@ -440,11 +440,11 @@ class TicketsController < ApplicationController
'tickets.organization_id' => params[:organization_id], 'tickets.organization_id' => params[:organization_id],
} }
org_tickets_open = Ticket.search( org_tickets_open = Ticket.search(
:limit => limit, limit: limit,
#:query => params[:term], #:query => params[:term],
:condition => condition, condition: condition,
:current_user => current_user, current_user: current_user,
:detail => true, detail: true,
) )
org_tickets_open_ids = assets_of_tickets(org_tickets_open, assets) org_tickets_open_ids = assets_of_tickets(org_tickets_open, assets)
@ -454,11 +454,11 @@ class TicketsController < ApplicationController
'tickets.organization_id' => params[:organization_id], 'tickets.organization_id' => params[:organization_id],
} }
org_tickets_closed = Ticket.search( org_tickets_closed = Ticket.search(
:limit => limit, limit: limit,
#:query => params[:term], #:query => params[:term],
:condition => condition, condition: condition,
:current_user => current_user, current_user: current_user,
:detail => true, detail: true,
) )
org_tickets_closed_ids = assets_of_tickets(org_tickets_closed, assets) org_tickets_closed_ids = assets_of_tickets(org_tickets_closed, assets)
@ -479,25 +479,25 @@ class TicketsController < ApplicationController
closed = Ticket.where('close_time > ? AND close_time < ?', date_start, date_end ).where(condition).count closed = Ticket.where('close_time > ? AND close_time < ?', date_start, date_end ).where(condition).count
data = { data = {
:month => date_to_check.month, month: date_to_check.month,
:year => date_to_check.year, year: date_to_check.year,
:text => Date::MONTHNAMES[date_to_check.month], text: Date::MONTHNAMES[date_to_check.month],
:created => created, created: created,
:closed => closed, closed: closed,
} }
org_ticket_volume_by_year.push data org_ticket_volume_by_year.push data
} }
end end
# return result # return result
render :json => { render json: {
:user_tickets_open_ids => user_tickets_open_ids, user_tickets_open_ids: user_tickets_open_ids,
:user_tickets_closed_ids => user_tickets_closed_ids, user_tickets_closed_ids: user_tickets_closed_ids,
:org_tickets_open_ids => org_tickets_open_ids, org_tickets_open_ids: org_tickets_open_ids,
:org_tickets_closed_ids => org_tickets_closed_ids, org_tickets_closed_ids: org_tickets_closed_ids,
:user_ticket_volume_by_year => user_ticket_volume_by_year, user_ticket_volume_by_year: user_ticket_volume_by_year,
:org_ticket_volume_by_year => org_ticket_volume_by_year, org_ticket_volume_by_year: org_ticket_volume_by_year,
:assets => assets, assets: assets,
} }
end end
@ -523,20 +523,20 @@ class TicketsController < ApplicationController
# find attachments in upload cache # find attachments in upload cache
if form_id if form_id
article.attachments = Store.list( article.attachments = Store.list(
:object => 'UploadCache', object: 'UploadCache',
:o_id => form_id, o_id: form_id,
) )
end end
if !article.save if !article.save
render :json => article.errors, :status => :unprocessable_entity render json: article.errors, status: :unprocessable_entity
return return
end end
# remove attachments from upload cache # remove attachments from upload cache
if form_id if form_id
Store.remove( Store.remove(
:object => 'UploadCache', object: 'UploadCache',
:o_id => form_id, o_id: form_id,
) )
end end
end end

View file

@ -1,17 +1,17 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class TranslationsController < ApplicationController class TranslationsController < ApplicationController
before_filter :authentication_check, :except => [:load] before_filter :authentication_check, except: [:load]
# GET /translations/lang/:locale # GET /translations/lang/:locale
def load def load
render :json => Translation.list( params[:locale] ) render json: Translation.list( params[:locale] )
end end
# GET /translations/admin/lang/:locale # GET /translations/admin/lang/:locale
def admin def admin
return if deny_if_not_role(Z_ROLENAME_ADMIN) return if deny_if_not_role(Z_ROLENAME_ADMIN)
render :json => Translation.list( params[:locale], true ) render json: Translation.list( params[:locale], true )
end end
# GET /translations # GET /translations

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class UsersController < ApplicationController class UsersController < ApplicationController
before_filter :authentication_check, :except => [:create, :password_reset_send, :password_reset_verify] before_filter :authentication_check, except: [:create, :password_reset_send, :password_reset_verify]
# @path [GET] /users # @path [GET] /users
# #
@ -16,15 +16,15 @@ class UsersController < ApplicationController
# only allow customer to fetch him self # only allow customer to fetch him self
if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role('Agent') if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role('Agent')
users = User.where( :id => current_user.id ) users = User.where( id: current_user.id )
else else
users = User.all users = User.all
end end
users_all = [] users_all = []
users.each {|user| users.each {|user|
users_all.push User.lookup( :id => user.id ).attributes_with_associations users_all.push User.lookup( id: user.id ).attributes_with_associations
} }
render :json => users_all, :status => :ok render json: users_all, status: :ok
end end
# @path [GET] /users/{id} # @path [GET] /users/{id}
@ -46,12 +46,12 @@ class UsersController < ApplicationController
if params[:full] if params[:full]
full = User.full( params[:id] ) full = User.full( params[:id] )
render :json => full render json: full
return return
end end
user = User.find( params[:id] ) user = User.find( params[:id] )
render :json => user render json: user
end end
# @path [POST] /users # @path [POST] /users
@ -77,7 +77,7 @@ class UsersController < ApplicationController
# check if feature is enabled # check if feature is enabled
if !Setting.get('user_create_account') if !Setting.get('user_create_account')
render :json => { :error => 'Feature not enabled!' }, :status => :unprocessable_entity render json: { error: 'Feature not enabled!' }, status: :unprocessable_entity
return return
end end
@ -85,7 +85,7 @@ class UsersController < ApplicationController
group_ids = [] group_ids = []
role_ids = [] role_ids = []
if count <= 2 if count <= 2
Role.where( :name => [ Z_ROLENAME_ADMIN, 'Agent'] ).each { |role| Role.where( name: [ Z_ROLENAME_ADMIN, 'Agent'] ).each { |role|
role_ids.push role.id role_ids.push role.id
} }
Group.all().each { |group| Group.all().each { |group|
@ -94,7 +94,7 @@ class UsersController < ApplicationController
# everybody else will go as customer per default # everybody else will go as customer per default
else else
role_ids.push Role.where( :name => Z_ROLENAME_CUSTOMER ).first.id role_ids.push Role.where( name: Z_ROLENAME_CUSTOMER ).first.id
end end
user.role_ids = role_ids user.role_ids = role_ids
user.group_ids = group_ids user.group_ids = group_ids
@ -115,9 +115,9 @@ class UsersController < ApplicationController
# check if user already exists # check if user already exists
if user.email if user.email
exists = User.where( :email => user.email ).first exists = User.where( email: user.email ).first
if exists if exists
render :json => { :error => 'User already exists!' }, :status => :unprocessable_entity render json: { error: 'User already exists!' }, status: :unprocessable_entity
return return
end end
end end
@ -133,7 +133,7 @@ class UsersController < ApplicationController
if params[:invite] && current_user if params[:invite] && current_user
# generate token # generate token
token = Token.create( :action => 'PasswordReset', :user_id => user.id ) token = Token.create( action: 'PasswordReset', user_id: user.id )
# send mail # send mail
data = {} data = {}
@ -156,28 +156,28 @@ class UsersController < ApplicationController
# prepare subject & body # prepare subject & body
[:subject, :body].each { |key| [:subject, :body].each { |key|
data[key.to_sym] = NotificationFactory.build( data[key.to_sym] = NotificationFactory.build(
:locale => user.preferences[:locale], locale: user.preferences[:locale],
:string => data[key.to_sym], string: data[key.to_sym],
:objects => { objects: {
:token => token, token: token,
:user => user, user: user,
:current_user => current_user, current_user: current_user,
} }
) )
} }
# send notification # send notification
NotificationFactory.send( NotificationFactory.send(
:recipient => user, recipient: user,
:subject => data[:subject], subject: data[:subject],
:body => data[:body] body: data[:body]
) )
end end
user_new = User.find( user.id ) user_new = User.find( user.id )
render :json => user_new, :status => :created render json: user_new, status: :created
rescue Exception => e rescue Exception => e
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
@ -219,9 +219,9 @@ class UsersController < ApplicationController
# get new data # get new data
user_new = User.find( params[:id] ) user_new = User.find( params[:id] )
render :json => user_new, :status => :ok render json: user_new, status: :ok
rescue Exception => e rescue Exception => e
render :json => { :error => e.message }, :status => :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
@ -266,9 +266,9 @@ class UsersController < ApplicationController
end end
query_params = { query_params = {
:query => params[:term], query: params[:term],
:limit => params[:limit], limit: params[:limit],
:current_user => current_user, current_user: current_user,
} }
if params[:role_ids] && !params[:role_ids].empty? if params[:role_ids] && !params[:role_ids].empty?
query_params[:role_ids] = params[:role_ids] query_params[:role_ids] = params[:role_ids]
@ -285,12 +285,12 @@ class UsersController < ApplicationController
if user.email && user.email.to_s != '' if user.email && user.email.to_s != ''
realname = realname + ' <' + user.email.to_s + '>' realname = realname + ' <' + user.email.to_s + '>'
end end
a = { :id => user.id, :label => realname, :value => realname } a = { id: user.id, label: realname, value: realname }
users.push a users.push a
} }
# return result # return result
render :json => users render json: users
return return
end end
@ -302,9 +302,9 @@ class UsersController < ApplicationController
} }
# return result # return result
render :json => { render json: {
:assets => assets, assets: assets,
:user_ids => user_ids.uniq, user_ids: user_ids.uniq,
} }
end end
@ -336,7 +336,7 @@ class UsersController < ApplicationController
history = user.history_get(true) history = user.history_get(true)
# return result # return result
render :json => history render json: history
end end
=begin =begin
@ -363,7 +363,7 @@ curl http://localhost/api/v1/users/password_reset.json -v -u #{login}:#{password
# check if feature is enabled # check if feature is enabled
if !Setting.get('user_lost_password') if !Setting.get('user_lost_password')
render :json => { :error => 'Feature not enabled!' }, :status => :unprocessable_entity render json: { error: 'Feature not enabled!' }, status: :unprocessable_entity
return return
end end
@ -372,17 +372,17 @@ curl http://localhost/api/v1/users/password_reset.json -v -u #{login}:#{password
# only if system is in develop mode, send token back to browser for browser tests # only if system is in develop mode, send token back to browser for browser tests
if Setting.get('developer_mode') == true if Setting.get('developer_mode') == true
render :json => { :message => 'ok', :token => token.name }, :status => :ok render json: { message: 'ok', token: token.name }, status: :ok
return return
end end
# token sent to user, send ok to browser # token sent to user, send ok to browser
render :json => { :message => 'ok' }, :status => :ok render json: { message: 'ok' }, status: :ok
return return
end end
# unable to generate token # unable to generate token
render :json => { :message => 'failed' }, :status => :ok render json: { message: 'failed' }, status: :ok
end end
=begin =begin
@ -412,7 +412,7 @@ curl http://localhost/api/v1/users/password_reset_verify.json -v -u #{login}:#{p
# check password policy # check password policy
result = password_policy(params[:password]) result = password_policy(params[:password])
if result != true if result != true
render :json => { :message => 'failed', :notice => result }, :status => :ok render json: { message: 'failed', notice: result }, status: :ok
return return
end end
@ -422,9 +422,9 @@ curl http://localhost/api/v1/users/password_reset_verify.json -v -u #{login}:#{p
user = User.password_reset_check( params[:token] ) user = User.password_reset_check( params[:token] )
end end
if user if user
render :json => { :message => 'ok', :user_login => user.login }, :status => :ok render json: { message: 'ok', user_login: user.login }, status: :ok
else else
render :json => { :message => 'failed' }, :status => :ok render json: { message: 'failed' }, status: :ok
end end
end end
@ -453,30 +453,30 @@ curl http://localhost/api/v1/users/password_change.json -v -u #{login}:#{passwor
# check old password # check old password
if !params[:password_old] if !params[:password_old]
render :json => { :message => 'failed', :notice => ['Current password needed!'] }, :status => :ok render json: { message: 'failed', notice: ['Current password needed!'] }, status: :ok
return return
end end
user = User.authenticate( current_user.login, params[:password_old] ) user = User.authenticate( current_user.login, params[:password_old] )
if !user if !user
render :json => { :message => 'failed', :notice => ['Current password is wrong!'] }, :status => :ok render json: { message: 'failed', notice: ['Current password is wrong!'] }, status: :ok
return return
end end
# set new password # set new password
if !params[:password_new] if !params[:password_new]
render :json => { :message => 'failed', :notice => ['Please supply your new password!'] }, :status => :ok render json: { message: 'failed', notice: ['Please supply your new password!'] }, status: :ok
return return
end end
# check password policy # check password policy
result = password_policy(params[:password_new]) result = password_policy(params[:password_new])
if result != true if result != true
render :json => { :message => 'failed', :notice => result }, :status => :ok render json: { message: 'failed', notice: result }, status: :ok
return return
end end
user.update_attributes( :password => params[:password_new] ) user.update_attributes( password: params[:password_new] )
render :json => { :message => 'ok', :user_login => user.login }, :status => :ok render json: { message: 'ok', user_login: user.login }, status: :ok
end end
=begin =begin
@ -502,7 +502,7 @@ curl http://localhost/api/v1/users/preferences.json -v -u #{login}:#{password} -
def preferences def preferences
if !current_user if !current_user
render :json => { :message => 'No current user!' }, :status => :unprocessable_entity render json: { message: 'No current user!' }, status: :unprocessable_entity
return return
end end
if params[:user] if params[:user]
@ -511,7 +511,7 @@ curl http://localhost/api/v1/users/preferences.json -v -u #{login}:#{password} -
} }
current_user.save current_user.save
end end
render :json => { :message => 'ok' }, :status => :ok render json: { message: 'ok' }, status: :ok
end end
=begin =begin
@ -537,32 +537,32 @@ curl http://localhost/api/v1/users/account.json -v -u #{login}:#{password} -H "C
def account_remove def account_remove
if !current_user if !current_user
render :json => { :message => 'No current user!' }, :status => :unprocessable_entity render json: { message: 'No current user!' }, status: :unprocessable_entity
return return
end end
# provider + uid to remove # provider + uid to remove
if !params[:provider] if !params[:provider]
render :json => { :message => 'provider needed!' }, :status => :unprocessable_entity render json: { message: 'provider needed!' }, status: :unprocessable_entity
return return
end end
if !params[:uid] if !params[:uid]
render :json => { :message => 'uid needed!' }, :status => :unprocessable_entity render json: { message: 'uid needed!' }, status: :unprocessable_entity
return return
end end
# remove from database # remove from database
record = Authorization.where( record = Authorization.where(
:user_id => current_user.id, user_id: current_user.id,
:provider => params[:provider], provider: params[:provider],
:uid => params[:uid], uid: params[:uid],
) )
if !record.first if !record.first
render :json => { :message => 'No record found!' }, :status => :unprocessable_entity render json: { message: 'No record found!' }, status: :unprocessable_entity
return return
end end
record.destroy_all record.destroy_all
render :json => { :message => 'ok' }, :status => :ok render json: { message: 'ok' }, status: :ok
end end
=begin =begin
@ -589,9 +589,9 @@ curl http://localhost/api/v1/users/image/8d6cca1c6bdc226cf2ba131e264ca2c7 -v -u
if file if file
send_data( send_data(
file.content, file.content,
:filename => file.filename, filename: file.filename,
:type => file.preferences['Content-Type'] || file.preferences['Mime-Type'], type: file.preferences['Content-Type'] || file.preferences['Mime-Type'],
:disposition => 'inline' disposition: 'inline'
) )
return return
end end
@ -600,9 +600,9 @@ curl http://localhost/api/v1/users/image/8d6cca1c6bdc226cf2ba131e264ca2c7 -v -u
image = 'R0lGODdhMAAwAOMAAMzMzJaWlr6+vqqqqqOjo8XFxbe3t7GxsZycnAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAMAAwAAAEcxDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru98TwuAA+KQAQqJK8EAgBAgMEqmkzUgBIeSwWGZtR5XhSqAULACCoGCJGwlm1MGQrq9RqgB8fm4ZTUgDBIEcRR9fz6HiImKi4yNjo+QkZKTlJWWkBEAOw==' image = 'R0lGODdhMAAwAOMAAMzMzJaWlr6+vqqqqqOjo8XFxbe3t7GxsZycnAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAMAAwAAAEcxDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru98TwuAA+KQAQqJK8EAgBAgMEqmkzUgBIeSwWGZtR5XhSqAULACCoGCJGwlm1MGQrq9RqgB8fm4ZTUgDBIEcRR9fz6HiImKi4yNjo+QkZKTlJWWkBEAOw=='
send_data( send_data(
Base64.decode64(image), Base64.decode64(image),
:filename => 'image.gif', filename: 'image.gif',
:type => 'image/gif', type: 'image/gif',
:disposition => 'inline' disposition: 'inline'
) )
end end
@ -634,24 +634,24 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
file_resize = StaticAssets.data_url_attributes( params[:avatar_resize] ) file_resize = StaticAssets.data_url_attributes( params[:avatar_resize] )
avatar = Avatar.add( avatar = Avatar.add(
:object => 'User', object: 'User',
:o_id => current_user.id, o_id: current_user.id,
:full => { full: {
:content => file_full[:content], content: file_full[:content],
:mime_type => file_full[:mime_type], mime_type: file_full[:mime_type],
}, },
:resize => { resize: {
:content => file_resize[:content], content: file_resize[:content],
:mime_type => file_resize[:mime_type], mime_type: file_resize[:mime_type],
}, },
:source => 'upload ' + Time.now.to_s, source: 'upload ' + Time.now.to_s,
:deletable => true, deletable: true,
) )
# update user link # update user link
current_user.update_attributes( :image => avatar.store_hash ) current_user.update_attributes( image: avatar.store_hash )
render :json => { :avatar => avatar }, :status => :ok render json: { avatar: avatar }, status: :ok
end end
def avatar_set_default def avatar_set_default
@ -659,7 +659,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
# get & validate image # get & validate image
if !params[:id] if !params[:id]
render :json => { :message => 'No id of avatar!' }, :status => :unprocessable_entity render json: { message: 'No id of avatar!' }, status: :unprocessable_entity
return return
end end
@ -667,9 +667,9 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
avatar = Avatar.set_default( 'User', current_user.id, params[:id] ) avatar = Avatar.set_default( 'User', current_user.id, params[:id] )
# update user link # update user link
current_user.update_attributes( :image => avatar.store_hash ) current_user.update_attributes( image: avatar.store_hash )
render :json => {}, :status => :ok render json: {}, status: :ok
end end
def avatar_destroy def avatar_destroy
@ -677,7 +677,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
# get & validate image # get & validate image
if !params[:id] if !params[:id]
render :json => { :message => 'No id of avatar!' }, :status => :unprocessable_entity render json: { message: 'No id of avatar!' }, status: :unprocessable_entity
return return
end end
@ -686,9 +686,9 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
# update user link # update user link
avatar = Avatar.get_default( 'User', current_user.id ) avatar = Avatar.get_default( 'User', current_user.id )
current_user.update_attributes( :image => avatar.store_hash ) current_user.update_attributes( image: avatar.store_hash )
render :json => {}, :status => :ok render json: {}, status: :ok
end end
def avatar_list def avatar_list
@ -696,7 +696,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
# list of avatars # list of avatars
result = Avatar.list( 'User', current_user.id ) result = Avatar.list( 'User', current_user.id )
render :json => { :avatars => result }, :status => :ok render json: { avatars: result }, status: :ok
end end
private private

View file

@ -2,8 +2,8 @@
class ActivityStream < ApplicationModel class ActivityStream < ApplicationModel
self.table_name = 'activity_streams' self.table_name = 'activity_streams'
belongs_to :activity_stream_type, :class_name => 'TypeLookup' belongs_to :activity_stream_type, class_name: 'TypeLookup'
belongs_to :activity_stream_object, :class_name => 'ObjectLookup' belongs_to :activity_stream_object, class_name: 'ObjectLookup'
=begin =begin
@ -32,7 +32,7 @@ add a new activity entry for an object
role_id = nil role_id = nil
if data[:role] if data[:role]
role = Role.lookup( :name => data[:role] ) role = Role.lookup( name: data[:role] )
if !role if !role
raise "No such Role #{data[:role]}" raise "No such Role #{data[:role]}"
end end
@ -41,11 +41,11 @@ add a new activity entry for an object
# check newest entry - is needed # check newest entry - is needed
result = ActivityStream.where( result = ActivityStream.where(
:o_id => data[:o_id], o_id: data[:o_id],
#:activity_stream_type_id => type_id, #:activity_stream_type_id => type_id,
:role_id => role_id, role_id: role_id,
:activity_stream_object_id => object_id, activity_stream_object_id: object_id,
:created_by_id => data[:created_by_id] created_by_id: data[:created_by_id]
).order('created_at DESC, id DESC').first ).order('created_at DESC, id DESC').first
# resturn if old entry is really fresh # resturn if old entry is really fresh
@ -53,13 +53,13 @@ add a new activity entry for an object
# create history # create history
record = { record = {
:o_id => data[:o_id], o_id: data[:o_id],
:activity_stream_type_id => type_id, activity_stream_type_id: type_id,
:activity_stream_object_id => object_id, activity_stream_object_id: object_id,
:role_id => role_id, role_id: role_id,
:group_id => data[:group_id], group_id: data[:group_id],
:created_at => data[:created_at], created_at: data[:created_at],
:created_by_id => data[:created_by_id] created_by_id: data[:created_by_id]
} }
ActivityStream.create(record) ActivityStream.create(record)
@ -76,8 +76,8 @@ remove whole activity entries of an object
def self.remove( object_name, o_id ) def self.remove( object_name, o_id )
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
ActivityStream.where( ActivityStream.where(
:activity_stream_object_id => object_id, activity_stream_object_id: object_id,
:o_id => o_id, o_id: o_id,
).destroy_all ).destroy_all
end end
@ -94,7 +94,7 @@ return all activity entries of an user
group_ids = user.group_ids group_ids = user.group_ids
# do not return an activity stream for custoers # do not return an activity stream for custoers
customer_role = Role.lookup( :name => 'Customer' ) customer_role = Role.lookup( name: 'Customer' )
return [] if role_ids.include?(customer_role.id) return [] if role_ids.include?(customer_role.id)
if group_ids.empty? if group_ids.empty?

View file

@ -316,14 +316,14 @@ returns
return cache if cache 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 record = self.where( id: data[:id] ).first
self.cache_set( data[:id], record ) self.cache_set( data[:id], record )
return record return record
elsif data[:name] elsif data[:name]
cache = self.cache_get( data[:name] ) cache = self.cache_get( data[:name] )
return cache if cache return cache if cache
records = self.where( :name => data[:name] ) records = self.where( name: data[:name] )
records.each {|record| records.each {|record|
if record.name == data[:name] if record.name == data[:name]
self.cache_set( data[:name], record ) self.cache_set( data[:name], record )
@ -335,7 +335,7 @@ returns
cache = self.cache_get( data[:login] ) cache = self.cache_get( data[:login] )
return cache if cache return cache if cache
records = self.where( :login => data[:login] ) records = self.where( login: data[:login] )
records.each {|record| records.each {|record|
if record.login == data[:login] if record.login == data[:login]
self.cache_set( data[:login], record ) self.cache_set( data[:login], record )
@ -362,20 +362,20 @@ returns
def self.create_if_not_exists(data) def self.create_if_not_exists(data)
if data[:id] if data[:id]
record = self.where( :id => data[:id] ).first record = self.where( id: data[:id] ).first
return record if record return record if record
elsif data[:name] elsif data[:name]
records = self.where( :name => data[:name] ) records = self.where( name: data[:name] )
records.each {|record| records.each {|record|
return record if record.name == data[:name] return record if record.name == data[:name]
} }
elsif data[:login] elsif data[:login]
records = self.where( :login => data[:login] ) records = self.where( login: data[:login] )
records.each {|record| records.each {|record|
return record if record.login == data[:login] return record if record.login == data[:login]
} }
elsif data[:locale] && data[:source] elsif data[:locale] && data[:source]
records = self.where( :locale => data[:locale], :source => data[:source] ) records = self.where( locale: data[:locale], source: data[:source] )
records.each {|record| records.each {|record|
return record if record.source == data[:source] return record if record.source == data[:source]
} }
@ -397,7 +397,7 @@ returns
def self.create_or_update(data) def self.create_or_update(data)
if data[:id] if data[:id]
records = self.where( :id => data[:id] ) records = self.where( id: data[:id] )
records.each {|record| records.each {|record|
record.update_attributes( data ) record.update_attributes( data )
return record return record
@ -406,7 +406,7 @@ returns
record.save record.save
return record return record
elsif data[:name] elsif data[:name]
records = self.where( :name => data[:name] ) records = self.where( name: data[:name] )
records.each {|record| records.each {|record|
if record.name == data[:name] if record.name == data[:name]
record.update_attributes( data ) record.update_attributes( data )
@ -417,7 +417,7 @@ returns
record.save record.save
return record return record
elsif data[:login] elsif data[:login]
records = self.where( :login => data[:login] ) records = self.where( login: data[:login] )
records.each {|record| records.each {|record|
if record.login.downcase == data[:login].downcase if record.login.downcase == data[:login].downcase
record.update_attributes( data ) record.update_attributes( data )
@ -428,7 +428,7 @@ returns
record.save record.save
return record return record
elsif data[:locale] elsif data[:locale]
records = self.where( :locale => data[:locale] ) records = self.where( locale: data[:locale] )
records.each {|record| records.each {|record|
if record.locale.downcase == data[:locale].downcase if record.locale.downcase == data[:locale].downcase
record.update_attributes( data ) record.update_attributes( data )
@ -474,7 +474,7 @@ end
if updated_at == nil if updated_at == nil
Cache.delete( key ) Cache.delete( key )
else else
Cache.write( key, updated_at, { :expires_in => expires_in } ) Cache.write( key, updated_at, { expires_in: expires_in } )
end end
end end
@ -545,8 +545,8 @@ class OwnModel < ApplicationModel
class_name = self.class.name class_name = self.class.name
class_name.gsub!(/::/, '') class_name.gsub!(/::/, '')
Sessions.broadcast( Sessions.broadcast(
:event => class_name + ':create', event: class_name + ':create',
:data => { :id => self.id, :updated_at => self.updated_at } data: { id: self.id, updated_at: self.updated_at }
) )
end end
@ -573,8 +573,8 @@ class OwnModel < ApplicationModel
class_name = self.class.name class_name = self.class.name
class_name.gsub!(/::/, '') class_name.gsub!(/::/, '')
Sessions.broadcast( Sessions.broadcast(
:event => class_name + ':update', event: class_name + ':update',
:data => { :id => self.id, :updated_at => self.updated_at } data: { id: self.id, updated_at: self.updated_at }
) )
end end
@ -600,8 +600,8 @@ class OwnModel < ApplicationModel
class_name = self.class.name class_name = self.class.name
class_name.gsub!(/::/, '') class_name.gsub!(/::/, '')
Sessions.broadcast( Sessions.broadcast(
:event => class_name + ':destroy', event: class_name + ':destroy',
:data => { :id => self.id, :updated_at => self.updated_at } data: { id: self.id, updated_at: self.updated_at }
) )
end end
@ -716,10 +716,10 @@ log object update activity stream, if configured - will be executed automaticall
# default ignored attributes # default ignored attributes
ignore_attributes = { ignore_attributes = {
:created_at => true, created_at: true,
:updated_at => true, updated_at: true,
:created_by_id => true, created_by_id: true,
:updated_by_id => true, updated_by_id: true,
} }
if self.class.activity_stream_support_config[:ignore_attributes] if self.class.activity_stream_support_config[:ignore_attributes]
self.class.activity_stream_support_config[:ignore_attributes].each {|key, value| self.class.activity_stream_support_config[:ignore_attributes].each {|key, value|
@ -823,10 +823,10 @@ log object update history with all updated attributes, if configured - will be e
# default ignored attributes # default ignored attributes
ignore_attributes = { ignore_attributes = {
:created_at => true, created_at: true,
:updated_at => true, updated_at: true,
:created_by_id => true, created_by_id: true,
:updated_by_id => true, updated_by_id: true,
} }
if self.class.history_support_config[:ignore_attributes] if self.class.history_support_config[:ignore_attributes]
self.class.history_support_config[:ignore_attributes].each {|key, value| self.class.history_support_config[:ignore_attributes].each {|key, value|
@ -854,7 +854,7 @@ log object update history with all updated attributes, if configured - will be e
if self.respond_to?( attribute_name ) && self.send(attribute_name) if self.respond_to?( attribute_name ) && self.send(attribute_name)
relation_class = self.send(attribute_name).class relation_class = self.send(attribute_name).class
if relation_class && value_id[0] if relation_class && value_id[0]
relation_model = relation_class.lookup( :id => value_id[0] ) relation_model = relation_class.lookup( id: value_id[0] )
if relation_model if relation_model
if relation_model['name'] if relation_model['name']
value_str[0] = relation_model['name'] value_str[0] = relation_model['name']
@ -864,7 +864,7 @@ log object update history with all updated attributes, if configured - will be e
end end
end end
if relation_class && value_id[1] if relation_class && value_id[1]
relation_model = relation_class.lookup( :id => value_id[1] ) relation_model = relation_class.lookup( id: value_id[1] )
if relation_model if relation_model
if relation_model['name'] if relation_model['name']
value_str[1] = relation_model['name'] value_str[1] = relation_model['name']
@ -876,11 +876,11 @@ log object update history with all updated attributes, if configured - will be e
end end
end end
data = { data = {
:history_attribute => attribute_name, history_attribute: attribute_name,
:value_from => value_str[0].to_s, value_from: value_str[0].to_s,
:value_to => value_str[1].to_s, value_to: value_str[1].to_s,
:id_from => value_id[0], id_from: value_id[0],
:id_to => value_id[1], id_to: value_id[1],
} }
#puts "HIST NEW #{self.class.to_s}.find(#{self.id}) #{data.inspect}" #puts "HIST NEW #{self.class.to_s}.find(#{self.id}) #{data.inspect}"
self.history_log( 'updated', self.updated_by_id, data ) self.history_log( 'updated', self.updated_by_id, data )
@ -915,7 +915,7 @@ returns
=end =end
def attachments def attachments
Store.list( :object => self.class.to_s, :o_id => self.id ) Store.list( object: self.class.to_s, o_id: self.id )
end end
=begin =begin
@ -952,8 +952,8 @@ return object and assets
object = self.find(id) object = self.find(id)
assets = object.assets({}) assets = object.assets({})
{ {
:id => id, id: id,
:assets => assets, assets: assets,
} }
end end
@ -1011,12 +1011,12 @@ get assets of object list
article_store = [] article_store = []
attachments_buffer.each do |attachment| attachments_buffer.each do |attachment|
article_store.push Store.add( article_store.push Store.add(
:object => self.class.to_s, object: self.class.to_s,
:o_id => self.id, o_id: self.id,
:data => attachment.content, data: attachment.content,
:filename => attachment.filename, filename: attachment.filename,
:preferences => attachment.preferences, preferences: attachment.preferences,
:created_by_id => self.created_by_id, created_by_id: self.created_by_id,
) )
end end
attachments_buffer = nil attachments_buffer = nil

View file

@ -32,13 +32,13 @@ returns
updated_at = Time.new updated_at = Time.new
end end
ActivityStream.add( ActivityStream.add(
:o_id => self['id'], o_id: self['id'],
:type => type, type: type,
:object => self.class.name, object: self.class.name,
:group_id => self['group_id'], group_id: self['group_id'],
:role => role, role: role,
:created_at => updated_at, created_at: updated_at,
:created_by_id => user_id, created_by_id: user_id,
) )
end end

View file

@ -33,7 +33,7 @@ returns
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( :id => self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end end

View file

@ -92,8 +92,8 @@ returns
end end
} }
return { return {
:history => history[:list], history: history[:list],
:assets => history[:assets], assets: history[:assets],
} }
end end

View file

@ -20,9 +20,9 @@ returns
# default ignored attributes # default ignored attributes
ignore_attributes = { ignore_attributes = {
:created_by_id => true, created_by_id: true,
:updated_by_id => true, updated_by_id: true,
:active => true, active: true,
} }
if self.class.search_index_support_config[:ignore_attributes] if self.class.search_index_support_config[:ignore_attributes]
self.class.search_index_support_config[:ignore_attributes].each {|key, value| self.class.search_index_support_config[:ignore_attributes].each {|key, value|
@ -123,7 +123,7 @@ returns
next if !relation_class next if !relation_class
# lookup ref object # lookup ref object
relation_model = relation_class.lookup( :id => value ) relation_model = relation_class.lookup( id: value )
next if !relation_model next if !relation_model
# get name of ref object # get name of ref object

View file

@ -6,22 +6,22 @@ class Authorization < ApplicationModel
after_update :delete_user_cache after_update :delete_user_cache
after_destroy :delete_user_cache after_destroy :delete_user_cache
validates_presence_of :user_id, :uid, :provider validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, :scope => :provider validates_uniqueness_of :uid, scope: :provider
def self.find_from_hash(hash) def self.find_from_hash(hash)
auth = Authorization.where( :provider => hash['provider'], :uid => hash['uid'] ).first auth = Authorization.where( provider: hash['provider'], uid: hash['uid'] ).first
if auth if auth
# update auth tokens # update auth tokens
auth.update_attributes( auth.update_attributes(
:token => hash['credentials']['token'], token: hash['credentials']['token'],
:secret => hash['credentials']['secret'] secret: hash['credentials']['secret']
) )
# update username of auth entry if empty # update username of auth entry if empty
if !auth.username && hash['info']['nickname'] if !auth.username && hash['info']['nickname']
auth.update_attributes( auth.update_attributes(
:username => hash['info']['nickname'], username: hash['info']['nickname'],
) )
end end
@ -31,13 +31,13 @@ class Authorization < ApplicationModel
# save/update avatar # save/update avatar
avatar = Avatar.add( avatar = Avatar.add(
:object => 'User', object: 'User',
:o_id => user.id, o_id: user.id,
:url => hash['info']['image'], url: hash['info']['image'],
:source => hash['provider'], source: hash['provider'],
:deletable => true, deletable: true,
:updated_by_id => user.id, updated_by_id: user.id,
:created_by_id => user.id, created_by_id: user.id,
) )
# update user link # update user link
@ -54,13 +54,13 @@ class Authorization < ApplicationModel
# save/update avatar # save/update avatar
avatar = Avatar.add( avatar = Avatar.add(
:object => 'User', object: 'User',
:o_id => user.id, o_id: user.id,
:url => hash['info']['image'], url: hash['info']['image'],
:source => hash['provider'], source: hash['provider'],
:deletable => true, deletable: true,
:updated_by_id => user.id, updated_by_id: user.id,
:created_by_id => user.id, created_by_id: user.id,
) )
# update user link # update user link
@ -76,12 +76,12 @@ class Authorization < ApplicationModel
end end
Authorization.create( Authorization.create(
:user => user, user: user,
:uid => hash['uid'], uid: hash['uid'],
:username => hash['info']['nickname'] || hash['username'], username: hash['info']['nickname'] || hash['username'],
:provider => hash['provider'], provider: hash['provider'],
:token => hash['credentials']['token'], token: hash['credentials']['token'],
:secret => hash['credentials']['secret'] secret: hash['credentials']['secret']
) )
end end

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Avatar < ApplicationModel class Avatar < ApplicationModel
belongs_to :object_lookup, :class_name => 'ObjectLookup' belongs_to :object_lookup, class_name: 'ObjectLookup'
=begin =begin
@ -31,13 +31,13 @@ add an avatar based on auto detection (email address)
puts "#{data[:url]}: #{url}" puts "#{data[:url]}: #{url}"
Avatar.add( Avatar.add(
:object => data[:object], object: data[:object],
:o_id => data[:o_id], o_id: data[:o_id],
:url => url, url: url,
:source => 'gravatar.com', source: 'gravatar.com',
:deletable => false, deletable: false,
:updated_by_id => 1, updated_by_id: 1,
:created_by_id => 1, created_by_id: 1,
) )
end end
@ -75,24 +75,24 @@ add a avatar
add_init_avatar(object_id, data[:o_id]) add_init_avatar(object_id, data[:o_id])
record = { record = {
:o_id => data[:o_id], o_id: data[:o_id],
:object_lookup_id => object_id, object_lookup_id: object_id,
:default => true, default: true,
:deletable => data[:deletable], deletable: data[:deletable],
:initial => false, initial: false,
:source => data[:source], source: data[:source],
:source_url => data[:url], source_url: data[:url],
:updated_by_id => data[:updated_by_id], updated_by_id: data[:updated_by_id],
:created_by_id => data[:created_by_id], created_by_id: data[:created_by_id],
} }
# check if avatar with url already exists # check if avatar with url already exists
avatar_already_exists = nil avatar_already_exists = nil
if data[:source] && !data[:source].empty? if data[:source] && !data[:source].empty?
avatar_already_exists = Avatar.where( avatar_already_exists = Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => data[:o_id], o_id: data[:o_id],
:source => data[:source], source: data[:source],
).first ).first
end end
@ -119,8 +119,8 @@ add a avatar
data[:url], data[:url],
{}, {},
{ {
:open_timeout => 4, open_timeout: 4,
:read_timeout => 6, read_timeout: 6,
}, },
) )
if !response.success? if !response.success?
@ -159,28 +159,28 @@ add a avatar
object_name = "Avatar::#{data[:object]}" object_name = "Avatar::#{data[:object]}"
if data[:full] if data[:full]
store_full = Store.add( store_full = Store.add(
:object => "#{object_name}::Full", object: "#{object_name}::Full",
:o_id => data[:o_id], o_id: data[:o_id],
:data => data[:full][:content], data: data[:full][:content],
:filename => 'avatar_full', filename: 'avatar_full',
:preferences => { preferences: {
'Mime-Type' => data[:full][:mime_type] 'Mime-Type' => data[:full][:mime_type]
}, },
:created_by_id => data[:created_by_id], created_by_id: data[:created_by_id],
) )
record[:store_full_id] = store_full.id record[:store_full_id] = store_full.id
record[:store_hash] = Digest::MD5.hexdigest( data[:full][:content] ) record[:store_hash] = Digest::MD5.hexdigest( data[:full][:content] )
end end
if data[:resize] if data[:resize]
store_resize = Store.add( store_resize = Store.add(
:object => "#{object_name}::Resize", object: "#{object_name}::Resize",
:o_id => data[:o_id], o_id: data[:o_id],
:data => data[:resize][:content], data: data[:resize][:content],
:filename => 'avatar', filename: 'avatar',
:preferences => { preferences: {
'Mime-Type' => data[:resize][:mime_type] 'Mime-Type' => data[:resize][:mime_type]
}, },
:created_by_id => data[:created_by_id], created_by_id: data[:created_by_id],
) )
record[:store_resize_id] = store_resize.id record[:store_resize_id] = store_resize.id
record[:store_hash] = Digest::MD5.hexdigest( data[:resize][:content] ) record[:store_hash] = Digest::MD5.hexdigest( data[:resize][:content] )
@ -211,9 +211,9 @@ set avatars as default
def self.set_default( object_name, o_id, avatar_id ) def self.set_default( object_name, o_id, avatar_id )
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
avatar = Avatar.where( avatar = Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
:id => avatar_id, id: avatar_id,
).first ).first
avatar.default = true avatar.default = true
avatar.save! avatar.save!
@ -235,18 +235,18 @@ remove all avatars of an object
def self.remove( object_name, o_id ) def self.remove( object_name, o_id )
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
Avatar.where( Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
).destroy_all ).destroy_all
object_name_store = "Avatar::#{object_name}" object_name_store = "Avatar::#{object_name}"
Store.remove( Store.remove(
:object => "#{object_name_store}::Full", object: "#{object_name_store}::Full",
:o_id => o_id, o_id: o_id,
) )
Store.remove( Store.remove(
:object => "#{object_name_store}::Resize", object: "#{object_name_store}::Resize",
:o_id => o_id, o_id: o_id,
) )
end end
@ -261,9 +261,9 @@ remove one avatars of an object
def self.remove_one( object_name, o_id, avatar_id ) def self.remove_one( object_name, o_id, avatar_id )
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
Avatar.where( Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
:id => avatar_id, id: avatar_id,
).destroy_all ).destroy_all
end end
@ -278,8 +278,8 @@ return all avatars of an user
def self.list(object_name, o_id) def self.list(object_name, o_id)
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
avatars = Avatar.where( avatars = Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
).order( 'initial DESC, deletable ASC, created_at ASC, id DESC' ) ).order( 'initial DESC, deletable ASC, created_at ASC, id DESC' )
# add initial avatar # add initial avatar
@ -311,7 +311,7 @@ returns:
def self.get_by_hash(hash) def self.get_by_hash(hash)
avatar = Avatar.where( avatar = Avatar.where(
:store_hash => hash, store_hash: hash,
).first ).first
return if !avatar return if !avatar
file = Store.find(avatar.store_resize_id) file = Store.find(avatar.store_resize_id)
@ -332,9 +332,9 @@ returns:
def self.get_default(object_name, o_id) def self.get_default(object_name, o_id)
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
Avatar.where( Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
:default => true, default: true,
).first ).first
end end
@ -342,8 +342,8 @@ returns:
def self.set_default_items(object_id, o_id, avatar_id) def self.set_default_items(object_id, o_id, avatar_id)
avatars = Avatar.where( avatars = Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
).order( 'created_at ASC, id DESC' ) ).order( 'created_at ASC, id DESC' )
avatars.each do |avatar| avatars.each do |avatar|
next if avatar.id == avatar_id next if avatar.id == avatar_id
@ -355,20 +355,20 @@ returns:
def self.add_init_avatar(object_id, o_id) def self.add_init_avatar(object_id, o_id)
count = Avatar.where( count = Avatar.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
).count ).count
return if count > 0 return if count > 0
Avatar.create( Avatar.create(
:o_id => o_id, o_id: o_id,
:object_lookup_id => object_id, object_lookup_id: object_id,
:default => true, default: true,
:source => 'init', source: 'init',
:initial => true, initial: true,
:deletable => false, deletable: false,
:updated_by_id => 1, updated_by_id: 1,
:created_by_id => 1, created_by_id: 1,
) )
end end
end end

View file

@ -130,7 +130,7 @@ class Channel::EmailParser
data[:body] = Encode.conv( mail.text_part.charset, data[:body] ) data[:body] = Encode.conv( mail.text_part.charset, data[:body] )
if !data[:body].valid_encoding? if !data[:body].valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '?') data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end end
# html attachment/body may exists and will be converted to text # html attachment/body may exists and will be converted to text
@ -143,7 +143,7 @@ class Channel::EmailParser
data[:body] = data[:body].html2text.to_s.force_encoding('utf-8') data[:body] = data[:body].html2text.to_s.force_encoding('utf-8')
if !data[:body].force_encoding('UTF-8').valid_encoding? if !data[:body].force_encoding('UTF-8').valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '?') data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end end
# any other attachments # any other attachments
@ -165,9 +165,9 @@ class Channel::EmailParser
headers_store['Charset'] = mail.html_part.charset headers_store['Charset'] = mail.html_part.charset
end end
attachment = { attachment = {
:data => mail.html_part.body.to_s, data: mail.html_part.body.to_s,
:filename => mail.html_part.filename || filename, filename: mail.html_part.filename || filename,
:preferences => headers_store preferences: headers_store
} }
data[:attachments].push attachment data[:attachments].push attachment
end end
@ -196,7 +196,7 @@ class Channel::EmailParser
data[:body] = Encode.conv( mail.charset, data[:body] ) data[:body] = Encode.conv( mail.charset, data[:body] )
if !data[:body].force_encoding('UTF-8').valid_encoding? if !data[:body].force_encoding('UTF-8').valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '?') data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end end
# html part only, convert ot text and add it as attachment # html part only, convert ot text and add it as attachment
@ -209,7 +209,7 @@ class Channel::EmailParser
data[:body] = data[:body].html2text.to_s.force_encoding('utf-8') data[:body] = data[:body].html2text.to_s.force_encoding('utf-8')
if !data[:body].valid_encoding? if !data[:body].valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '?') data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end end
# any other attachments # any other attachments
@ -228,9 +228,9 @@ class Channel::EmailParser
headers_store['Charset'] = mail.charset headers_store['Charset'] = mail.charset
end end
attachment = { attachment = {
:data => mail.body.decoded, data: mail.body.decoded,
:filename => mail.filename || filename, filename: mail.filename || filename,
:preferences => headers_store preferences: headers_store
} }
data[:attachments].push attachment data[:attachments].push attachment
end end
@ -316,9 +316,9 @@ class Channel::EmailParser
headers_store.delete('Content-Disposition') headers_store.delete('Content-Disposition')
attach = { attach = {
:data => file.body.to_s, data: file.body.to_s,
:filename => filename, filename: filename,
:preferences => headers_store, preferences: headers_store,
} }
[attach] [attach]
end end
@ -358,18 +358,18 @@ class Channel::EmailParser
# create sender # create sender
if mail[ 'x-zammad-customer-login'.to_sym ] if mail[ 'x-zammad-customer-login'.to_sym ]
user = User.where( :login => mail[ 'x-zammad-customer-login'.to_sym ] ).first user = User.where( login: mail[ 'x-zammad-customer-login'.to_sym ] ).first
end end
if !user if !user
user = User.where( :email => mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email] ).first user = User.where( email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email] ).first
end end
if !user if !user
puts 'create user...' puts 'create user...'
user = user_create( user = user_create(
:login => mail[ 'x-zammad-customer-login'.to_sym ] || mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email], login: mail[ 'x-zammad-customer-login'.to_sym ] || mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
:firstname => mail[ 'x-zammad-customer-firstname'.to_sym ] || mail[:from_display_name], firstname: mail[ 'x-zammad-customer-firstname'.to_sym ] || mail[:from_display_name],
:lastname => mail[ 'x-zammad-customer-lastname'.to_sym ], lastname: mail[ 'x-zammad-customer-lastname'.to_sym ],
:email => mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email], email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
) )
end end
@ -379,9 +379,9 @@ class Channel::EmailParser
items = mail[item.to_sym].tree items = mail[item.to_sym].tree
items.addresses.each {|item| items.addresses.each {|item|
user_create( user_create(
:firstname => item.display_name, firstname: item.display_name,
:lastname => '', lastname: '',
:email => item.address, email: item.address,
) )
} }
end end
@ -404,7 +404,7 @@ class Channel::EmailParser
end end
if state_type.name != 'new' if state_type.name != 'new'
ticket.state = Ticket::State.where( :name => 'open' ).first ticket.state = Ticket::State.where( name: 'open' ).first
ticket.save ticket.save
end end
end end
@ -414,11 +414,11 @@ class Channel::EmailParser
# set attributes # set attributes
ticket = Ticket.new( ticket = Ticket.new(
:group_id => channel[:group_id] || 1, group_id: channel[:group_id] || 1,
:customer_id => user.id, customer_id: user.id,
:title => mail[:subject] || '', title: mail[:subject] || '',
:state_id => Ticket::State.where( :name => 'new' ).first.id, state_id: Ticket::State.where( name: 'new' ).first.id,
:priority_id => Ticket::Priority.where( :name => '2 normal' ).first.id, priority_id: Ticket::Priority.where( name: '2 normal' ).first.id,
) )
set_attributes_by_x_headers( ticket, 'ticket', mail ) set_attributes_by_x_headers( ticket, 'ticket', mail )
@ -431,16 +431,16 @@ class Channel::EmailParser
# set attributes # set attributes
article = Ticket::Article.new( article = Ticket::Article.new(
:ticket_id => ticket.id, ticket_id: ticket.id,
:type_id => Ticket::Article::Type.where( :name => 'email' ).first.id, type_id: Ticket::Article::Type.where( name: 'email' ).first.id,
:sender_id => Ticket::Article::Sender.where( :name => 'Customer' ).first.id, sender_id: Ticket::Article::Sender.where( name: 'Customer' ).first.id,
:body => mail[:body], body: mail[:body],
:from => mail[:from], from: mail[:from],
:to => mail[:to], to: mail[:to],
:cc => mail[:cc], cc: mail[:cc],
:subject => mail[:subject], subject: mail[:subject],
:message_id => mail[:message_id], message_id: mail[:message_id],
:internal => false, internal: false,
) )
# x-headers lookup # x-headers lookup
@ -451,22 +451,22 @@ class Channel::EmailParser
# store mail plain # store mail plain
Store.add( Store.add(
:object => 'Ticket::Article::Mail', object: 'Ticket::Article::Mail',
:o_id => article.id, o_id: article.id,
:data => msg, data: msg,
:filename => "ticket-#{ticket.number}-#{article.id}.eml", filename: "ticket-#{ticket.number}-#{article.id}.eml",
:preferences => {} preferences: {}
) )
# store attachments # store attachments
if mail[:attachments] if mail[:attachments]
mail[:attachments].each do |attachment| mail[:attachments].each do |attachment|
Store.add( Store.add(
:object => 'Ticket::Article', object: 'Ticket::Article',
:o_id => article.id, o_id: article.id,
:data => attachment[:data], data: attachment[:data],
:filename => attachment[:filename], filename: attachment[:filename],
:preferences => attachment[:preferences] preferences: attachment[:preferences]
) )
end end
end end
@ -497,11 +497,11 @@ class Channel::EmailParser
def user_create(data) def user_create(data)
# return existing # return existing
user = User.where( :login => data[:email].downcase ).first user = User.where( login: data[:email].downcase ).first
return user if user return user if user
# create new user # create new user
roles = Role.where( :name => 'Customer' ) roles = Role.where( name: 'Customer' )
# fillup # fillup
['firstname', 'lastname'].each { |item| ['firstname', 'lastname'].each { |item|
@ -517,8 +517,8 @@ class Channel::EmailParser
user = User.create(data) user = User.create(data)
user.update_attributes( user.update_attributes(
:updated_by_id => user.id, updated_by_id: user.id,
:created_by_id => user.id, created_by_id: user.id,
) )
user user
end end
@ -547,12 +547,12 @@ class Channel::EmailParser
item = assoc.class_name.constantize item = assoc.class_name.constantize
if item.respond_to?(:name) if item.respond_to?(:name)
if item.lookup( :name => mail[ header.to_sym ] ) if item.lookup( name: mail[ header.to_sym ] )
item_object[key] = item.lookup( :name => mail[ header.to_sym ] ).id item_object[key] = item.lookup( name: mail[ header.to_sym ] ).id
end end
elsif item.respond_to?(:login) elsif item.respond_to?(:login)
if item.lookup( :login => mail[ header.to_sym ] ) if item.lookup( login: mail[ header.to_sym ] )
item_object[key] = item.lookup( :login => mail[ header.to_sym ] ).id item_object[key] = item.lookup( login: mail[ header.to_sym ] ).id
end end
end end
end end

View file

@ -4,7 +4,7 @@ require 'net/imap'
module Channel::EmailSend module Channel::EmailSend
def self.send(attr, notification = false) def self.send(attr, notification = false)
channel = Channel.where( :area => 'Email::Outbound', :active => true ).first channel = Channel.where( area: 'Email::Outbound', active: true ).first
begin begin
c = eval 'Channel::' + channel[:adapter] + '.new' c = eval 'Channel::' + channel[:adapter] + '.new'
c.send(attr, channel, notification) c.send(attr, channel, notification)

View file

@ -25,7 +25,7 @@ class Channel::Facebook
'id', 'id',
'comments', 'comments',
{ {
:message => self.body message: self.body
} }
) )
# client.direct_message_create( # client.direct_message_create(

View file

@ -6,7 +6,7 @@ module Channel::Filter::Database
def self.run( channel, mail ) def self.run( channel, mail )
# process postmaster filter # process postmaster filter
filters = PostmasterFilter.where( :active => true, :channel => 'email' ) filters = PostmasterFilter.where( active: true, channel: 'email' )
filters.each {|filter| filters.each {|filter|
puts " proccess filter #{filter.name} ..." puts " proccess filter #{filter.name} ..."
match = true match = true

View file

@ -8,13 +8,13 @@ class Channel::SMTP
mail = Channel::EmailBuild.build(attr, notification) mail = Channel::EmailBuild.build(attr, notification)
mail.delivery_method :smtp, { mail.delivery_method :smtp, {
:openssl_verify_mode => 'none', openssl_verify_mode: 'none',
:address => channel[:options][:host], address: channel[:options][:host],
:port => channel[:options][:port] || 25, port: channel[:options][:port] || 25,
:domain => channel[:options][:host], domain: channel[:options][:host],
:user_name => channel[:options][:user], user_name: channel[:options][:user],
:password => channel[:options][:password], password: channel[:options][:password],
:enable_starttls_auto => true, enable_starttls_auto: true,
} }
mail.deliver mail.deliver
end end

View file

@ -28,7 +28,7 @@ class Channel::TWITTER2
channel[:options][:search].each { |search| channel[:options][:search].each { |search|
puts " - searching for #{search[:item]}" puts " - searching for #{search[:item]}"
tweets = [] tweets = []
@client.search( search[:item], :count => 50, :result_type => 'recent' ).collect do |tweet| @client.search( search[:item], count: 50, result_type: 'recent' ).collect do |tweet|
tweets.push tweet tweets.push tweet
end end
@article_type = 'twitter status' @article_type = 'twitter status'
@ -74,7 +74,7 @@ class Channel::TWITTER2
all_tweets.each do |tweet| all_tweets.each do |tweet|
# check if tweet is already imported # check if tweet is already imported
article = Ticket::Article.where( :message_id => tweet.id.to_s ).first article = Ticket::Article.where( message_id: tweet.id.to_s ).first
# check if sender already exists # check if sender already exists
next if article next if article
@ -140,34 +140,34 @@ class Channel::TWITTER2
# create sender in db # create sender in db
# puts tweet.inspect # puts tweet.inspect
# user = User.where( :login => tweet.sender.screen_name ).first # user = User.where( :login => tweet.sender.screen_name ).first
auth = Authorization.where( :uid => sender.id, :provider => 'twitter' ).first auth = Authorization.where( uid: sender.id, provider: 'twitter' ).first
user = nil user = nil
if auth if auth
puts 'user_id', auth.user_id puts 'user_id', auth.user_id
user = User.where( :id => auth.user_id ).first user = User.where( id: auth.user_id ).first
end end
if !user if !user
puts 'create user...' puts 'create user...'
roles = Role.where( :name => 'Customer' ) roles = Role.where( name: 'Customer' )
user = User.create( user = User.create(
:login => sender.screen_name, login: sender.screen_name,
:firstname => sender.name, firstname: sender.name,
:lastname => '', lastname: '',
:email => '', email: '',
:password => '', password: '',
:image_source => sender.profile_image_url.to_s, image_source: sender.profile_image_url.to_s,
:note => sender.description, note: sender.description,
:active => true, active: true,
:roles => roles, roles: roles,
:updated_by_id => 1, updated_by_id: 1,
:created_by_id => 1 created_by_id: 1
) )
puts 'autentication create...' puts 'autentication create...'
authentication = Authorization.create( authentication = Authorization.create(
:uid => sender.id, uid: sender.id,
:username => sender.screen_name, username: sender.screen_name,
:user_id => user.id, user_id: user.id,
:provider => 'twitter' provider: 'twitter'
) )
else else
puts 'user exists'#, user.inspect puts 'user exists'#, user.inspect
@ -185,7 +185,7 @@ class Channel::TWITTER2
# check if ticket exists # check if ticket exists
if tweet.respond_to?('in_reply_to_status_id') && tweet.in_reply_to_status_id && tweet.in_reply_to_status_id.to_s != '' if tweet.respond_to?('in_reply_to_status_id') && tweet.in_reply_to_status_id && tweet.in_reply_to_status_id.to_s != ''
puts 'tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s puts 'tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s
article = Ticket::Article.where( :message_id => tweet.in_reply_to_status_id.to_s ).first article = Ticket::Article.where( message_id: tweet.in_reply_to_status_id.to_s ).first
if article if article
puts 'article with id found tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s puts 'article with id found tweet.in_reply_to_status_id found: ' + tweet.in_reply_to_status_id.to_s
return article.ticket return article.ticket
@ -193,14 +193,14 @@ class Channel::TWITTER2
end end
# find if record already exists # find if record already exists
article = Ticket::Article.where( :message_id => tweet.id.to_s ).first article = Ticket::Article.where( message_id: tweet.id.to_s ).first
if article if article
return article.ticket return article.ticket
end end
ticket = nil ticket = nil
if @article_type == 'twitter direct-message' if @article_type == 'twitter direct-message'
ticket = Ticket.where( :customer_id => user.id ).first ticket = Ticket.where( customer_id: user.id ).first
if ticket if ticket
state_type = Ticket::StateType.where( ticket.state.state_type_id ) state_type = Ticket::StateType.where( ticket.state.state_type_id )
if state_type.name == 'closed' || state_type.name == 'closed' if state_type.name == 'closed' || state_type.name == 'closed'
@ -209,27 +209,27 @@ class Channel::TWITTER2
end end
end end
if !ticket if !ticket
group = Group.where( :name => group ).first group = Group.where( name: group ).first
group_id = 1 group_id = 1
if group if group
group_id = group.id group_id = group.id
end end
state = Ticket::State.where( :name => 'new' ).first state = Ticket::State.where( name: 'new' ).first
state_id = 1 state_id = 1
if state if state
state_id = state.id state_id = state.id
end end
priority = Ticket::Priority.where( :name => '2 normal' ).first priority = Ticket::Priority.where( name: '2 normal' ).first
priority_id = 1 priority_id = 1
if priority if priority
priority_id = priority.id priority_id = priority.id
end end
ticket = Ticket.create( ticket = Ticket.create(
:group_id => group_id, group_id: group_id,
:customer_id => user.id, customer_id: user.id,
:title => tweet.text[0,40], title: tweet.text[0,40],
:state_id => state_id, state_id: state_id,
:priority_id => priority_id, priority_id: priority_id,
) )
end end
@ -239,12 +239,12 @@ class Channel::TWITTER2
def fetch_article_create( user, ticket, tweet, sender ) def fetch_article_create( user, ticket, tweet, sender )
# find if record already exists # find if record already exists
article = Ticket::Article.where( :message_id => tweet.id.to_s ).first article = Ticket::Article.where( message_id: tweet.id.to_s ).first
return article if article return article if article
# set ticket state to open if not new # set ticket state to open if not new
if ticket.state.name != 'new' if ticket.state.name != 'new'
ticket.state = Ticket::State.where( :name => 'open' ).first ticket.state = Ticket::State.where( name: 'open' ).first
ticket.save ticket.save
end end
@ -255,21 +255,21 @@ class Channel::TWITTER2
end end
article = Ticket::Article.create( article = Ticket::Article.create(
:ticket_id => ticket.id, ticket_id: ticket.id,
:type_id => Ticket::Article::Type.where( :name => @article_type ).first.id, type_id: Ticket::Article::Type.where( name: @article_type ).first.id,
:sender_id => Ticket::Article::Sender.where( :name => 'Customer' ).first.id, sender_id: Ticket::Article::Sender.where( name: 'Customer' ).first.id,
:body => tweet.text, body: tweet.text,
:from => sender.name, from: sender.name,
:to => to, to: to,
:message_id => tweet.id, message_id: tweet.id,
:internal => false, internal: false,
) )
end end
def send(attr, notification = false) def send(attr, notification = false)
# logger.debug('tweeeeettttt!!!!!!') # logger.debug('tweeeeettttt!!!!!!')
channel = Channel.where( :area => 'Twitter::Inbound', :active => true ).first channel = Channel.where( area: 'Twitter::Inbound', active: true ).first
client = Twitter::REST::Client.new do |config| client = Twitter::REST::Client.new do |config|
config.consumer_key = channel[:options][:consumer_key] config.consumer_key = channel[:options][:consumer_key]
@ -292,7 +292,7 @@ class Channel::TWITTER2
message = client.update( message = client.update(
attr[:body].to_s, attr[:body].to_s,
{ {
:in_reply_to_status_id => attr[:in_reply_to] in_reply_to_status_id: attr[:in_reply_to]
} }
) )
# puts message.inspect # puts message.inspect

View file

@ -1,9 +1,9 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class EmailAddress < ApplicationModel class EmailAddress < ApplicationModel
has_many :groups, :after_add => :cache_update, :after_remove => :cache_update has_many :groups, after_add: :cache_update, after_remove: :cache_update
validates :realname, :presence => true validates :realname, presence: true
validates :email, :presence => true validates :email, presence: true
latest_change_support latest_change_support

View file

@ -1,12 +1,12 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Group < ApplicationModel class Group < ApplicationModel
has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update
belongs_to :email_address belongs_to :email_address
belongs_to :signature belongs_to :signature
validates :name, :presence => true validates :name, presence: true
activity_stream_support :role => Z_ROLENAME_ADMIN activity_stream_support role: Z_ROLENAME_ADMIN
history_support history_support
latest_change_support latest_change_support
end end

View file

@ -5,9 +5,9 @@ class History < ApplicationModel
include History::Assets include History::Assets
self.table_name = 'histories' self.table_name = 'histories'
belongs_to :history_type, :class_name => 'History::Type' belongs_to :history_type, class_name: 'History::Type'
belongs_to :history_object, :class_name => 'History::Object' belongs_to :history_object, class_name: 'History::Object'
belongs_to :history_attribute, :class_name => 'History::Attribute' belongs_to :history_attribute, class_name: 'History::Attribute'
# before_validation :check_type, :check_object # before_validation :check_type, :check_object
# attr_writer :history_type, :history_object # attr_writer :history_type, :history_object
@ -60,23 +60,23 @@ add a new history entry for an object
# create history # create history
record = { record = {
:id => data[:id], id: data[:id],
:o_id => data[:o_id], o_id: data[:o_id],
:history_type_id => history_type.id, history_type_id: history_type.id,
:history_object_id => history_object.id, history_object_id: history_object.id,
:history_attribute_id => history_attribute_id, history_attribute_id: history_attribute_id,
:related_history_object_id => related_history_object_id, related_history_object_id: related_history_object_id,
:related_o_id => data[:related_o_id], related_o_id: data[:related_o_id],
:value_from => data[:value_from], value_from: data[:value_from],
:value_to => data[:value_to], value_to: data[:value_to],
:id_from => data[:id_from], id_from: data[:id_from],
:id_to => data[:id_to], id_to: data[:id_to],
:created_at => data[:created_at], created_at: data[:created_at],
:created_by_id => data[:created_by_id] created_by_id: data[:created_by_id]
} }
history_record = nil history_record = nil
if data[:id] if data[:id]
history_record = History.where( :id => data[:id] ).first history_record = History.where( id: data[:id] ).first
end end
if history_record if history_record
history_record.update_attributes(record) history_record.update_attributes(record)
@ -98,11 +98,11 @@ remove whole history entries of an object
=end =end
def self.remove( requested_object, requested_object_id ) def self.remove( requested_object, requested_object_id )
history_object = History::Object.where( :name => requested_object ).first history_object = History::Object.where( name: requested_object ).first
return if !history_object return if !history_object
History.where( History.where(
:history_object_id => history_object.id, history_object_id: history_object.id,
:o_id => requested_object_id, o_id: requested_object_id,
).destroy_all ).destroy_all
end end
@ -152,8 +152,8 @@ returns
def self.list( requested_object, requested_object_id, related_history_object = nil, assets = nil ) def self.list( requested_object, requested_object_id, related_history_object = nil, assets = nil )
if !related_history_object if !related_history_object
history_object = self.object_lookup( requested_object ) history_object = self.object_lookup( requested_object )
history = History.where( :history_object_id => history_object.id ). history = History.where( history_object_id: history_object.id ).
where( :o_id => requested_object_id ). where( o_id: requested_object_id ).
order('created_at ASC, id ASC') order('created_at ASC, id ASC')
else else
history_object_requested = self.object_lookup( requested_object ) history_object_requested = self.object_lookup( requested_object )
@ -208,8 +208,8 @@ returns
end end
if assets if assets
return { return {
:list => list, list: list,
:assets => asset_list, assets: asset_list,
} }
end end
list list
@ -223,7 +223,7 @@ returns
return @@cache_type[ id ] if @@cache_type[ id ] return @@cache_type[ id ] if @@cache_type[ id ]
# lookup # lookup
history_type = History::Type.lookup( :id => id ) history_type = History::Type.lookup( id: id )
@@cache_type[ id ] = history_type @@cache_type[ id ] = history_type
return history_type return history_type
end end
@ -234,7 +234,7 @@ returns
return @@cache_type[ name ] if @@cache_type[ name ] return @@cache_type[ name ] if @@cache_type[ name ]
# lookup # lookup
history_type = History::Type.lookup( :name => name ) history_type = History::Type.lookup( name: name )
if history_type if history_type
@@cache_type[ name ] = history_type @@cache_type[ name ] = history_type
return history_type return history_type
@ -242,7 +242,7 @@ returns
# create # create
history_type = History::Type.create( history_type = History::Type.create(
:name => name name: name
) )
@@cache_type[ name ] = history_type @@cache_type[ name ] = history_type
return history_type return history_type
@ -254,7 +254,7 @@ returns
return @@cache_object[ id ] if @@cache_object[ id ] return @@cache_object[ id ] if @@cache_object[ id ]
# lookup # lookup
history_object = History::Object.lookup( :id => id ) history_object = History::Object.lookup( id: id )
@@cache_object[ id ] = history_object @@cache_object[ id ] = history_object
return history_object return history_object
end end
@ -265,7 +265,7 @@ returns
return @@cache_object[ name ] if @@cache_object[ name ] return @@cache_object[ name ] if @@cache_object[ name ]
# lookup # lookup
history_object = History::Object.lookup( :name => name ) history_object = History::Object.lookup( name: name )
if history_object if history_object
@@cache_object[ name ] = history_object @@cache_object[ name ] = history_object
return history_object return history_object
@ -273,7 +273,7 @@ returns
# create # create
history_object = History::Object.create( history_object = History::Object.create(
:name => name name: name
) )
@@cache_object[ name ] = history_object @@cache_object[ name ] = history_object
return history_object return history_object
@ -285,7 +285,7 @@ returns
return @@cache_attribute[ id ] if @@cache_attribute[ id ] return @@cache_attribute[ id ] if @@cache_attribute[ id ]
# lookup # lookup
history_attribute = History::Attribute.lookup( :id => id ) history_attribute = History::Attribute.lookup( id: id )
@@cache_attribute[ id ] = history_attribute @@cache_attribute[ id ] = history_attribute
return history_attribute return history_attribute
end end
@ -296,7 +296,7 @@ returns
return @@cache_attribute[ name ] if @@cache_attribute[ name ] return @@cache_attribute[ name ] if @@cache_attribute[ name ]
# lookup # lookup
history_attribute = History::Attribute.lookup( :name => name ) history_attribute = History::Attribute.lookup( name: name )
if history_attribute if history_attribute
@@cache_attribute[ name ] = history_attribute @@cache_attribute[ name ] = history_attribute
return history_attribute return history_attribute
@ -304,7 +304,7 @@ returns
# create # create
history_attribute = History::Attribute.create( history_attribute = History::Attribute.create(
:name => name name: name
) )
@@cache_attribute[ name ] = history_attribute @@cache_attribute[ name ] = history_attribute
return history_attribute return history_attribute

View file

@ -23,7 +23,7 @@ returns
def assets (data) def assets (data)
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self['created_by_id'] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self['created_by_id'] ]
user = User.lookup( :id => self['created_by_id'] ) user = User.lookup( id: self['created_by_id'] )
data = user.assets( data ) data = user.assets( data )
end end

View file

@ -4,7 +4,7 @@ class Job < ApplicationModel
store :timeplan store :timeplan
store :condition store :condition
store :execute store :execute
validates :name, :presence => true validates :name, presence: true
before_create :updated_matching before_create :updated_matching
before_update :updated_matching before_update :updated_matching
@ -22,7 +22,7 @@ class Job < ApplicationModel
5 => 'fri', 5 => 'fri',
6 => 'sat', 6 => 'sat',
} }
jobs = Job.where( :active => true ) jobs = Job.where( active: true )
jobs.each do |job| jobs.each do |job|
# only execute jobs, older then 1 min, to give admin posibility to change # only execute jobs, older then 1 min, to give admin posibility to change

View file

@ -1,8 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Link < ApplicationModel class Link < ApplicationModel
belongs_to :link_type, :class_name => 'Link::Type' belongs_to :link_type, class_name: 'Link::Type'
belongs_to :link_object, :class_name => 'Link::Object' belongs_to :link_object, class_name: 'Link::Object'
@map = { @map = {
'normal' => 'normal', 'normal' => 'normal',
@ -20,7 +20,7 @@ class Link < ApplicationModel
=end =end
def self.list(data) def self.list(data)
linkobject = self.link_object_get( :name => data[:link_object] ) linkobject = self.link_object_get( name: data[:link_object] )
return if !linkobject return if !linkobject
items = [] items = []
@ -75,19 +75,19 @@ class Link < ApplicationModel
def self.add(data) def self.add(data)
if data.has_key?(:link_type) if data.has_key?(:link_type)
linktype = self.link_type_get( :name => data[:link_type] ) linktype = self.link_type_get( name: data[:link_type] )
data[:link_type_id] = linktype.id data[:link_type_id] = linktype.id
data.delete( :link_type ) data.delete( :link_type )
end end
if data.has_key?(:link_object_source) if data.has_key?(:link_object_source)
linkobject = self.link_object_get( :name => data[:link_object_source] ) linkobject = self.link_object_get( name: data[:link_object_source] )
data[:link_object_source_id] = linkobject.id data[:link_object_source_id] = linkobject.id
data.delete( :link_object_source ) data.delete( :link_object_source )
end end
if data.has_key?(:link_object_target) if data.has_key?(:link_object_target)
linkobject = self.link_object_get( :name => data[:link_object_target] ) linkobject = self.link_object_get( name: data[:link_object_target] )
data[:link_object_target_id] = linkobject.id data[:link_object_target_id] = linkobject.id
data.delete( :link_object_target ) data.delete( :link_object_target )
end end
@ -109,26 +109,26 @@ class Link < ApplicationModel
def self.remove(data) def self.remove(data)
if data.has_key?(:link_object_source) if data.has_key?(:link_object_source)
linkobject = self.link_object_get( :name => data[:link_object_source] ) linkobject = self.link_object_get( name: data[:link_object_source] )
data[:link_object_source_id] = linkobject.id data[:link_object_source_id] = linkobject.id
end end
if data.has_key?(:link_object_target) if data.has_key?(:link_object_target)
linkobject = self.link_object_get( :name => data[:link_object_target] ) linkobject = self.link_object_get( name: data[:link_object_target] )
data[:link_object_target_id] = linkobject.id data[:link_object_target_id] = linkobject.id
end end
# from one site # from one site
if data.has_key?(:link_type) if data.has_key?(:link_type)
linktype = self.link_type_get( :name => data[:link_type] ) linktype = self.link_type_get( name: data[:link_type] )
data[:link_type_id] = linktype.id data[:link_type_id] = linktype.id
end end
links = Link.where( links = Link.where(
:link_type_id => data[:link_type_id], link_type_id: data[:link_type_id],
:link_object_source_id => data[:link_object_source_id], link_object_source_id: data[:link_object_source_id],
:link_object_source_value => data[:link_object_source_value], link_object_source_value: data[:link_object_source_value],
:link_object_target_id => data[:link_object_target_id], link_object_target_id: data[:link_object_target_id],
:link_object_target_value => data[:link_object_target_value] link_object_target_value: data[:link_object_target_value]
) )
links.each { |link| links.each { |link|
link.destroy link.destroy
@ -136,15 +136,15 @@ class Link < ApplicationModel
# from the other site # from the other site
if data.has_key?(:link_type) if data.has_key?(:link_type)
linktype = self.link_type_get( :name => @map[ data[:link_type] ] ) linktype = self.link_type_get( name: @map[ data[:link_type] ] )
data[:link_type_id] = linktype.id data[:link_type_id] = linktype.id
end end
links = Link.where( links = Link.where(
:link_type_id => data[:link_type_id], link_type_id: data[:link_type_id],
:link_object_target_id => data[:link_object_source_id], link_object_target_id: data[:link_object_source_id],
:link_object_target_value => data[:link_object_source_value], link_object_target_value: data[:link_object_source_value],
:link_object_source_id => data[:link_object_target_id], link_object_source_id: data[:link_object_target_id],
:link_object_source_value => data[:link_object_target_value] link_object_source_value: data[:link_object_target_value]
) )
links.each { |link| links.each { |link|
link.destroy link.destroy
@ -153,20 +153,20 @@ class Link < ApplicationModel
private private
def self.link_type_get(data) def self.link_type_get(data)
linktype = Link::Type.where( :name => data[:name] ).first linktype = Link::Type.where( name: data[:name] ).first
if !linktype if !linktype
linktype = Link::Type.create( linktype = Link::Type.create(
:name => data[:name] name: data[:name]
) )
end end
return linktype return linktype
end end
def self.link_object_get(data) def self.link_object_get(data)
linkobject = Link::Object.where( :name => data[:name] ).first linkobject = Link::Object.where( name: data[:name] ).first
if !linkobject if !linkobject
linkobject = Link::Object.create( linkobject = Link::Object.create(
:name => data[:name] name: data[:name]
) )
end end
return linkobject return linkobject
@ -175,9 +175,9 @@ class Link < ApplicationModel
end end
class Link::Type < ApplicationModel class Link::Type < ApplicationModel
validates :name, :presence => true validates :name, presence: true
end end
class Link::Object < ApplicationModel class Link::Object < ApplicationModel
validates :name, :presence => true validates :name, presence: true
end end

View file

@ -9,7 +9,7 @@ class Locale < ApplicationModel
url, url,
{}, {},
{ {
:json => true, json: true,
} }
) )
@ -17,7 +17,7 @@ class Locale < ApplicationModel
result.data.each {|locale| result.data.each {|locale|
puts locale.inspect puts locale.inspect
exists = Locale.where(:locale => locale['locale']).first exists = Locale.where(locale: locale['locale']).first
if exists if exists
exists.update(locale.symbolize_keys!) exists.update(locale.symbolize_keys!)
else else

View file

@ -9,7 +9,7 @@ class ObjectLookup < ApplicationModel
return @@cache_object[ id ] if @@cache_object[ id ] return @@cache_object[ id ] if @@cache_object[ id ]
# lookup # lookup
lookup = self.lookup( :id => id ) lookup = self.lookup( id: id )
return if !lookup return if !lookup
@@cache_object[ id ] = lookup.name @@cache_object[ id ] = lookup.name
lookup.name lookup.name
@ -21,7 +21,7 @@ class ObjectLookup < ApplicationModel
return @@cache_object[ name ] if @@cache_object[ name ] return @@cache_object[ name ] if @@cache_object[ name ]
# lookup # lookup
lookup = self.lookup( :name => name ) lookup = self.lookup( name: name )
if lookup if lookup
@@cache_object[ name ] = lookup.id @@cache_object[ name ] = lookup.id
return lookup.id return lookup.id
@ -29,7 +29,7 @@ class ObjectLookup < ApplicationModel
# create # create
lookup = self.create( lookup = self.create(
:name => name name: name
) )
@@cache_object[ name ] = lookup.id @@cache_object[ name ] = lookup.id
lookup.id lookup.id

View file

@ -30,8 +30,8 @@ end
class ObjectManager::Attribute < ApplicationModel class ObjectManager::Attribute < ApplicationModel
self.table_name = 'object_manager_attributes' self.table_name = 'object_manager_attributes'
belongs_to :object_lookup, :class_name => 'ObjectLookup' belongs_to :object_lookup, class_name: 'ObjectLookup'
validates :name, :presence => true validates :name, presence: true
store :screens store :screens
store :data_option store :data_option
@ -113,8 +113,8 @@ add a new attribute entry for an object
# check newest entry - is needed # check newest entry - is needed
result = ObjectManager::Attribute.where( result = ObjectManager::Attribute.where(
:object_lookup_id => data[:object_lookup_id], object_lookup_id: data[:object_lookup_id],
:name => data[:name], name: data[:name],
).first ).first
if result if result
# raise "ERROR: attribute #{data[:name]} for #{data[:object]} already exists" # raise "ERROR: attribute #{data[:name]} for #{data[:object]} already exists"
@ -145,8 +145,8 @@ get the attribute model based on object and name
end end
ObjectManager::Attribute.where( ObjectManager::Attribute.where(
:object_lookup_id => data[:object_lookup_id], object_lookup_id: data[:object_lookup_id],
:name => data[:name], name: data[:name],
).first ).first
end end
@ -175,15 +175,15 @@ returns:
# get attributes in right order # get attributes in right order
result = ObjectManager::Attribute.where( result = ObjectManager::Attribute.where(
:object_lookup_id => object_lookup_id, object_lookup_id: object_lookup_id,
:active => true, active: true,
).order('position ASC') ).order('position ASC')
attributes = [] attributes = []
result.each {|item| result.each {|item|
data = { data = {
:name => item.name, name: item.name,
:display => item.display, display: item.display,
:tag => item.data_type, tag: item.data_type,
#:null => item.null, #:null => item.null,
} }
if item.screens if item.screens

View file

@ -19,7 +19,7 @@ class Observer::Organization::RefObjectTouch < ActiveRecord::Observer
return if Setting.get('import_mode') return if Setting.get('import_mode')
# touch organizations tickets # touch organizations tickets
Ticket.select('id').where( :organization_id => record.id ).each {|ticket| Ticket.select('id').where( organization_id: record.id ).each {|ticket|
ticket.touch ticket.touch
} }

View file

@ -12,11 +12,11 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer
# add ticket history # add ticket history
History.add( History.add(
:o_id => record.o_id, o_id: record.o_id,
:history_type => 'added', history_type: 'added',
:history_object => 'Ticket', history_object: 'Ticket',
:history_attribute => 'tag', history_attribute: 'tag',
:value_to => record.tag_item.name, value_to: record.tag_item.name,
) )
end end
def after_destroy(record) def after_destroy(record)
@ -26,11 +26,11 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer
# add ticket history # add ticket history
History.add( History.add(
:o_id => record.o_id, o_id: record.o_id,
:history_type => 'removed', history_type: 'removed',
:history_object => 'Ticket', history_object: 'Ticket',
:history_attribute => 'tag', history_attribute: 'tag',
:value_to => record.tag_item.name, value_to: record.tag_item.name,
) )
end end
end end

View file

@ -9,12 +9,12 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
return if Setting.get('import_mode') return if Setting.get('import_mode')
# if sender is customer, do not communication # if sender is customer, do not communication
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
return 1 if sender == nil return 1 if sender == nil
return 1 if sender['name'] == 'Customer' return 1 if sender['name'] == 'Customer'
# only apply on emails # only apply on emails
type = Ticket::Article::Type.lookup( :id => record.type_id ) type = Ticket::Article::Type.lookup( id: record.type_id )
return if type['name'] != 'email' return if type['name'] != 'email'
# send background job # send background job

View file

@ -6,32 +6,32 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
record = Ticket::Article.find( @article_id ) record = Ticket::Article.find( @article_id )
# build subject # build subject
ticket = Ticket.lookup( :id => record.ticket_id ) ticket = Ticket.lookup( id: record.ticket_id )
subject = ticket.subject_build( record.subject ) subject = ticket.subject_build( record.subject )
# send email # send email
message = Channel::EmailSend.send( message = Channel::EmailSend.send(
{ {
:message_id => record.message_id, message_id: record.message_id,
:in_reply_to => record.in_reply_to, in_reply_to: record.in_reply_to,
:from => record.from, from: record.from,
:to => record.to, to: record.to,
:cc => record.cc, cc: record.cc,
:subject => subject, subject: subject,
:content_type => record.content_type, content_type: record.content_type,
:body => record.body, body: record.body,
:attachments => record.attachments attachments: record.attachments
} }
) )
# store mail plain # store mail plain
Store.add( Store.add(
:object => 'Ticket::Article::Mail', object: 'Ticket::Article::Mail',
:o_id => record.id, o_id: record.id,
:data => message.to_s, data: message.to_s,
:filename => "ticket-#{ticket.number}-#{record.id}.eml", filename: "ticket-#{ticket.number}-#{record.id}.eml",
:preferences => {}, preferences: {},
:created_by_id => record.created_by_id, created_by_id: record.created_by_id,
) )
# add history record # add history record
@ -46,14 +46,14 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
} }
if recipient_list != '' if recipient_list != ''
History.add( History.add(
:o_id => record.id, o_id: record.id,
:history_type => 'email', history_type: 'email',
:history_object => 'Ticket::Article', history_object: 'Ticket::Article',
:related_o_id => ticket.id, related_o_id: ticket.id,
:related_history_object => 'Ticket', related_history_object: 'Ticket',
:value_from => record.subject, value_from: record.subject,
:value_to => recipient_list, value_to: recipient_list,
:created_by_id => record.created_by_id, created_by_id: record.created_by_id,
) )
end end
end end

View file

@ -9,20 +9,20 @@ class Observer::Ticket::Article::CommunicateFacebook < ActiveRecord::Observer
return if Setting.get('import_mode') return if Setting.get('import_mode')
# if sender is customer, do not communication # if sender is customer, do not communication
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
return 1 if sender == nil return 1 if sender == nil
return 1 if sender['name'] == 'Customer' return 1 if sender['name'] == 'Customer'
# only apply on emails # only apply on emails
type = Ticket::Article::Type.lookup( :id => record.type_id ) type = Ticket::Article::Type.lookup( id: record.type_id )
return if type['name'] != 'facebook' return if type['name'] != 'facebook'
a = Channel::Facebook.new a = Channel::Facebook.new
a.send( a.send(
{ {
:from => 'me@znuny.com', from: 'me@znuny.com',
:to => 'medenhofer', to: 'medenhofer',
:body => record.body body: record.body
} }
) )
end end

View file

@ -9,21 +9,21 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
return if Setting.get('import_mode') return if Setting.get('import_mode')
# if sender is customer, do not communication # if sender is customer, do not communication
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
return 1 if sender == nil return 1 if sender == nil
return 1 if sender['name'] == 'Customer' return 1 if sender['name'] == 'Customer'
# only apply on tweets # only apply on tweets
type = Ticket::Article::Type.lookup( :id => record.type_id ) type = Ticket::Article::Type.lookup( id: record.type_id )
return if type['name'] != 'twitter direct-message' && type['name'] != 'twitter status' return if type['name'] != 'twitter direct-message' && type['name'] != 'twitter status'
a = Channel::TWITTER2.new a = Channel::TWITTER2.new
message = a.send( message = a.send(
{ {
:type => type['name'], type: type['name'],
:to => record.to, to: record.to,
:body => record.body, body: record.body,
:in_reply_to => record.in_reply_to in_reply_to: record.in_reply_to
}, },
# Rails.application.config.channel_twitter # Rails.application.config.channel_twitter
) )

View file

@ -9,16 +9,16 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
return if Setting.get('import_mode') return if Setting.get('import_mode')
# if sender is customer, do not change anything # if sender is customer, do not change anything
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
return if sender == nil return if sender == nil
return if sender['name'] == 'Customer' return if sender['name'] == 'Customer'
# set email attributes # set email attributes
type = Ticket::Article::Type.lookup( :id => record.type_id ) type = Ticket::Article::Type.lookup( id: record.type_id )
return if type['name'] != 'email' return if type['name'] != 'email'
# set subject if empty # set subject if empty
ticket = Ticket.lookup( :id => record.ticket_id ) ticket = Ticket.lookup( id: record.ticket_id )
if !record.subject || record.subject == '' if !record.subject || record.subject == ''
record.subject = ticket.title record.subject = ticket.title
end end

View file

@ -9,7 +9,7 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
return if Setting.get('import_mode') return if Setting.get('import_mode')
# if sender is customer, do not change anything # if sender is customer, do not change anything
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
return if sender == nil return if sender == nil
return if sender['name'] == 'Customer' return if sender['name'] == 'Customer'

View file

@ -6,7 +6,7 @@ class Observer::Ticket::ArticleSenderType < ActiveRecord::Observer
def after_create(record) def after_create(record)
# get article count # get article count
count = Ticket::Article.where( :ticket_id => record.ticket_id ).count count = Ticket::Article.where( ticket_id: record.ticket_id ).count
return if count > 1 return if count > 1
record.ticket.create_article_type_id = record.type_id record.ticket.create_article_type_id = record.type_id

View file

@ -22,8 +22,8 @@ class Observer::Ticket::CloseTime < ActiveRecord::Observer
return true if record.close_time return true if record.close_time
# check if ticket is closed now # check if ticket is closed now
state = Ticket::State.lookup( :id => record.state_id ) state = Ticket::State.lookup( id: record.state_id )
state_type = Ticket::StateType.lookup( :id => state.state_type_id ) state_type = Ticket::StateType.lookup( id: state.state_type_id )
return true if state_type.name != 'closed' return true if state_type.name != 'closed'
# set close_time # set close_time

View file

@ -13,8 +13,8 @@ class Observer::Ticket::FirstResponse < ActiveRecord::Observer
return true if record.internal return true if record.internal
# if sender is not agent # if sender is not agent
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
type = Ticket::Article::Type.lookup( :id => record.type_id ) type = Ticket::Article::Type.lookup( id: record.type_id )
if sender.name != 'Agent' && type.name !~ /^phone/ if sender.name != 'Agent' && type.name !~ /^phone/
return true return true
end end

View file

@ -10,10 +10,10 @@ class Observer::Ticket::LastContact < ActiveRecord::Observer
return true if record.internal return true if record.internal
# if article is a message to customer # if article is a message to customer
return true if !Ticket::Article::Type.lookup( :id => record.type_id ).communication return true if !Ticket::Article::Type.lookup( id: record.type_id ).communication
# if sender is not customer # if sender is not customer
sender = Ticket::Article::Sender.lookup( :id => record.sender_id ) sender = Ticket::Article::Sender.lookup( id: record.sender_id )
if sender.name == 'Customer' if sender.name == 'Customer'
# check if last communication is done by agent, else do not set last_contact_customer # check if last communication is done by agent, else do not set last_contact_customer

View file

@ -54,7 +54,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
# get current state of objects # get current state of objects
if event[:name] == 'Ticket::Article' if event[:name] == 'Ticket::Article'
article = Ticket::Article.lookup( :id => event[:id] ) article = Ticket::Article.lookup( id: event[:id] )
# next if article is already deleted # next if article is already deleted
next if !article next if !article
@ -71,7 +71,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
end end
elsif event[:name] == 'Ticket' elsif event[:name] == 'Ticket'
ticket = Ticket.lookup( :id => event[:id] ) ticket = Ticket.lookup( id: event[:id] )
# next if ticket is already deleted # next if ticket is already deleted
next if !ticket next if !ticket
@ -115,10 +115,10 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
# puts 'CREATED!!!!' # puts 'CREATED!!!!'
# puts record.inspect # puts record.inspect
e = { e = {
:name => record.class.name, name: record.class.name,
:type => 'create', type: 'create',
:data => record, data: record,
:id => record.id, id: record.id,
} }
EventBuffer.add(e) EventBuffer.add(e)
end end
@ -150,11 +150,11 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
return if real_changes.empty? return if real_changes.empty?
e = { e = {
:name => record.class.name, name: record.class.name,
:type => 'update', type: 'update',
:data => record, data: record,
:changes => real_changes, changes: real_changes,
:id => record.id, id: record.id,
} }
EventBuffer.add(e) EventBuffer.add(e)
end end

View file

@ -66,12 +66,12 @@ class Observer::Ticket::Notification::BackgroundJob
# create online notification # create online notification
seen = ticket.online_notification_seen_state seen = ticket.online_notification_seen_state
OnlineNotification.add( OnlineNotification.add(
:type => @p[:type], type: @p[:type],
:object => 'Ticket', object: 'Ticket',
:o_id => ticket.id, o_id: ticket.id,
:seen => seen, seen: seen,
:created_by_id => ticket.updated_by_id || 1, created_by_id: ticket.updated_by_id || 1,
:user_id => user.id, user_id: user.id,
) )
# create email notification # create email notification
@ -103,12 +103,12 @@ class Observer::Ticket::Notification::BackgroundJob
notification = {} notification = {}
[:subject, :body].each { |key| [:subject, :body].each { |key|
notification[key.to_sym] = NotificationFactory.build( notification[key.to_sym] = NotificationFactory.build(
:locale => user.preferences[:locale], locale: user.preferences[:locale],
:string => template[key], string: template[key],
:objects => { objects: {
:ticket => ticket, ticket: ticket,
:article => article, article: article,
:recipient => user, recipient: user,
} }
) )
} }
@ -120,21 +120,21 @@ class Observer::Ticket::Notification::BackgroundJob
puts "send ticket notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})" puts "send ticket notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
NotificationFactory.send( NotificationFactory.send(
:recipient => user, recipient: user,
:subject => notification[:subject], subject: notification[:subject],
:body => notification[:body], body: notification[:body],
:content_type => 'text/html', content_type: 'text/html',
) )
end end
# add history record # add history record
if recipient_list != '' if recipient_list != ''
History.add( History.add(
:o_id => ticket.id, o_id: ticket.id,
:history_type => 'notification', history_type: 'notification',
:history_object => 'Ticket', history_object: 'Ticket',
:value_to => recipient_list, value_to: recipient_list,
:created_by_id => ticket.updated_by_id || 1 created_by_id: ticket.updated_by_id || 1
) )
end end
end end
@ -184,7 +184,7 @@ class Observer::Ticket::Notification::BackgroundJob
if record.respond_to?( attribute_name ) && record.send(attribute_name) if record.respond_to?( attribute_name ) && record.send(attribute_name)
relation_class = record.send(attribute_name).class relation_class = record.send(attribute_name).class
if relation_class && value_id[0] if relation_class && value_id[0]
relation_model = relation_class.lookup( :id => value_id[0] ) relation_model = relation_class.lookup( id: value_id[0] )
if relation_model if relation_model
if relation_model['name'] if relation_model['name']
value_str[0] = relation_model['name'] value_str[0] = relation_model['name']
@ -194,7 +194,7 @@ class Observer::Ticket::Notification::BackgroundJob
end end
end end
if relation_class && value_id[1] if relation_class && value_id[1]
relation_model = relation_class.lookup( :id => value_id[1] ) relation_model = relation_class.lookup( id: value_id[1] )
if relation_model if relation_model
if relation_model['name'] if relation_model['name']
value_str[1] = relation_model['name'] value_str[1] = relation_model['name']
@ -281,8 +281,8 @@ State: i18n(#{ticket.state.name.text2html})<br>
body += template_footer(user, ticket, article) body += template_footer(user, ticket, article)
template = { template = {
:subject => subject, subject: subject,
:body => body, body: body,
} }
template template
end end
@ -342,8 +342,8 @@ Changes:<br>
body += template_footer(user,ticket, article) body += template_footer(user,ticket, article)
template = { template = {
:subject => subject, subject: subject,
:body => body, body: body,
} }
template template
end end

View file

@ -13,17 +13,17 @@ class Observer::Ticket::ResetNewState < ActiveRecord::Observer
return true if record.internal return true if record.internal
# if sender is agent # if sender is agent
return true if Ticket::Article::Sender.lookup( :id => record.sender_id ).name != 'Agent' return true if Ticket::Article::Sender.lookup( id: record.sender_id ).name != 'Agent'
# if article is a message to customer # if article is a message to customer
return true if !Ticket::Article::Type.lookup( :id => record.type_id ).communication return true if !Ticket::Article::Type.lookup( id: record.type_id ).communication
# if current ticket state is still new # if current ticket state is still new
ticket = Ticket.lookup( :id => record.ticket_id ) ticket = Ticket.lookup( id: record.ticket_id )
return true if ticket.state.state_type.name != 'new' return true if ticket.state.state_type.name != 'new'
# TODO: add config option to state managment in UI # TODO: add config option to state managment in UI
state = Ticket::State.lookup( :name => 'open' ) state = Ticket::State.lookup( name: 'open' )
return if !state return if !state
# set ticket to open # set ticket to open

View file

@ -20,19 +20,19 @@ class Observer::Ticket::UserTicketCounter < ActiveRecord::Observer
# open ticket count # open ticket count
state_open = Ticket::State.by_category( 'open' ) state_open = Ticket::State.by_category( 'open' )
tickets_open = Ticket.where( tickets_open = Ticket.where(
:customer_id => record.customer_id, customer_id: record.customer_id,
:state_id => state_open, state_id: state_open,
).count() ).count()
# closed ticket count # closed ticket count
state_closed = Ticket::State.by_category( 'closed' ) state_closed = Ticket::State.by_category( 'closed' )
tickets_closed = Ticket.where( tickets_closed = Ticket.where(
:customer_id => record.customer_id, customer_id: record.customer_id,
:state_id => state_closed, state_id: state_closed,
).count() ).count()
# check if update is needed # check if update is needed
customer = User.lookup( :id => record.customer_id ) customer = User.lookup( id: record.customer_id )
need_update = false need_update = false
if customer[:preferences][:tickets_open] != tickets_open if customer[:preferences][:tickets_open] != tickets_open
need_update = true need_update = true

View file

@ -17,7 +17,7 @@ class Observer::User::Geo < ActiveRecord::Observer
# check if geo update is needed based on old/new location # check if geo update is needed based on old/new location
if record.id if record.id
current = User.where( :id => record.id ).first current = User.where( id: record.id ).first
return if !current return if !current
current_location = {} current_location = {}

View file

@ -17,7 +17,7 @@ class Observer::User::TicketOrganization < ActiveRecord::Observer
return if !record.changes['organization_id'] return if !record.changes['organization_id']
# update last 100 tickets of user # update last 100 tickets of user
tickets = Ticket.where( :customer_id => record.id ).limit(100) tickets = Ticket.where( customer_id: record.id ).limit(100)
tickets.each {|ticket| tickets.each {|ticket|
if ticket.organization_id != record.organization_id if ticket.organization_id != record.organization_id
ticket.organization_id = record.organization_id ticket.organization_id = record.organization_id

View file

@ -1,8 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class OnlineNotification < ApplicationModel class OnlineNotification < ApplicationModel
belongs_to :type_lookup, :class_name => 'TypeLookup' belongs_to :type_lookup, class_name: 'TypeLookup'
belongs_to :object_lookup, :class_name => 'ObjectLookup' belongs_to :object_lookup, class_name: 'ObjectLookup'
after_create :notify_clients_after_change after_create :notify_clients_after_change
after_update :notify_clients_after_change after_update :notify_clients_after_change
@ -34,12 +34,12 @@ add a new online notification for this user
end end
record = { record = {
:o_id => data[:o_id], o_id: data[:o_id],
:object_lookup_id => object_id, object_lookup_id: object_id,
:type_lookup_id => type_id, type_lookup_id: type_id,
:seen => data[:seen], seen: data[:seen],
:user_id => data[:user_id], user_id: data[:user_id],
:created_by_id => data[:created_by_id] created_by_id: data[:created_by_id]
} }
OnlineNotification.create(record) OnlineNotification.create(record)
@ -72,8 +72,8 @@ remove whole online notifications of an object
def self.remove( object_name, o_id ) def self.remove( object_name, o_id )
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
OnlineNotification.where( OnlineNotification.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
).destroy_all ).destroy_all
end end
@ -87,7 +87,7 @@ return all online notifications of an user
def self.list(user,limit) def self.list(user,limit)
notifications = OnlineNotification.where(:user_id => user.id). notifications = OnlineNotification.where(user_id: user.id).
order( 'created_at DESC, id DESC' ). order( 'created_at DESC, id DESC' ).
limit( limit ) limit( limit )
list = [] list = []
@ -113,8 +113,8 @@ return all online notifications of an object
def self.list_by_object( object_name, o_id) def self.list_by_object( object_name, o_id)
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
notifications = OnlineNotification.where( notifications = OnlineNotification.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
). ).
order( 'created_at DESC, id DESC' ). order( 'created_at DESC, id DESC' ).
limit( 10_000 ) limit( 10_000 )
@ -141,9 +141,9 @@ mark online notification as seen by object
def self.seen_by_object(object_name, o_id) def self.seen_by_object(object_name, o_id)
object_id = ObjectLookup.by_name( object_name ) object_id = ObjectLookup.by_name( object_name )
notifications = OnlineNotification.where( notifications = OnlineNotification.where(
:object_lookup_id => object_id, object_lookup_id: object_id,
:o_id => o_id, o_id: o_id,
:seen => false, seen: false,
) )
notifications.each do |notification| notifications.each do |notification|
notification.seen = true notification.seen = true
@ -172,8 +172,8 @@ returns:
notifications = OnlineNotification.list(user, limit) notifications = OnlineNotification.list(user, limit)
assets = ApplicationModel.assets_of_object_list(notifications) assets = ApplicationModel.assets_of_object_list(notifications)
return { return {
:stream => notifications, stream: notifications,
:assets => assets assets: assets
} }
end end
@ -181,8 +181,8 @@ returns:
Sessions.send_to( Sessions.send_to(
self.user_id, self.user_id,
{ {
:event => 'OnlineNotification::changed', event: 'OnlineNotification::changed',
:data => {} data: {}
} }
) )
end end

View file

@ -8,10 +8,10 @@ class Organization < ApplicationModel
include Organization::SearchIndex include Organization::SearchIndex
has_and_belongs_to_many :users has_and_belongs_to_many :users
has_many :members, :class_name => 'User' has_many :members, class_name: 'User'
validates :name, :presence => true validates :name, presence: true
activity_stream_support :role => Z_ROLENAME_ADMIN activity_stream_support role: Z_ROLENAME_ADMIN
history_support history_support
search_index_support search_index_support
notify_clients_support notify_clients_support

View file

@ -33,7 +33,7 @@ returns
if data[ Organization.to_app_model ][ self.id ]['member_ids'] if data[ Organization.to_app_model ][ self.id ]['member_ids']
data[ Organization.to_app_model ][ self.id ]['member_ids'].each {|user_id| data[ Organization.to_app_model ][ self.id ]['member_ids'].each {|user_id|
if !data[ User.to_app_model ][ user_id ] if !data[ User.to_app_model ][ user_id ]
user = User.lookup( :id => user_id ) user = User.lookup( id: user_id )
data = user.assets( data ) data = user.assets( data )
end end
} }
@ -42,7 +42,7 @@ returns
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( :id => self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end end

View file

@ -33,7 +33,7 @@ returns
items = SearchIndexBackend.search( query, limit, 'Organization' ) items = SearchIndexBackend.search( query, limit, 'Organization' )
organizations = [] organizations = []
items.each { |item| items.each { |item|
organizations.push Organization.lookup( :id => item[:id] ) organizations.push Organization.lookup( id: item[:id] )
} }
return organizations return organizations
end end

View file

@ -32,7 +32,7 @@ returns
next if !relation_class next if !relation_class
# lookup ref object # lookup ref object
relation_model = relation_class.lookup( :id => value ) relation_model = relation_class.lookup( id: value )
next if !relation_model next if !relation_model
# get name of ref object # get name of ref object
@ -49,7 +49,7 @@ returns
# add org member for search index data # add org member for search index data
attributes['member'] = [] attributes['member'] = []
users = User.where( :organization_id => self.id ) users = User.where( organization_id: self.id )
users.each { |user| users.each { |user|
attributes['member'].push user.search_index_data attributes['member'].push user.search_index_data
} }

View file

@ -4,7 +4,7 @@ class Overview < ApplicationModel
store :condition store :condition
store :order store :order
store :view store :view
validates :name, :presence => true validates :name, presence: true
validates :prio, :presence => true validates :prio, presence: true
validates :link, :presence => true validates :link, presence: true
end end

View file

@ -55,7 +55,7 @@ class Package < ApplicationModel
end end
end end
data.each {|file| data.each {|file|
self.install( :file => path + '/' + file ) self.install( file: path + '/' + file )
} }
data data
end end
@ -186,16 +186,16 @@ class Package < ApplicationModel
# package meta data # package meta data
meta = { meta = {
:name => package.elements['zpm/name'].text, name: package.elements['zpm/name'].text,
:version => package.elements['zpm/version'].text, version: package.elements['zpm/version'].text,
:vendor => package.elements['zpm/vendor'].text, vendor: package.elements['zpm/vendor'].text,
:state => 'uninstalled', state: 'uninstalled',
:created_by_id => 1, created_by_id: 1,
:updated_by_id => 1, updated_by_id: 1,
} }
# verify if package can get installed # verify if package can get installed
package_db = Package.where( :name => meta[:name] ).first package_db = Package.where( name: meta[:name] ).first
if package_db if package_db
if !data[:reinstall] if !data[:reinstall]
if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] ) if Gem::Version.new( package_db.version ) == Gem::Version.new( meta[:version] )
@ -208,9 +208,9 @@ class Package < ApplicationModel
# uninstall files of old package # uninstall files of old package
self.uninstall({ self.uninstall({
:name => package_db.name, name: package_db.name,
:version => package_db.version, version: package_db.version,
:migration_not_down => true, migration_not_down: true,
}) })
end end
@ -218,12 +218,12 @@ class Package < ApplicationModel
record = Package.create( meta ) record = Package.create( meta )
if !data[:reinstall] if !data[:reinstall]
Store.add( Store.add(
:object => 'Package', object: 'Package',
:o_id => record.id, o_id: record.id,
:data => package.to_s, data: package.to_s,
:filename => meta[:name] + '-' + meta[:version] + '.zpm', filename: meta[:name] + '-' + meta[:version] + '.zpm',
:preferences => {}, preferences: {},
:created_by_id => UserInfo.current_user_id || 1, created_by_id: UserInfo.current_user_id || 1,
) )
end end
@ -253,13 +253,13 @@ class Package < ApplicationModel
# Package.reinstall( package_name ) # Package.reinstall( package_name )
def self.reinstall(package_name) def self.reinstall(package_name)
package = Package.where( :name => package_name ).first package = Package.where( name: package_name ).first
if !package if !package
raise "No such package '#{package_name}'" raise "No such package '#{package_name}'"
end end
file = self._get_bin( package.name, package.version ) file = self._get_bin( package.name, package.version )
self.install( :string => file, :reinstall => true ) self.install( string: file, reinstall: true )
end end
# Package.uninstall( :name => 'package', :version => '0.1.1' ) # Package.uninstall( :name => 'package', :version => '0.1.1' )
@ -275,8 +275,8 @@ class Package < ApplicationModel
# package meta data # package meta data
meta = { meta = {
:name => package.elements['zpm/name'].text, name: package.elements['zpm/name'].text,
:version => package.elements['zpm/version'].text, version: package.elements['zpm/version'].text,
} }
# down migrations # down migrations
@ -301,8 +301,8 @@ class Package < ApplicationModel
# delete package # delete package
record = Package.where( record = Package.where(
:name => meta[:name], name: meta[:name],
:version => meta[:version], version: meta[:version],
).first ).first
record.destroy record.destroy
@ -340,15 +340,15 @@ class Package < ApplicationModel
def self._get_bin( name, version ) def self._get_bin( name, version )
package = Package.where( package = Package.where(
:name => name, name: name,
:version => version, version: version,
).first ).first
if !package if !package
raise "No such package '#{name}' version '#{version}'" raise "No such package '#{name}' version '#{version}'"
end end
list = Store.list( list = Store.list(
:object => 'Package', object: 'Package',
:o_id => package.id, o_id: package.id,
) )
# find file # find file
@ -442,7 +442,7 @@ class Package < ApplicationModel
location = @@root + '/db/addon/' + package.underscore location = @@root + '/db/addon/' + package.underscore
return true if !File.exists?( location ) return true if !File.exists?( location )
migrations_done = Package::Migration.where( :name => package.underscore ) migrations_done = Package::Migration.where( name: package.underscore )
# get existing migrations # get existing migrations
migrations_existing = [] migrations_existing = []
@ -474,26 +474,26 @@ class Package < ApplicationModel
# down # down
if direction == 'reverse' if direction == 'reverse'
done = Package::Migration.where( :name => package.underscore, :version => version ).first done = Package::Migration.where( name: package.underscore, version: version ).first
next if !done next if !done
logger.info "NOTICE: down package migration '#{migration}'" logger.info "NOTICE: down package migration '#{migration}'"
load "#{location}/#{migration}" load "#{location}/#{migration}"
classname = name.camelcase classname = name.camelcase
Kernel.const_get(classname).down Kernel.const_get(classname).down
record = Package::Migration.where( :name => package.underscore, :version => version ).first record = Package::Migration.where( name: package.underscore, version: version ).first
if record if record
record.destroy record.destroy
end end
# up # up
else else
done = Package::Migration.where( :name => package.underscore, :version => version ).first done = Package::Migration.where( name: package.underscore, version: version ).first
next if done next if done
logger.info "NOTICE: up package migration '#{migration}'" logger.info "NOTICE: up package migration '#{migration}'"
load "#{location}/#{migration}" load "#{location}/#{migration}"
classname = name.camelcase classname = name.camelcase
Kernel.const_get(classname).up Kernel.const_get(classname).up
Package::Migration.create( :name => package.underscore, :version => version ) Package::Migration.create( name: package.underscore, version: version )
end end
# reload new files # reload new files

View file

@ -3,5 +3,5 @@
class PostmasterFilter < ApplicationModel class PostmasterFilter < ApplicationModel
store :perform store :perform
store :match store :match
validates :name, :presence => true validates :name, presence: true
end end

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class RecentView < ApplicationModel class RecentView < ApplicationModel
belongs_to :object_lookup, :class_name => 'ObjectLookup' belongs_to :object_lookup, class_name: 'ObjectLookup'
after_create :notify_clients after_create :notify_clients
after_update :notify_clients after_update :notify_clients
@ -17,31 +17,31 @@ class RecentView < ApplicationModel
# create entry # create entry
record = { record = {
:o_id => o_id, o_id: o_id,
:recent_view_object_id => object_lookup_id.to_i, recent_view_object_id: object_lookup_id.to_i,
:created_by_id => user.id, created_by_id: user.id,
} }
RecentView.create(record) RecentView.create(record)
end end
def self.log_destroy( requested_object, requested_object_id ) def self.log_destroy( requested_object, requested_object_id )
return if requested_object == 'RecentView' return if requested_object == 'RecentView'
RecentView.where( :recent_view_object_id => ObjectLookup.by_name( requested_object ) ). RecentView.where( recent_view_object_id: ObjectLookup.by_name( requested_object ) ).
where( :o_id => requested_object_id ). where( o_id: requested_object_id ).
destroy_all destroy_all
end end
def self.user_log_destroy( user ) def self.user_log_destroy( user )
RecentView.where( :created_by_id => user.id ).destroy_all RecentView.where( created_by_id: user.id ).destroy_all
end end
def self.list( user, limit = 10, type = nil ) def self.list( user, limit = 10, type = nil )
if !type if !type
recent_views = RecentView.where( :created_by_id => user.id ). recent_views = RecentView.where( created_by_id: user.id ).
order('created_at DESC, id DESC'). order('created_at DESC, id DESC').
limit(limit) limit(limit)
else else
recent_views = RecentView.select('DISTINCT(o_id), recent_view_object_id').where( :created_by_id => user.id, :recent_view_object_id => ObjectLookup.by_name(type) ) . recent_views = RecentView.select('DISTINCT(o_id), recent_view_object_id').where( created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type) ) .
order('created_at DESC, id DESC'). order('created_at DESC, id DESC').
limit(limit) limit(limit)
end end
@ -68,8 +68,8 @@ class RecentView < ApplicationModel
assets = ApplicationModel.assets_of_object_list(recent_viewed) assets = ApplicationModel.assets_of_object_list(recent_viewed)
return { return {
:stream => recent_viewed, stream: recent_viewed,
:assets => assets, assets: assets,
} }
end end
@ -77,8 +77,8 @@ class RecentView < ApplicationModel
Sessions.send_to( Sessions.send_to(
self.created_by_id, self.created_by_id,
{ {
:event => 'RecentView::changed', event: 'RecentView::changed',
:data => {} data: {}
} }
) )
end end
@ -90,7 +90,7 @@ class RecentView < ApplicationModel
# check if object exists # check if object exists
begin begin
return if !Kernel.const_get( object ) return if !Kernel.const_get( object )
record = Kernel.const_get( object ).lookup( :id => o_id ) record = Kernel.const_get( object ).lookup( id: o_id )
return if !record return if !record
rescue rescue
return return
@ -98,6 +98,6 @@ class RecentView < ApplicationModel
# check permission # check permission
return if !record.respond_to?(:permission) return if !record.respond_to?(:permission)
record.permission( :current_user => user ) record.permission( current_user: user )
end end
end end

View file

@ -2,8 +2,8 @@
class Role < ApplicationModel class Role < ApplicationModel
has_and_belongs_to_many :users, :after_add => :cache_update, :after_remove => :cache_update has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update
validates :name, :presence => true validates :name, presence: true
activity_stream_support :role => Z_ROLENAME_ADMIN activity_stream_support role: Z_ROLENAME_ADMIN
latest_change_support latest_change_support
end end

View file

@ -36,7 +36,7 @@ class Scheduler < ApplicationModel
if job.period if job.period
while true while true
self._start_job( job, runner, runner_count ) self._start_job( job, runner, runner_count )
job = Scheduler.lookup( :id => job.id ) job = Scheduler.lookup( id: job.id )
# exit is job got deleted # exit is job got deleted
break if !job break if !job
@ -124,7 +124,7 @@ class Scheduler < ApplicationModel
def self.check( name, time_warning = 10, time_critical = 20 ) def self.check( name, time_warning = 10, time_critical = 20 )
time_warning_time = Time.now - time_warning.minutes time_warning_time = Time.now - time_warning.minutes
time_critical_time = Time.now - time_critical.minutes time_critical_time = Time.now - time_critical.minutes
scheduler = Scheduler.where( :name => name ).first scheduler = Scheduler.where( name: name ).first
if !scheduler if !scheduler
puts "CRITICAL - no such scheduler jobs '#{name}'" puts "CRITICAL - no such scheduler jobs '#{name}'"
return true return true

View file

@ -36,11 +36,11 @@ class Setting < ApplicationModel
end end
def self.set(name, value) def self.set(name, value)
setting = Setting.where( :name => name ).first setting = Setting.where( name: name ).first
if !setting if !setting
raise "Can't find config setting '#{name}'" raise "Can't find config setting '#{name}'"
end end
setting.state = { :value => value } setting.state = { value: value }
setting.save setting.save
logger.info "Setting.set() name:#{name}, value:#{value.inspect}" logger.info "Setting.set() name:#{name}, value:#{value.inspect}"
end end
@ -60,7 +60,7 @@ class Setting < ApplicationModel
def state_check def state_check
if self.state || self.state == false if self.state || self.state == false
if !self.state.respond_to?('has_key?') || !self.state.has_key?(:value) if !self.state.respond_to?('has_key?') || !self.state.has_key?(:value)
self.state = { :value => self.state } self.state = { value: self.state }
end end
end end
end end

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Signature < ApplicationModel class Signature < ApplicationModel
has_many :groups, :after_add => :cache_update, :after_remove => :cache_update has_many :groups, after_add: :cache_update, after_remove: :cache_update
validates :name, :presence => true validates :name, presence: true
latest_change_support latest_change_support
end end

View file

@ -3,7 +3,7 @@
class Sla < ApplicationModel class Sla < ApplicationModel
store :condition store :condition
store :data store :data
validates :name, :presence => true validates :name, presence: true
after_create :escalation_calculation_rebuild after_create :escalation_calculation_rebuild
after_update :escalation_calculation_rebuild after_update :escalation_calculation_rebuild

View file

@ -5,9 +5,9 @@ class Store < ApplicationModel
load 'store/file.rb' load 'store/file.rb'
store :preferences store :preferences
belongs_to :store_object, :class_name => 'Store::Object' belongs_to :store_object, class_name: 'Store::Object'
belongs_to :store_file, :class_name => 'Store::File' belongs_to :store_file, class_name: 'Store::File'
validates :filename, :presence => true validates :filename, presence: true
=begin =begin
@ -33,7 +33,7 @@ returns
data = data.stringify_keys data = data.stringify_keys
# lookup store_object.id # lookup store_object.id
store_object = Store::Object.create_if_not_exists( :name => data['object'] ) store_object = Store::Object.create_if_not_exists( name: data['object'] )
data['store_object_id'] = store_object.id data['store_object_id'] = store_object.id
# add to real store # add to real store
@ -79,8 +79,8 @@ returns
def self.list(data) def self.list(data)
# search # search
store_object_id = Store::Object.lookup( :name => data[:object] ) 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 ). 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 return stores
end end
@ -102,9 +102,9 @@ returns
def self.remove(data) def self.remove(data)
# search # search
store_object_id = Store::Object.lookup( :name => data[:object] ) store_object_id = Store::Object.lookup( name: data[:object] )
stores = Store.where( :store_object_id => store_object_id ). stores = Store.where( store_object_id: store_object_id ).
where( :o_id => data[:o_id] ). where( o_id: data[:o_id] ).
order('created_at ASC, id ASC') order('created_at ASC, id ASC')
stores.each do |store| stores.each do |store|
@ -130,7 +130,7 @@ returns
# check backend for references # check backend for references
store = Store.find(store_id) store = Store.find(store_id)
files = Store.where( :store_file_id => store.store_file_id ) files = Store.where( store_file_id: store.store_file_id )
if files.count == 1 && files.first.id == store.id if files.count == 1 && files.first.id == store.id
Store::File.find( store.store_file_id ).destroy Store::File.find( store.store_file_id ).destroy
end end
@ -140,7 +140,7 @@ returns
end end
def content def content
file = Store::File.where( :id => self.store_file_id ).first file = Store::File.where( id: self.store_file_id ).first
if !file if !file
raise "No such file #{ self.store_file_id }!" raise "No such file #{ self.store_file_id }!"
end end
@ -148,7 +148,7 @@ returns
end end
def provider def provider
file = Store::File.where( :id => self.store_file_id ).first file = Store::File.where( id: self.store_file_id ).first
if !file if !file
raise "No such file #{ self.store_file_id }!" raise "No such file #{ self.store_file_id }!"
end end

View file

@ -8,7 +8,7 @@ class Store::File < ApplicationModel
def self.add(data) def self.add(data)
sha = Digest::SHA256.hexdigest( data ) sha = Digest::SHA256.hexdigest( data )
file = Store::File.where( :sha => sha ).first file = Store::File.where( sha: sha ).first
if file == nil if file == nil
# load backend based on config # load backend based on config
@ -19,8 +19,8 @@ class Store::File < ApplicationModel
adapter = self.load_adapter( "Store::Provider::#{ adapter_name }" ) adapter = self.load_adapter( "Store::Provider::#{ adapter_name }" )
adapter.add( data, sha ) adapter.add( data, sha )
file = Store::File.create( file = Store::File.create(
:provider => adapter_name, provider: adapter_name,
:sha => sha, sha: sha,
) )
end end
file file
@ -33,7 +33,7 @@ class Store::File < ApplicationModel
c = adapter.get( self.sha ) c = adapter.get( self.sha )
else else
# fallback until migration is done # fallback until migration is done
c = Store::Provider::DB.where( :md5 => self.md5 ).first.data c = Store::Provider::DB.where( md5: self.md5 ).first.data
end end
c c
end end

View file

@ -1,5 +1,5 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Store::Object < ApplicationModel class Store::Object < ApplicationModel
validates :name, :presence => true validates :name, presence: true
end end

View file

@ -5,20 +5,20 @@ class Store::Provider::DB < ApplicationModel
def self.add(data, sha) def self.add(data, sha)
Store::Provider::DB.create( Store::Provider::DB.create(
:data => data, data: data,
:sha => sha, sha: sha,
) )
true true
end end
def self.get(sha) def self.get(sha)
file = Store::Provider::DB.where( :sha => sha ).first file = Store::Provider::DB.where( sha: sha ).first
return if !file return if !file
file.data file.data
end end
def self.delete(sha) def self.delete(sha)
Store::Provider::DB.where( :sha => sha ).destroy_all Store::Provider::DB.where( sha: sha ).destroy_all
true true
end end

View file

@ -1,8 +1,8 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Tag < ApplicationModel class Tag < ApplicationModel
belongs_to :tag_object, :class_name => 'Tag::Object' belongs_to :tag_object, class_name: 'Tag::Object'
belongs_to :tag_item, :class_name => 'Tag::Item' belongs_to :tag_item, class_name: 'Tag::Item'
@@cache_item = {} @@cache_item = {}
@@cache_object = {} @@cache_object = {}
@ -19,10 +19,10 @@ class Tag < ApplicationModel
# create history # create history
Tag.create( Tag.create(
:tag_object_id => tag_object_id, tag_object_id: tag_object_id,
:tag_item_id => tag_item_id, tag_item_id: tag_item_id,
:o_id => data[:o_id], o_id: data[:o_id],
:created_by_id => data[:created_by_id], created_by_id: data[:created_by_id],
) )
return true return true
end end
@ -39,9 +39,9 @@ class Tag < ApplicationModel
# create history # create history
result = Tag.where( result = Tag.where(
:tag_object_id => tag_object_id, tag_object_id: tag_object_id,
:tag_item_id => tag_item_id, tag_item_id: tag_item_id,
:o_id => data[:o_id], o_id: data[:o_id],
) )
result.each { |item| result.each { |item|
item.destroy item.destroy
@ -52,8 +52,8 @@ class Tag < ApplicationModel
def self.tag_list( data ) def self.tag_list( data )
tag_object_id_requested = self.tag_object_lookup( data[:object] ) tag_object_id_requested = self.tag_object_lookup( data[:object] )
tag_search = Tag.where( tag_search = Tag.where(
:tag_object_id => tag_object_id_requested, tag_object_id: tag_object_id_requested,
:o_id => data[:o_id], o_id: data[:o_id],
) )
tags = [] tags = []
tag_search.each {|tag| tag_search.each {|tag|
@ -83,7 +83,7 @@ class Tag < ApplicationModel
return @@cache_item[ name ] if @@cache_item[ name ] return @@cache_item[ name ] if @@cache_item[ name ]
# lookup # lookup
tag_item = Tag::Item.where( :name => name ).first tag_item = Tag::Item.where( name: name ).first
if tag_item if tag_item
@@cache_item[ name ] = tag_item.id @@cache_item[ name ] = tag_item.id
return tag_item.id return tag_item.id
@ -91,7 +91,7 @@ class Tag < ApplicationModel
# create # create
tag_item = Tag::Item.create( tag_item = Tag::Item.create(
:name => name name: name
) )
@@cache_item[ name ] = tag_item.id @@cache_item[ name ] = tag_item.id
return tag_item.id return tag_item.id
@ -114,7 +114,7 @@ class Tag < ApplicationModel
return @@cache_object[ name ] if @@cache_object[ name ] return @@cache_object[ name ] if @@cache_object[ name ]
# lookup # lookup
tag_object = Tag::Object.where( :name => name ).first tag_object = Tag::Object.where( name: name ).first
if tag_object if tag_object
@@cache_object[ name ] = tag_object.id @@cache_object[ name ] = tag_object.id
return tag_object.id return tag_object.id
@ -122,7 +122,7 @@ class Tag < ApplicationModel
# create # create
tag_object = Tag::Object.create( tag_object = Tag::Object.create(
:name => name name: name
) )
@@cache_object[ name ] = tag_object.id @@cache_object[ name ] = tag_object.id
return tag_object.id return tag_object.id

View file

@ -2,6 +2,6 @@
class Template < ApplicationModel class Template < ApplicationModel
store :options store :options
validates :name, :presence => true validates :name, presence: true
notify_clients_support notify_clients_support
end end

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class TextModule < ApplicationModel class TextModule < ApplicationModel
validates :name, :presence => true validates :name, presence: true
validates :content, :presence => true validates :content, presence: true
notify_clients_support notify_clients_support
end end

View file

@ -22,41 +22,41 @@ class Ticket < ApplicationModel
latest_change_support latest_change_support
activity_stream_support :ignore_attributes => { activity_stream_support ignore_attributes: {
:create_article_type_id => true, create_article_type_id: true,
:create_article_sender_id => true, create_article_sender_id: true,
:article_count => true, article_count: true,
} }
history_support :ignore_attributes => { history_support ignore_attributes: {
:create_article_type_id => true, create_article_type_id: true,
:create_article_sender_id => true, create_article_sender_id: true,
:article_count => true, article_count: true,
} }
search_index_support( search_index_support(
:ignore_attributes => { ignore_attributes: {
:create_article_type_id => true, create_article_type_id: true,
:create_article_sender_id => true, create_article_sender_id: true,
:article_count => true, article_count: true,
}, },
:keep_attributes => { keep_attributes: {
:customer_id => true, customer_id: true,
:organization_id => true, organization_id: true,
}, },
) )
belongs_to :group belongs_to :group
has_many :articles, :class_name => 'Ticket::Article', :after_add => :cache_update, :after_remove => :cache_update has_many :articles, class_name: 'Ticket::Article', after_add: :cache_update, after_remove: :cache_update
belongs_to :organization belongs_to :organization
belongs_to :state, :class_name => 'Ticket::State' belongs_to :state, class_name: 'Ticket::State'
belongs_to :priority, :class_name => 'Ticket::Priority' belongs_to :priority, class_name: 'Ticket::Priority'
belongs_to :owner, :class_name => 'User' belongs_to :owner, class_name: 'User'
belongs_to :customer, :class_name => 'User' belongs_to :customer, class_name: 'User'
belongs_to :created_by, :class_name => 'User' belongs_to :created_by, class_name: 'User'
belongs_to :updated_by, :class_name => 'User' belongs_to :updated_by, class_name: 'User'
belongs_to :create_article_type, :class_name => 'Ticket::Article::Type' belongs_to :create_article_type, class_name: 'Ticket::Article::Type'
belongs_to :create_article_sender, :class_name => 'Ticket::Article::Sender' belongs_to :create_article_sender, class_name: 'Ticket::Article::Sender'
self.inheritance_column = nil self.inheritance_column = nil
@ -76,7 +76,7 @@ returns
=end =end
def agent_of_group def agent_of_group
Group.find( self.group_id ).users.where( :active => true ).joins(:roles).where( 'roles.name' => Z_ROLENAME_AGENT, 'roles.active' => true ).uniq() Group.find( self.group_id ).users.where( active: true ).joins(:roles).where( 'roles.name' => Z_ROLENAME_AGENT, 'roles.active' => true ).uniq()
end end
=begin =begin
@ -128,12 +128,12 @@ returns
def merge_to(data) def merge_to(data)
# update articles # update articles
Ticket::Article.where( :ticket_id => self.id ).each {|article| Ticket::Article.where( ticket_id: self.id ).each {|article|
article.touch article.touch
} }
# quiet update of reassign of articles # quiet update of reassign of articles
Ticket::Article.where( :ticket_id => self.id ).update_all( ['ticket_id = ?', data[:ticket_id] ] ) Ticket::Article.where( ticket_id: self.id ).update_all( ['ticket_id = ?', data[:ticket_id] ] )
# touch new ticket (to broadcast change) # touch new ticket (to broadcast change)
Ticket.find( data[:ticket_id] ).touch Ticket.find( data[:ticket_id] ).touch
@ -142,31 +142,31 @@ returns
# create new merge article # create new merge article
Ticket::Article.create( Ticket::Article.create(
:ticket_id => self.id, ticket_id: self.id,
:type_id => Ticket::Article::Type.lookup( :name => 'note' ).id, type_id: Ticket::Article::Type.lookup( name: 'note' ).id,
:sender_id => Ticket::Article::Sender.lookup( :name => Z_ROLENAME_AGENT ).id, sender_id: Ticket::Article::Sender.lookup( name: Z_ROLENAME_AGENT ).id,
:body => 'merged', body: 'merged',
:internal => false, internal: false,
:created_by_id => data[:user_id], created_by_id: data[:user_id],
:updated_by_id => data[:user_id], updated_by_id: data[:user_id],
) )
# add history to both # add history to both
# link tickets # link tickets
Link.add( Link.add(
:link_type => 'parent', link_type: 'parent',
:link_object_source => 'Ticket', link_object_source: 'Ticket',
:link_object_source_value => data[:ticket_id], link_object_source_value: data[:ticket_id],
:link_object_target => 'Ticket', link_object_target: 'Ticket',
:link_object_target_value => self.id link_object_target_value: self.id
) )
# set state to 'merged' # set state to 'merged'
self.state_id = Ticket::State.lookup( :name => 'merged' ).id self.state_id = Ticket::State.lookup( name: 'merged' ).id
# rest owner # rest owner
self.owner_id = User.where( :login => '-' ).first.id self.owner_id = User.where( login: '-' ).first.id
# save ticket # save ticket
self.save self.save
@ -186,8 +186,8 @@ returns
=end =end
def online_notification_seen_state def online_notification_seen_state
state = Ticket::State.lookup( :id => self.state_id ) state = Ticket::State.lookup( id: self.state_id )
state_type = Ticket::StateType.lookup( :id => state.state_type_id ) state_type = Ticket::StateType.lookup( id: state.state_type_id )
return true if state_type.name == 'closed' return true if state_type.name == 'closed'
return true if state_type.name == 'merged' return true if state_type.name == 'merged'
false false
@ -224,8 +224,8 @@ returns
return if !self.changes['state_id'] return if !self.changes['state_id']
# check if new state isn't pending* # check if new state isn't pending*
current_state = Ticket::State.lookup( :id => self.state_id ) current_state = Ticket::State.lookup( id: self.state_id )
current_state_type = Ticket::StateType.lookup( :id => current_state.state_type_id ) current_state_type = Ticket::StateType.lookup( id: current_state.state_type_id )
# in case, set pending_time to nil # in case, set pending_time to nil
if current_state_type.name !~ /^pending/i if current_state_type.name !~ /^pending/i

View file

@ -26,13 +26,13 @@ returns
return if !self.class.activity_stream_support_config return if !self.class.activity_stream_support_config
role = self.class.activity_stream_support_config[:role] role = self.class.activity_stream_support_config[:role]
ActivityStream.add( ActivityStream.add(
:o_id => self['id'], o_id: self['id'],
:type => type, type: type,
:object => self.class.name, object: self.class.name,
:group_id => self['group_id'], group_id: self['group_id'],
:role => role, role: role,
:created_at => self.updated_at, created_at: self.updated_at,
:created_by_id => user_id, created_by_id: user_id,
) )
end end

View file

@ -9,22 +9,22 @@ class Ticket::Article < ApplicationModel
include Ticket::Article::ActivityStreamLog include Ticket::Article::ActivityStreamLog
belongs_to :ticket belongs_to :ticket
belongs_to :type, :class_name => 'Ticket::Article::Type' belongs_to :type, class_name: 'Ticket::Article::Type'
belongs_to :sender, :class_name => 'Ticket::Article::Sender' belongs_to :sender, class_name: 'Ticket::Article::Sender'
belongs_to :created_by, :class_name => 'User' belongs_to :created_by, class_name: 'User'
belongs_to :updated_by, :class_name => 'User' belongs_to :updated_by, class_name: 'User'
before_create :check_subject before_create :check_subject
before_update :check_subject before_update :check_subject
notify_clients_support notify_clients_support
activity_stream_support :ignore_attributes => { activity_stream_support ignore_attributes: {
:type_id => true, type_id: true,
:sender_id => true, sender_id: true,
} }
history_support :ignore_attributes => { history_support ignore_attributes: {
:type_id => true, type_id: true,
:sender_id => true, sender_id: true,
} }
private private
@ -39,12 +39,12 @@ class Ticket::Article < ApplicationModel
end end
class Sender < ApplicationModel class Sender < ApplicationModel
validates :name, :presence => true validates :name, presence: true
latest_change_support latest_change_support
end end
class Type < ApplicationModel class Type < ApplicationModel
validates :name, :presence => true validates :name, presence: true
latest_change_support latest_change_support
end end
end end

View file

@ -25,15 +25,15 @@ returns
return if !self.class.activity_stream_support_config return if !self.class.activity_stream_support_config
role = self.class.activity_stream_support_config[:role] role = self.class.activity_stream_support_config[:role]
ticket = Ticket.lookup( :id => self.ticket_id ) ticket = Ticket.lookup( id: self.ticket_id )
ActivityStream.add( ActivityStream.add(
:o_id => self['id'], o_id: self['id'],
:type => type, type: type,
:object => self.class.name, object: self.class.name,
:group_id => ticket.group_id, group_id: ticket.group_id,
:role => role, role: role,
:created_at => self.updated_at, created_at: self.updated_at,
:created_by_id => user_id, created_by_id: user_id,
) )
end end

View file

@ -44,7 +44,7 @@ returns
['created_by_id', 'updated_by_id'].each {|item| ['created_by_id', 'updated_by_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( :id => self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end end

View file

@ -32,7 +32,7 @@ returns
['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item| ['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item|
if self[ item ] if self[ item ]
if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ]
user = User.lookup( :id => self[ item ] ) user = User.lookup( id: self[ item ] )
data = user.assets( data ) data = user.assets( data )
end end
end end

View file

@ -17,7 +17,7 @@ returns
def self.rebuild_all def self.rebuild_all
state_list_open = Ticket::State.by_category( 'open' ) state_list_open = Ticket::State.by_category( 'open' )
tickets = Ticket.where( :state_id => state_list_open ) tickets = Ticket.where( state_id: state_list_open )
tickets.each {|ticket| tickets.each {|ticket|
ticket.escalation_calculation ticket.escalation_calculation
} }
@ -39,7 +39,7 @@ returns
def escalation_calculation def escalation_calculation
# set escalation off if ticket is already closed # set escalation off if ticket is already closed
state = Ticket::State.lookup( :id => self.state_id ) state = Ticket::State.lookup( id: self.state_id )
if state.ignore_escalation? if state.ignore_escalation?
# nothing to change # nothing to change
@ -177,8 +177,8 @@ returns
sla_selected = nil sla_selected = nil
sla_list = Cache.get( 'SLA::List::Active' ) sla_list = Cache.get( 'SLA::List::Active' )
if sla_list == nil if sla_list == nil
sla_list = Sla.where( :active => true ) sla_list = Sla.where( active: true )
Cache.write( 'SLA::List::Active', sla_list, { :expires_in => 1.hour } ) Cache.write( 'SLA::List::Active', sla_list, { expires_in: 1.hour } )
end end
sla_list.each {|sla| sla_list.each {|sla|
if !sla.condition || sla.condition.empty? if !sla.condition || sla.condition.empty?

View file

@ -73,8 +73,8 @@ returns
end end
} }
return { return {
:history => list, history: list,
:assets => assets, assets: assets,
} }
end end

View file

@ -20,7 +20,7 @@ returns
# generate number # generate number
(1..50_000).each { |i| (1..50_000).each { |i|
number = adapter.generate number = adapter.generate
ticket = Ticket.where( :number => number ).first ticket = Ticket.where( number: number ).first
return number if !ticket return number if !ticket
} }
raise "Can't generate new ticket number!" raise "Can't generate new ticket number!"

View file

@ -14,9 +14,9 @@ module Ticket::Number::Date
# read counter # read counter
counter_increment = nil counter_increment = nil
Ticket::Counter.transaction do Ticket::Counter.transaction do
counter = Ticket::Counter.where( :generator => 'Date' ).lock(true).first counter = Ticket::Counter.where( generator: 'Date' ).lock(true).first
if !counter if !counter
counter = Ticket::Counter.new( :generator => 'Date', :content => '0' ) counter = Ticket::Counter.new( generator: 'Date', content: '0' )
end end
# increase counter # increase counter
@ -74,9 +74,9 @@ module Ticket::Number::Date
# probe format # probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i then if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i then
ticket = Ticket.where( :number => $1 ).first ticket = Ticket.where( number: $1 ).first
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,50})/i then elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,50})/i then
ticket = Ticket.where( :number => $1 ).first ticket = Ticket.where( number: $1 ).first
end end
return ticket return ticket
end end

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