Skip to content

Commit 0c98319

Browse files
committed
Issue #3561 - Refactoring code based on comments bt @aaronskiba
Changes: - Refactored Org model org_admin_plans() method. - Refactored Paginable Plans controller method org_admin().
1 parent 79d4571 commit 0c98319

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

app/controllers/paginable/plans_controller.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ def org_admin
4646
@super_admin = current_user.can_super_admin?
4747
@clicked_through = params[:click_through].present?
4848

49-
plans = if @super_admin
50-
Plan.all.joins(:template, roles: [user: :org])
51-
.where(Role.creator_condition)
52-
else
53-
current_user.org.org_admin_plans
54-
.joins(:template, roles: [user: :org])
55-
end
49+
plans = @super_admin ? Plan.where(Role.creator_condition) : current_user.org.org_admin_plans
50+
plans = plans.joins(:template, roles: [user: :org])
5651

5752
paginable_renderise(
5853
partial: 'org_admin',

app/models/org.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,17 @@ def org_admins
288288
# This replaces the old plans method. We now use the native plans method and this.
289289
# rubocop:disable Metrics/AbcSize
290290
def org_admin_plans
291-
combined_plan_ids = (native_plan_ids + affiliated_plan_ids).flatten.uniq
292-
293-
if Rails.configuration.x.plans.org_admins_read_all
294-
Plan.includes(:template, :phases, :roles, :users).where(id: combined_plan_ids)
295-
.where(roles: { active: true })
296-
.where(Role.creator_condition)
297-
else
298-
Plan.includes(:template, :phases, :roles, :users).where(id: combined_plan_ids)
299-
.where.not(visibility: Plan.visibilities[:privately_visible])
300-
.where.not(visibility: Plan.visibilities[:is_test])
301-
.where(roles: { active: true })
302-
.where(Role.creator_condition)
291+
scope = Plan.includes(:template, :phases, :roles, :users)
292+
.where(id: (native_plan_ids + affiliated_plan_ids).uniq)
293+
.where(roles: { active: true })
294+
.where(Role.creator_condition)
295+
296+
unless Rails.configuration.x.plans.org_admins_read_all
297+
scope = scope.where.not(visibility: Plan.visibilities[:privately_visible])
298+
.where.not(visibility: Plan.visibilities[:is_test])
303299
end
300+
301+
scope
304302
end
305303
# rubocop:enable Metrics/AbcSize
306304

0 commit comments

Comments
 (0)