Skip to content

[6.19.z] hostgroup nonadmin viewer read - #20886

Merged
Satellite-QE merged 1 commit into
6.19.zfrom
cherry-pick-6.19.z-0da20aba3a316b090dff2355ba0b152b2a213a94
Feb 26, 2026
Merged

[6.19.z] hostgroup nonadmin viewer read#20886
Satellite-QE merged 1 commit into
6.19.zfrom
cherry-pick-6.19.z-0da20aba3a316b090dff2355ba0b152b2a213a94

Conversation

@Satellite-QE

@Satellite-QE Satellite-QE commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

Cherrypick of PR: #20875

Problem Statement

New test coverage for bug SAT-38451: Non-admin users on Satellite with viewer role, unable to see the hostgroup.

Solution

Ensure that non-admin user with viewer role can see hostgroup created by admin user.

Also added new UserFactory class to help with more reusable user fixtures.

PRT

trigger: test-robottelo
pytest: tests/foreman/ui/test_hostgroup.py -k test_positive_non_admin_viewer_role_read

Summary by Sourcery

Add UI test coverage ensuring non-admin users with the Viewer role can see host groups created by an admin, and introduce reusable user and hostgroup fixtures to support this scenario.

New Features:

  • Introduce a UserFactory helper to create user objects with defaulted passwords for reuse in fixtures.
  • Add a module-scoped fixture for host groups associated with a specific organization and location.
  • Add a module-scoped fixture for non-admin users with the Viewer role assigned.

Enhancements:

  • Refactor existing viewer-role user fixture to use the new UserFactory helper and share a common Viewer role fixture.

Tests:

  • Add a UI test verifying that a non-admin user with the Viewer role can view host groups created by an admin user.

hostgroups: new test for non-admin viewer role

Verifies: SAT-38451

New test for bug "Non-admin users on Satellite with viewer role, unable to see the hostgroup."
Ensure that non-admin user with viewer role can see hostgroup created by admin user.

Also added new `UserFactory` class to help with more reusable user fixtures.

(cherry picked from commit 0da20ab)
@Satellite-QE Satellite-QE added 6.19.z Auto_Cherry_Picked Automatically cherrypicked PR using GHA No-CherryPick PR doesnt need CherryPick to previous branches labels Feb 26, 2026
@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

trigger: test-robottelo
pytest: tests/foreman/ui/test_hostgroup.py -k test_positive_non_admin_viewer_role_read

@Satellite-QE Satellite-QE added the AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing label Feb 26, 2026
@Satellite-QE
Satellite-QE merged commit 728a881 into 6.19.z Feb 26, 2026
20 checks passed
@Satellite-QE
Satellite-QE deleted the cherry-pick-6.19.z-0da20aba3a316b090dff2355ba0b152b2a213a94 branch February 26, 2026 09:42
@Satellite-QE

Copy link
Copy Markdown
Collaborator Author

PRT Result

Build Number: 14492
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_hostgroup.py -k test_positive_non_admin_viewer_role_read --external-logging
Test Result : =========== 1 passed, 7 deselected, 8 warnings in 1144.45s (0:19:04) ===========

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Feb 26, 2026
@sourcery-ai

sourcery-ai Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds UI test coverage to verify that a non-admin user with the Viewer role can see host groups created by an admin, and introduces reusable fixtures (including a UserFactory and hostgroup fixture with org/location) to support this scenario.

Sequence diagram for non-admin Viewer user reading host group

sequenceDiagram
    actor AdminUser
    actor ViewerUser
    participant UITest as UITestRunner
    participant SatUI as Satellite_UI
    participant SatAPI as Satellite_API

    UITest->>AdminUser: Use admin credentials
    AdminUser->>SatUI: Login
    SatUI->>SatAPI: Authenticate admin
    SatAPI-->>SatUI: Admin session

    AdminUser->>SatUI: Create host group (with org and location)
    SatUI->>SatAPI: HostGroup.create(organization, location)
    SatAPI-->>SatUI: Host group created

    UITest->>ViewerUser: Use viewer credentials (fixture module_user_viewer)
    ViewerUser->>SatUI: Login
    SatUI->>SatAPI: Authenticate viewer (non-admin, Viewer role)
    SatAPI-->>SatUI: Viewer session

    ViewerUser->>SatUI: Navigate to Host Groups page
    SatUI->>SatAPI: HostGroup.search(filters: organization, location)
    SatAPI-->>SatUI: List including admin-created host group
    SatUI-->>ViewerUser: Host group visible in UI
Loading

Class diagram for new UserFactory and related fixtures

classDiagram
    class UserFactory {
      +create_user(target_sat, params) User
    }

    class Satellite {
      api
    }

    class APIUser {
      +admin : bool
      +default_organization
      +location
      +organization
      +role
      +password
      +create()
    }

    class Role {
    }

    class HostGroup {
      +organization
      +location
      +create()
    }

    class viewer_role_fixture {
    }

    class default_viewer_role_fixture {
    }

    class module_user_viewer_fixture {
    }

    class module_hostgroup_with_org_loc_fixture {
    }

    UserFactory ..> APIUser : creates
    Satellite "1" *-- "many" APIUser : api.User
    Satellite "1" *-- "many" Role : api.Role
    Satellite "1" *-- "many" HostGroup : api.HostGroup

    viewer_role_fixture ..> Role : returns
    default_viewer_role_fixture ..> UserFactory : uses
    default_viewer_role_fixture ..> viewer_role_fixture : uses

    module_user_viewer_fixture ..> UserFactory : uses
    module_user_viewer_fixture ..> viewer_role_fixture : uses

    module_hostgroup_with_org_loc_fixture ..> HostGroup : creates
Loading

File-Level Changes

Change Details Files
Introduce a reusable UserFactory and shared Viewer role fixture for user-related tests.
  • Add UserFactory helper class with a static create_user method that ensures a password is set, creates the API user, and stores the password on the returned object.
  • Add a session-scoped viewer_role fixture that searches for and returns the existing Viewer role from Satellite.
  • Refactor the default_viewer_role fixture to use the shared viewer_role fixture and the UserFactory instead of manually creating the user and password.
  • Add a module_user_viewer fixture that creates a non-admin user with the Viewer role scoped to a specific organization and location via UserFactory.
pytest_fixtures/component/user_role.py
Add a hostgroup fixture bound to specific organization and location to support visibility tests.
  • Introduce module_hostgroup_with_org_loc fixture that creates a HostGroup associated with a given organization and location.
pytest_fixtures/component/hostgroup.py
Add UI test ensuring non-admin Viewer-role user can view host groups created by admin user.
  • Add test_positive_non_admin_viewer_role_read UI test that logs in as a Viewer-role non-admin user, selects the appropriate organization and location, and asserts that the host group created with org/location is visible in the host group list.
tests/foreman/ui/test_hostgroup.py

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In test_positive_non_admin_viewer_role_read, indexing directly into session.hostgroup.search(...)[0]['Name'] will raise an IndexError if the host group isn’t found; consider first asserting that the search result is non-empty (or using a more defensive pattern like checking any() over the results) so the failure clearly indicates that the host group was not visible rather than surfacing as an index error.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `test_positive_non_admin_viewer_role_read`, indexing directly into `session.hostgroup.search(...)[0]['Name']` will raise an `IndexError` if the host group isn’t found; consider first asserting that the search result is non-empty (or using a more defensive pattern like checking `any()` over the results) so the failure clearly indicates that the host group was not visible rather than surfacing as an index error.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.19.z Auto_Cherry_Picked Automatically cherrypicked PR using GHA AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing No-CherryPick PR doesnt need CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants