From 25ae3c1f19a9ceead007a65da94c40f56d545511 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:56:52 +0100 Subject: [PATCH] Revert "Refactor visible organisations logic into a class method" This reverts commit 7af73979b0c4640e5c7762e6e4274808893fbea8. --- app/models/user.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f196bcb9a..241994bfa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,12 +10,6 @@ class User < ApplicationRecord Thread.current[:current_user] end - def self.visible_organisations - return [] unless current - - current.organisation.child_organisations + [current.organisation] - end - # 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 @@ -95,10 +89,11 @@ class User < ApplicationRecord scope :deactivated, -> { where(active: false) } scope :active_status, -> { where(active: true).where.not(last_sign_in_at: nil) } scope :visible, lambda { - if User.current&.support? + current_user = User.current + if current_user&.support? where(discarded_at: nil) else - where(discarded_at: nil, organisation: visible_organisations) + where(discarded_at: nil, organisation: current_user.organisation.child_organisations + [current_user.organisation]) end }