Scope issues dashboard to organizations

What does this MR do and why?

Scopes the "Your Work" issues dashboard to a specific organization. Currently if a user is a member of multiple organizations then the dashboard shows issues from all organizations. After this change, the issues dashboard URL is now scoped: /dashboard/issues to /o/my-organization/dashboard_issues and the issues displayed are confined to that organization.

References

#568126

Database

The only change to the query is the addition of where organization_id = 1234. My understanding is that this query already performed quite poorly. I don't believe this addition changes the performance by any measurable factor but please advise if you see some optimization. Timings vary each time I test the query but the below timings seem to accurately reflect the lack of difference between the before and after query.

Before:

Time: 1.853 s  
  - planning: 13.771 ms  
  - execution: 1.840 s  
    - I/O read: 1.808 s  
    - I/O write: 0.000 ms  

After:

Time: 1.820 s  
  - planning: 16.000 ms  
  - execution: 1.804 s  
    - I/O read: 1.774 s  
    - I/O write: 0.000 ms  

Explain

SELECT
    issues.id,
    issues.title,
    issues.author_id,
    issues.project_id,
    issues.created_at,
    issues.updated_at,
    issues.description,
    issues.milestone_id,
    issues.iid,
    issues.updated_by_id,
    issues.weight,
    issues.confidential,
    issues.due_date,
    issues.moved_to_id,
    issues.lock_version,
    issues.title_html,
    issues.description_html,
    issues.time_estimate,
    issues.relative_position,
    issues.service_desk_reply_to,
    issues.cached_markdown_version,
    issues.last_edited_at,
    issues.last_edited_by_id,
    issues.discussion_locked,
    issues.closed_at,
    issues.closed_by_id,
    issues.state_id,
    issues.duplicated_to_id,
    issues.promoted_to_epic_id,
    issues.health_status,
    issues.sprint_id,
    issues.blocking_issues_count,
    issues.upvotes_count,
    issues.work_item_type_id,
    issues.namespace_id,
    issues.start_date,
    issues.imported_from,
    issues.namespace_traversal_ids
FROM
    issues
    JOIN projects ON projects.id = issues.project_id
    LEFT JOIN project_features ON projects.id = project_features.project_id
WHERE
    (
        NOT EXISTS (
            SELECT
                1
            FROM
                banned_users
            WHERE
                banned_users.user_id = ( issues.author_id + 0 )
        )
    ) AND
    (
        EXISTS (
            SELECT
                1
            FROM
                project_authorizations
            WHERE
                project_authorizations.user_id = 13356 AND
                project_authorizations.project_id = projects.id AND
                project_authorizations.access_level >= 10
        ) OR
        projects.visibility_level IN ( 10, 20 )
    ) AND
    (
        project_features.issues_access_level IS NULL OR
        project_features.issues_access_level IN ( 20, 30 ) OR
        (
            project_features.issues_access_level = 10 AND
            EXISTS (
                SELECT
                    1
                FROM
                    project_authorizations
                WHERE
                    project_authorizations.user_id = 13356 AND
                    project_authorizations.project_id = project_features.project_id AND
                    project_authorizations.access_level >= 10
            )
        )
    ) AND
    projects.organization_id = 1 AND
    issues.state_id = 1 AND
    EXISTS (
        SELECT
            issue_assignees.*
        FROM
            issue_assignees
        WHERE
            issue_assignees.user_id = 13356 AND
            issue_id = issues.id
    ) AND
    (
        issues.project_id IS NULL OR
        projects.archived = false
    ) AND
    issues.work_item_type_id IN ( 1, 2, 5 )
ORDER BY
    issues.created_at DESC,
    issues.id DESC
LIMIT 21;

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Pull the changes from this MR. Then you must restart rails-web since there are routing changes: gdk restart rails-web

  2. Enable the organizations-related feature flags:

    Feature.enable :ui_for_organizations
    Feature.enable :organization_switching
    Feature.enable :organization_scoped_paths
  3. Create a new organization in + menu > New organization.

  4. Create at least one group, one project and one issue in the new organization. Create a group in the new organization by first choosing the new organization in the switcher dropdown, then + menu > New group. The project will be scoped to the organization by choosing the newly created group as the namespace for the project.

  5. Assign yourself when you create the issue.

  6. Ensure the new organization is selected from the switcher dropdown.

  7. Visit Issues in the "Your work" sidebar.

  8. Observe that you will see only the new issue you assigned yourself.

  9. Ensure the Default organization is selected from the switcher dropdown.

  10. Visit Issues in the "Your work" sidebar.

  11. Observe that you will see all of your previously assigned issues.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Drew Blessing

Merge request reports

Loading