Skip to content

[WIP ] Fix vm provisioning owning group bug - #24002

Open
jrafanie wants to merge 2 commits into
ManageIQ:masterfrom
jrafanie:fix-vm-provisioning-owning-group
Open

jrafanie wants to merge 2 commits into
ManageIQ:masterfrom
jrafanie:fix-vm-provisioning-owning-group

Conversation

@jrafanie

@jrafanie jrafanie commented Oct 7, 2026

Copy link
Copy Markdown
Member

Fixes the following bug:

When you provision a VM, the VM has its group ownership set to the group you were in when you submitted the request. But if you switch your active group between submitting and approving — which is common when an admin approves their own requests — the VM ends up with the wrong group.

For example: User X submits a provision request while in Group A, then switches to Group B to approve it. The VM should be owned by Group A, but instead gets owned by Group B.

… DB group

When a user switches their active group between request creation and provision
time, vm.miq_group should reflect the group active at request time -- not
whatever group is current in the database when the task runs.

The broken path (new failing tests):
  - owner_email is set in options so get_owner returns the user
  - owner_group and requester_group are both absent from options
    (e.g. a legacy or API request that bypassed set_request_values)
  - the user switched current_group in the DB after submitting the request

get_owner finds the user via email but skips current_group_by_description
because owner_group is blank.  get_user is never called because get_owner
returned non-nil.  set_ownership then uses user.current_group -- the live DB
value -- and stamps the wrong group on the VM.

Scenario matrix (owner = provisioning user, R = request-time, P = provision-time):

  owner_email  owner_group  requester_group  R group  P group (DB)  Expected   Result
  present      present      any              U         U             U          pass
  present      present      any              U         S             U          pass (get_owner applies owner_group)
  present      absent       absent           U         S             U          FAIL (new test; DB group S stamped)
  present      absent       present          U         S             U          pass (get_user cache applies requester_group)
  absent       absent       present          U         S             U          pass (get_user applies requester_group)

Two new examples in the 'sets ownership' context reproduce the FAIL row and
are expected to fail until the fix is applied.
When owner_email is set in options but owner_group is absent, get_owner
finds the user via email but never calls current_group_by_description.
set_ownership then uses user.current_group -- the live DB value -- which
will be wrong if the user switched active groups between request creation
and provision time.

set_request_values always stamps requester_group on new requests, so
requester_group is the authoritative fallback for the request-time group
when owner_group is not available.

Fall back to requester_group in get_owner when owner_group is blank:

  group = get_option(:owner_group).presence || get_option(:requester_group)
  owner.current_group_by_description = group if owner && group

This makes the group resolution explicit in get_owner rather than relying
on the side-effect of passing get_user as the email-lookup cache.
@miq-bot

miq-bot commented Oct 9, 2026

Copy link
Copy Markdown
Member

Checked commits jrafanie/manageiq@8f8ffd5~...789e196 with ruby 3.3.12, rubocop 1.91.0, haml-lint 0.78.0, and yamllint 1.37.1
3 files checked, 0 offenses detected
Everything looks fine. 🏆

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants