diff --git a/app/models/concerns/api/v2/hosts_controller_extensions.rb b/app/models/concerns/api/v2/hosts_controller_extensions.rb new file mode 100644 index 000000000..8f4f98416 --- /dev/null +++ b/app/models/concerns/api/v2/hosts_controller_extensions.rb @@ -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 diff --git a/app/views/api/v2/host/main.rabl b/app/views/api/v2/host/main.rabl index c364f0df3..a6db41c11 100644 --- a/app/views/api/v2/host/main.rabl +++ b/app/views/api/v2/host/main.rabl @@ -1,3 +1 @@ attributes :cockpit_url - -extends "api/v2/host/permissions" diff --git a/app/views/api/v2/host/permissions.rabl b/app/views/api/v2/host/permissions.rabl deleted file mode 100644 index 6dd18a1f9..000000000 --- a/app/views/api/v2/host/permissions.rabl +++ /dev/null @@ -1,7 +0,0 @@ -if params.has_key?(:include_permissions) - node do |resource| - if resource&.class&.try(:include?, Authorizable) - node(:can_create_job_invocations) { authorized_for(:auth_object => resource, :authorizer => authorizer, :permission => "create_job_invocations") } - end - end -end diff --git a/lib/foreman_remote_execution/engine.rb b/lib/foreman_remote_execution/engine.rb index b7db148d6..b748fbe34 100644 --- a/lib/foreman_remote_execution/engine.rb +++ b/lib/foreman_remote_execution/engine.rb @@ -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 diff --git a/webpack/react_app/components/FeaturesDropdown/index.js b/webpack/react_app/components/FeaturesDropdown/index.js index ee1a16404..729a6b6ea 100644 --- a/webpack/react_app/components/FeaturesDropdown/index.js +++ b/webpack/react_app/components/FeaturesDropdown/index.js @@ -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 { @@ -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; }