Skip to content

Discrepancy in Org Admin view of the Organisation Plans and the related CSV Download #3561

Description

@johnpinto1

There is a discrepancy in Org Admin view of the Organisation Plans and the related CSV Download.
The CSV download shows de-activated plans whilst the view only displays active plans.

The code for both use the same method org_admin_plans in the Org model

roadmap/app/models/org.rb

Lines 287 to 302 in bfbb518

# This replaces the old plans method. We now use the native plans method and this.
# rubocop:disable Metrics/AbcSize
def org_admin_plans
combined_plan_ids = (native_plan_ids + affiliated_plan_ids).flatten.uniq
if Rails.configuration.x.plans.org_admins_read_all
Plan.includes(:template, :phases, :roles, :users).where(id: combined_plan_ids)
.where(roles: { active: true })
else
Plan.includes(:template, :phases, :roles, :users).where(id: combined_plan_ids)
.where.not(visibility: Plan.visibilities[:privately_visible])
.where.not(visibility: Plan.visibilities[:is_test])
.where(roles: { active: true })
end
end
# rubocop:enable Metrics/AbcSize

The paginable method org_admin for Org Admin plans by including the filter condition where(Role.creator_condition) ensures the view for Org Admins and Super Admins only see active plans (as we set Role of the creator (owner or co-owner who removes plan) to active: false).

# GET /paginable/plans/org_admin/:page
# rubocop:disable Metrics/AbcSize
def org_admin
raise Pundit::NotAuthorizedError unless current_user.present? && current_user.can_org_admin?
# check if current user if super_admin
@super_admin = current_user.can_super_admin?
@clicked_through = params[:click_through].present?
plans = @super_admin ? Plan.all : current_user.org.org_admin_plans
plans = plans.joins(:template, roles: [user: :org]).where(Role.creator_condition)
paginable_renderise(
partial: 'org_admin',
scope: plans,
view_all: !current_user.can_super_admin?,
query_params: { sort_field: 'plans.updated_at', sort_direction: :desc },
format: :json
)
end
# rubocop:enable Metrics/AbcSize

We think discrepancy between view and download data should be fixed in Org model's method org_admin_plans rather than having it done in the paginable method org_admin as the former method is used in several places:

app/models/plan.rb
172: plan_ids = user.org.org_admin_plans.where(complete: true).pluck(:id).uniq

app/controllers/paginable/plans_controller.rb
48: plans = @super_admin ? Plan.all : current_user.org.org_admin_plans

app/controllers/api/v0/plans_controller.rb
75: org_admin_plans = @user.org.org_admin_plans

app/controllers/org_admin/plans_controller.rb
23: current_user.org.org_admin_plans.page(1)
71: org.org_admin_plans.includes(template: :org).order(updated_at: :desc).each do |plan|

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions