Browse Source

CLDC-3626 Changes to filtering by specific users (#2646)

pull/2675/head v0.4.77
Manny Dinssa 3 months ago committed by GitHub
parent
commit
42419bd193
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      app/controllers/users_controller.rb
  2. 11
      app/helpers/filters_helper.rb
  3. 2
      app/models/lettings_log.rb
  4. 2
      app/models/log.rb
  5. 9
      app/models/user.rb

3
app/controllers/users_controller.rb

@ -33,8 +33,7 @@ class UsersController < ApplicationController
end
def search
user_options = current_user.support? ? User.all : User.own_and_managing_org_users(current_user.organisation)
users = user_options.search_by(params["query"]).limit(20)
users = User.visible(current_user).search_by(params["query"]).limit(20)
user_data = users.each_with_object({}) do |user, hash|
hash[user.id] = { value: user.name, hint: user.email }

11
app/helpers/filters_helper.rb

@ -112,11 +112,7 @@ module FiltersHelper
def assigned_to_filter_options(filter_type)
if applied_filters(filter_type)["assigned_to"] == "specific_user" && applied_filters(filter_type)["user"].present?
user_id = applied_filters(filter_type)["user"]
selected_user = if current_user.support?
User.where(id: user_id)&.first
else
User.own_and_managing_org_users(current_user.organisation).where(id: user_id)&.first
end
selected_user = User.visible(current_user).where(id: user_id)&.first
return [OpenStruct.new(id: selected_user.id, name: selected_user.name, hint: selected_user.email)] if selected_user.present?
end
@ -309,8 +305,9 @@ private
return "All" if session_filters["assigned_to"].include?("all")
return "You" if session_filters["assigned_to"].include?("you")
User.own_and_managing_org_users(current_user.organisation).find(session_filters["user"].to_i).name
selected_user_option = User.own_and_managing_org_users(current_user.organisation).find(session_filters["user"].to_i)
user_id = session_filters["user"].to_i
selected_user_option = User.visible(current_user).where(id: user_id)&.first
return unless selected_user_option
"#{selected_user_option.name} (#{selected_user_option.email})"

2
app/models/lettings_log.rb

@ -140,7 +140,7 @@ class LettingsLog < Log
illness_type_10: false)
}
scope :filter_by_user_text_search, ->(param, user) { where(assigned_to: user.support? ? User.search_by(param) : User.own_and_managing_org_users(user.organisation).search_by(param)) }
scope :filter_by_user_text_search, ->(param, user) { where(assigned_to: User.visible(user).search_by(param)) }
scope :filter_by_owning_organisation_text_search, ->(param, _user) { where(owning_organisation: Organisation.search_by(param)) }
scope :filter_by_managing_organisation_text_search, ->(param, _user) { where(managing_organisation: Organisation.search_by(param)) }

2
app/models/log.rb

@ -53,7 +53,7 @@ class Log < ApplicationRecord
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_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 :filter_by_user_text_search, ->(param, user) { where(assigned_to: user.support? ? User.search_by(param) : User.own_and_managing_org_users(user.organisation).search_by(param)) }
scope :filter_by_user_text_search, ->(param, user) { where(assigned_to: User.visible(user).search_by(param)) }
scope :filter_by_owning_organisation_text_search, ->(param, _user) { where(owning_organisation: Organisation.search_by(param)) }
scope :filter_by_managing_organisation_text_search, ->(param, _user) { where(managing_organisation: Organisation.search_by(param)) }

9
app/models/user.rb

@ -84,8 +84,13 @@ class User < ApplicationRecord
scope :not_signed_in, -> { where(last_sign_in_at: nil, active: true) }
scope :deactivated, -> { where(active: false) }
scope :active_status, -> { where(active: true).where.not(last_sign_in_at: nil) }
scope :visible, -> { where(discarded_at: nil) }
scope :own_and_managing_org_users, ->(organisation) { where(organisation: organisation.child_organisations + [organisation]) }
scope :visible, lambda { |user = nil|
if user && !user.support?
where(discarded_at: nil, organisation: user.organisation.child_organisations + [user.organisation])
else
where(discarded_at: nil)
end
}
attr_accessor :log_reassignment

Loading…
Cancel
Save