41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'app/models/has_helpers/user_methods.rb', line 41
def ()
org_id = ["organization_id_or_uuid"] || ["organization_id"]
org = ::HasHelpers::Organization.find_or_initialize_by(id: org_id)
time_zone = ::TimeZone.find_by(name: ["organization_time_zone_name"])
if time_zone.nil?
time_zone = org.time_zone
data = {
message: "TimeZone Lookup Failed",
organization: org.inspect,
user: self.inspect,
extra_attributes: ,
}.inspect
HasHelpers::LogNotifier.notify(
HasHelpers::HQException.new(data, backtrace: caller)
)
end
organization_attributes = {
code_name: ["organization_code_name"],
domain: ["organization_domain"],
ip_whitelist: ["organization_ip_whitelist"],
is_use_roles_for_authorization: ["organization_is_use_roles_for_authorization"],
name: ["organization_name"],
time_zone_id: time_zone.id,
}
organization_attributes[:is_active] = ["organization_is_active"] if ::HasHelpers::Organization.column_names.include?("is_active")
organization_attributes[:start_date] = ["organization_go_live_date"] if org.start_date.blank?
if !org.update(organization_attributes) && ::Rails.application.config.x.support_email_address.present?
notifier_body = {
"User" => username,
"Class" => self.class.name,
"Org ID" => org.id,
"Organization name" => org.name,
"Org name of extra attrs" => ["organization_name"] || "no attr found",
"Test org name" => ["organization_name_test"] || "no name found",
"Created at" => ["created_at_test"],
"Errors" => org.errors.full_messages.join(", "),
"Backtrace" => Thread.current.backtrace.first(100),
}
::HasHelpers::EmailNotifier.system(subject: "Error synchronizing organization attributes", to: "tools@onehq.com", body: notifier_body).deliver_now
end
link = user_organizations.find_or_initialize_by(organization_id: org.id)
link.is_primary = true
self.assign_attributes(
applications_array: ["user_applications_array"],
import_key: ["user_import_key"],
ip_whitelist: ["user_ip_whitelist"],
is_support: ["user_is_support"] ? true : nil, permissions_hash: ["user_permissions_hash"],
photo_content_type: ["user_photo_content_type"],
photo_file_name: ["user_photo_file_name"],
photo_file_size: ["user_photo_file_size"],
photo_updated_at: ["user_photo_updated_at"],
production_api_key: ["user_production_api_key"],
staging_api_key: ["user_staging_api_key"],
username: ["user_username"],
)
self.first_name = ["user_first_name"] if respond_to?(:first_name)
self.last_name = ["user_last_name"] if respond_to?(:last_name)
if new_record?
self.id = ["user_id"]
self.created_by = self
self.updated_by = self
end
self.skip_update_master_record = true
self. = .select { |attr_name, _| attr_name.start_with?("user") }
org. = .select { |attr_name, _| attr_name.start_with?("organization") }
self.send(:handle_extra_attributes) if self.respond_to?(:handle_extra_attributes, true)
org.send(:handle_extra_attributes) if org.respond_to?(:handle_extra_attributes, true)
link.save!
user_organizations.where.not(id: link.id).update_all(is_primary: nil)
end
|