Merge branch 'develop' of github.com:martini/zammad into develop

This commit is contained in:
Martin Edenhofer 2016-01-15 20:09:25 +01:00
commit 815666a994
88 changed files with 769 additions and 800 deletions

View file

@ -2,13 +2,15 @@
# https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
AllCops: AllCops:
RunRailsCops: true
Exclude: Exclude:
- 'bin/rails' - 'bin/rails'
- 'bin/rake' - 'bin/rake'
- 'bin/spring' - 'bin/spring'
- 'db/schema.rb' - 'db/schema.rb'
Rails:
Enabled: true
# Zammad StyleGuide # Zammad StyleGuide
Metrics/LineLength: Metrics/LineLength:
@ -30,8 +32,13 @@ Style/IfUnlessModifier:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
Enabled: false Enabled: false
Style/TrailingComma: Style/TrailingCommaInLiteral:
Description: 'Checks for trailing comma in parameter lists and literals.' Description: 'Checks for trailing comma in array and hash literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Enabled: false
Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
Enabled: false Enabled: false
@ -47,12 +54,6 @@ Style/SpaceAfterMethodName:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
Enabled: false Enabled: false
Style/SingleSpaceBeforeFirstArg:
Description: >-
Checks that exactly one space is used between a method name
and the first argument for method calls without parentheses.
Enabled: false
Style/LeadingCommentSpace: Style/LeadingCommentSpace:
Description: 'Comments should start with a space.' Description: 'Comments should start with a space.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'

View file

@ -44,9 +44,7 @@ GEM
addressable (2.4.0) addressable (2.4.0)
arel (6.0.3) arel (6.0.3)
ast (2.2.0) ast (2.2.0)
astrolabe (1.3.1) autoprefixer-rails (6.3.1)
parser (~> 2.2)
autoprefixer-rails (6.2.3)
execjs execjs
json json
biz (1.3.3) biz (1.3.3)
@ -58,7 +56,7 @@ GEM
browser (1.1.0) browser (1.1.0)
buftok (0.2.0) buftok (0.2.0)
builder (3.2.2) builder (3.2.2)
childprocess (0.5.8) childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
clavius (1.0.1) clavius (1.0.1)
memoizable (~> 0.4.0) memoizable (~> 0.4.0)
@ -95,7 +93,7 @@ GEM
http_parser.rb (~> 0.6.0) http_parser.rb (~> 0.6.0)
equalizer (0.0.10) equalizer (0.0.10)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.0.8) eventmachine (1.0.9.1)
execjs (2.6.0) execjs (2.6.0)
faraday (0.9.2) faraday (0.9.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
@ -159,7 +157,7 @@ GEM
mysql2 (0.3.20) mysql2 (0.3.20)
naught (1.1.0) naught (1.1.0)
nenv (0.2.0) nenv (0.2.0)
net-ldap (0.12.1) net-ldap (0.13.0)
nokogiri (1.6.7.1) nokogiri (1.6.7.1)
mini_portile2 (~> 2.0.0.rc2) mini_portile2 (~> 2.0.0.rc2)
notiffany (0.0.8) notiffany (0.0.8)
@ -177,28 +175,28 @@ GEM
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
omniauth-facebook (3.0.0) omniauth-facebook (3.0.0)
omniauth-oauth2 (~> 1.2) omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (0.2.10) omniauth-google-oauth2 (0.3.0)
addressable (~> 2.3) addressable (~> 2.3)
jwt (~> 1.0) jwt (~> 1.0)
multi_json (~> 1.3) multi_json (~> 1.3)
omniauth (>= 1.1.1) omniauth (>= 1.1.1)
omniauth-oauth2 (~> 1.3.1) omniauth-oauth2 (>= 1.3.1)
omniauth-linkedin (0.2.0) omniauth-linkedin (0.2.0)
omniauth-oauth (~> 1.0) omniauth-oauth (~> 1.0)
omniauth-oauth (1.1.0) omniauth-oauth (1.1.0)
oauth oauth
omniauth (~> 1.0) omniauth (~> 1.0)
omniauth-oauth2 (1.3.1) omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0) oauth2 (~> 1.0)
omniauth (~> 1.2) omniauth (~> 1.2)
omniauth-twitter (1.2.1) omniauth-twitter (1.2.1)
json (~> 1.3) json (~> 1.3)
omniauth-oauth (~> 1.1) omniauth-oauth (~> 1.1)
parser (2.2.3.0) parser (2.3.0.1)
ast (>= 1.1, < 3.0) ast (~> 2.2)
pluginator (1.3.0) pluginator (1.3.0)
polyglot (0.3.5) polyglot (0.3.5)
power_assert (0.2.6) power_assert (0.2.7)
powerpack (0.1.1) powerpack (0.1.1)
pre-commit (0.26.0) pre-commit (0.26.0)
pluginator (~> 1.1) pluginator (~> 1.1)
@ -239,21 +237,19 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.0.0) rainbow (2.0.0)
rake (10.4.2) rake (10.5.0)
rb-fsevent (0.9.7) rb-fsevent (0.9.7)
rb-inotify (0.9.5) rb-inotify (0.9.5)
ffi (>= 0.5.0) ffi (>= 0.5.0)
ref (2.0.0) ref (2.0.0)
rubocop (0.35.1) rubocop (0.36.0)
astrolabe (~> 1.3) parser (>= 2.3.0.0, < 3.0)
parser (>= 2.2.3.0, < 3.0)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0) rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
tins (<= 1.6.0)
ruby-progressbar (1.7.5) ruby-progressbar (1.7.5)
rubyzip (1.1.7) rubyzip (1.1.7)
sass (3.4.20) sass (3.4.21)
sass-rails (5.0.4) sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
sass (~> 3.1) sass (~> 3.1)
@ -261,7 +257,7 @@ GEM
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
scrub_rb (1.0.1) scrub_rb (1.0.1)
selenium-webdriver (2.48.1) selenium-webdriver (2.49.0)
childprocess (~> 0.5) childprocess (~> 0.5)
multi_json (~> 1.0) multi_json (~> 1.0)
rubyzip (~> 1.0) rubyzip (~> 1.0)
@ -277,7 +273,7 @@ GEM
simplecov-rcov (0.2.3) simplecov-rcov (0.2.3)
simplecov (>= 0.4.1) simplecov (>= 0.4.1)
slop (3.6.0) slop (3.6.0)
spring (1.6.1) spring (1.6.2)
sprockets (3.5.2) sprockets (3.5.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
@ -293,8 +289,7 @@ GEM
ref ref
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (2.0.1) tilt (2.0.2)
tins (1.6.0)
treetop (1.4.15) treetop (1.4.15)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)

View file

@ -20,11 +20,11 @@ class SearchController < ApplicationController
# convert objects string into array of class names # convert objects string into array of class names
# e.g. user-ticket-another_object = %w( User Ticket AnotherObject ) # e.g. user-ticket-another_object = %w( User Ticket AnotherObject )
if !params[:objects] objects = if !params[:objects]
objects = Setting.get('models_searchable') Setting.get('models_searchable')
else else
objects = params[:objects].split('-').map(&:camelize) params[:objects].split('-').map(&:camelize)
end end
# get priorities of result # get priorities of result
objects_in_order = [] objects_in_order = []

View file

@ -18,11 +18,9 @@ class SessionsController < ApplicationController
end end
# remember me - set session cookie to expire later # remember me - set session cookie to expire later
if params[:remember_me] request.env['rack.session.options'][:expire_after] = if params[:remember_me]
request.env['rack.session.options'][:expire_after] = 1.year 1.year
else end
request.env['rack.session.options'][:expire_after] = nil
end
# both not needed to set :expire_after works fine # both not needed to set :expire_after works fine
# request.env['rack.session.options'][:renew] = true # request.env['rack.session.options'][:renew] = true
# reset_session # reset_session

View file

@ -19,7 +19,7 @@ class TicketArticlesController < ApplicationController
# POST /articles # POST /articles
def create def create
form_id = params[:ticket_article][:form_id] form_id = params[:ticket_article][:form_id]
params[:ticket_article].delete(:form_id) params[:ticket_article].delete(:form_id)
@article = Ticket::Article.new( Ticket::Article.param_validation( params[:ticket_article] ) ) @article = Ticket::Article.new( Ticket::Article.param_validation( params[:ticket_article] ) )
@ -93,11 +93,11 @@ class TicketArticlesController < ApplicationController
file = params[:File] file = params[:File]
content_type = file.content_type content_type = file.content_type
if !content_type || content_type == 'application/octet-stream' if !content_type || content_type == 'application/octet-stream'
if MIME::Types.type_for(file.original_filename).first content_type = if MIME::Types.type_for(file.original_filename).first
content_type = MIME::Types.type_for(file.original_filename).first.content_type MIME::Types.type_for(file.original_filename).first.content_type
else else
content_type = 'application/octet-stream' 'application/octet-stream'
end end
end end
headers_store = { headers_store = {
'Content-Type' => content_type 'Content-Type' => content_type

View file

@ -117,10 +117,10 @@ class TicketsController < ApplicationController
# open tickets by customer # open tickets by customer
group_ids = Group.select( 'groups.id' ) group_ids = Group.select( 'groups.id' )
.joins(:users) .joins(:users)
.where( 'groups_users.user_id = ?', current_user.id ) .where( 'groups_users.user_id = ?', current_user.id )
.where( 'groups.active = ?', true ) .where( 'groups.active = ?', true )
.map( &:id ) .map( &:id )
access_condition = [ 'group_id IN (?)', group_ids ] access_condition = [ 'group_id IN (?)', group_ids ]
@ -142,7 +142,7 @@ class TicketsController < ApplicationController
} }
ticket_ids_recent_viewed = [] ticket_ids_recent_viewed = []
recent_views = RecentView.list( current_user, 8, 'Ticket' ) recent_views = RecentView.list( current_user, 8, 'Ticket' )
recent_views.each {|recent_view| recent_views.each {|recent_view|
next if recent_view['object'] != 'Ticket' next if recent_view['object'] != 'Ticket'
ticket_ids_recent_viewed.push recent_view['o_id'] ticket_ids_recent_viewed.push recent_view['o_id']
@ -417,15 +417,15 @@ class TicketsController < ApplicationController
# created # created
created = Ticket.where('created_at > ? AND created_at < ?', date_start, date_end ) created = Ticket.where('created_at > ? AND created_at < ?', date_start, date_end )
.where(access_condition) .where(access_condition)
.where(condition) .where(condition)
.count .count
# closed # closed
closed = Ticket.where('close_time > ? AND close_time < ?', date_start, date_end ) closed = Ticket.where('close_time > ? AND close_time < ?', date_start, date_end )
.where(access_condition) .where(access_condition)
.where(condition) .where(condition)
.count .count
data = { data = {
month: date_to_check.month, month: date_to_check.month,
@ -532,7 +532,7 @@ class TicketsController < ApplicationController
def article_create(ticket, params) def article_create(ticket, params)
# create article if given # create article if given
form_id = params[:form_id] form_id = params[:form_id]
params.delete(:form_id) params.delete(:form_id)
article = Ticket::Article.new( Ticket::Article.param_validation( params ) ) article = Ticket::Article.new( Ticket::Article.param_validation( params ) )
article.ticket_id = ticket.id article.ticket_id = ticket.id

View file

@ -15,11 +15,11 @@ class UsersController < ApplicationController
def index def index
# only allow customer to fetch him self # only allow customer to fetch him self
if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent') users = if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
users = User.where( id: current_user.id ) User.where( id: current_user.id )
else else
users = User.all 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
@ -337,11 +337,11 @@ class UsersController < ApplicationController
end end
# do query # do query
if params[:role_ids] && !params[:role_ids].empty? user_all = if params[:role_ids] && !params[:role_ids].empty?
user_all = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 ) User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 )
else else
user_all = User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 ) User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 )
end end
# build result list # build result list
if !params[:full] if !params[:full]

View file

@ -97,15 +97,15 @@ return all activity entries of an user
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? stream = if group_ids.empty?
stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids ) ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids )
.order( 'created_at DESC, id DESC' ) .order( 'created_at DESC, id DESC' )
.limit( limit ) .limit( limit )
else else
stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids ) ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids )
.order( 'created_at DESC, id DESC' ) .order( 'created_at DESC, id DESC' )
.limit( limit ) .limit( limit )
end end
list = [] list = []
stream.each do |item| stream.each do |item|
data = item.attributes data = item.attributes

View file

@ -142,7 +142,7 @@ returns
attributes = self.attributes attributes = self.attributes
self.class.reflect_on_all_associations.map { |assoc| self.class.reflect_on_all_associations.map { |assoc|
real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids' real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids'
if self.respond_to?(real_key) if respond_to?(real_key)
attributes[ real_key ] = send(real_key) attributes[ real_key ] = send(real_key)
end end
} }
@ -230,7 +230,7 @@ returns
end end
def cache_update(o) def cache_update(o)
cache_delete if self.respond_to?('cache_delete') cache_delete if respond_to?('cache_delete')
o.cache_delete if o.respond_to?('cache_delete') o.cache_delete if o.respond_to?('cache_delete')
end end
@ -241,7 +241,7 @@ returns
Cache.delete(key) Cache.delete(key)
# delete old name / login caches # delete old name / login caches
if self.changed? if changed?
if changes.key?('name') if changes.key?('name')
name = changes['name'][0] name = changes['name'][0]
key = "#{self.class}::#{name}" key = "#{self.class}::#{name}"
@ -349,9 +349,9 @@ returns
end end
} }
return return
else
fail 'Need name, id or login for lookup()'
end end
fail 'Need name, id or login for lookup()'
end end
=begin =begin
@ -442,7 +442,7 @@ returns
# do lookup with == to handle case insensitive databases # do lookup with == to handle case insensitive databases
records = where(login: data[:login]) records = where(login: data[:login])
records.each {|loop_record| records.each {|loop_record|
if loop_record.login.downcase == data[:login].downcase if loop_record.login.casecmp data[:login] == 0
loop_record.update_attributes(data) loop_record.update_attributes(data)
return loop_record return loop_record
end end
@ -455,7 +455,7 @@ returns
# do lookup with == to handle case insensitive databases # do lookup with == to handle case insensitive databases
records = where(email: data[:email]) records = where(email: data[:email])
records.each {|loop_record| records.each {|loop_record|
if loop_record.email.downcase == data[:email].downcase if loop_record.email.casecmp data[:email] == 0
loop_record.update_attributes(data) loop_record.update_attributes(data)
return loop_record return loop_record
end end
@ -468,7 +468,7 @@ returns
# do lookup with == to handle case insensitive databases # do lookup with == to handle case insensitive databases
records = where(locale: data[:locale]) records = where(locale: data[:locale])
records.each {|loop_record| records.each {|loop_record|
if loop_record.locale.downcase == data[:locale].downcase if loop_record.locale.casecmp data[:locale] == 0
loop_record.update_attributes(data) loop_record.update_attributes(data)
return loop_record return loop_record
end end
@ -783,7 +783,7 @@ log object update activity stream, if configured - will be executed automaticall
def activity_stream_update def activity_stream_update
return if !self.class.activity_stream_support_config return if !self.class.activity_stream_support_config
return if !self.changed? return if !changed?
# default ignored attributes # default ignored attributes
ignore_attributes = { ignore_attributes = {
@ -872,10 +872,10 @@ log object update history with all updated attributes, if configured - will be e
def history_update def history_update
return if !self.class.history_support_config return if !self.class.history_support_config
return if !self.changed? return if !changed?
# return if it's no update # return if it's no update
return if self.new_record? return if new_record?
# new record also triggers update, so ignore new records # new record also triggers update, so ignore new records
changes = self.changes changes = self.changes
@ -921,7 +921,7 @@ log object update history with all updated attributes, if configured - will be e
value_id[0] = value[0] value_id[0] = value[0]
value_id[1] = value[1] value_id[1] = value[1]
if self.respond_to?( attribute_name ) && send(attribute_name) if respond_to?( attribute_name ) && send(attribute_name)
relation_class = send(attribute_name).class relation_class = 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] )

View file

@ -344,11 +344,11 @@ returns
if public_holidays_was && public_holidays_was[day] && public_holidays_was[day]['feed'] if public_holidays_was && public_holidays_was[day] && public_holidays_was[day]['feed']
meta['feed'] = public_holidays_was[day]['feed'] meta['feed'] = public_holidays_was[day]['feed']
end end
if meta['active'] meta['active'] = if meta['active']
meta['active'] = true true
else else
meta['active'] = false false
end end
} }
end end

View file

@ -40,11 +40,11 @@ module Channel::EmailBuild
next if key.to_s == 'attachments' next if key.to_s == 'attachments'
next if key.to_s == 'body' next if key.to_s == 'body'
next if key.to_s == 'content_type' next if key.to_s == 'content_type'
if value && value.class != Array mail[key.to_s] = if value && value.class != Array
mail[key.to_s] = value.to_s value.to_s
else else
mail[key.to_s] = value value
end end
end end
# add html part # add html part

View file

@ -191,58 +191,56 @@ class Channel::EmailParser
end end
# not multipart email # not multipart email
else
# text part only # text part only
if !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.downcase == 'text/plain' elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain')
data[:body] = mail.body.decoded
data[:body] = Encode.conv(mail.charset, data[:body])
if !data[:body].force_encoding('UTF-8').valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end
# html part only, convert ot text and add it as attachment
else
filename = '-no name-'
if mail.mime_type.to_s.casecmp('text/html')
filename = 'message.html'
data[:body] = mail.body.decoded data[:body] = mail.body.decoded
data[:body] = Encode.conv(mail.charset, data[:body]) data[:body] = Encode.conv(mail.charset, data[:body])
data[:body] = data[:body].html2text.to_s.force_encoding('utf-8')
if !data[:body].force_encoding('UTF-8').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 part only, convert ot text and add it as attachment # any other attachments
else else
filename = '-no name-' data[:body] = 'no visible content'
if mail.mime_type.to_s.downcase == 'text/html'
filename = 'message.html'
data[:body] = mail.body.decoded
data[:body] = Encode.conv(mail.charset, data[:body])
data[:body] = data[:body].html2text.to_s.force_encoding('utf-8')
if !data[:body].valid_encoding?
data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
end
# any other attachments
else
data[:body] = 'no visible content'
end
# add body as attachment
headers_store = {
'content-alternative' => true,
}
if mail.mime_type
headers_store['Mime-Type'] = mail.mime_type
end
if mail.charset
headers_store['Charset'] = mail.charset
end
attachment = {
data: mail.body.decoded,
filename: mail.filename || filename,
preferences: headers_store
}
data[:attachments].push attachment
end end
# add body as attachment
headers_store = {
'content-alternative' => true,
}
if mail.mime_type
headers_store['Mime-Type'] = mail.mime_type
end
if mail.charset
headers_store['Charset'] = mail.charset
end
attachment = {
data: mail.body.decoded,
filename: mail.filename || filename,
preferences: headers_store
}
data[:attachments].push attachment
end end
# strip not wanted chars # strip not wanted chars
data[:body].gsub!(/\n\r/, "\n") data[:body].gsub!(/\n\r/, "\n")
data[:body].gsub!(/\r\n/, "\n") data[:body].gsub!(/\r\n/, "\n")
data[:body].gsub!(/\r/, "\n") data[:body].tr!("\r", "\n")
# remember original mail instance # remember original mail instance
data[:mail_instance] = mail data[:mail_instance] = mail

View file

@ -29,7 +29,7 @@ class ExternalCredential < ApplicationModel
def self.load_backend(provider) def self.load_backend(provider)
adapter = "ExternalCredential::#{provider.camelcase}" adapter = "ExternalCredential::#{provider.camelcase}"
require "#{adapter.to_filename}" require adapter.to_filename.to_s
load_adapter(adapter) load_adapter(adapter)
end end

View file

@ -153,8 +153,8 @@ returns
if !related_history_object if !related_history_object
history_object = object_lookup( requested_object ) history_object = 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 = object_lookup( requested_object ) history_object_requested = object_lookup( requested_object )
history_object_related = object_lookup( related_history_object ) history_object_related = object_lookup( related_history_object )
@ -165,7 +165,7 @@ returns
history_object_related.id, history_object_related.id,
requested_object_id, requested_object_id,
) )
.order('created_at ASC, id ASC') # rubocop:disable Style/MultilineOperationIndentation .order('created_at ASC, id ASC')
end end
asset_list = {} asset_list = {}
list = [] list = []

View file

@ -43,8 +43,8 @@ class Job < ApplicationModel
# find tickets to change # find tickets to change
tickets = Ticket.where( job.condition.permit! ) tickets = Ticket.where( job.condition.permit! )
.order( '`tickets`.`created_at` DESC' ) .order( '`tickets`.`created_at` DESC' )
.limit( 1_000 ) .limit( 1_000 )
job.processed = tickets.count job.processed = tickets.count
tickets.each do |ticket| tickets.each do |ticket|
logger.debug "CHANGE #{job.execute.inspect}" logger.debug "CHANGE #{job.execute.inspect}"
@ -83,4 +83,5 @@ class Job < ApplicationModel
minutes.gsub!(/(\d)\d/, '\\1') minutes.gsub!(/(\d)\d/, '\\1')
minutes.to_s + '0' minutes.to_s + '0'
end end
private_class_method :match_minutes
end end

View file

@ -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

View file

@ -6,7 +6,7 @@ class Observer::Ticket::Notification::BackgroundJob
end end
def perform def perform
ticket = Ticket.find(@p[:ticket_id]) ticket = Ticket.find(@p[:ticket_id])
if @p[:article_id] if @p[:article_id]
article = Ticket::Article.find(@p[:article_id]) article = Ticket::Article.find(@p[:article_id])
end end
@ -53,11 +53,8 @@ class Observer::Ticket::Notification::BackgroundJob
recipients.each do |user| recipients.each do |user|
# ignore user who changed it by him self # ignore user who changed it by him self
if article next if article && article.updated_by_id == user.id
next if article.updated_by_id == user.id next if !article && ticket.updated_by_id == user.id
else
next if ticket.updated_by_id == user.id
end
# ignore inactive users # ignore inactive users
next if !user.active next if !user.active
@ -217,11 +214,11 @@ class Observer::Ticket::Notification::BackgroundJob
# set new key # set new key
display = object_manager_attribute[:display].to_s display = object_manager_attribute[:display].to_s
end end
if object_manager_attribute && object_manager_attribute[:translate] changes[display] = if object_manager_attribute && object_manager_attribute[:translate]
changes[display] = ["i18n(#{value_str[0]})", "i18n(#{value_str[1]})"] ["i18n(#{value_str[0]})", "i18n(#{value_str[1]})"]
else else
changes[display] = [value_str[0].to_s, value_str[1].to_s] [value_str[0].to_s, value_str[1].to_s]
end end
} }
changes changes
end end

View file

