Skip to content

Conversation

@jnovinger
Copy link
Member

Fixes: #20929

  • Modified ObjectRenderConfigView.has_permission() to require both view and render_config permissions
  • Added remove_permissions() test helper to remove permissions from existing ObjectPermission objects
  • Added regression tests for Device and VirtualMachine render-config permission enforcement

The render_config permission action was introduced in #16681 for API endpoints. This extends PR_7604_description to the UI render-config tabs, preventing users from viewing rendered configurations without explicit permission.

- Modified `ObjectRenderConfigView.has_permission()` to require both view and render_config permissions
- Added `remove_permissions()` test helper to remove permissions from existing ObjectPermission objects
- Added regression tests for Device and VirtualMachine render-config permission enforcement

The `render_config` permission action was introduced in #16681 for API endpoints. This extends PR_7604_description
to the UI render-config tabs, preventing users from viewing rendered configurations without explicit permission.
@jnovinger jnovinger requested review from a team and jeremystretch and removed request for a team December 12, 2025 19:24
Comment on lines +2343 to +2344
@tag('regression') # #20929
def test_device_renderconfig_permission(self):
Copy link
Member

Choose a reason for hiding this comment

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

Could we make this a standard view test?

Suggested change
@tag('regression') # #20929
def test_device_renderconfig_permission(self):
def test_device_renderconfig(self):

Comment on lines +330 to +331
@tag('regression') # #20929
def test_virtualmachine_renderconfig_permission(self):
Copy link
Member

Choose a reason for hiding this comment

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

Same question as above.

actions__contains=[action], object_types=object_type, users=self.user
)
for obj_perm in obj_perms:
obj_perm.users.remove(self.user)
Copy link
Member

Choose a reason for hiding this comment

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

add_permissions() creates a new ObjectPermission instance for each permission passed, so it might be prudent to simply delete the instance here instead of removing the assigned user. (This approach could also create a name conflict if calling add_permissions() after remove_permissions() for the same model & action.)

if super().has_permission(): # enforce base required permission
perm = get_permission_for_model(self.queryset.model, 'render_config')
if self.request.user.has_perm(perm):
self.queryset = self.queryset.restrict(self.request.user, 'render_config')
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to avoid altering the queryset directly here if we can. Instead, how about just adding the necessary permission by name to additional_permissions under each view?

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.

3 participants