Skip to content

Commit

Permalink
Refs #36887 - use general permission, not per-host
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Nov 21, 2023
1 parent fdd71fe commit 681168e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
12 changes: 12 additions & 0 deletions app/models/concerns/api/v2/hosts_controller_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Api
module V2
module HostsControllerExtensions
extend ActiveSupport::Concern
def index_node_permissions
super.merge({
:can_create_job_invocations => authorized_for(:controller => 'job_invocations', :action => 'create'),
})
end
end
end
end
2 changes: 0 additions & 2 deletions app/views/api/v2/host/main.rabl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
attributes :cockpit_url

extends "api/v2/host/permissions"
7 changes: 0 additions & 7 deletions app/views/api/v2/host/permissions.rabl

This file was deleted.

1 change: 1 addition & 0 deletions lib/foreman_remote_execution/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ class Engine < ::Rails::Engine

ForemanRemoteExecution.register_rex_feature

::Api::V2::HostsController.include Api::V2::HostsControllerExtensions
::Api::V2::SubnetsController.include ::ForemanRemoteExecution::Concerns::Api::V2::SubnetsControllerExtensions
::Api::V2::RegistrationController.prepend ::ForemanRemoteExecution::Concerns::Api::V2::RegistrationControllerExtensions
::Api::V2::RegistrationController.include ::ForemanRemoteExecution::Concerns::Api::V2::RegistrationControllerExtensions::ApipieExtensions
Expand Down
12 changes: 6 additions & 6 deletions webpack/react_app/components/FeaturesDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { push } from 'connected-react-router';

import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
import { translate as __ } from 'foremanReact/common/I18n';
import { foremanUrl } from 'foremanReact/common/helpers';
import { foremanUrl, propsToCamelCase } from 'foremanReact/common/helpers';
import { STATUS } from 'foremanReact/constants';

import {
Expand All @@ -36,12 +36,12 @@ const FeaturesDropdown = ({
: ALL_REX_FEATURES_URL;
const { response, status } = useAPI('get', foremanUrl(rexFeaturesUrl));
const dispatch = useDispatch();
const permissions = propsToCamelCase(
(isSingleHost ? response?.permissions : hostResponse?.response) || {}
);
const canRunJob = isSingleHost
? // eslint-disable-next-line camelcase
response?.permissions?.can_run_job
: hostResponse?.response?.results?.some(
result => result.can_create_job_invocations
);
? permissions.canRunJob
: permissions.canCreateJobInvocations;
if (!canRunJob) {
return null;
}
Expand Down

0 comments on commit 681168e

Please sign in to comment.