@ -89,8 +89,8 @@ 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 = []
notifications.each do |item| notifications.each do |item|
data = item.attributes data = item.attributes
@ -117,8 +117,8 @@ return all online notifications of an object
object_lookup_id: object_id, object_lookup_id: object_id,
o_id: o_id, o_id: o_id,
) )
.order( 'created_at DESC, id DESC' ) # rubocop:disable Style/MultilineOperationIndentation .order( 'created_at DESC, id DESC' )
.limit( 10_000 ) # rubocop:disable Style/MultilineOperationIndentation .limit( 10_000 )
notifications notifications
end end

View file

@ -11,7 +11,7 @@ class Organization < ApplicationModel
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

@ -96,7 +96,7 @@ class Package < ApplicationModel
def self.unlink(package_base_dir) def self.unlink(package_base_dir)
# check if zpm is a package source repo # check if zpm is a package source repo
package = self._package_base_dir?(package_base_dir) package = _package_base_dir?(package_base_dir)
# migration down # migration down
Package::Migration.migrate( package, 'reverse' ) Package::Migration.migrate( package, 'reverse' )
@ -126,7 +126,7 @@ class Package < ApplicationModel
def self.link(package_base_dir) def self.link(package_base_dir)
# check if zpm is a package source repo # check if zpm is a package source repo
package = self._package_base_dir?(package_base_dir) package = _package_base_dir?(package_base_dir)
# link files # link files
Dir.glob( package_base_dir + '/**/*' ) do |entry| Dir.glob( package_base_dir + '/**/*' ) do |entry|
@ -337,13 +337,13 @@ class Package < ApplicationModel
end end
def self._read_file(file, fullpath = false) def self._read_file(file, fullpath = false)
if fullpath == false location = if fullpath == false
location = @@root + '/' + file @@root + '/' + file
elsif fullpath == true elsif fullpath == true
location = file file
else else
location = fullpath + '/' + file fullpath + '/' + file
end end
begin begin
data = File.open( location, 'rb' ) data = File.open( location, 'rb' )

View file

@ -27,8 +27,8 @@ class RecentView < ApplicationModel
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 )
@ -36,15 +36,15 @@ class RecentView < ApplicationModel
end end
def self.list( user, limit = 10, type = nil ) def self.list( user, limit = 10, type = nil )
if !type recent_views = if !type
recent_views = RecentView.where( created_by_id: user.id ) 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) ) 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
list = [] list = []
recent_views.each { |item| recent_views.each { |item|

View file

@ -16,11 +16,11 @@ class Setting < ApplicationModel
@@current = {} # rubocop:disable Style/ClassVars @@current = {} # rubocop:disable Style/ClassVars
@@change_id = nil # rubocop:disable Style/ClassVars @@change_id = nil # rubocop:disable Style/ClassVars
@@lookup_at = nil # rubocop:disable Style/ClassVars @@lookup_at = nil # rubocop:disable Style/ClassVars
if ENV['ZAMMAD_SETTING_TTL'] @@lookup_timeout = if ENV['ZAMMAD_SETTING_TTL'] # rubocop:disable Style/ClassVars
@@lookup_timeout = ENV['ZAMMAD_SETTING_TTL'].to_i.seconds # rubocop:disable Style/ClassVars ENV['ZAMMAD_SETTING_TTL'].to_i.seconds
else else
@@lookup_timeout = 2.minutes # rubocop:disable Style/ClassVars 2.minutes
end end
=begin =begin
@ -118,6 +118,7 @@ reload config settings
cache(config) cache(config)
true true
end end
private_class_method :load
# set initial value in state_initial # set initial value in state_initial
def set_initial def set_initial
@ -131,6 +132,7 @@ reload config settings
logger.debug "Setting.cache: set cache, #{@@change_id}" logger.debug "Setting.cache: set cache, #{@@change_id}"
@@lookup_at = Time.zone.now # rubocop:disable Style/ClassVars @@lookup_at = Time.zone.now # rubocop:disable Style/ClassVars
end end
private_class_method :cache
# reset cache # reset cache
def reset_cache def reset_cache
@ -156,6 +158,7 @@ reload config settings
logger.debug "Setting.cache_valid?: cache has changed, #{@@change_id}/#{change_id}" logger.debug "Setting.cache_valid?: cache has changed, #{@@change_id}/#{change_id}"
false false
end end
private_class_method :cache_valid?
# convert state into hash to be able to store it as store # convert state into hash to be able to store it as store
def state_check def state_check

View file

@ -23,7 +23,7 @@ class StatsStore < ApplicationModel
end end
StatsStore.where(stats_store_object_id: object_id, o_id: data[:o_id], key: data[:key]) StatsStore.where(stats_store_object_id: object_id, o_id: data[:o_id], key: data[:key])
.where('created_at > ? AND created_at < ?', data[:start], data[:end]).count .where('created_at > ? AND created_at < ?', data[:start], data[:end]).count
end end
=begin =begin

View file

@ -81,7 +81,7 @@ returns
# 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')
stores stores
end end
@ -104,8 +104,8 @@ returns
# 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|
# check backend for references # check backend for references

View file

@ -46,12 +46,12 @@ read content of a file
def content def content
adapter = self.class.load_adapter("Store::Provider::#{provider}") adapter = self.class.load_adapter("Store::Provider::#{provider}")
if sha c = if sha
c = adapter.get( sha ) adapter.get( sha )
else else
# fallback until migration is done # fallback until migration is done
c = Store::Provider::DB.find_by( md5: md5 ).data Store::Provider::DB.find_by( md5: md5 ).data
end end
c c
end end

View file

@ -103,16 +103,16 @@ returns
access_condition = [] access_condition = []
if user.role?(Z_ROLENAME_AGENT) if user.role?(Z_ROLENAME_AGENT)
group_ids = Group.select( 'groups.id' ).joins(:users) group_ids = Group.select( 'groups.id' ).joins(:users)
.where( 'groups_users.user_id = ?', user.id ) .where( 'groups_users.user_id = ?', user.id )
.where( 'groups.active = ?', true ) .where( 'groups.active = ?', true )
.map( &:id ) .map( &:id )
access_condition = [ 'group_id IN (?)', group_ids ] access_condition = [ 'group_id IN (?)', group_ids ]
else else
if !user.organization || ( !user.organization.shared || user.organization.shared == false ) access_condition = if !user.organization || ( !user.organization.shared || user.organization.shared == false )
access_condition = [ 'tickets.customer_id = ?', user.id ] [ 'tickets.customer_id = ?', user.id ]
else else
access_condition = [ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ] [ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ]
end end
end end
access_condition access_condition
end end
@ -134,7 +134,7 @@ returns
ticket_states = Ticket::State.where( ticket_states = Ticket::State.where(
state_type_id: Ticket::StateType.find_by( name: 'pending action' ), state_type_id: Ticket::StateType.find_by( name: 'pending action' ),
) )
.where.not(next_state_id: nil) # rubocop:disable Style/MultilineOperationIndentation .where.not(next_state_id: nil)
return [] if !ticket_states return [] if !ticket_states
@ -146,7 +146,7 @@ returns
tickets = where( tickets = where(
state_id: next_state_map.keys, state_id: next_state_map.keys,
) )
.where( 'pending_time <= ?', Time.zone.now ) # rubocop:disable Style/MultilineOperationIndentation .where( 'pending_time <= ?', Time.zone.now )
return [] if !tickets return [] if !tickets

View file

@ -49,12 +49,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

@ -171,10 +171,8 @@ returns
# get close time in min # get close time in min
if close_time if close_time
self.close_time_in_min = pending_minutes(created_at, close_time, biz, 'business_minutes') self.close_time_in_min = pending_minutes(created_at, close_time, biz, 'business_minutes')
else elsif close_time_escal_date && ((!escalation_time && close_time_escal_date) || close_time_escal_date < escalation_time)
if close_time_escal_date && ((!escalation_time && close_time_escal_date) || close_time_escal_date < escalation_time) self.escalation_time = close_time_escal_date
self.escalation_time = close_time_escal_date
end
end end
# set time to show if sla is raised or not # set time to show if sla is raised or not
@ -186,7 +184,7 @@ returns
self.escalation_time = nil self.escalation_time = nil
end end
return if !self.changed? return if !changed?
self.callback_loop = true self.callback_loop = true
save save
@ -279,11 +277,11 @@ returns
end end
total_time_in_min = total_time_in_min + diff total_time_in_min = total_time_in_min + diff
if history_item['value_to'] == 'pending reminder' last_state_is_pending = if history_item['value_to'] == 'pending reminder'
last_state_is_pending = true true
else else
last_state_is_pending = false false
end end
# remember for next loop last state # remember for next loop last state
last_state = history_item['value_to'] last_state = history_item['value_to']

View file

@ -20,11 +20,11 @@ module Ticket::Number::Date
# increase counter # increase counter
counter_increment, date_file = counter.content.to_s.split(';') counter_increment, date_file = counter.content.to_s.split(';')
if date_file == date counter_increment = if date_file == date
counter_increment = counter_increment.to_i + 1 counter_increment.to_i + 1
else else
counter_increment = 1 1
end end
# store new counter value # store new counter value
counter.content = counter_increment.to_s + ';' + date counter.content = counter_increment.to_s + ';' + date

View file

@ -9,7 +9,7 @@ module Ticket::Number::Increment
config = Setting.get('ticket_number_increment') config = Setting.get('ticket_number_increment')
# read counter # read counter
min_digs = config[:min_size] || 4 min_digs = config[:min_size] || 4
counter_increment = nil counter_increment = nil
Ticket::Counter.transaction do Ticket::Counter.transaction do
counter = Ticket::Counter.where( generator: 'Increment' ).lock(true).first counter = Ticket::Counter.where( generator: 'Increment' ).lock(true).first

View file

@ -20,11 +20,11 @@ returns
# get customer overviews # get customer overviews
if data[:current_user].role?('Customer') if data[:current_user].role?('Customer')
role = Role.find_by( name: 'Customer' ) role = Role.find_by( name: 'Customer' )
if data[:current_user].organization_id && data[:current_user].organization.shared overviews = if data[:current_user].organization_id && data[:current_user].organization.shared
overviews = Overview.where( role_id: role.id, active: true ) Overview.where( role_id: role.id, active: true )
else else
overviews = Overview.where( role_id: role.id, organization_shared: false, active: true ) Overview.where( role_id: role.id, organization_shared: false, active: true )
end end
return overviews return overviews
end end
@ -113,10 +113,10 @@ returns
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user]) query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user])
tickets = Ticket.select('id') tickets = Ticket.select('id')
.where( access_condition ) .where( access_condition )
.where( query_condition, *bind_condition ) .where( query_condition, *bind_condition )
.order( order_by ) .order( order_by )
.limit( 500 ) .limit( 500 )
ticket_ids = [] ticket_ids = []
tickets.each { |ticket| tickets.each { |ticket|
@ -136,8 +136,8 @@ returns
data[:start_page] ||= 1 data[:start_page] ||= 1
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user]) query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user])
tickets = Ticket.where( access_condition ) tickets = Ticket.where( access_condition )
.where( query_condition, *bind_condition ) .where( query_condition, *bind_condition )
.order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ) .order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )
tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count() tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count()

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 Ticket::Priority < ApplicationModel class Ticket::Priority < ApplicationModel
self.table_name = 'ticket_priorities' self.table_name = 'ticket_priorities'
validates :name, presence: true validates :name, presence: true
end end

View file

@ -104,8 +104,8 @@ returns
if current_user.role?('Agent') if current_user.role?('Agent')
groups = Group.joins(:users) groups = Group.joins(:users)
.where( 'groups_users.user_id = ?', current_user.id ) .where( 'groups_users.user_id = ?', current_user.id )
.where( 'groups.active = ?', true ) .where( 'groups.active = ?', true )
group_condition = [] group_condition = []
groups.each {|group| groups.each {|group|
group_condition.push group.name group_condition.push group.name
@ -113,24 +113,24 @@ returns
access_condition = { access_condition = {
'query_string' => { 'default_field' => 'Ticket.group.name', 'query' => "\"#{group_condition.join('" OR "')}\"" } 'query_string' => { 'default_field' => 'Ticket.group.name', 'query' => "\"#{group_condition.join('" OR "')}\"" }
} }
query_extention['bool']['must'].push access_condition
else else
if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false )
access_condition = { {
'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id } 'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id }
} }
# customer_id: XXX # customer_id: XXX
# conditions = [ 'customer_id = ?', current_user.id ] # conditions = [ 'customer_id = ?', current_user.id ]
else else
access_condition = { {
'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" } 'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" }
} }
# customer_id: XXX OR organization_id: XXX # customer_id: XXX OR organization_id: XXX
# conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ]
end end
query_extention['bool']['must'].push access_condition
end end
query_extention['bool']['must'].push access_condition
items = SearchIndexBackend.search( query, limit, 'Ticket', query_extention ) items = SearchIndexBackend.search( query, limit, 'Ticket', query_extention )
if !full if !full
ids = [] ids = []
@ -154,18 +154,18 @@ returns
if query if query
query.delete! '*' query.delete! '*'
tickets_all = Ticket.select('DISTINCT(tickets.id)') tickets_all = Ticket.select('DISTINCT(tickets.id)')
.where(access_condition) .where(access_condition)
.where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ) .where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" )
.joins(:articles) .joins(:articles)
.order('`tickets`.`created_at` DESC') .order('`tickets`.`created_at` DESC')
.limit(limit) .limit(limit)
else else
query_condition, bind_condition = selector2sql(params[:condition]) query_condition, bind_condition = selector2sql(params[:condition])
tickets_all = Ticket.select('DISTINCT(tickets.id)') tickets_all = Ticket.select('DISTINCT(tickets.id)')
.where(access_condition) .where(access_condition)
.where(query_condition, *bind_condition) .where(query_condition, *bind_condition)
.order('`tickets`.`created_at` DESC') .order('`tickets`.`created_at` DESC')
.limit(limit) .limit(limit)
end end
# build result list # build result list

View file

@ -175,30 +175,30 @@ get list of translations
'total' => Translation.where(locale: 'de-de').count, 'total' => Translation.where(locale: 'de-de').count,
} }
list = [] list = []
if admin translations = if admin
translations = Translation.where(locale: locale.downcase).order(:source) Translation.where(locale: locale.downcase).order(:source)
else else
translations = Translation.where(locale: locale.downcase).where.not(target: '').order(:source) Translation.where(locale: locale.downcase).where.not(target: '').order(:source)
end end
translations.each { |item| translations.each { |item|
if admin translation_item = []
translation_item = [ translation_item = if admin
item.id, [
item.source, item.id,
item.target, item.source,
item.target_initial, item.target,
item.format, item.target_initial,
] item.format,
list.push translation_item ]
else else
translation_item = [ [
item.id, item.id,
item.source, item.source,
item.target, item.target,
item.format, item.format,
] ]
list.push translation_item end
end list.push translation_item
} }
data['list'] = list data['list'] = list
@ -250,8 +250,10 @@ translate strings in ruby context, e. g. for notifications
def self.cache_set(locale, data) def self.cache_set(locale, data)
Cache.write('TranslationMapOnlyContent::' + locale.downcase, data) Cache.write('TranslationMapOnlyContent::' + locale.downcase, data)
end end
private_class_method :cache_set
def self.cache_get(locale) def self.cache_get(locale)
Cache.get('TranslationMapOnlyContent::' + locale.downcase) Cache.get('TranslationMapOnlyContent::' + locale.downcase)
end end
private_class_method :cache_get
end end

View file

@ -124,8 +124,8 @@ returns
roles.each { |role| roles.each { |role|
if role_name.class == Array if role_name.class == Array
next if !role_name.include?(role.name) next if !role_name.include?(role.name)
else elsif role.name != role_name
next if role.name != role_name next
end end
result = true result = true
break break

View file

@ -69,15 +69,15 @@ returns
# fallback do sql query # fallback do sql query
# - stip out * we already search for *query* - # - stip out * we already search for *query* -
query.delete! '*' query.delete! '*'
if params[:role_ids] users = if params[:role_ids]
users = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where( User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where(
'(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" '(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
).order('firstname').limit(limit) ).order('firstname').limit(limit)
else else
users = User.where( User.where(
'(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" '(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"
).order('firstname').limit(limit) ).order('firstname').limit(limit)
end end
users users
end end
end end

View file

@ -3,6 +3,6 @@
# Prefix all zammad constants w/ Z_ # Prefix all zammad constants w/ Z_
# Prefix all rolenames with Z_ROLENAME # Prefix all rolenames with Z_ROLENAME
Z_ROLENAME_ADMIN = 'Admin' Z_ROLENAME_ADMIN = 'Admin'.freeze
Z_ROLENAME_AGENT = 'Agent' Z_ROLENAME_AGENT = 'Agent'.freeze
Z_ROLENAME_CUSTOMER = 'Customer' Z_ROLENAME_CUSTOMER = 'Customer'.freeze

View file

@ -5,7 +5,7 @@ class CreateBase < ActiveRecord::Migration
t.string :session_id, null: false t.string :session_id, null: false
t.boolean :persistent, null: true t.boolean :persistent, null: true
t.text :data t.text :data
t.timestamps null: false t.timestamps null: false
end end
add_index :sessions, :session_id add_index :sessions, :session_id
add_index :sessions, :updated_at add_index :sessions, :updated_at
@ -465,7 +465,7 @@ class CreateBase < ActiveRecord::Migration
t.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) t.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
t.string :locked_by # Who is working on this object (if locked) t.string :locked_by # Who is working on this object (if locked)
t.string :queue # The name of the queue this job is in t.string :queue # The name of the queue this job is in
t.timestamps null: false t.timestamps null: false
end end
add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority' add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority'

View file

@ -18,10 +18,10 @@ class CreateMacro < ActiveRecord::Migration
Macro.create_or_update( Macro.create_or_update(
name: 'Close & Tag as Spam', name: 'Close & Tag as Spam',
perform: { perform: {
'ticket.state_id': { 'ticket.state_id' => {
value: Ticket::State.find_by(name: 'closed').id, value: Ticket::State.find_by(name: 'closed').id,
}, },
'ticket.tags': { 'ticket.tags' => {
operator: 'add', operator: 'add',
value: 'spam', value: 'spam',
}, },

View file

@ -1644,10 +1644,10 @@ Ticket::Article::Sender.create_if_not_exists( id: 3, name: 'System' )
Macro.create_if_not_exists( Macro.create_if_not_exists(
name: 'Close & Tag as Spam', name: 'Close & Tag as Spam',
perform: { perform: {
'ticket.state_id': { 'ticket.state_id' => {
value: Ticket::State.find_by(name: 'closed').id, value: Ticket::State.find_by(name: 'closed').id,
}, },
'ticket.tags': { 'ticket.tags' => {
operator: 'add', operator: 'add',
value: 'spam', value: 'spam',
}, },

View file

@ -147,11 +147,10 @@ returns
admin_user admin_user
end end
private
def self.file_location def self.file_location
auto_wizard_file_name = 'auto_wizard.json' auto_wizard_file_name = 'auto_wizard.json'
auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}" auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}"
auto_wizard_file_location auto_wizard_file_location
end end
private_class_method :file_location
end end

View file

@ -2,10 +2,10 @@ class Class
def to_app_model_url def to_app_model_url
camel_cased_word = to_s camel_cased_word = to_s
camel_cased_word.gsub(/::/, '_') camel_cased_word.gsub(/::/, '_')
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr('-', '_') .tr('-', '_')
.downcase .downcase
end end
def to_app_model def to_app_model

View file

@ -31,11 +31,11 @@ class String
=end =end
def to_filename def to_filename
camel_cased_word = "#{self}" camel_cased_word = to_s
camel_cased_word.gsub(/::/, '/') camel_cased_word.gsub(/::/, '/')
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr('-', '_').downcase .tr('-', '_').downcase
end end
=begin =begin
@ -48,7 +48,7 @@ class String
=end =end
def to_classname def to_classname
camel_cased_word = "#{self}" camel_cased_word = to_s
camel_cased_word.gsub!(/\.rb$/, '') camel_cased_word.gsub!(/\.rb$/, '')
camel_cased_word.split('/').map(&:camelize).join('::') camel_cased_word.split('/').map(&:camelize).join('::')
end end
@ -65,7 +65,7 @@ class String
end end
c c
} }
.join('') # rubocop:disable Style/MultilineOperationIndentation .join('')
end end
=begin =begin
@ -79,7 +79,7 @@ class String
=end =end
def html2text(string_only = false) def html2text(string_only = false)
string = "#{self}" string = to_s
# in case of invalid encodeing, strip invalid chars # in case of invalid encodeing, strip invalid chars
# see also test/fixtures/mail21.box # see also test/fixtures/mail21.box
@ -94,7 +94,7 @@ class String
if !string_only if !string_only
string.gsub!( /<a\s.*?href=("|')(.+?)("|').*?>/ix ) { string.gsub!( /<a\s.*?href=("|')(.+?)("|').*?>/ix ) {
link = $2 link = $2
counter = counter + 1 counter = counter + 1
link_list += "[#{counter}] #{link}\n" link_list += "[#{counter}] #{link}\n"
"[#{counter}] " "[#{counter}] "
} }

View file

@ -280,21 +280,21 @@ returns on fail
end end
# prepare test email # prepare test email
if subject mail = if subject
mail = { {
from: email, from: email,
to: email, to: email,
subject: "Zammad Getting started Test Email #{subject}", subject: "Zammad Getting started Test Email #{subject}",
body: "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.", body: "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.",
} }
else else
mail = { {
from: email, from: email,
to: 'emailtrytest@znuny.com', to: 'emailtrytest@znuny.com',
subject: 'This is a Test Email', subject: 'This is a Test Email',
body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.", body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.",
} }
end end
if subject if subject
mail['X-Zammad-Test-Message'] = subject mail['X-Zammad-Test-Message'] = subject
end end

View file

@ -56,11 +56,11 @@ or
def self.email(params) def self.email(params)
# send verify email # send verify email
if !params[:subject] || params[:subject].empty? subject = if !params[:subject] || params[:subject].empty?
subject = '#' + rand(99_999_999_999).to_s '#' + rand(99_999_999_999).to_s
else else
subject = params[:subject] params[:subject]
end end
result = EmailHelper::Probe.outbound(params[:outbound], params[:sender], subject) result = EmailHelper::Probe.outbound(params[:outbound], params[:sender], subject)
if result[:result] != 'ok' if result[:result] != 'ok'
result[:source] = 'outbound' result[:source] = 'outbound'

View file

@ -11,7 +11,7 @@ module Encode
end end
# validate already existing utf8 strings # validate already existing utf8 strings
if charset.downcase == 'utf8' || charset.downcase == 'utf-8' if charset.casecmp('utf8') || charset.casecmp('utf-8')
begin begin
# return if encoding is valid # return if encoding is valid

View file

@ -44,7 +44,7 @@ e. g.
# create agents # create agents
agent_pool = [] agent_pool = []
if agents && !agents.zero? if agents && !agents.zero?
roles = Role.where( name: [ 'Agent'] ) roles = Role.where( name: [ 'Agent'] )
groups_all = Group.all groups_all = Group.all
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@ -73,7 +73,7 @@ e. g.
# create customer # create customer
customer_pool = [] customer_pool = []
if customers && !customers.zero? if customers && !customers.zero?
roles = Role.where( name: [ 'Customer'] ) roles = Role.where( name: [ 'Customer'] )
groups_all = Group.all groups_all = Group.all
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do

View file

@ -1,6 +1,6 @@
# Monkey-patch HTTP::URI # Monkey-patch HTTP::URI
class HTTP::URI class HTTP::URI
def port def port
443 if self.https? 443 if https?
end end
end end

View file

@ -609,22 +609,22 @@ module Import::OTRS
# find owner # find owner
if ticket_new[:owner] if ticket_new[:owner]
user = User.lookup( login: ticket_new[:owner].downcase ) user = User.lookup( login: ticket_new[:owner].downcase )
if user ticket_new[:owner_id] = if user
ticket_new[:owner_id] = user.id user.id
else else
ticket_new[:owner_id] = 1 1
end end
ticket_new.delete(:owner) ticket_new.delete(:owner)
end end
# find customer # find customer
if ticket_new[:customer] if ticket_new[:customer]
user = User.lookup( login: ticket_new[:customer].downcase ) user = User.lookup( login: ticket_new[:customer].downcase )
if user ticket_new[:customer_id] = if user
ticket_new[:customer_id] = user.id user.id
else else
ticket_new[:customer_id] = 1 1
end end
ticket_new.delete(:customer) ticket_new.delete(:customer)
else else
ticket_new[:customer_id] = 1 ticket_new[:customer_id] = 1
@ -1345,19 +1345,19 @@ module Import::OTRS
def self._set_valid(record) def self._set_valid(record)
# map # map
if record['ValidID'].to_s == '3' record['ValidID'] = if record['ValidID'].to_s == '3'
record['ValidID'] = false false
elsif record['ValidID'].to_s == '2' elsif record['ValidID'].to_s == '2'
record['ValidID'] = false false
elsif record['ValidID'].to_s == '1' elsif record['ValidID'].to_s == '1'
record['ValidID'] = true true
elsif record['ValidID'].to_s == '0' elsif record['ValidID'].to_s == '0'
record['ValidID'] = false false
# fallback # fallback
else else
record['ValidID'] = true true
end end
end end
# cleanup invalid values # cleanup invalid values

View file

@ -192,11 +192,11 @@ module Import::Zendesk
def import_field(local_object, zendesk_field) def import_field(local_object, zendesk_field)
name = '' name = ''
if local_object == 'Ticket' name = if local_object == 'Ticket'
name = zendesk_field.title zendesk_field.title
else else
name = zendesk_field['key'] # TODO: y?! zendesk_field['key'] # TODO: y?!
end end
@zendesk_ticket_field_mapping ||= {} @zendesk_ticket_field_mapping ||= {}
@zendesk_ticket_field_mapping[ zendesk_field.id ] = name @zendesk_ticket_field_mapping[ zendesk_field.id ] = name
@ -512,13 +512,13 @@ module Import::Zendesk
ticket_author = User.find( @zendesk_user_mapping[ zendesk_ticket.requester_id ] ) ticket_author = User.find( @zendesk_user_mapping[ zendesk_ticket.requester_id ] )
if ticket_author.role?('Customer') local_ticket_fields[:create_article_sender_id] = if ticket_author.role?('Customer')
local_ticket_fields[:create_article_sender_id] = article_sender_customer.id article_sender_customer.id
elsif ticket_author.role?('Agent') elsif ticket_author.role?('Agent')
local_ticket_fields[:create_article_sender_id] = article_sender_agent.id article_sender_agent.id
else else
local_ticket_fields[:create_article_sender_id] = article_sender_system.id article_sender_system.id
end end
# TODO: zendesk_ticket.external_id ? # TODO: zendesk_ticket.external_id ?
if zendesk_ticket.via.channel == 'web' if zendesk_ticket.via.channel == 'web'
@ -530,20 +530,20 @@ module Import::Zendesk
elsif zendesk_ticket.via.channel == 'twitter' elsif zendesk_ticket.via.channel == 'twitter'
# TODO # TODO
if zendesk_ticket.via.source.rel == 'mention' local_ticket_fields[:create_article_type_id] = if zendesk_ticket.via.source.rel == 'mention'
local_ticket_fields[:create_article_type_id] = article_type_twitter_status.id article_type_twitter_status.id
else else
local_ticket_fields[:create_article_type_id] = article_type_twitter_dm.id article_type_twitter_dm.id
end end
elsif zendesk_ticket.via.channel == 'facebook' elsif zendesk_ticket.via.channel == 'facebook'
# TODO # TODO
if zendesk_ticket.via.source.rel == 'post' local_ticket_fields[:create_article_type_id] = if zendesk_ticket.via.source.rel == 'post'
local_ticket_fields[:create_article_type_id] = article_type_facebook_feed_post.id article_type_facebook_feed_post.id
else else
local_ticket_fields[:create_article_type_id] = article_type_facebook_feed_comment.id article_type_facebook_feed_comment.id
end end
end end
local_ticket = Ticket.create( local_ticket_fields ) local_ticket = Ticket.create( local_ticket_fields )
@ -587,13 +587,13 @@ module Import::Zendesk
article_author = User.find( @zendesk_user_mapping[ zendesk_article.author_id ] ) article_author = User.find( @zendesk_user_mapping[ zendesk_article.author_id ] )
if article_author.role?('Customer') local_article_fields[:sender_id] = if article_author.role?('Customer')
local_article_fields[:sender_id] = article_sender_customer.id article_sender_customer.id
elsif article_author.role?('Agent') elsif article_author.role?('Agent')
local_article_fields[:sender_id] = article_sender_agent.id article_sender_agent.id
else else
local_article_fields[:sender_id] = article_sender_system.id article_sender_system.id
end end
if zendesk_article.via.channel == 'web' if zendesk_article.via.channel == 'web'
local_article_fields[:message_id] = zendesk_article.id local_article_fields[:message_id] = zendesk_article.id
@ -610,11 +610,11 @@ module Import::Zendesk
local_article_fields[:message_id] = zendesk_article.id local_article_fields[:message_id] = zendesk_article.id
# TODO # TODO
if zendesk_article.via.source.rel == 'mention' local_article_fields[:type_id] = if zendesk_article.via.source.rel == 'mention'
local_article_fields[:type_id] = article_type_twitter_status.id article_type_twitter_status.id
else else
local_article_fields[:type_id] = article_type_twitter_dm.id article_type_twitter_dm.id
end end
elsif zendesk_article.via.channel == 'facebook' elsif zendesk_article.via.channel == 'facebook'
@ -623,11 +623,11 @@ module Import::Zendesk
local_article_fields[:message_id] = zendesk_article.id local_article_fields[:message_id] = zendesk_article.id
# TODO # TODO
if zendesk_article.via.source.rel == 'post' local_article_fields[:type_id] = if zendesk_article.via.source.rel == 'post'
local_article_fields[:type_id] = article_type_facebook_feed_post.id article_type_facebook_feed_post.id
else else
local_article_fields[:type_id] = article_type_facebook_feed_comment.id article_type_facebook_feed_comment.id
end end
end end
# create article # create article

View file

@ -70,11 +70,11 @@ module NotificationFactory
object_refs = object_refs.html2text.chomp object_refs = object_refs.html2text.chomp
} }
if !value placeholder = if !value
placeholder = object_refs object_refs
else else
placeholder = value value
end end
end end
end end
placeholder placeholder

View file

@ -59,14 +59,14 @@ returns
sender = Ticket::Article::Sender.lookup( name: params[:params][:sender] ) sender = Ticket::Article::Sender.lookup( name: params[:params][:sender] )
type = Ticket::Article::Type.lookup( name: params[:params][:type] ) type = Ticket::Article::Type.lookup( name: params[:params][:type] )
count = Ticket::Article.joins('INNER JOIN tickets ON tickets.id = ticket_articles.ticket_id') count = Ticket::Article.joins('INNER JOIN tickets ON tickets.id = ticket_articles.ticket_id')
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
.where( .where(
'ticket_articles.created_at >= ? AND ticket_articles.created_at <= ? AND ticket_articles.type_id = ? AND ticket_articles.sender_id = ?', 'ticket_articles.created_at >= ? AND ticket_articles.created_at <= ? AND ticket_articles.type_id = ? AND ticket_articles.sender_id = ?',
start, start,
stop, stop,
type.id, type.id,
sender.id, sender.id,
).count ).count
result.push count result.push count
start = stop start = stop
} }

View file

@ -21,10 +21,10 @@ class Report::Base
if params[:type] == 'created' if params[:type] == 'created'
history_type = History::Type.lookup( name: 'created' ) history_type = History::Type.lookup( name: 'created' )
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', params[:start], params[:end], history_object.id, history_type.id 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', params[:start], params[:end], history_object.id, history_type.id
) )
.where(query, *bind_params).joins(tables).count .where(query, *bind_params).joins(tables).count
end end
# updated # updated
@ -33,74 +33,72 @@ class Report::Base
history_attribute = History::Attribute.lookup( name: params[:attribute] ) history_attribute = History::Attribute.lookup( name: params[:attribute] )
if !history_attribute || !history_type if !history_attribute || !history_type
count = 0 count = 0
else elsif params[:id_not_from] && params[:id_to]
if params[:id_not_from] && params[:id_to] return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') .where(query, *bind_params).joins(tables)
.where(query, *bind_params).joins(tables) .where(
.where( 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)',
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)', params[:start],
params[:start], params[:end],
params[:end], history_object.id,
history_object.id, history_type.id,
history_type.id, history_attribute.id,
history_attribute.id, params[:id_not_from],
params[:id_not_from], params[:id_to],
params[:id_to], ).count
).count elsif params[:id_from] && params[:id_not_to]
elsif params[:id_from] && params[:id_not_to] return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') .where(query, *bind_params).joins(tables)
.where(query, *bind_params).joins(tables) .where(
.where( 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)',
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)', params[:start],
params[:start], params[:end],
params[:end], history_object.id,
history_object.id, history_type.id,
history_type.id, history_attribute.id,
history_attribute.id, params[:id_from],
params[:id_from], params[:id_not_to],
params[:id_not_to], ).count
).count elsif params[:value_from] && params[:value_not_to]
elsif params[:value_from] && params[:value_not_to] return History.joins('INNER JOIN tickets ON tickets.id = histories.o_id')
return History.joins('INNER JOIN tickets ON tickets.id = histories.o_id') .where(query, *bind_params).joins(tables)
.where(query, *bind_params).joins(tables) .where(
.where( 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)',
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)', params[:start],
params[:start], params[:end],
params[:end], history_object.id,
history_object.id, history_type.id,
history_type.id, history_attribute.id,
history_attribute.id, params[:value_from],
params[:value_from], params[:value_not_to],
params[:value_not_to], ).count
).count elsif params[:value_to]
elsif params[:value_to] return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') .where(query, *bind_params).joins(tables)
.where(query, *bind_params).joins(tables) .where(
.where( 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)',
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)', params[:start],
params[:start], params[:end],
params[:end], history_object.id,
history_object.id, history_type.id,
history_type.id, history_attribute.id,
history_attribute.id, params[:value_to],
params[:value_to], ).count
).count elsif params[:id_to]
elsif params[:id_to] return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') .where(query, *bind_params).joins(tables)
.where(query, *bind_params).joins(tables) .where(
.where( 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)',
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)', params[:start],
params[:start], params[:end],
params[:end], history_object.id,
history_object.id, history_type.id,
history_type.id, history_attribute.id,
history_attribute.id, params[:id_to],
params[:id_to], ).count
).count
else
fail "UNKOWN params (#{params.inspect})!"
end
end end
fail "UNKOWN params (#{params.inspect})!"
end end
fail "UNKOWN :type (#{params[:type]})!" fail "UNKOWN :type (#{params[:type]})!"
end end
@ -126,10 +124,10 @@ class Report::Base
if data[:type] == 'created' if data[:type] == 'created'
history_type = History::Type.lookup( name: 'created' ) history_type = History::Type.lookup( name: 'created' )
histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', data[:start], data[:end], history_object.id, history_type.id 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', data[:start], data[:end], history_object.id, history_type.id
) )
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
histories.each {|history| histories.each {|history|
count += 1 count += 1
ticket_ids.push history.o_id ticket_ids.push history.o_id
@ -149,67 +147,67 @@ class Report::Base
else else
if data[:id_not_from] && data[:id_to] if data[:id_not_from] && data[:id_to]
histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)', 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)',
data[:start], data[:start],
data[:end], data[:end],
history_object.id, history_object.id,
history_type.id, history_type.id,
history_attribute.id, history_attribute.id,
data[:id_not_from], data[:id_not_from],
data[:id_to], data[:id_to],
) )
elsif data[:id_from] && data[:id_not_to] elsif data[:id_from] && data[:id_not_to]
histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)', 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)',
data[:start], data[:start],
data[:end], data[:end],
history_object.id, history_object.id,
history_type.id, history_type.id,
history_attribute.id, history_attribute.id,
data[:id_from], data[:id_from],
data[:id_not_to], data[:id_not_to],
) )
elsif data[:value_from] && data[:value_not_to] elsif data[:value_from] && data[:value_not_to]
histories = History.joins('INNER JOIN tickets ON tickets.id = histories.o_id') histories = History.joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)', 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)',
data[:start], data[:start],
data[:end], data[:end],
history_object.id, history_object.id,
history_type.id, history_type.id,
history_attribute.id, history_attribute.id,
data[:value_from], data[:value_from],
data[:value_not_to], data[:value_not_to],
) )
elsif data[:value_to] elsif data[:value_to]
histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)', 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)',
data[:start], data[:start],
data[:end], data[:end],
history_object.id, history_object.id,
history_type.id, history_type.id,
history_attribute.id, history_attribute.id,
data[:value_to], data[:value_to],
) )
elsif data[:id_to] elsif data[:id_to]
histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
.where( .where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)', 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)',
data[:start], data[:start],
data[:end], data[:end],
history_object.id, history_object.id,
history_type.id, history_type.id,
history_attribute.id, history_attribute.id,
data[:id_to], data[:id_to],
) )
end end
histories.each {|history| histories.each {|history|
count += 1 count += 1
@ -231,7 +229,7 @@ class Report::Base
def self.time_average(data) def self.time_average(data)
query, bind_params, tables = Ticket.selector2sql(data[:condition]) query, bind_params, tables = Ticket.selector2sql(data[:condition])
ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] ) ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] )
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
tickets = 0 tickets = 0
time_total = 0 time_total = 0
ticket_list.each {|ticket| ticket_list.each {|ticket|
@ -262,7 +260,7 @@ class Report::Base
def self.time_min(data) def self.time_min(data)
query, bind_params, tables = Ticket.selector2sql(data[:condition]) query, bind_params, tables = Ticket.selector2sql(data[:condition])
ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] ) ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] )
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
tickets = 0 tickets = 0
time_min = 0 time_min = 0
ticket_ids = [] ticket_ids = []
@ -281,11 +279,11 @@ class Report::Base
time_min = diff time_min = diff
end end
} }
if time_min == 0 tickets = if time_min == 0
tickets = -0.001 -0.001
else else
tickets = (time_min / 60).to_i (time_min / 60).to_i
end end
{ {
count: tickets, count: tickets,
ticket_ids: ticket_ids, ticket_ids: ticket_ids,
@ -299,7 +297,7 @@ class Report::Base
def self.time_max(data) def self.time_max(data)
query, bind_params, tables = Ticket.selector2sql(data[:condition]) query, bind_params, tables = Ticket.selector2sql(data[:condition])
ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] ) ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] )
.where(query, *bind_params).joins(tables) .where(query, *bind_params).joins(tables)
tickets = 0 tickets = 0
time_max = 0 time_max = 0
ticket_ids = [] ticket_ids = []
@ -319,11 +317,11 @@ class Report::Base
time_max = diff time_max = diff
end end
} }
if time_max == 0 tickets = if time_max == 0
tickets = -0.001 -0.001
else else
tickets = (time_max / 60).to_i (time_max / 60).to_i
end end
{ {
count: tickets, count: tickets,
ticket_ids: ticket_ids, ticket_ids: ticket_ids,

View file

@ -155,27 +155,27 @@ return search result
url = build_url() url = build_url()
return if !url return if !url
if index url += if index
if index.class == Array if index.class == Array
url += "/#{index.join(',')}/_search" "/#{index.join(',')}/_search"
else else
url += "/#{index}/_search" "/#{index}/_search"
end end
else else
url += '/_search' '/_search'
end end
data = {} data = {}
data['from'] = 0 data['from'] = 0
data['size'] = limit data['size'] = limit
data['sort'] = data['sort'] =
[ [
{ {
updated_at: { updated_at: {
order: 'desc' order: 'desc'
} }
}, },
'_score' '_score'
] ]
data['query'] = query_extention || {} data['query'] = query_extention || {}
if !data['query']['bool'] if !data['query']['bool']
@ -274,15 +274,15 @@ get count of tickets and tickets which match on selector
url = build_url() url = build_url()
return if !url return if !url
if index url += if index
if index.class == Array if index.class == Array
url += "/#{index.join(',')}/_search" "/#{index.join(',')}/_search"
else else
url += "/#{index}/_search" "/#{index}/_search"
end end
else else
url += '/_search' '/_search'
end end
data = selector2query(selectors, current_user, aggs_interval, limit) data = selector2query(selectors, current_user, aggs_interval, limit)
@ -444,15 +444,15 @@ return true if backend is configured
return if !SearchIndexBackend.enabled? return if !SearchIndexBackend.enabled?
index = Setting.get('es_index').to_s + "_#{Rails.env}" index = Setting.get('es_index').to_s + "_#{Rails.env}"
url = Setting.get('es_url') url = Setting.get('es_url')
if type url = if type
if o_id if o_id
url = "#{url}/#{index}/#{type}/#{o_id}" "#{url}/#{index}/#{type}/#{o_id}"
else else
url = "#{url}/#{index}/#{type}" "#{url}/#{index}/#{type}"
end end
else else
url = "#{url}/#{index}" "#{url}/#{index}"
end end
url url
end end

View file

@ -12,11 +12,11 @@ class Service::GeoCalendar::Zammad
# do lookup # do lookup
host = 'https://geo.zammad.com' host = 'https://geo.zammad.com'
if address url = if address
url = "/calendar?ip=#{CGI.escape address}" "/calendar?ip=#{CGI.escape address}"
else else
url = '/calendar' '/calendar'
end end
data = {} data = {}
begin begin
response = UserAgent.get( response = UserAgent.get(

View file

@ -401,7 +401,7 @@ returns
} }
files.sort.each {|entry| files.sort.each {|entry|
filename = "#{path}/#{entry}" filename = "#{path}/#{entry}"
if /^send/.match(entry) if /^send/ =~ entry
data.push Sessions.queue_file_read(path, entry) data.push Sessions.queue_file_read(path, entry)
end end
} }

View file

@ -7,10 +7,8 @@ class Sessions::Backend::Collections::Organization < Sessions::Backend::Collecti
all = [] all = []
if !@user.role?('Customer') if !@user.role?('Customer')
all = Organization.all all = Organization.all
else elsif @user.organization_id
if @user.organization_id all = Organization.where( id: @user.organization_id )
all = Organization.where( id: @user.organization_id )
end
end end
all all

View file

@ -11,11 +11,11 @@ class Sessions::Event::Base
end end
def websocket_send(recipient_client_id, data) def websocket_send(recipient_client_id, data)
if data.class != Array msg = if data.class != Array
msg = "[#{data.to_json}]" "[#{data.to_json}]"
else else
msg = data.to_json data.to_json
end end
if @clients[recipient_client_id] if @clients[recipient_client_id]
log 'debug', "ws send #{msg}", recipient_client_id log 'debug', "ws send #{msg}", recipient_client_id
@clients[recipient_client_id][:websocket].send(msg) @clients[recipient_client_id][:websocket].send(msg)

View file

@ -14,22 +14,18 @@ class Sessions::Event::Broadcast < Sessions::Event::Base
if @payload['recipient'] if @payload['recipient']
if @payload['recipient'].class != Hash if @payload['recipient'].class != Hash
log 'error', "recipient attribute isn't a hash '#{@payload['recipient'].inspect}'" log 'error', "recipient attribute isn't a hash '#{@payload['recipient'].inspect}'"
elsif !@payload['recipient'].key?('user_id')
log 'error', "need recipient.user_id attribute '#{@payload['recipient'].inspect}'"
elsif @payload['recipient']['user_id'].class != Array
log 'error', "recipient.user_id attribute isn't an array '#{@payload['recipient']['user_id'].inspect}'"
else else
if !@payload['recipient'].key?('user_id') @payload['recipient']['user_id'].each { |user_id|
log 'error', "need recipient.user_id attribute '#{@payload['recipient'].inspect}'"
else
if @payload['recipient']['user_id'].class != Array
log 'error', "recipient.user_id attribute isn't an array '#{@payload['recipient']['user_id'].inspect}'"
else
@payload['recipient']['user_id'].each { |user_id|
next if local_client[:user]['id'].to_i != user_id.to_i next if local_client[:user]['id'].to_i != user_id.to_i
log 'notice', "send broadcast from (#{@client_id}) to (user_id=#{user_id})", local_client_id log 'notice', "send broadcast from (#{@client_id}) to (user_id=#{user_id})", local_client_id
websocket_send(local_client_id, @payload['data']) websocket_send(local_client_id, @payload['data'])
} }
end
end
end end
# broadcast every client # broadcast every client

View file

@ -13,11 +13,11 @@ class Sessions::Event::Login < Sessions::Event::Base
end end
end end
if session && session.data && session.data['user_id'] new_session_data = if session && session.data && session.data['user_id']
new_session_data = { 'id' => session.data['user_id'] } { 'id' => session.data['user_id'] }
else else
new_session_data = {} {}
end end
if @clients[@client_id] if @clients[@client_id]
@clients[@client_id][:session] = new_session_data @clients[@client_id][:session] = new_session_data

View file

@ -21,11 +21,10 @@ class Sessions::Event::Spool < Sessions::Event::Base
# create new msg to push to client # create new msg to push to client
if item[:type] == 'direct' if item[:type] == 'direct'
log 'notice', "send spool to (user_id=#{@session['id']})" log 'notice', "send spool to (user_id=#{@session['id']})"
websocket_send(@client_id, item[:message])
else else
log 'notice', 'send spool' log 'notice', 'send spool'
websocket_send(@client_id, item[:message])
end end
websocket_send(@client_id, item[:message])
} }
# send spool:sent event to client # send spool:sent event to client

View file

@ -67,19 +67,19 @@ class Stats::TicketChannelDistribution
channels.each {|channel| channels.each {|channel|
count = result[channel[:sender].to_sym][:inbound] count = result[channel[:sender].to_sym][:inbound]
#puts "#{channel.inspect}:in/#{result.inspect}:#{count}" #puts "#{channel.inspect}:in/#{result.inspect}:#{count}"
if count == 0 in_process_precent = if count == 0
in_process_precent = 0 0
else else
in_process_precent = (count * 1000) / ((total_in * 1000) / 100) (count * 1000) / ((total_in * 1000) / 100)
end end
result[channel[:sender].to_sym][:inbound_in_percent] = in_process_precent result[channel[:sender].to_sym][:inbound_in_percent] = in_process_precent
count = result[channel[:sender].to_sym][:outbound] count = result[channel[:sender].to_sym][:outbound]
if count == 0 out_process_precent = if count == 0
out_process_precent = 0 0
else else
out_process_precent = (count * 1000) / ((total_out * 1000) / 100) (count * 1000) / ((total_out * 1000) / 100)
end end
result[channel[:sender].to_sym][:outbound_in_percent] = out_process_precent result[channel[:sender].to_sym][:outbound_in_percent] = out_process_precent
} }

View file

@ -21,15 +21,15 @@ class Stats::TicketEscalation
average = '-' average = '-'
state = 'supergood' state = 'supergood'
if own_escalated == 0 state = if own_escalated == 0
state = 'supergood' 'supergood'
elsif own_escalated <= 1 elsif own_escalated <= 1
state = 'good' 'good'
elsif own_escalated <= 4 elsif own_escalated <= 4
state = 'ok' 'ok'
else else
state = 'bad' 'bad'
end end
{ {
used_for_average: own_escalated, used_for_average: own_escalated,

View file

@ -63,17 +63,17 @@ class Stats::TicketInProcess
end end
in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1) in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1)
if in_percent >= 90 result[:state] = if in_percent >= 90
result[:state] = 'supergood' 'supergood'
elsif in_percent >= 65 elsif in_percent >= 65
result[:state] = 'good' 'good'
elsif in_percent >= 40 elsif in_percent >= 40
result[:state] = 'ok' 'ok'
elsif in_percent >= 20 elsif in_percent >= 20
result[:state] = 'bad' 'bad'
else else
result[:state] = 'superbad' 'superbad'
end end
result result
end end

View file

@ -44,17 +44,17 @@ class Stats::TicketLoadMeasure
in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1) in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1)
result[:average_per_agent_in_percent] = in_percent result[:average_per_agent_in_percent] = in_percent
if in_percent >= 90 result[:state] = if in_percent >= 90
result[:state] = 'supergood' 'supergood'
elsif in_percent >= 65 elsif in_percent >= 65
result[:state] = 'good' 'good'
elsif in_percent >= 40 elsif in_percent >= 40
result[:state] = 'ok' 'ok'
elsif in_percent >= 20 elsif in_percent >= 20
result[:state] = 'bad' 'bad'
else else
result[:state] = 'superbad' 'superbad'
end end
# convert result[:used_for_average] in percent to related total # convert result[:used_for_average] in percent to related total
result[:average_per_agent] = ( (result[:total].to_f / 100) * result[:average_per_agent] ).round(1) result[:average_per_agent] = ( (result[:total].to_f / 100) * result[:average_per_agent] ).round(1)

View file

@ -49,17 +49,17 @@ class Stats::TicketReopen
#in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1) #in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1)
#result[:average_per_agent_in_percent] = in_percent #result[:average_per_agent_in_percent] = in_percent
in_percent = ( result[:count].to_f / (result[:total].to_f / 100) ).round(1) in_percent = ( result[:count].to_f / (result[:total].to_f / 100) ).round(1)
if in_percent >= 90 result[:state] = if in_percent >= 90
result[:state] = 'superbad' 'superbad'
elsif in_percent >= 65 elsif in_percent >= 65
result[:state] = 'bad' 'bad'
elsif in_percent >= 40 elsif in_percent >= 40
result[:state] = 'ok' 'ok'
elsif in_percent >= 20 elsif in_percent >= 20
result[:state] = 'good' 'good'
else else
result[:state] = 'supergood' 'supergood'
end end
result result
end end

View file

@ -56,17 +56,17 @@ class Stats::TicketResponseTime
end end
in_percent = ( result[:used_for_average].to_f / (result[:total].to_f / 100) ).round(1) in_percent = ( result[:used_for_average].to_f / (result[:total].to_f / 100) ).round(1)
if in_percent >= 90 result[:state] = if in_percent >= 90
result[:state] = 'supergood' 'supergood'
elsif in_percent >= 65 elsif in_percent >= 65
result[:state] = 'good' 'good'
elsif in_percent >= 40 elsif in_percent >= 40
result[:state] = 'ok' 'ok'
elsif in_percent >= 20 elsif in_percent >= 20
result[:state] = 'bad' 'bad'
else else
result[:state] = 'superbad' 'superbad'
end end
result result
end end

View file

@ -4,8 +4,8 @@ class Twitter::Streaming::ConnectionCustom < Twitter::Streaming::Connection
def stream(request, response) def stream(request, response)
client_context = OpenSSL::SSL::SSLContext.new client_context = OpenSSL::SSL::SSLContext.new
@client = @tcp_socket_class.new(Resolv.getaddress(request.uri.host), request.uri.port) @client = @tcp_socket_class.new(Resolv.getaddress(request.uri.host), request.uri.port)
ssl_client = @ssl_socket_class.new(@client, client_context) ssl_client = @ssl_socket_class.new(@client, client_context)
ssl_client.connect ssl_client.connect
request.stream(ssl_client) request.stream(ssl_client)

View file

@ -274,10 +274,8 @@ returns
if !params.empty? if !params.empty?
request.body = params.to_json request.body = params.to_json
end end
else elsif !params.empty?
if !params.empty? request.set_form_data(params)
request.set_form_data(params)
end
end end
request request
end end

View file

@ -238,11 +238,11 @@ EventMachine.run {
end end
def websocket_send(client_id, data) def websocket_send(client_id, data)
if data.class != Array msg = if data.class != Array
msg = "[#{data.to_json}]" "[#{data.to_json}]"
else else
msg = data.to_json data.to_json
end end
log 'debug', "send #{msg}", client_id log 'debug', "send #{msg}", client_id
if !@clients[client_id] if !@clients[client_id]
log 'error', "no such @clients for #{client_id}", client_id log 'error', "no such @clients for #{client_id}", client_id

View file

@ -107,11 +107,11 @@ class TranslationTest < TestCase
) )
@browser.action.key_down(:control) @browser.action.key_down(:control)
.key_down(:alt) .key_down(:alt)
.send_keys('t') .send_keys('t')
.key_up(:alt) .key_up(:alt)
.key_up(:control) .key_up(:control)
.perform .perform
watch_for( watch_for(
css: 'span.translation[title="Overviews"]', css: 'span.translation[title="Overviews"]',
@ -126,11 +126,11 @@ class TranslationTest < TestCase
sleep 5 sleep 5
@browser.action.key_down(:control) @browser.action.key_down(:control)
.key_down(:alt) .key_down(:alt)
.send_keys('t') .send_keys('t')
.key_up(:alt) .key_up(:alt)
.key_up(:control) .key_up(:control)
.perform .perform
sleep 5 sleep 5
exists_not( exists_not(
@ -192,11 +192,11 @@ class TranslationTest < TestCase
sleep 5 sleep 5
@browser.action.key_down(:control) @browser.action.key_down(:control)
.key_down(:alt) .key_down(:alt)
.send_keys('t') .send_keys('t')
.key_up(:alt) .key_up(:alt)
.key_up(:control) .key_up(:control)
.perform .perform
watch_for( watch_for(
css: 'span.translation[title="Overviews"]', css: 'span.translation[title="Overviews"]',
@ -211,11 +211,11 @@ class TranslationTest < TestCase
sleep 5 sleep 5
@browser.action.key_down(:control) @browser.action.key_down(:control)
.key_down(:alt) .key_down(:alt)
.send_keys('t') .send_keys('t')
.key_up(:alt) .key_up(:alt)
.key_up(:control) .key_up(:control)
.perform .perform
sleep 5 sleep 5
exists_not( exists_not(

View file

@ -512,10 +512,8 @@ class TestCase < Test::Unit::TestCase
if params[:type] == 'on' if params[:type] == 'on'
instance.find_elements({ css: "#{params[:css]} label" })[0].click instance.find_elements({ css: "#{params[:css]} label" })[0].click
end end
else elsif params[:type] == 'off'
if params[:type] == 'off' instance.find_elements({ css: "#{params[:css]} label" })[0].click
instance.find_elements({ css: "#{params[:css]} label" })[0].click
end
end end
end end
@ -622,32 +620,30 @@ class TestCase < Test::Unit::TestCase
if success if success
fail "should not match '#{params[:value]}' in select list, but is matching" fail "should not match '#{params[:value]}' in select list, but is matching"
end end
return true elsif !success
else fail "not matching '#{params[:value]}' in select list"
if !success
fail "not matching '#{params[:value]}' in select list"
end
return true
end end
return true
end end
# match on attribute # match on attribute
begin begin
if params[:attribute] text = if params[:attribute]
text = element.attribute(params[:attribute]) element.attribute(params[:attribute])
elsif params[:css] =~ /(input|textarea)/i elsif params[:css] =~ /(input|textarea)/i
text = element.attribute('value') element.attribute('value')
else else
text = element.text element.text
end end
rescue => e rescue => e
# just try again # just try again
if !fallback if !fallback
return match(params, true) return match(params, true)
else
raise e.inspect
end end
raise e.inspect
end end
# do cleanups (needed for richtext tests) # do cleanups (needed for richtext tests)
@ -662,19 +658,16 @@ class TestCase < Test::Unit::TestCase
if text =~ /#{params[:value]}/i if text =~ /#{params[:value]}/i
match = $1 || true match = $1 || true
end end
else elsif text =~ /#{Regexp.quote(params[:value])}/i
if text =~ /#{Regexp.quote(params[:value])}/i match = true
match = true
end
end end
if match if match
if params[:should_not_match] if params[:should_not_match]
fail "matching '#{params[:value]}' in content '#{text}' but should not!" fail "matching '#{params[:value]}' in content '#{text}' but should not!"
end end
else elsif !params[:should_not_match]
if !params[:should_not_match] fail "not matching '#{params[:value]}' in content '#{text}' but should!"
fail "not matching '#{params[:value]}' in content '#{text}' but should!"
end
end end
sleep 0.8 sleep 0.8
match match
@ -855,14 +848,12 @@ class TestCase < Test::Unit::TestCase
else else
fail "task '#{data[:title]}' is not modifed" fail "task '#{data[:title]}' is not modifed"
end end
elsif !is_modified
assert(true, "task '#{data[:title]}' is modifed")
elsif !exists
fail "task '#{data[:title]}' not exists, should be not modified"
else else
if !is_modified fail "task '#{data[:title]}' is modifed, but should not"
assert(true, "task '#{data[:title]}' is modifed")
elsif !exists
fail "task '#{data[:title]}' not exists, should be not modified"
else
fail "task '#{data[:title]}' is modifed, but should not"
end
end end
end end
rescue => e rescue => e
@ -870,9 +861,8 @@ class TestCase < Test::Unit::TestCase
# just try again # just try again
if !fallback if !fallback
verify_task(params, true) verify_task(params, true)
else
raise 'ERROR: ' + e.inspect
end end
raise 'ERROR: ' + e.inspect
end end
true true
end end
@ -948,7 +938,7 @@ class TestCase < Test::Unit::TestCase
if params[:timeout] if params[:timeout]
timeout = params[:timeout] timeout = params[:timeout]
end end
loops = (timeout).to_i * 2 loops = timeout.to_i * 2
text = '' text = ''
(1..loops).each { (1..loops).each {
element = instance.find_elements({ css: params[:css] })[0] element = instance.find_elements({ css: params[:css] })[0]
@ -956,13 +946,13 @@ class TestCase < Test::Unit::TestCase
begin begin
# match pn attribute # match pn attribute
if params[:attribute] text = if params[:attribute]
text = element.attribute(params[:attribute]) element.attribute(params[:attribute])
elsif params[:css] =~ /(input|textarea)/i elsif params[:css] =~ /(input|textarea)/i
text = element.attribute('value') element.attribute('value')
else else
text = element.text element.text
end end
if text =~ /#{params[:value]}/i if text =~ /#{params[:value]}/i
assert(true, "'#{params[:value]}' found in '#{text}'") assert(true, "'#{params[:value]}' found in '#{text}'")
sleep 0.5 sleep 0.5
@ -1009,7 +999,7 @@ wait untill text in selector disabppears
if params[:timeout] if params[:timeout]
timeout = params[:timeout] timeout = params[:timeout]
end end
loops = (timeout).to_i loops = timeout.to_i
text = '' text = ''
(1..loops).each { (1..loops).each {
element = instance.find_elements({ css: params[:css] })[0] element = instance.find_elements({ css: params[:css] })[0]

View file

@ -46,7 +46,7 @@ class ElasticsearchTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1 created_by_id: 1
) )
roles = Role.where( name: 'Customer' ) roles = Role.where( name: 'Customer' )
organization1 = Organization.create_if_not_exists( organization1 = Organization.create_if_not_exists(
name: 'Customer Organization Update', name: 'Customer Organization Update',
updated_by_id: 1, updated_by_id: 1,

View file

@ -215,12 +215,12 @@ class TwitterBrowserTest < TestCase
watch_for( watch_for(
css: '.content.active', css: '.content.active',
value: "#{hash}", value: hash.to_s,
timeout: 20, timeout: 20,
) )
ticket_open_by_title( ticket_open_by_title(
title: "#{hash}", title: hash.to_s,
) )
# reply via app # reply via app

View file

@ -301,7 +301,7 @@ class TwitterTest < ActiveSupport::TestCase
ticket.state = Ticket::State.find_by(name: 'pending reminder') ticket.state = Ticket::State.find_by(name: 'pending reminder')
ticket.save ticket.save
text = 'Ok. ' + hash text = 'Ok. ' + hash
dm = client.create_direct_message( dm = client.create_direct_message(
'armin_theo', 'armin_theo',
text, text,

View file

@ -109,20 +109,20 @@ class AaaStringTest < ActiveSupport::TestCase
result = 'Was soll verbessert werden:' result = 'Was soll verbessert werden:'
assert_equal(result, html.html2text) assert_equal(result, html.html2text)
html = "<!-- some comment --> html = "<!-- some comment -->
<div> <div>
test<br><br><br>\n<br>\n<br>\n test<br><br><br>\n<br>\n<br>\n
</div>" </div>"
result = 'test' result = 'test'
assert_equal(result, html.html2text) assert_equal(result, html.html2text)
html = "\n<div><a href=\"http://zammad.org\">Best Tool of the World</a> html = "\n<div><a href=\"http://zammad.org\">Best Tool of the World</a>
some other text</div> some other text</div>
<div>" <div>"
result = "[1] Best Tool of the Worldsome other text\n\n\n[1] http://zammad.org" result = "[1] Best Tool of the Worldsome other text\n\n\n[1] http://zammad.org"
assert_equal(result, html.html2text) assert_equal(result, html.html2text)
html = "<!-- some comment --> html = "<!-- some comment -->
<div> <div>
test<br><br><br>\n<hr/>\n<br>\n test<br><br><br>\n<hr/>\n<br>\n
</div>" </div>"
@ -259,7 +259,7 @@ div.wordsection1
should = 'IT-Infrastruktur' should = 'IT-Infrastruktur'
assert_equal( should, html.html2text) assert_equal( should, html.html2text)
html = "<h1>some head</h1> html = "<h1>some head</h1>
some content some content
<blockquote> <blockquote>
<p>line 1</p> <p>line 1</p>
@ -274,7 +274,7 @@ some content
some text later' some text later'
assert_equal(result, html.html2text) assert_equal(result, html.html2text)
html = "<h1>some head</h1> html = "<h1>some head</h1>
some content some content
<blockquote> <blockquote>
line 1<br/> line 1<br/>
@ -289,7 +289,7 @@ some content
some text later' some text later'
assert_equal(result, html.html2text) assert_equal(result, html.html2text)
html = "<h1>some head</h1> html = "<h1>some head</h1>
some content some content
<blockquote> <blockquote>
<div><div>line 1</div><br></div> <div><div>line 1</div><br></div>

View file

@ -383,10 +383,8 @@ class ActivityStreamTest < ActiveSupport::TestCase
assert_equal( check_item[:object], item['object'] ) assert_equal( check_item[:object], item['object'] )
assert_equal( check_item[:type], item['type'] ) assert_equal( check_item[:type], item['type'] )
assert_equal( check_item[:o_id], item['o_id'] ) assert_equal( check_item[:o_id], item['o_id'] )
else elsif check_item[:object] == item['object'] && check_item[:type] == item['type'] && check_item[:o_id] == item['o_id']
if check_item[:object] == item['object'] && check_item[:type] == item['type'] && check_item[:o_id] == item['o_id'] assert( false, "entry should not exist #{item['object']}/#{item['type']}/#{item['o_id']}" )
assert( false, "entry should not exist #{item['object']}/#{item['type']}/#{item['o_id']}" )
end
end end
} }
} }

View file

@ -41,7 +41,7 @@ class EmailBuildTest < ActiveSupport::TestCase
content_type: 'text/html', content_type: 'text/html',
attachments: [ attachments: [
{ {
'Mime-Type' => 'image/png', 'Mime-Type' => 'image/png',
:content => 'xxx', :content => 'xxx',
:filename => 'somename.png', :filename => 'somename.png',
}, },
@ -95,7 +95,7 @@ class EmailBuildTest < ActiveSupport::TestCase
body: text, body: text,
attachments: [ attachments: [
{ {
'Mime-Type' => 'image/png', 'Mime-Type' => 'image/png',
:content => 'xxx', :content => 'xxx',
:filename => 'somename.png', :filename => 'somename.png',
}, },

View file

@ -98,7 +98,7 @@ class ObjectCacheTest < ActiveSupport::TestCase
assert_equal( name, group_new[:name], 'verify by where' ) assert_equal( name, group_new[:name], 'verify by where' )
# lookup by name # lookup by name
cache_key = "#{group_new.name}" cache_key = group_new.name.to_s
assert_nil( Group.cache_get(cache_key) ) assert_nil( Group.cache_get(cache_key) )
group_lookup_name = Group.lookup( name: group_new.name ) group_lookup_name = Group.lookup( name: group_new.name )
@ -106,7 +106,7 @@ class ObjectCacheTest < ActiveSupport::TestCase
assert( Group.cache_get(cache_key) ) assert( Group.cache_get(cache_key) )
# lookup by id # lookup by id
cache_key = "#{group_new.id}" cache_key = group_new.id.to_s
assert_nil( Group.cache_get(cache_key) ) assert_nil( Group.cache_get(cache_key) )
group_lookup_id = Group.lookup( id: group.id ) group_lookup_id = Group.lookup( id: group.id )
@ -119,7 +119,7 @@ class ObjectCacheTest < ActiveSupport::TestCase
group.save group.save
# lookup by name # lookup by name
cache_key = "#{group.name}" cache_key = group.name.to_s
assert_nil( Group.cache_get(cache_key) ) assert_nil( Group.cache_get(cache_key) )
group_lookup = Group.where( name: group_new.name ).first group_lookup = Group.where( name: group_new.name ).first
@ -139,7 +139,7 @@ class ObjectCacheTest < ActiveSupport::TestCase
assert( Group.cache_get(cache_key) ) assert( Group.cache_get(cache_key) )
# lookup by id # lookup by id
cache_key = "#{group_new.id}" cache_key = group_new.id.to_s
assert_nil( Group.cache_get(cache_key) ) assert_nil( Group.cache_get(cache_key) )
group_lookup_id = Group.lookup( id: group.id ) group_lookup_id = Group.lookup( id: group.id )

View file

@ -19,7 +19,7 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
roles = Role.where( name: 'Customer' ) roles = Role.where( name: 'Customer' )
organization1 = Organization.create_if_not_exists( organization1 = Organization.create_if_not_exists(
name: 'Ref Object Update Org 1', name: 'Ref Object Update Org 1',
updated_at: '2015-02-05 16:37:00', updated_at: '2015-02-05 16:37:00',

View file

@ -25,7 +25,7 @@ class RecentViewTest < ActiveSupport::TestCase
created_by_id: 1, created_by_id: 1,
) )
assert( ticket2, 'ticket created' ) assert( ticket2, 'ticket created' )
user1 = User.find(2) user1 = User.find(2)
RecentView.user_log_destroy(user1) RecentView.user_log_destroy(user1)
RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) RecentView.log( ticket1.class.to_s, ticket1.id, user1 )

View file

@ -180,7 +180,7 @@ class SessionBasicTest < ActiveSupport::TestCase
end end
user = User.lookup(id: 1) user = User.lookup(id: 1)
roles = Role.where( name: %w(Agent Admin) ) roles = Role.where( name: %w(Agent Admin) )
user.roles = roles user.roles = roles
user.save user.save

View file

@ -40,7 +40,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase
agent2.roles = roles agent2.roles = roles
agent2.save agent2.save
roles = Role.where( name: [ 'Customer'] ) roles = Role.where( name: [ 'Customer'] )
customer1 = User.create_or_update( customer1 = User.create_or_update(
login: 'session-collections-customer-1', login: 'session-collections-customer-1',
firstname: 'Session', firstname: 'Session',

View file

@ -116,11 +116,11 @@ class TagTest < ActiveSupport::TestCase
# delete tags # delete tags
tests.each { |test| tests.each { |test|
tags = nil tags = nil
if test[:tag_add] tags = if test[:tag_add]
tags = test[:tag_add] test[:tag_add]
else else
tags = test[:tag_remove] test[:tag_remove]
end end
success = Tag.tag_remove( tags ) success = Tag.tag_remove( tags )
assert( success, 'Tag.tag_remove successful') assert( success, 'Tag.tag_remove successful')
list = Tag.tag_list( tags ) list = Tag.tag_list( tags )

View file

@ -19,7 +19,7 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
roles = Role.where( name: 'Customer' ) roles = Role.where( name: 'Customer' )
organization1 = Organization.create_if_not_exists( organization1 = Organization.create_if_not_exists(
name: 'Customer Organization Update', name: 'Customer Organization Update',
updated_at: '2015-02-05 16:37:00', updated_at: '2015-02-05 16:37:00',

View file

@ -19,7 +19,7 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
roles = Role.where( name: 'Customer' ) roles = Role.where( name: 'Customer' )
organization1 = Organization.create_if_not_exists( organization1 = Organization.create_if_not_exists(
name: 'Ref Object Update Org', name: 'Ref Object Update Org',
updated_at: '2015-02-05 16:37:00', updated_at: '2015-02-05 16:37:00',

View file

@ -37,7 +37,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
roles = Role.where( name: 'Customer' ) roles = Role.where( name: 'Customer' )
organization1 = Organization.create_if_not_exists( organization1 = Organization.create_if_not_exists(
name: 'Selector Org', name: 'Selector Org',
updated_at: '2015-02-05 16:37:00', updated_at: '2015-02-05 16:37:00',

View file

@ -19,7 +19,7 @@ class UserRefObjectTouchTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
roles = Role.where( name: 'Customer' ) roles = Role.where( name: 'Customer' )
organization1 = Organization.create_if_not_exists( organization1 = Organization.create_if_not_exists(
name: 'Ref Object Update Org', name: 'Ref Object Update Org',
updated_at: '2015-02-05 16:37:00', updated_at: '2015-02-05 16:37:00',