From 861af32e7a3302e6beff9325d97fe5218e58065e Mon Sep 17 00:00:00 2001 From: John Pinto Date: Thu, 12 Aug 2021 09:58:28 +0100 Subject: [PATCH] Issue #496 - Fix for search bug of Plans on the "My Dashboard". Changes: - In the search scope in the Plan model the clause where(Role.creator_condition) has been removed. - Paginable::PlansController method org_admin_other_user the paginable_renderiseblock has scope: Plan.active(@user) replaced by scope: Plan.active(@user).where(Role.creator_condition). -In PublicPagesController method plan_index @plans = Plan.publicly_visible.includes(:template) has been replaced by @plans = Plan.where(Role.creator_condition).publicly_visible.includes(:template). --- app/controllers/paginable/plans_controller.rb | 2 +- app/controllers/public_pages_controller.rb | 2 +- app/models/plan.rb | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/paginable/plans_controller.rb b/app/controllers/paginable/plans_controller.rb index e29d26bdf9..f152c5e459 100644 --- a/app/controllers/paginable/plans_controller.rb +++ b/app/controllers/paginable/plans_controller.rb @@ -69,7 +69,7 @@ def org_admin_other_user paginable_renderise( partial: "org_admin_other_user", - scope: Plan.active(@user), + scope: Plan.active(@user).where(Role.creator_condition), query_params: { sort_field: "plans.updated_at", sort_direction: :desc } ) end diff --git a/app/controllers/public_pages_controller.rb b/app/controllers/public_pages_controller.rb index d6dd911315..005dfc73cf 100644 --- a/app/controllers/public_pages_controller.rb +++ b/app/controllers/public_pages_controller.rb @@ -88,7 +88,7 @@ def template_export # GET /plans_index # ------------------------------------------------------------------------------------ def plan_index - @plans = Plan.publicly_visible.includes(:template) + @plans = Plan.where(Role.creator_condition).publicly_visible.includes(:template) render "plan_index", locals: { query_params: { page: paginable_params.fetch(:page, 1), diff --git a/app/models/plan.rb b/app/models/plan.rb index a5fe102007..e687e4f352 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -169,13 +169,11 @@ class Plan < ApplicationRecord scope :search, lambda { |term| if date_range?(term: term) joins(:template, roles: [user: :org]) - .where(Role.creator_condition) .by_date_range(:created_at, term) else search_pattern = "%#{term}%" joins(:template, roles: [user: :org]) .left_outer_joins(:identifiers, :contributors) - .where(Role.creator_condition) .where("lower(plans.title) LIKE lower(:search_pattern) OR lower(orgs.name) LIKE lower (:search_pattern) OR lower(orgs.abbreviation) LIKE lower (:search_pattern)