Improved tests (do not break on before/after callbacks).
This commit is contained in:
parent
350c3ead51
commit
d93d404902
38 changed files with 218 additions and 165 deletions
|
@ -23,7 +23,7 @@ returns
|
|||
|
||||
# if we do not have it cached, do lookup
|
||||
if !updated_at
|
||||
o = select(:updated_at).order(updated_at: :desc).limit(1).first
|
||||
o = select(:updated_at).order(updated_at: :desc, id: :desc).limit(1).first
|
||||
if o
|
||||
updated_at = o.updated_at
|
||||
latest_change_set(updated_at)
|
||||
|
@ -34,7 +34,7 @@ returns
|
|||
|
||||
def latest_change_set(updated_at)
|
||||
key = "#{new.class.name}_latest_change"
|
||||
expires_in = 31_536_000 # 1 year
|
||||
expires_in = 86_400 # 1 day
|
||||
|
||||
if updated_at.nil?
|
||||
Cache.delete(key)
|
||||
|
|
|
@ -34,5 +34,6 @@ check string/varchar size and cut them if needed
|
|||
self[attribute[0]] = self[ attribute[0] ].utf8_to_3bytesutf8
|
||||
end
|
||||
}
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,5 +15,6 @@ module ApplicationModel::ChecksImport
|
|||
return if Setting.get('import_mode') && import_class_list.include?(self.class.to_s)
|
||||
return if !has_attribute?(:id)
|
||||
self[:id] = nil
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,14 +31,15 @@ returns
|
|||
end
|
||||
end
|
||||
|
||||
return if !self.class.column_names.include? 'created_by_id'
|
||||
return true if !self.class.column_names.include? 'created_by_id'
|
||||
|
||||
return if !UserInfo.current_user_id
|
||||
return true if !UserInfo.current_user_id
|
||||
|
||||
if created_by_id && created_by_id != UserInfo.current_user_id
|
||||
logger.info "NOTICE create - self.created_by_id is different: #{created_by_id}/#{UserInfo.current_user_id}"
|
||||
end
|
||||
self.created_by_id = UserInfo.current_user_id
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -56,9 +57,10 @@ returns
|
|||
=end
|
||||
|
||||
def fill_up_user_update
|
||||
return if !self.class.column_names.include? 'updated_by_id'
|
||||
return if !UserInfo.current_user_id
|
||||
return true if !self.class.column_names.include? 'updated_by_id'
|
||||
return true if !UserInfo.current_user_id
|
||||
|
||||
self.updated_by_id = UserInfo.current_user_id
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,5 +17,6 @@ delete object recent viewed list, will be executed automatically
|
|||
|
||||
def recent_view_destroy
|
||||
RecentView.log_destroy(self.class.to_s, id)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -240,13 +240,14 @@ returns
|
|||
|
||||
# if changed calendar is default, set all others default to false
|
||||
def sync_default
|
||||
return if !default
|
||||
return true if !default
|
||||
Calendar.find_each { |calendar|
|
||||
next if calendar.id == id
|
||||
next if !calendar.default
|
||||
calendar.default = false
|
||||
calendar.save
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
# check if min one is set to default true
|
||||
|
@ -270,11 +271,13 @@ returns
|
|||
sla.save!
|
||||
end
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
# fetch ical feed
|
||||
def fetch_ical
|
||||
sync(true)
|
||||
true
|
||||
end
|
||||
|
||||
# validate format of public holidays
|
||||
|
@ -292,6 +295,6 @@ returns
|
|||
false
|
||||
end
|
||||
}
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,8 +27,7 @@ module ChecksConditionValidation
|
|||
}
|
||||
|
||||
ticket_count, tickets = Ticket.selectors(validate_condition, 1, User.find(1))
|
||||
return if ticket_count.present?
|
||||
|
||||
return true if ticket_count.present?
|
||||
raise Exceptions::UnprocessableEntity, 'Invalid ticket selector conditions'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module ChecksHtmlSanitized
|
|||
|
||||
def sanitized_html_attributes
|
||||
html_attributes = self.class.instance_variable_get(:@sanitized_html) || []
|
||||
return if html_attributes.empty?
|
||||
return true if html_attributes.empty?
|
||||
|
||||
html_attributes.each do |attribute|
|
||||
value = send(attribute)
|
||||
|
@ -19,6 +19,7 @@ module ChecksHtmlSanitized
|
|||
|
||||
send("#{attribute}=".to_sym, HtmlSanitizer.strict(value))
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def sanitizeable?(_attribute, _value)
|
||||
|
|
|
@ -11,9 +11,11 @@ module ChecksLatestChangeObserved
|
|||
|
||||
def latest_change_set_from_observer
|
||||
self.class.latest_change_set(updated_at)
|
||||
true
|
||||
end
|
||||
|
||||
def latest_change_set_from_observer_destroy
|
||||
self.class.latest_change_set(nil)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,7 @@ log object create activity stream, if configured - will be executed automaticall
|
|||
|
||||
def activity_stream_create
|
||||
activity_stream_log('create', self['created_by_id'])
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -31,7 +32,7 @@ log object update activity stream, if configured - will be executed automaticall
|
|||
=end
|
||||
|
||||
def activity_stream_update
|
||||
return if !changed?
|
||||
return true if !changed?
|
||||
|
||||
ignored_attributes = self.class.instance_variable_get(:@activity_stream_attributes_ignored) || []
|
||||
ignored_attributes += %i(created_at updated_at created_by_id updated_by_id)
|
||||
|
@ -42,10 +43,9 @@ log object update activity stream, if configured - will be executed automaticall
|
|||
|
||||
log = true
|
||||
}
|
||||
|
||||
return if !log
|
||||
|
||||
return true if !log
|
||||
activity_stream_log('update', self['updated_by_id'])
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -59,6 +59,7 @@ delete object activity stream, will be executed automatically
|
|||
|
||||
def activity_stream_destroy
|
||||
ActivityStream.remove(self.class.to_s, id)
|
||||
true
|
||||
end
|
||||
|
||||
# methods defined here are going to extend the class, not the instance of it
|
||||
|
|
|
@ -17,5 +17,6 @@ delete object online notification list, will be executed automatically
|
|||
|
||||
def karma_activity_log_destroy
|
||||
Karma::ActivityLog.remove(self.class.to_s, id)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,5 +20,6 @@ delete object link list, will be executed automatically
|
|||
link_object: self.class.to_s,
|
||||
link_object_value: id,
|
||||
)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,5 +17,6 @@ delete object online notification list, will be executed automatically
|
|||
|
||||
def online_notification_destroy
|
||||
OnlineNotification.remove(self.class.to_s, id)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,6 +24,7 @@ update search index, if configured - will be executed automatically
|
|||
# start background job to transfer data to search index
|
||||
return if !SearchIndexBackend.enabled?
|
||||
Delayed::Job.enqueue(BackgroundJobSearchIndex.new(self.class.to_s, id))
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -38,6 +39,7 @@ delete search index object, will be executed automatically
|
|||
def search_index_destroy
|
||||
return if ignore_search_indexing?(:destroy)
|
||||
SearchIndexBackend.remove(self.class.to_s, id)
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -60,6 +62,7 @@ returns
|
|||
|
||||
# update backend
|
||||
SearchIndexBackend.add(self.class.to_s, attributes)
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
|
@ -73,6 +73,7 @@ destroy all tags of an object
|
|||
o_id: id,
|
||||
created_by_id: current_user_id,
|
||||
)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -203,10 +203,12 @@ class Job < ApplicationModel
|
|||
|
||||
def updated_matching
|
||||
self.matching = matching_count
|
||||
true
|
||||
end
|
||||
|
||||
def update_next_run_at
|
||||
self.next_run_at = next_run_at_calculate
|
||||
true
|
||||
end
|
||||
|
||||
def match_minutes(minutes)
|
||||
|
|
|
@ -6,22 +6,22 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
|
|||
def before_create(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
# only do fill of email from if article got created via application_server (e. g. not
|
||||
# if article and sender type is set via *.postmaster)
|
||||
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||
return true if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||
|
||||
# if sender is customer, do not change anything
|
||||
return if !record.sender_id
|
||||
return true if !record.sender_id
|
||||
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||
return if sender.nil?
|
||||
return if sender['name'] == 'Customer'
|
||||
return true if sender.nil?
|
||||
return true if sender['name'] == 'Customer'
|
||||
|
||||
# set email attributes
|
||||
return if !record.type_id
|
||||
return true if !record.type_id
|
||||
type = Ticket::Article::Type.lookup(id: record.type_id)
|
||||
return if type['name'] != 'email'
|
||||
return true if type['name'] != 'email'
|
||||
|
||||
# set subject if empty
|
||||
ticket = Ticket.lookup(id: record.ticket_id)
|
||||
|
@ -59,5 +59,6 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
|
|||
else
|
||||
record.from = Channel::EmailBuild.recipient_line(email_address.realname, email_address.email)
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,24 +6,24 @@ class Observer::Ticket::Article::FillupFromGeneral < ActiveRecord::Observer
|
|||
def before_create(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
# only do fill of from if article got created via application_server (e. g. not
|
||||
# if article and sender type is set via *.postmaster)
|
||||
return if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||
return true if ApplicationHandleInfo.current.split('.')[1] == 'postmaster'
|
||||
|
||||
# set from on all article types excluding email|twitter status|twitter direct-message|facebook feed post|facebook feed comment
|
||||
return if !record.type_id
|
||||
return true if !record.type_id
|
||||
type = Ticket::Article::Type.lookup(id: record.type_id)
|
||||
return if type['name'] == 'email'
|
||||
return true if type['name'] == 'email'
|
||||
|
||||
# from will be set by channel backend
|
||||
return if type['name'] == 'twitter status'
|
||||
return if type['name'] == 'twitter direct-message'
|
||||
return if type['name'] == 'facebook feed post'
|
||||
return if type['name'] == 'facebook feed comment'
|
||||
return true if type['name'] == 'twitter status'
|
||||
return true if type['name'] == 'twitter direct-message'
|
||||
return true if type['name'] == 'facebook feed post'
|
||||
return true if type['name'] == 'facebook feed comment'
|
||||
|
||||
return if !record.created_by_id
|
||||
return true if !record.created_by_id
|
||||
user = User.find(record.created_by_id)
|
||||
if type.name == 'web'
|
||||
record.from = "#{user.firstname} #{user.lastname} <#{user.email}>"
|
||||
|
|
|
@ -16,13 +16,13 @@ class Observer::Ticket::CloseTime < ActiveRecord::Observer
|
|||
def _check(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
# check if close_at is already set
|
||||
return true if record.close_at
|
||||
|
||||
# check if ticket is closed now
|
||||
return if !record.state_id
|
||||
return true if !record.state_id
|
||||
state = Ticket::State.lookup(id: record.state_id)
|
||||
state_type = Ticket::StateType.lookup(id: state.state_type_id)
|
||||
return true if state_type.name != 'closed'
|
||||
|
|
|
@ -176,7 +176,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
|||
def after_create(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
e = {
|
||||
object: record.class.name,
|
||||
|
@ -187,12 +187,13 @@ class Observer::Transaction < ActiveRecord::Observer
|
|||
created_at: Time.zone.now,
|
||||
}
|
||||
EventBuffer.add('transaction', e)
|
||||
true
|
||||
end
|
||||
|
||||
def before_update(record)
|
||||
|
||||
# return if we run import mode
|
||||
return if Setting.get('import_mode')
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
# ignore certain attributes
|
||||
real_changes = {}
|
||||
|
@ -210,7 +211,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
|||
}
|
||||
|
||||
# do not send anything if nothing has changed
|
||||
return if real_changes.empty?
|
||||
return true if real_changes.empty?
|
||||
|
||||
changed_by_id = nil
|
||||
changed_by_id = if record.respond_to?('updated_by_id')
|
||||
|
@ -229,6 +230,7 @@ class Observer::Transaction < ActiveRecord::Observer
|
|||
created_at: Time.zone.now,
|
||||
}
|
||||
EventBuffer.add('transaction', e)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,10 +5,12 @@ class Observer::User::Geo < ActiveRecord::Observer
|
|||
|
||||
def before_create(record)
|
||||
check_geo(record)
|
||||
true
|
||||
end
|
||||
|
||||
def before_update(record)
|
||||
check_geo(record)
|
||||
true
|
||||
end
|
||||
|
||||
# check if geo need to be updated
|
||||
|
|
|
@ -25,11 +25,12 @@ class Organization < ApplicationModel
|
|||
private
|
||||
|
||||
def domain_cleanup
|
||||
return if domain.blank?
|
||||
return true if domain.blank?
|
||||
domain.gsub!(/@/, '')
|
||||
domain.gsub!(/\s*/, '')
|
||||
domain.strip!
|
||||
domain.downcase!
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,17 +24,20 @@ class Overview < ApplicationModel
|
|||
def fill_prio
|
||||
return true if prio
|
||||
self.prio = 9999
|
||||
true
|
||||
end
|
||||
|
||||
def fill_link_on_create
|
||||
return true if !link.empty?
|
||||
self.link = link_name(name)
|
||||
true
|
||||
end
|
||||
|
||||
def fill_link_on_update
|
||||
return true if link.empty?
|
||||
return true if !changes['name']
|
||||
self.link = link_name(name)
|
||||
true
|
||||
end
|
||||
|
||||
def link_name(name)
|
||||
|
|
|
@ -125,7 +125,7 @@ returns
|
|||
private
|
||||
|
||||
def validate_permissions
|
||||
return if !self.permission_ids
|
||||
return true if !self.permission_ids
|
||||
permission_ids.each { |permission_id|
|
||||
permission = Permission.lookup(id: permission_id)
|
||||
raise "Unable to find permission for id #{permission_id}" if !permission
|
||||
|
@ -137,17 +137,19 @@ returns
|
|||
raise "Permission #{permission.name} conflicts with #{local_permission.name}" if permission_ids.include?(local_permission.id)
|
||||
}
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
def validate_agent_limit(permission)
|
||||
return if !Setting.get('system_agent_limit')
|
||||
return if permission.name != 'ticket.agent'
|
||||
return true if !Setting.get('system_agent_limit')
|
||||
return true if permission.name != 'ticket.agent'
|
||||
|
||||
ticket_agent_role_ids = Role.joins(:permissions).where(permissions: { name: 'ticket.agent' }).pluck(:id)
|
||||
ticket_agent_role_ids.push(id)
|
||||
count = User.joins(:roles).where(roles: { id: ticket_agent_role_ids }, users: { active: true }).count
|
||||
|
||||
raise Exceptions::UnprocessableEntity, 'Agent limit exceeded, please check your account settings.' if count > Setting.get('system_agent_limit')
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -131,6 +131,7 @@ reload config settings
|
|||
# set initial value in state_initial
|
||||
def set_initial
|
||||
self.state_initial = state_current
|
||||
true
|
||||
end
|
||||
|
||||
def reset_change_id
|
||||
|
@ -139,6 +140,7 @@ reload config settings
|
|||
logger.debug "Setting.reset_change_id: set new cache, #{change_id}"
|
||||
Cache.write('Setting::ChangeId', change_id, { expires_in: 24.hours })
|
||||
@@lookup_at = nil # rubocop:disable Style/ClassVars
|
||||
true
|
||||
end
|
||||
|
||||
# check if cache is still valid
|
||||
|
@ -160,14 +162,15 @@ reload config settings
|
|||
|
||||
# convert state into hash to be able to store it as store
|
||||
def state_check
|
||||
return if !state
|
||||
return if state && state.respond_to?('has_key?') && state.key?(:value)
|
||||
return true if !state
|
||||
return true if state && state.respond_to?('has_key?') && state.key?(:value)
|
||||
self.state_current = { value: state }
|
||||
true
|
||||
end
|
||||
|
||||
# notify clients about public config changes
|
||||
def check_broadcast
|
||||
return if frontend != true
|
||||
return true if frontend != true
|
||||
value = state_current
|
||||
if state_current.key?(:value)
|
||||
value = state_current[:value]
|
||||
|
@ -179,5 +182,6 @@ reload config settings
|
|||
},
|
||||
'public'
|
||||
)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -292,6 +292,7 @@ remove tag item (destroy with reverences)
|
|||
|
||||
def fill_namedowncase
|
||||
self.name_downcase = name.downcase
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1045,42 +1045,42 @@ result
|
|||
private
|
||||
|
||||
def check_generate
|
||||
return if number
|
||||
return true if number
|
||||
self.number = Ticket::Number.generate
|
||||
true
|
||||
end
|
||||
|
||||
def check_title
|
||||
return if !title
|
||||
return true if !title
|
||||
title.gsub!(/\s|\t|\r/, ' ')
|
||||
true
|
||||
end
|
||||
|
||||
def check_defaults
|
||||
if !owner_id
|
||||
self.owner_id = 1
|
||||
end
|
||||
|
||||
return if !customer_id
|
||||
|
||||
return true if !customer_id
|
||||
customer = User.find_by(id: customer_id)
|
||||
return if !customer
|
||||
return if organization_id == customer.organization_id
|
||||
|
||||
return true if !customer
|
||||
return true if organization_id == customer.organization_id
|
||||
self.organization_id = customer.organization_id
|
||||
true
|
||||
end
|
||||
|
||||
def reset_pending_time
|
||||
|
||||
# ignore if no state has changed
|
||||
return if !changes['state_id']
|
||||
return true if !changes['state_id']
|
||||
|
||||
# check if new state isn't pending*
|
||||
current_state = Ticket::State.lookup(id: state_id)
|
||||
current_state_type = Ticket::StateType.lookup(id: current_state.state_type_id)
|
||||
|
||||
# in case, set pending_time to nil
|
||||
return if current_state_type.name =~ /^pending/i
|
||||
|
||||
return true if current_state_type.name =~ /^pending/i
|
||||
self.pending_time = nil
|
||||
true
|
||||
end
|
||||
|
||||
def check_escalation_update
|
||||
|
@ -1089,20 +1089,18 @@ result
|
|||
end
|
||||
|
||||
def set_default_state
|
||||
return if state_id
|
||||
|
||||
return true if state_id
|
||||
default_ticket_state = Ticket::State.find_by(default_create: true)
|
||||
return if !default_ticket_state
|
||||
|
||||
return true if !default_ticket_state
|
||||
self.state_id = default_ticket_state.id
|
||||
true
|
||||
end
|
||||
|
||||
def set_default_priority
|
||||
return if priority_id
|
||||
|
||||
return true if priority_id
|
||||
default_ticket_priority = Ticket::Priority.find_by(default_create: true)
|
||||
return if !default_ticket_priority
|
||||
|
||||
return true if !default_ticket_priority
|
||||
self.priority_id = default_ticket_priority.id
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,8 +37,7 @@ class Ticket::Article < ApplicationModel
|
|||
|
||||
# fillup md5 of message id to search easier on very long message ids
|
||||
def check_message_id_md5
|
||||
return if !message_id
|
||||
return if message_id_md5
|
||||
return true if message_id.blank?
|
||||
self.message_id_md5 = Digest::MD5.hexdigest(message_id.to_s)
|
||||
end
|
||||
|
||||
|
@ -55,7 +54,7 @@ returns
|
|||
=end
|
||||
|
||||
def self.insert_urls(article)
|
||||
return article if article['attachments'].empty?
|
||||
return article if article['attachments'].blank?
|
||||
return article if article['content_type'] !~ %r{text/html}i
|
||||
return article if article['body'] !~ /<img/i
|
||||
|
||||
|
@ -183,9 +182,7 @@ returns:
|
|||
object: 'Ticket::Article::Mail',
|
||||
o_id: id,
|
||||
)
|
||||
return if !list
|
||||
return if list.empty?
|
||||
return if !list[0]
|
||||
return if list.blank?
|
||||
list[0]
|
||||
end
|
||||
|
||||
|
@ -282,8 +279,9 @@ returns
|
|||
|
||||
# strip not wanted chars
|
||||
def check_subject
|
||||
return if !subject
|
||||
return true if subject.blank?
|
||||
subject.gsub!(/\s|\t|\r/, ' ')
|
||||
true
|
||||
end
|
||||
|
||||
def history_log_attributes
|
||||
|
|
|
@ -119,10 +119,10 @@ cleanup old token
|
|||
private
|
||||
|
||||
def generate_token
|
||||
|
||||
loop do
|
||||
self.name = SecureRandom.urlsafe_base64(48)
|
||||
break if !Token.exists?(name: name)
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -341,13 +341,15 @@ all:
|
|||
private
|
||||
|
||||
def set_initial
|
||||
return if target_initial
|
||||
return if target_initial == ''
|
||||
return true if target_initial
|
||||
return true if target_initial == ''
|
||||
self.target_initial = target
|
||||
true
|
||||
end
|
||||
|
||||
def cache_clear
|
||||
Cache.delete('TranslationMapOnlyContent::' + locale.downcase)
|
||||
true
|
||||
end
|
||||
|
||||
def self.cache_set(locale, data)
|
||||
|
|
|
@ -801,7 +801,7 @@ returns
|
|||
end
|
||||
|
||||
def check_name
|
||||
return if !firstname.empty? && !lastname.empty?
|
||||
return true if !firstname.empty? && !lastname.empty?
|
||||
|
||||
if !firstname.empty? && lastname.empty?
|
||||
|
||||
|
@ -815,7 +815,7 @@ returns
|
|||
if !name[1].nil?
|
||||
self.firstname = name[1]
|
||||
end
|
||||
return
|
||||
return true
|
||||
end
|
||||
|
||||
# "Firstname Lastname"
|
||||
|
@ -826,7 +826,7 @@ returns
|
|||
if !name[1].nil?
|
||||
self.lastname = name[1]
|
||||
end
|
||||
return
|
||||
return true
|
||||
|
||||
# -no name- "firstname.lastname@example.com"
|
||||
elsif firstname.empty? && lastname.empty? && !email.empty?
|
||||
|
@ -840,21 +840,23 @@ returns
|
|||
end
|
||||
end
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def check_email
|
||||
return if Setting.get('import_mode')
|
||||
return if email.empty?
|
||||
return true if Setting.get('import_mode')
|
||||
return true if email.empty?
|
||||
self.email = email.downcase.strip
|
||||
return if id == 1
|
||||
return true if id == 1
|
||||
raise Exceptions::UnprocessableEntity, 'Invalid email' if email !~ /@/
|
||||
raise Exceptions::UnprocessableEntity, 'Invalid email' if email =~ /\s/
|
||||
true
|
||||
end
|
||||
|
||||
def check_login
|
||||
|
||||
# use email as login if not given
|
||||
if login.empty? && !email.empty?
|
||||
if login.blank?
|
||||
self.login = email
|
||||
end
|
||||
|
||||
|
@ -866,7 +868,7 @@ returns
|
|||
end
|
||||
|
||||
# if no email, complain about missing login
|
||||
if id != 1 && login.empty? && email.empty?
|
||||
if id != 1 && login.blank?
|
||||
raise Exceptions::UnprocessableEntity, 'Attribute \'login\' required!'
|
||||
end
|
||||
|
||||
|
@ -881,10 +883,11 @@ returns
|
|||
check = false
|
||||
end
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def validate_roles
|
||||
return if !role_ids
|
||||
return true if !role_ids
|
||||
role_ids.each { |role_id|
|
||||
role = Role.lookup(id: role_id)
|
||||
raise "Unable to find role for id #{role_id}" if !role
|
||||
|
@ -895,6 +898,7 @@ returns
|
|||
raise "Role #{role.name} conflicts with #{local_role.name}" if role_ids.include?(local_role.id)
|
||||
}
|
||||
}
|
||||
true
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -909,7 +913,7 @@ raise 'Minimum one user need to have admin permissions'
|
|||
=end
|
||||
|
||||
def last_admin_check(role)
|
||||
return if Setting.get('import_mode')
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
ticket_admin_role_ids = Role.joins(:permissions).where(permissions: { name: ['admin', 'admin.user'] }).pluck(:id)
|
||||
count = User.joins(:roles).where(roles: { id: ticket_admin_role_ids }, users: { active: true }).count
|
||||
|
@ -918,10 +922,11 @@ raise 'Minimum one user need to have admin permissions'
|
|||
end
|
||||
|
||||
raise Exceptions::UnprocessableEntity, 'Minimum one user needs to have admin permissions.' if count < 1
|
||||
true
|
||||
end
|
||||
|
||||
def validate_agent_limit(role)
|
||||
return if !Setting.get('system_agent_limit')
|
||||
return true if !Setting.get('system_agent_limit')
|
||||
|
||||
ticket_agent_role_ids = Role.joins(:permissions).where(permissions: { name: 'ticket.agent' }).pluck(:id)
|
||||
count = User.joins(:roles).where(roles: { id: ticket_agent_role_ids }, users: { active: true }).count
|
||||
|
@ -930,38 +935,41 @@ raise 'Minimum one user need to have admin permissions'
|
|||
end
|
||||
|
||||
raise Exceptions::UnprocessableEntity, 'Agent limit exceeded, please check your account settings.' if count > Setting.get('system_agent_limit')
|
||||
true
|
||||
end
|
||||
|
||||
def domain_based_assignment
|
||||
return if !email
|
||||
return if organization_id
|
||||
return true if !email
|
||||
return true if organization_id
|
||||
begin
|
||||
domain = Mail::Address.new(email).domain
|
||||
return if !domain
|
||||
return true if !domain
|
||||
organization = Organization.find_by(domain: domain.downcase, domain_assignment: true)
|
||||
return if !organization
|
||||
return true if !organization
|
||||
self.organization_id = organization.id
|
||||
rescue
|
||||
return
|
||||
return true
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
# sets locale of the user
|
||||
def set_locale
|
||||
|
||||
# set the user's locale to the one of the "executing" user
|
||||
return if !UserInfo.current_user_id
|
||||
return true if !UserInfo.current_user_id
|
||||
user = User.find_by(id: UserInfo.current_user_id)
|
||||
return if !user
|
||||
return if !user.preferences[:locale]
|
||||
return true if !user
|
||||
return true if !user.preferences[:locale]
|
||||
|
||||
preferences[:locale] = user.preferences[:locale]
|
||||
true
|
||||
end
|
||||
|
||||
def avatar_for_email_check
|
||||
return if email.blank?
|
||||
return if email !~ /@/
|
||||
return if !changes['email'] && updated_at > Time.zone.now - 10.days
|
||||
return true if email.blank?
|
||||
return true if email !~ /@/
|
||||
return true if !changes['email'] && updated_at > Time.zone.now - 10.days
|
||||
|
||||
# save/update avatar
|
||||
avatar = Avatar.auto_detection(
|
||||
|
@ -974,10 +982,11 @@ raise 'Minimum one user need to have admin permissions'
|
|||
)
|
||||
|
||||
# update user link
|
||||
return if !avatar
|
||||
return true if !avatar
|
||||
|
||||
update_column(:image, avatar.store_hash)
|
||||
cache_delete
|
||||
true
|
||||
end
|
||||
|
||||
def avatar_destroy
|
||||
|
@ -985,9 +994,10 @@ raise 'Minimum one user need to have admin permissions'
|
|||
end
|
||||
|
||||
def ensure_password
|
||||
return if password_empty?
|
||||
return if PasswordHash.crypted?(password)
|
||||
return true if password_empty?
|
||||
return true if PasswordHash.crypted?(password)
|
||||
self.password = PasswordHash.crypt(password)
|
||||
true
|
||||
end
|
||||
|
||||
def password_empty?
|
||||
|
@ -1006,8 +1016,9 @@ raise 'Minimum one user need to have admin permissions'
|
|||
|
||||
# reset login_failed if password is changed
|
||||
def reset_login_failed
|
||||
return if !changes
|
||||
return if !changes['password']
|
||||
return true if !changes
|
||||
return true if !changes['password']
|
||||
self.login_failed = 0
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,13 +36,13 @@ class Sessions::Backend::Collections::Base < Sessions::Backend::Base
|
|||
|
||||
# check if update has been done
|
||||
last_change = self.class.model.constantize.latest_change
|
||||
return if last_change == @last_change
|
||||
@last_change = last_change
|
||||
return if last_change.to_s == @last_change
|
||||
@last_change = last_change.to_s
|
||||
|
||||
# load current data
|
||||
items = load
|
||||
|
||||
return if !items || items.empty?
|
||||
return if items.blank?
|
||||
|
||||
# get relations of data
|
||||
all = []
|
||||
|
|
|
@ -85,8 +85,6 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
|||
organization_id: @organization.id,
|
||||
)
|
||||
|
||||
Ticket.all.destroy_all
|
||||
|
||||
@ticket1 = Ticket.create!(
|
||||
title: 'test 1234-1',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
|
@ -105,7 +103,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
|||
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
||||
type: Ticket::Article::Type.where(name: 'email').first,
|
||||
)
|
||||
sleep 1
|
||||
travel 1.second
|
||||
@ticket2 = Ticket.create!(
|
||||
title: 'test 1234-2',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
|
@ -124,7 +122,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
|||
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
||||
type: Ticket::Article::Type.where(name: 'email').first,
|
||||
)
|
||||
sleep 1
|
||||
travel 1.second
|
||||
@ticket3 = Ticket.create!(
|
||||
title: 'test 1234-2',
|
||||
group: Group.lookup(name: 'Users'),
|
||||
|
@ -162,6 +160,8 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
|||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
end
|
||||
|
||||
travel 1.minute
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
|
|
|
@ -822,7 +822,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
|
|||
created_by_id: 1,
|
||||
)
|
||||
tickets.push ticket
|
||||
sleep 1
|
||||
travel 2.seconds
|
||||
}
|
||||
|
||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin', 'adminpw')
|
||||
|
|
|
@ -2,12 +2,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class SessionBasicTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = User.lookup(id: 1)
|
||||
roles = Role.where(name: %w(Agent Admin))
|
||||
user.roles = roles
|
||||
user.save!
|
||||
end
|
||||
|
||||
test 'b cache' do
|
||||
Sessions::CacheIn.set('last_run_test', true, { expires_in: 1.second })
|
||||
|
@ -59,7 +53,6 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
roles = Role.where(name: %w(Agent))
|
||||
groups = Group.all
|
||||
|
||||
UserInfo.current_user_id = 1
|
||||
agent1 = User.create_or_update(
|
||||
login: 'session-agent-1',
|
||||
firstname: 'Session',
|
||||
|
@ -69,9 +62,9 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
agent1.roles = roles
|
||||
agent1.save
|
||||
|
||||
# create sessions
|
||||
client_id1 = '123456789'
|
||||
|
@ -109,10 +102,25 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
test 'c collections group' do
|
||||
require 'sessions/backend/collections/group.rb'
|
||||
|
||||
UserInfo.current_user_id = 2
|
||||
user = User.lookup(id: 1)
|
||||
collection_client1 = Sessions::Backend::Collections::Group.new(user, {}, false, '123-1', 3)
|
||||
collection_client2 = Sessions::Backend::Collections::Group.new(user, {}, false, '234-2', 3)
|
||||
# create users
|
||||
roles = Role.where(name: ['Agent'])
|
||||
groups = Group.all
|
||||
|
||||
agent1 = User.create_or_update(
|
||||
login: 'session-collection-agent-1',
|
||||
firstname: 'Session',
|
||||
lastname: 'Agent 1',
|
||||
email: 'session-collection-agent1@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
collection_client1 = Sessions::Backend::Collections::Group.new(agent1, {}, false, '123-1', 3)
|
||||
collection_client2 = Sessions::Backend::Collections::Group.new(agent1, {}, false, '234-2', 3)
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
@ -131,12 +139,14 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
|
||||
# change collection
|
||||
group = Group.first
|
||||
travel 4.seconds
|
||||
group.touch
|
||||
travel 4.seconds
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
assert(!result1.empty?, 'check collections - after touch')
|
||||
|
||||
result2 = collection_client2.push
|
||||
assert(!result2.empty?, 'check collections - after touch')
|
||||
assert_equal(result1.to_yaml, result2.to_yaml, 'check collections')
|
||||
|
@ -148,9 +158,11 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
assert_nil(result2, 'check collections - after touch - recall')
|
||||
|
||||
# change collection
|
||||
group = Group.create(
|
||||
name: "SomeGroup::#{rand(999_999)}",
|
||||
active: true
|
||||
group = Group.create!(
|
||||
name: "SomeGroup::#{rand(999_999)}",
|
||||
active: true,
|
||||
created_by_id: 1,
|
||||
updated_by_id: 1,
|
||||
)
|
||||
travel 4.seconds
|
||||
|
||||
|
@ -194,7 +206,6 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
roles = Role.where(name: %w(Agent Admin))
|
||||
groups = Group.all
|
||||
|
||||
UserInfo.current_user_id = 2
|
||||
agent1 = User.create_or_update(
|
||||
login: 'activity-stream-agent-1',
|
||||
firstname: 'Session',
|
||||
|
@ -204,9 +215,9 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
agent1.roles = roles
|
||||
assert(agent1.save, 'create/update agent1')
|
||||
|
||||
# create min. on activity record
|
||||
random_name = "Random:#{rand(9_999_999_999)}"
|
||||
|
@ -233,7 +244,15 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
assert(!result1, 'check as agent1 - recall 2')
|
||||
|
||||
agent1.update_attribute(:email, 'activity-stream-agent11@example.com')
|
||||
ticket = Ticket.create(title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
||||
ticket = Ticket.create(
|
||||
title: '12323',
|
||||
group_id: 1,
|
||||
priority_id: 1,
|
||||
state_id: 1,
|
||||
customer_id: 1,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
travel 4.seconds
|
||||
|
||||
|
@ -246,21 +265,21 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
test 'c ticket_create' do
|
||||
|
||||
# create users
|
||||
roles = Role.where(name: %w(Agent))
|
||||
roles = Role.where(name: %w(Agent Admin))
|
||||
groups = Group.all
|
||||
|
||||
UserInfo.current_user_id = 1
|
||||
agent1 = User.create_or_update(
|
||||
login: 'session-agent-1',
|
||||
login: 'ticket_create-agent-1',
|
||||
firstname: 'Session',
|
||||
lastname: 'Agent 1',
|
||||
email: 'session-agent-1@example.com',
|
||||
lastname: "ticket_create #{rand(99_999)}",
|
||||
email: 'ticket_create-agent1@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
agent1.save!
|
||||
|
||||
ticket_create_client1 = Sessions::Backend::TicketCreate.new(agent1, {}, false, '123-1', 3)
|
||||
|
||||
|
@ -278,19 +297,18 @@ class SessionBasicTest < ActiveSupport::TestCase
|
|||
result1 = ticket_create_client1.push
|
||||
assert(!result1, 'check ticket_create - recall 2')
|
||||
|
||||
group = Group.create(name: "SomeTicketCreateGroup::#{rand(999_999)}", active: true)
|
||||
agent1.groups = Group.all
|
||||
agent1.save!
|
||||
|
||||
# next check should be empty
|
||||
result1 = ticket_create_client1.push
|
||||
Group.create(
|
||||
name: "SomeTicketCreateGroup::#{rand(999_999)}",
|
||||
active: true,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
||||
travel 4.seconds
|
||||
|
||||
# get as stream
|
||||
result1 = ticket_create_client1.push
|
||||
assert(result1, 'check ticket_create - recall 3')
|
||||
|
||||
travel_back
|
||||
end
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
|
||||
test 'b ticket_overview_List' do
|
||||
UserInfo.current_user_id = 1
|
||||
Ticket.destroy_all
|
||||
|
||||
# create users
|
||||
roles = Role.where(name: ['Agent'])
|
||||
groups = Group.all
|
||||
|
||||
|
@ -21,9 +18,7 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
|
||||
agent1.roles = roles
|
||||
assert(agent1.save, 'create/update agent1')
|
||||
assert(agent1.save!, 'create/update agent1')
|
||||
|
||||
Ticket.create(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent1.roles = roles
|
||||
agent1.save
|
||||
agent1.save!
|
||||
|
||||
roles = Role.where(name: ['Agent'])
|
||||
groups = Group.all
|
||||
|
@ -39,8 +38,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent2.roles = roles
|
||||
agent2.save
|
||||
agent2.save!
|
||||
|
||||
roles = Role.where(name: ['Customer'])
|
||||
customer1 = User.create_or_update(
|
||||
|
@ -53,9 +51,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
active: true,
|
||||
roles: roles,
|
||||
)
|
||||
customer1.roles = roles
|
||||
customer1.save
|
||||
|
||||
customer1.save!
|
||||
collection_client1 = Sessions::Backend::Collections.new(agent1, {}, nil, 'aaa-1', 2)
|
||||
collection_client2 = Sessions::Backend::Collections.new(agent2, {}, nil, 'bbb-2', 2)
|
||||
collection_client3 = Sessions::Backend::Collections.new(customer1, {}, nil, 'ccc-2', 2)
|
||||
|
@ -107,11 +103,13 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
|
||||
# change collection
|
||||
group = Group.first
|
||||
travel 6.seconds
|
||||
group.touch
|
||||
travel 4.seconds
|
||||
travel 6.seconds
|
||||
|
||||
# get whole collections
|
||||
result1 = collection_client1.push
|
||||
|
||||
assert(result1, 'check collections - after touch')
|
||||
assert(check_if_collection_exists(result1, :Group), 'check collections - after touch')
|
||||
travel 0.1.seconds
|
||||
|
@ -173,7 +171,6 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'b assets' do
|
||||
# create users
|
||||
roles = Role.where(name: %w(Agent Admin))
|
||||
groups = Group.all.order(id: :asc)
|
||||
|
||||
|
@ -188,7 +185,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
assert(agent1.save, 'create/update agent1')
|
||||
assert(agent1.save!, 'create/update agent1')
|
||||
|
||||
assets = {}
|
||||
client1 = Sessions::Backend::Collections::Group.new(agent1, assets, false, '123-1', 4)
|
||||
|
|
|
@ -19,8 +19,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent1.roles = roles
|
||||
agent1.save
|
||||
agent1.save!
|
||||
agent2 = User.create_or_update(
|
||||
login: 'session-agent-2',
|
||||
firstname: 'Session',
|
||||
|
@ -31,8 +30,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent2.roles = roles
|
||||
agent2.save
|
||||
agent2.save!
|
||||
agent3 = User.create_or_update(
|
||||
login: 'session-agent-3',
|
||||
firstname: 'Session',
|
||||
|
@ -43,8 +41,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent3.roles = roles
|
||||
agent3.save
|
||||
agent3.save!
|
||||
|
||||
# create sessions
|
||||
client_id1 = 'a1234'
|
||||
|
@ -197,7 +194,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent1.save
|
||||
agent1.save!
|
||||
agent2 = User.create_or_update(
|
||||
login: 'session-agent-2',
|
||||
firstname: 'Session',
|
||||
|
@ -209,7 +206,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent2.save
|
||||
agent2.save!
|
||||
agent3 = User.create_or_update(
|
||||
login: 'session-agent-3',
|
||||
firstname: 'Session',
|
||||
|
@ -221,7 +218,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
agent3.save
|
||||
agent3.save!
|
||||
|
||||
# create sessions
|
||||
client_id1_0 = 'b1234-1'
|
||||
|
@ -288,6 +285,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
|||
|
||||
# change collection
|
||||
group = Group.first
|
||||
travel 4.seconds
|
||||
group.touch
|
||||
|
||||
travel 12.seconds
|
||||
|
|
Loading…
Reference in a new issue