Class: Owner

Inherits:
ApplicationRecord show all
Includes:
HungryHub::DynamicTime, IdentityCache, TypesOfActor
Defined in:
app/models/owner.rb

Overview

The model to handle this is StaffPackage

Instance Method Summary collapse

Methods included from HungryHub::DynamicTime

#time_zone

Methods included from TypesOfActor

#kinda_like_owner?, #owner?, #restaurant_group?, #staff?, #user?

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#authenticate(password) ⇒ Object



90
91
92
# File 'app/models/owner.rb', line 90

def authenticate(password)
  valid_password? password
end

#restaurant_idsObject

mimic Restaurant Group



86
87
88
# File 'app/models/owner.rb', line 86

def restaurant_ids
  [restaurant.id]
end

#to_json(options = nil) ⇒ Object



72
73
74
75
76
77
78
79
# File 'app/models/owner.rb', line 72

def to_json(options = nil)
  data = attributes.dup
  excluded_attributes = %w[encrypted_password reset_password_token reset_password_sent_at remember_created_at
                           sign_in_count current_sign_in_at last_sign_in_at current_sign_in_ip last_sign_in_ip created_at updated_at]
  data.delete_if { |k, _v| excluded_attributes.include?(k) }
  data[:manager_emails] = managers.map(&:email)
  ActiveSupport::JSON.encode(data, options)
end

#to_url_hashObject



81
82
83
# File 'app/models/owner.rb', line 81

def to_url_hash
  HungryHub::Owner::Codec.encode(id)
end

#update_staffObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/owner.rb', line 94

def update_staff
  # Skip if this is triggered by a staff update to prevent recursion
  return if @skip_staff_update
  return if staff.blank?

  if password.present?
    # Set a flag on the staff to prevent it from updating this owner again
    staff.instance_variable_set(:@skip_password_sync, true)
    staff.password = password
    staff.audit_comment = "Password synchronized from Owner ID: #{id}"
  end

  if email.present?
    staff.email = email
    staff.audit_comment = "Email synchronized from Owner ID: #{id}" unless staff.audit_comment
  end

  staff.save
end