2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
module ApplicationHandleInfo
|
2021-08-20 03:36:30 +00:00
|
|
|
# stores current application handler.
|
|
|
|
# for example application_server, scheduler, websocket, postmaster...
|
|
|
|
thread_mattr_accessor :current
|
2017-11-23 08:09:44 +00:00
|
|
|
|
|
|
|
def self.postmaster?
|
|
|
|
return false if current.blank?
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
current.split('.')[1] == 'postmaster'
|
|
|
|
end
|
2019-04-10 17:14:34 +00:00
|
|
|
|
|
|
|
def self.use(name)
|
|
|
|
raise ArgumentError, 'requires a block' if !block_given?
|
|
|
|
|
|
|
|
orig = current
|
|
|
|
self.current = name
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
self.current = orig
|
|
|
|
end
|
2021-08-20 03:36:30 +00:00
|
|
|
|
|
|
|
# stores action context
|
|
|
|
# for example merge, twitter, telegram....
|
|
|
|
# used to determine if custom attribute validation shall run
|
|
|
|
thread_mattr_accessor :context
|
|
|
|
|
|
|
|
def self.in_context(name)
|
|
|
|
raise ArgumentError, 'requires a block' if !block_given?
|
|
|
|
|
|
|
|
orig = context
|
|
|
|
self.context = name
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
self.context = orig
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.context_without_custom_attributes?
|
|
|
|
%w[merge twitter telegram facebook form mail sms].include? context.to_s
|
|
|
|
end
|
2016-08-20 19:29:22 +00:00
|
|
|
end
|