Browse Source

feat: add absorbed org to user relations

pull/1789/head
natdeanlewissoftwire 3 years ago
parent
commit
28b43cb81c
  1. 2
      app/models/lettings_log.rb
  2. 3
      app/models/sales_log.rb
  3. 17
      app/models/user.rb

2
app/models/lettings_log.rb

@ -54,7 +54,7 @@ class LettingsLog < Log
scope :unresolved, -> { where(unresolved: true) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_owning_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) }
scope :filter_by_managing_organisation, ->(managing_organisation, _user = nil) { where(managing_organisation:) }
scope :duplicate_logs, lambda { |log|

3
app/models/sales_log.rb

@ -40,8 +40,7 @@ class SalesLog < Log
.or(filter_by_postcode(param))
.or(filter_by_id(param))
}
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
scope :filter_by_owning_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) }
scope :duplicate_logs, lambda { |log|
visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES))
.where.not(id: log.id)

17
app/models/user.rb

@ -7,9 +7,6 @@ class User < ApplicationRecord
# Marked as optional because we validate organisation_id below instead so that
# the error message is linked to the right field on the form
belongs_to :organisation, optional: true
has_many :owned_lettings_logs, through: :organisation
has_many :managed_lettings_logs, through: :organisation
has_many :owned_sales_logs, through: :organisation
has_many :legacy_users
has_many :bulk_uploads
@ -68,10 +65,22 @@ class User < ApplicationRecord
if support?
SalesLog.all
else
SalesLog.filter_by_organisation(organisation.absorbed_organisations << organisation)
SalesLog.filter_by_owning_organisation(organisation.absorbed_organisations << organisation)
end
end
def owned_lettings_logs
LettingsLog.filter_by_owning_organisation(organisation.absorbed_organisations << organisation)
end
def managed_lettings_logs
LettingsLog.filter_by_managing_organisation(organisation.absorbed_organisations << organisation)
end
def owned_sales_logs
SalesLog.filter_by_owning_organisation(organisation.absorbed_organisations << organisation)
end
def is_key_contact?
is_key_contact
end

Loading…
Cancel
Save