Updated dependencies and applied new rubocop rules.

This commit is contained in:
Thorsten Eckel 2016-01-15 18:22:57 +01:00
parent 29b41125d2
commit d7995bc6d3
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
AllCops:
RunRailsCops: true
Exclude:
- 'bin/rails'
- 'bin/rake'
- 'bin/spring'
- 'db/schema.rb'
Rails:
Enabled: true
# Zammad StyleGuide
Metrics/LineLength:
@ -30,8 +32,13 @@ Style/IfUnlessModifier:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
Enabled: false
Style/TrailingComma:
Description: 'Checks for trailing comma in parameter lists and literals.'
Style/TrailingCommaInLiteral:
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'
Enabled: false
@ -47,12 +54,6 @@ Style/SpaceAfterMethodName:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces'
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:
Description: 'Comments should start with a space.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space'

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -191,58 +191,56 @@ class Channel::EmailParser
end
# not multipart email
else
# text part only
if !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.downcase == 'text/plain'
# text part only
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] = 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: '?')
end
# html part only, convert ot text and add it as attachment
# any other attachments
else
filename = '-no name-'
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
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
# strip not wanted chars
data[:body].gsub!(/\n\r/, "\n")
data[:body].gsub!(/\r\n/, "\n")
data[:body].gsub!(/\r/, "\n")
data[:body].tr!("\r", "\n")
# remember original mail instance
data[:mail_instance] = mail

View file

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

View file

@ -153,8 +153,8 @@ returns
if !related_history_object
history_object = object_lookup( requested_object )
history = History.where( history_object_id: history_object.id )
.where( o_id: requested_object_id )
.order('created_at ASC, id ASC')
.where( o_id: requested_object_id )
.order('created_at ASC, id ASC')
else
history_object_requested = object_lookup( requested_object )
history_object_related = object_lookup( related_history_object )
@ -165,7 +165,7 @@ returns
history_object_related.id,
requested_object_id,
)
.order('created_at ASC, id ASC') # rubocop:disable Style/MultilineOperationIndentation
.order('created_at ASC, id ASC')
end
asset_list = {}
list = []

View file

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

View file

@ -71,7 +71,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
end
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

View file

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

View file

@ -89,8 +89,8 @@ return all online notifications of an user
def self.list(user, limit)
notifications = OnlineNotification.where(user_id: user.id)
.order( 'created_at DESC, id DESC' )
.limit( limit )
.order( 'created_at DESC, id DESC' )
.limit( limit )
list = []
notifications.each do |item|
data = item.attributes
@ -117,8 +117,8 @@ return all online notifications of an object
object_lookup_id: object_id,
o_id: o_id,
)
.order( 'created_at DESC, id DESC' ) # rubocop:disable Style/MultilineOperationIndentation
.limit( 10_000 ) # rubocop:disable Style/MultilineOperationIndentation
.order( 'created_at DESC, id DESC' )
.limit( 10_000 )
notifications
end

View file

@ -11,7 +11,7 @@ class Organization < ApplicationModel
has_many :members, class_name: 'User'
validates :name, presence: true
activity_stream_support role: Z_ROLENAME_ADMIN
activity_stream_support role: Z_ROLENAME_ADMIN
history_support
search_index_support
notify_clients_support

View file

@ -96,7 +96,7 @@ class Package < ApplicationModel
def self.unlink(package_base_dir)
# 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
Package::Migration.migrate( package, 'reverse' )
@ -126,7 +126,7 @@ class Package < ApplicationModel
def self.link(package_base_dir)
# 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
Dir.glob( package_base_dir + '/**/*' ) do |entry|
@ -337,13 +337,13 @@ class Package < ApplicationModel
end
def self._read_file(file, fullpath = false)
if fullpath == false
location = @@root + '/' + file
elsif fullpath == true
location = file
else
location = fullpath + '/' + file
end
location = if fullpath == false
@@root + '/' + file
elsif fullpath == true
file
else
fullpath + '/' + file
end
begin
data = File.open( location, 'rb' )

View file

@ -27,8 +27,8 @@ class RecentView < ApplicationModel
def self.log_destroy( requested_object, requested_object_id )
return if requested_object == 'RecentView'
RecentView.where( recent_view_object_id: ObjectLookup.by_name( requested_object ) )
.where( o_id: requested_object_id )
.destroy_all
.where( o_id: requested_object_id )
.destroy_all
end
def self.user_log_destroy( user )
@ -36,15 +36,15 @@ class RecentView < ApplicationModel
end
def self.list( user, limit = 10, type = nil )
if !type
recent_views = RecentView.where( created_by_id: user.id )
.order('created_at DESC, id DESC')
.limit(limit)
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) )
.order('created_at DESC, id DESC')
.limit(limit)
end
recent_views = if !type
RecentView.where( created_by_id: user.id )
.order('created_at DESC, id DESC')
.limit(limit)
else
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')
.limit(limit)
end
list = []
recent_views.each { |item|

View file

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

View file

@ -23,7 +23,7 @@ class StatsStore < ApplicationModel
end
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
=begin

View file

@ -81,7 +81,7 @@ returns
# search
store_object_id = Store::Object.lookup( name: data[:object] )
stores = Store.where( store_object_id: store_object_id, o_id: data[:o_id].to_i )
.order('created_at ASC, id ASC')
.order('created_at ASC, id ASC')
stores
end
@ -104,8 +104,8 @@ returns
# search
store_object_id = Store::Object.lookup( name: data[:object] )
stores = Store.where( store_object_id: store_object_id )
.where( o_id: data[:o_id] )
.order('created_at ASC, id ASC')
.where( o_id: data[:o_id] )
.order('created_at ASC, id ASC')
stores.each do |store|
# check backend for references

View file

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

View file

@ -103,16 +103,16 @@ returns
access_condition = []
if user.role?(Z_ROLENAME_AGENT)
group_ids = Group.select( 'groups.id' ).joins(:users)
.where( 'groups_users.user_id = ?', user.id )
.where( 'groups.active = ?', true )
.map( &:id )
.where( 'groups_users.user_id = ?', user.id )
.where( 'groups.active = ?', true )
.map( &:id )
access_condition = [ 'group_id IN (?)', group_ids ]
else
if !user.organization || ( !user.organization.shared || user.organization.shared == false )
access_condition = [ 'tickets.customer_id = ?', user.id ]
else
access_condition = [ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ]
end
access_condition = if !user.organization || ( !user.organization.shared || user.organization.shared == false )
[ 'tickets.customer_id = ?', user.id ]
else
[ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ]
end
end
access_condition
end
@ -134,7 +134,7 @@ returns
ticket_states = Ticket::State.where(
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
@ -146,7 +146,7 @@ returns
tickets = where(
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

View file

@ -49,12 +49,12 @@ class Ticket::Article < ApplicationModel
end
class Sender < ApplicationModel
validates :name, presence: true
validates :name, presence: true
latest_change_support
end
class Type < ApplicationModel
validates :name, presence: true
validates :name, presence: true
latest_change_support
end
end

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Ticket::Priority < ApplicationModel
self.table_name = 'ticket_priorities'
validates :name, presence: true
validates :name, presence: true
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@ class CreateBase < ActiveRecord::Migration
t.string :session_id, null: false
t.boolean :persistent, null: true
t.text :data
t.timestamps null: false
t.timestamps null: false
end
add_index :sessions, :session_id
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.string :locked_by # Who is working on this object (if locked)
t.string :queue # The name of the queue this job is in
t.timestamps null: false
t.timestamps null: false
end
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(
name: 'Close & Tag as Spam',
perform: {
'ticket.state_id': {
'ticket.state_id' => {
value: Ticket::State.find_by(name: 'closed').id,
},
'ticket.tags': {
'ticket.tags' => {
operator: 'add',
value: 'spam',
},

View file

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

View file

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

View file

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

View file

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

View file

@ -280,21 +280,21 @@ returns on fail
end
# prepare test email
if subject
mail = {
from: email,
to: email,
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.",
}
else
mail = {
from: email,
to: 'emailtrytest@znuny.com',
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.",
}
end
mail = if subject
{
from: email,
to: email,
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.",
}
else
{
from: email,
to: 'emailtrytest@znuny.com',
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.",
}
end
if subject
mail['X-Zammad-Test-Message'] = subject
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -11,11 +11,11 @@ class Sessions::Event::Base
end
def websocket_send(recipient_client_id, data)
if data.class != Array
msg = "[#{data.to_json}]"
else
msg = data.to_json
end
msg = if data.class != Array
"[#{data.to_json}]"
else
data.to_json
end
if @clients[recipient_client_id]
log 'debug', "ws send #{msg}", recipient_client_id
@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'].class != Hash
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
if !@payload['recipient'].key?('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|
@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
websocket_send(local_client_id, @payload['data'])
}
end
end
log 'notice', "send broadcast from (#{@client_id}) to (user_id=#{user_id})", local_client_id
websocket_send(local_client_id, @payload['data'])
}
end
# broadcast every client

View file

@ -13,11 +13,11 @@ class Sessions::Event::Login < Sessions::Event::Base
end
end
if session && session.data && session.data['user_id']
new_session_data = { 'id' => session.data['user_id'] }
else
new_session_data = {}
end
new_session_data = if session && session.data && session.data['user_id']
{ 'id' => session.data['user_id'] }
else
{}
end
if @clients[@client_id]
@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
if item[:type] == 'direct'
log 'notice', "send spool to (user_id=#{@session['id']})"
websocket_send(@client_id, item[:message])
else
log 'notice', 'send spool'
websocket_send(@client_id, item[:message])
end
websocket_send(@client_id, item[:message])
}
# send spool:sent event to client

View file

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

View file

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

View file

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

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)
#result[:average_per_agent_in_percent] = in_percent
in_percent = ( result[:count].to_f / (result[:total].to_f / 100) ).round(1)
if in_percent >= 90
result[:state] = 'superbad'
elsif in_percent >= 65
result[:state] = 'bad'
elsif in_percent >= 40
result[:state] = 'ok'
elsif in_percent >= 20
result[:state] = 'good'
else
result[:state] = 'supergood'
end
result[:state] = if in_percent >= 90
'superbad'
elsif in_percent >= 65
'bad'
elsif in_percent >= 40
'ok'
elsif in_percent >= 20
'good'
else
'supergood'
end
result
end

View file

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

View file

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

View file

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

View file

@ -238,11 +238,11 @@ EventMachine.run {
end
def websocket_send(client_id, data)
if data.class != Array
msg = "[#{data.to_json}]"
else
msg = data.to_json
end
msg = if data.class != Array
"[#{data.to_json}]"
else
data.to_json
end
log 'debug', "send #{msg}", client_id
if !@clients[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)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
watch_for(
css: 'span.translation[title="Overviews"]',
@ -126,11 +126,11 @@ class TranslationTest < TestCase
sleep 5
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
sleep 5
exists_not(
@ -192,11 +192,11 @@ class TranslationTest < TestCase
sleep 5
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
watch_for(
css: 'span.translation[title="Overviews"]',
@ -211,11 +211,11 @@ class TranslationTest < TestCase
sleep 5
@browser.action.key_down(:control)
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
.key_down(:alt)
.send_keys('t')
.key_up(:alt)
.key_up(:control)
.perform
sleep 5
exists_not(

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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