Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does method Org#org_admin_plans include plans with same org_id? #3346

Open
nicolasfranck opened this issue Sep 29, 2023 · 1 comment
Open

Comments

@nicolasfranck
Copy link
Contributor

Please complete the following fields as applicable:

What version of the DMPRoadmap code are you running? (e.g. v2.2.0)

4.1.0

Behaviour:

I see that method Org#org_admin_plans
not only lists plans with owners and coowners of that same organization, but also plans that happen to have the attribute org_id set to that organization:

combined_plan_ids = (native_plan_ids + affiliated_plan_ids).flatten.uniq

where native_plan_ids is equal to SELECT * FROM plans where org_id = ?

In PlansController#create the plan.org_id is often set to organization of the logged in user. So in that case the organization is equal to the organization of the owner. No problem here

But on this line

if plan_params[:org].present? && plan_params[:org][:id].present?
        attrs = plan_params[:org]
        attrs[:org_id] = attrs[:id]
        @plan.org = org_from_params(params_in: attrs, allow_create: false)

.. plan.org_id is set to the organization of the selected primary research organization, as I understand.

I see that this method is used on these pages:

  • /org_admin/plans
  • /api/v0/plans

Is this intended? I would expect that the org admin would only receive a list of plans
that he/she is affiliated with.

Access policy is different though, and correct in my opinion

@aaronskiba
Copy link
Contributor

I think this issue relates to #3345.

  # app/models/plan.rb
  # Retrieves any plan organisationally or publicly visible for a given org id
  scope :organisationally_or_publicly_visible, lambda { |user|
    plan_ids = user.org.org_admin_plans.where(complete: true).pluck(:id).uniq
    includes(:template, roles: :user)
      .where(id: plan_ids, visibility: [
               visibilities[:organisationally_visible],
               visibilities[:publicly_visible]
             ])
      .where(
        'NOT EXISTS (SELECT 1 FROM roles WHERE plan_id = plans.id AND user_id = ?)',
        user.id
      )
  }

The above scope is used to populate the "Organizational plans" section on the /plans page. However, I think that unwanted plans may be listed here due to the inclusion of native_plan_ids.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants