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,10 +20,10 @@ 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

View file

@ -18,10 +18,8 @@ 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
request.env['rack.session.options'][:expire_after] = nil
end 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

View file

@ -93,10 +93,10 @@ 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 = {

View file

@ -15,10 +15,10 @@ 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|
@ -337,10 +337,10 @@ 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

View file

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

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,10 +344,10 @@ 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
} }

View file

@ -40,10 +40,10 @@ 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

View file

@ -191,10 +191,9 @@ 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] = mail.body.decoded
data[:body] = Encode.conv(mail.charset, data[:body]) data[:body] = Encode.conv(mail.charset, data[:body])
@ -205,7 +204,7 @@ class Channel::EmailParser
# html part only, convert ot text and add it as attachment # html part only, convert ot text and add it as attachment
else else
filename = '-no name-' filename = '-no name-'
if mail.mime_type.to_s.downcase == 'text/html' if mail.mime_type.to_s.casecmp('text/html')
filename = 'message.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])
@ -237,12 +236,11 @@ class Channel::EmailParser
} }
data[:attachments].push attachment data[:attachments].push attachment
end 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

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

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

@ -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,10 +214,10 @@ 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

View file

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

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

View file

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

View file

@ -16,10 +16,10 @@ 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

@ -46,11 +46,11 @@ 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

@ -108,10 +108,10 @@ returns
.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
@ -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

@ -171,11 +171,9 @@ 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
if sla.solution_time && close_time_in_min if sla.solution_time && close_time_in_min
@ -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,10 +277,10 @@ 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

View file

@ -20,10 +20,10 @@ 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

View file

@ -20,10 +20,10 @@ 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

View file

@ -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 = []

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.id,
item.source, item.source,
item.target, item.target,
item.target_initial, item.target_initial,
item.format, 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,12 +69,12 @@ 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

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

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

@ -31,7 +31,7 @@ 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')
@ -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

View file

@ -280,15 +280,15 @@ 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',

View file

@ -56,10 +56,10 @@ 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'

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

@ -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,10 +609,10 @@ 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
@ -620,10 +620,10 @@ module Import::OTRS
# 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
@ -1345,18 +1345,18 @@ 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

View file

@ -192,10 +192,10 @@ 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 ||= {}
@ -512,12 +512,12 @@ 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 ?
@ -530,19 +530,19 @@ 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
@ -587,12 +587,12 @@ 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'
@ -610,10 +610,10 @@ 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,10 +623,10 @@ 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

View file

@ -70,10 +70,10 @@ 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

View file

@ -33,8 +33,7 @@ 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(
@ -97,11 +96,10 @@ class Report::Base
history_attribute.id, history_attribute.id,
params[:id_to], params[:id_to],
).count ).count
else end
fail "UNKOWN params (#{params.inspect})!" fail "UNKOWN params (#{params.inspect})!"
end end
end
end
fail "UNKOWN :type (#{params[:type]})!" fail "UNKOWN :type (#{params[:type]})!"
end end
@ -281,10 +279,10 @@ 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,
@ -319,10 +317,10 @@ 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,

View file

@ -155,14 +155,14 @@ 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
@ -274,14 +274,14 @@ 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,14 +444,14 @@ 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,10 +12,10 @@ 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

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,11 +7,9 @@ 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
end end

View file

@ -11,10 +11,10 @@ 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

View file

@ -14,11 +14,9 @@ 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}'"
else elsif !@payload['recipient'].key?('user_id')
if !@payload['recipient'].key?('user_id')
log 'error', "need recipient.user_id attribute '#{@payload['recipient'].inspect}'" log 'error', "need recipient.user_id attribute '#{@payload['recipient'].inspect}'"
else elsif @payload['recipient']['user_id'].class != Array
if @payload['recipient']['user_id'].class != Array
log 'error', "recipient.user_id attribute isn't an array '#{@payload['recipient']['user_id'].inspect}'" log 'error', "recipient.user_id attribute isn't an array '#{@payload['recipient']['user_id'].inspect}'"
else else
@payload['recipient']['user_id'].each { |user_id| @payload['recipient']['user_id'].each { |user_id|
@ -29,8 +27,6 @@ class Sessions::Event::Broadcast < Sessions::Event::Base
websocket_send(local_client_id, @payload['data']) websocket_send(local_client_id, @payload['data'])
} }
end end
end
end
# broadcast every client # broadcast every client
else else

View file

@ -13,10 +13,10 @@ 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]

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,18 +67,18 @@ 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,14 +21,14 @@ 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
{ {

View file

@ -63,16 +63,16 @@ 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

View file

@ -44,16 +44,16 @@ 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

View file

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

View file

@ -274,11 +274,9 @@ 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,10 +238,10 @@ 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]

View file

@ -512,12 +512,10 @@ 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
=begin =begin
@ -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
if !success
fail "not matching '#{params[:value]}' in select list" fail "not matching '#{params[:value]}' in select list"
end end
return true return true
end 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,20 +658,17 @@ 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
end end
@ -855,8 +848,7 @@ class TestCase < Test::Unit::TestCase
else else
fail "task '#{data[:title]}' is not modifed" fail "task '#{data[:title]}' is not modifed"
end end
else elsif !is_modified
if !is_modified
assert(true, "task '#{data[:title]}' is modifed") assert(true, "task '#{data[:title]}' is modifed")
elsif !exists elsif !exists
fail "task '#{data[:title]}' not exists, should be not modified" fail "task '#{data[:title]}' not exists, should be not modified"
@ -864,15 +856,13 @@ class TestCase < Test::Unit::TestCase
fail "task '#{data[:title]}' is modifed, but should not" fail "task '#{data[:title]}' is modifed, but should not"
end end
end end
end
rescue => e rescue => e
# 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,12 +946,12 @@ 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}'")
@ -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

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

@ -383,11 +383,9 @@ 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
} }
} }
end end

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

@ -116,10 +116,10 @@ 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')