Skip to content

Conversation

@nofaralfasi
Copy link
Collaborator

@nofaralfasi nofaralfasi commented Jan 8, 2026

What are the changes introduced in this pull request?

Add Insights application permissions for Vulnerability and Advisor

Introduce new Foreman permissions to control access to Insights
applications (Vulnerability and Advisor). These permissions map to
Insights Chrome API permissions for frontend access control.

New permissions added:

  • view_vulnerability: Read access to Vulnerability app data
  • edit_vulnerability: Write access to CVE status, business risk, opt-out
  • view_advisor: Read access to Advisor recommendations and exports
  • edit_advisor: Write access to acknowledge/unacknowledge recommendations

Permissions are organized into two groups for clarity:

  • rh_cloud_permissions: Core inventory upload and sync permissions
  • insights_permissions: Insights app-specific permissions

All permissions are included in the ForemanRhCloud role and added to
default admin roles (ORG_ADMIN, MANAGER, SYSTEM_ADMIN).

Considerations taken when implementing this change?

This is Part 1 of a 3-part PR series. The new permissions should be applied in SCOPED_REQUESTS within app/services/foreman_rh_cloud/insights_api_forwarder.rb.

What are the testing steps for this pull request?

This PR should be tested in conjunction with the other related PRs. For now, ensure that:

  1. The new permissions are visible in the UI.
  2. The permissions exist in the database (this can be verified using the Rails console).

Summary by Sourcery

Add new role-based permissions for controlling access to Insights Vulnerability and Advisor features and include them in the ForemanRhCloud role.

New Features:

  • Introduce view and edit permissions for Insights Vulnerability data and actions.
  • Introduce view and edit permissions for Insights Advisor recommendations and actions.

Enhancements:

  • Extend the ForemanRhCloud role to include the new Insights Vulnerability and Advisor permissions for consistent access control.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 8, 2026

Reviewer's Guide

Adds four new Insights application permissions (Vulnerability and Advisor view/edit) to the Foreman RH Cloud plugin and includes them in the ForemanRhCloud role, setting the stage for finer-grained access control to Insights apps.

Class diagram for ForemanRhCloud plugin permissions including new Insights app permissions

classDiagram
    class ForemanRhCloudPlugin {
      +register()
    }

    class Permission {
      +symbol
      +resource_type
    }

    class Role {
      +name
      +permissions
    }

    class ForemanRhCloudPermissions {
      +view_foreman_rh_cloud
      +generate_foreman_rh_cloud
      +view_insights_hits
      +dispatch_cloud_requests
      +control_organization_insights
    }

    class InsightsAppPermissions {
      +view_vulnerability
      +edit_vulnerability
      +view_advisor
      +edit_advisor
    }

    ForemanRhCloudPlugin "1" --> "*" Permission : defines
    Role "1" --> "*" Permission : includes

    ForemanRhCloudPermissions <|-- InsightsAppPermissions
    Role --> ForemanRhCloudPermissions
    Role --> InsightsAppPermissions
Loading

Flow diagram for adding new Vulnerability and Advisor permissions to ForemanRhCloud role

flowchart TD
    A["ForemanRhCloudPlugin register"] --> B["Define existing core permissions
view_foreman_rh_cloud
generate_foreman_rh_cloud
view_insights_hits
dispatch_cloud_requests
control_organization_insights"]
    B --> C["Define new Insights app permissions
view_vulnerability
edit_vulnerability
view_advisor
edit_advisor
resource_type = ForemanRhCloud"]
    C --> D["Assemble plugin_permissions array
(core + new permissions)"]
    D --> E["Create/extend ForemanRhCloud role
with plugin_permissions"]
    E --> F["ForemanRhCloud role used by admin roles
ORG_ADMIN, MANAGER, SYSTEM_ADMIN"]
Loading

File-Level Changes

Change Details Files
Define new Insights Vulnerability and Advisor permissions on the ForemanRhCloud resource type.
  • Register view_vulnerability permission with resource_type ForemanRhCloud and no explicit actions
  • Register edit_vulnerability permission with resource_type ForemanRhCloud and no explicit actions
  • Register view_advisor permission with resource_type ForemanRhCloud and no explicit actions
  • Register edit_advisor permission with resource_type ForemanRhCloud and no explicit actions
lib/foreman_rh_cloud/plugin.rb
Grant the new Insights permissions to the existing ForemanRhCloud role.
  • Extend plugin_permissions array to include the four new Insights permissions so they are assigned to the ForemanRhCloud role by default
lib/foreman_rh_cloud/plugin.rb

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new insights permissions are all added under ForemanRhCloud without reflecting the described grouping (e.g., rh_cloud_permissions vs insights_permissions), which might be clearer and easier to maintain if expressed as separate arrays/constants composed into plugin_permissions.
  • The ForemanRhCloud role description still only mentions inventory and report-related capabilities; consider updating the description to reflect the newly granted Vulnerability and Advisor permissions so the role’s behavior matches its documented intent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new insights permissions are all added under `ForemanRhCloud` without reflecting the described grouping (e.g., `rh_cloud_permissions` vs `insights_permissions`), which might be clearer and easier to maintain if expressed as separate arrays/constants composed into `plugin_permissions`.
- The `ForemanRhCloud` role description still only mentions inventory and report-related capabilities; consider updating the description to reflect the newly granted Vulnerability and Advisor permissions so the role’s behavior matches its documented intent.

## Individual Comments

### Comment 1
<location> `lib/foreman_rh_cloud/plugin.rb:100-101` </location>
<code_context>
-        plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights]
+        plugin_permissions = [:view_foreman_rh_cloud, :generate_foreman_rh_cloud, :view_insights_hits, :dispatch_cloud_requests, :control_organization_insights, :view_vulnerability, :edit_vulnerability, :view_advisor, :edit_advisor]

         role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
                                                     generate a report, upload it to the cloud and download it locally'
</code_context>

<issue_to_address>
**suggestion:** Update the role description to reflect the new Advisor and Vulnerability permissions.

Since this role now grants `view/edit_vulnerability` and `view/edit_advisor`, the description should also mention the Insights Vulnerability and Advisor access it provides so admins can understand its full scope.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 100 to 107
role 'ForemanRhCloud', plugin_permissions, 'Role granting permissions to view the hosts inventory,
generate a report, upload it to the cloud and download it locally'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Update the role description to reflect the new Advisor and Vulnerability permissions.

Since this role now grants view/edit_vulnerability and view/edit_advisor, the description should also mention the Insights Vulnerability and Advisor access it provides so admins can understand its full scope.

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