Skip to content

feat(workspaces): initial pass at workspace permission utility #1865

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

florkbr
Copy link
Contributor

@florkbr florkbr commented Jun 30, 2025

Description

Adds workspace permissions utility hook and ties into the managed selector component.

https://issues.redhat.com/browse/RHCLOUD-40591


Screenshots

Before (or with withPermissions set to false on ManagedSelector props):

image

After:

image


Checklist ☑️

  • PR only fixes one issue or story
  • Change reviewed for extraneous code
  • UI best practices adhered to
  • Commits squashed and meaningfully named
  • All PR checks pass locally (build, lint, test, E2E)

  • (Optional) QE: Needs QE attention (OUIA changed, perceived impact to tests, no test coverage)
  • (Optional) QE: Has been mentioned
  • (Optional) UX: Needs UX attention (end user UX modified, missing designs)
  • (Optional) UX: Has been mentioned

Summary by Sourcery

Add a workspace permissions utility and integrate it into the ManagedSelector to filter and disable unauthorized workspace entries

New Features:

  • Provide a useWorkspacePermissions hook to fetch user workspace RBAC permissions
  • Introduce a canViewWorkspaceById helper to evaluate view permission for individual workspaces

Enhancements:

  • Extend ManagedSelector with a withPermissions flag and pass permission data into the workspace data fetcher
  • Enhance workspace tree builder to mark or disable nodes without view access

Copy link
Contributor

sourcery-ai bot commented Jun 30, 2025

Reviewer's Guide

This PR introduces a workspace permissions utility hook and integrates it into the ManagedSelector component by extending the data fetcher and tree builder to conditionally disable inaccessible workspaces based on user permissions.

Class diagram for WorkspacePermissions utility and integration

classDiagram
    class WorkspacePermissions {
      <<enum>>
      AllPermission
      ReadPermission
      WritePermission
    }
    class WorkspacePermissionsObject {
      <<type>>
      [WorkspacePermissions]: ResourceDefinition[]
    }
    class useWorkspacePermissions {
      +[WorkspacePermissionsObject, Error|undefined] useWorkspacePermissions()
    }
    class canViewWorkspaceById {
      +boolean canViewWorkspaceById(workspaceId: string, workspacePermissions: WorkspacePermissionsObject)
    }
    class ManagedSelector {
      +withPermissions: boolean
    }
    class ManagedSelectorInternal {
      +withPermissions: boolean
    }
    class createWorkspaceDataFetcher {
      +function(storeActions, workspacePermissions)
    }
    class buildWorkspaceTree {
      +function(wps: Workspace[], workspacePermissions: WorkspacePermissionsObject|undefined)
    }
    class TreeViewWorkspaceItem {
      +parentTreeViewItem?: TreeViewWorkspaceItem
      +workspace: Workspace
      +disabled?: boolean
    }
    WorkspacePermissionsObject o-- WorkspacePermissions
    useWorkspacePermissions ..> WorkspacePermissionsObject
    canViewWorkspaceById ..> WorkspacePermissionsObject
    ManagedSelector --> ManagedSelectorInternal
    ManagedSelectorInternal ..> useWorkspacePermissions
    ManagedSelectorInternal ..> createWorkspaceDataFetcher
    createWorkspaceDataFetcher ..> buildWorkspaceTree
    buildWorkspaceTree ..> WorkspacePermissionsObject
    buildWorkspaceTree ..> TreeViewWorkspaceItem
    TreeViewWorkspaceItem --> Workspace
Loading

File-Level Changes

Change Details Files
Added workspace permissions utility hook and helper functions
  • Defined WorkspacePermissions enum and types
  • Implemented useWorkspacePermissions hook fetching user permissions via Chrome API
  • Added canViewWorkspaceById helper to evaluate access by workspace ID
src/smart-components/workspaces/managed-selector/WorkspacePermissions.ts
Extended data fetcher to accept and propagate permissions
  • Updated createWorkspaceDataFetcher signature to take optional workspacePermissions
  • Passed permissions into buildWorkspaceTree call
  • Modified fetcher invocation in ManagedSelectorInternal to use withPermissions flag
src/smart-components/workspaces/managed-selector/ManagedSelector.tsx
Enhanced tree builder to mark disabled items
  • Updated buildWorkspaceTree to accept permissions parameter
  • Inserted logic to prefix and flag nodes as disabled when access is denied
  • Added disabled property to TreeViewWorkspaceItem interface
src/smart-components/workspaces/managed-selector/WorkspaceTreeBuilder.ts
src/smart-components/workspaces/managed-selector/TreeViewWorkspaceItem.ts
Exposed withPermissions prop on ManagedSelector
  • Added withPermissions boolean prop with default true
  • Forwarded prop to internal component to toggle permission-based behavior
src/smart-components/workspaces/managed-selector/ManagedSelector.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

Successfully merging this pull request may close these issues.

1 participant