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