|
@@ -30,7 +30,8 @@ class Ticket < ApplicationModel
|
|
|
include ::Ticket::Search
|
|
|
include ::Ticket::MergeHistory
|
|
|
|
|
|
- store :preferences
|
|
|
+ store :preferences
|
|
|
+ after_initialize :check_defaults, if: :new_record?
|
|
|
before_create :check_generate, :check_defaults, :check_title, :set_default_state, :set_default_priority
|
|
|
before_update :check_defaults, :check_title, :reset_pending_time, :check_owner_active
|
|
|
|
|
@@ -1026,17 +1027,28 @@ returns a hex color code
|
|
|
end
|
|
|
|
|
|
def check_defaults
|
|
|
- if !owner_id
|
|
|
- self.owner_id = 1
|
|
|
- end
|
|
|
- return true if !customer_id
|
|
|
+ check_default_owner
|
|
|
+ check_default_organization
|
|
|
+ true
|
|
|
+ end
|
|
|
+
|
|
|
+ def check_default_owner
|
|
|
+ return if !has_attribute?(:owner_id)
|
|
|
+ return if owner_id || owner
|
|
|
+
|
|
|
+ self.owner_id = 1
|
|
|
+ end
|
|
|
+
|
|
|
+ def check_default_organization
|
|
|
+ return if !has_attribute?(:organization_id)
|
|
|
+ return if !customer_id
|
|
|
|
|
|
customer = User.find_by(id: customer_id)
|
|
|
- return true if !customer
|
|
|
- return true if organization_id.present? && customer.organization_id?(organization_id)
|
|
|
+ return if !customer
|
|
|
+ return if organization_id.present? && customer.organization_id?(organization_id)
|
|
|
+ return if organization.present? && customer.organization_id?(organization.id)
|
|
|
|
|
|
self.organization_id = customer.organization_id
|
|
|
- true
|
|
|
end
|
|
|
|
|
|
def reset_pending_time
|