Skip to content

Refactor method Org#plans? #2724

@nicolasfranck

Description

@nicolasfranck

Please complete the following fields as applicable:

Expected behaviour:

The method Org#plans should only return plans of the current Org.

Actual behaviour:

It also returns plans of other orgs.

Besides, it generates very large queries, that are reexecuted every time someone uses org.plans
in his code. If I remove this method, and so use the more simple (and cached) relation plans,
the global page loading time goes from 4s to 40ms.

Reason: The relation plans in the model Org is defined,
but overridden a few lines further (https://github.com/DMPRoadmap/roadmap/blob/master/app/models/org.rb#L287).
But that last method is slow and does not work as expected.

How it works now:

  • Select all roles with active:true, access in set of administrative, and user_id in list of org.users.pluck(:id)
  • Pluck attribute plan_id, make it unique, and store it in plan_ids
  • Fetch all plans with id in list of plan_ids

Why it does not work: some users can have administrative rights to plans that actually belong to another organisation

Is this intended behaviour?

Steps to reproduce:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions