From 290e13fa87e940c9cbf207b44be3572579c42b49 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Mon, 6 Nov 2023 17:43:16 -0500 Subject: [PATCH] Refs #36887 - hide dropdown based on permissions --- app/views/api/v2/host/main.rabl | 2 ++ app/views/api/v2/host/permissions.rabl | 7 +++++++ webpack/react_app/components/FeaturesDropdown/index.js | 8 +++++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 app/views/api/v2/host/permissions.rabl diff --git a/app/views/api/v2/host/main.rabl b/app/views/api/v2/host/main.rabl index a6db41c11..a2b2e8142 100644 --- a/app/views/api/v2/host/main.rabl +++ b/app/views/api/v2/host/main.rabl @@ -1 +1,3 @@ attributes :cockpit_url + +extends "api/v2/host/permissions" \ No newline at end of file diff --git a/app/views/api/v2/host/permissions.rabl b/app/views/api/v2/host/permissions.rabl new file mode 100644 index 000000000..faad4751b --- /dev/null +++ b/app/views/api/v2/host/permissions.rabl @@ -0,0 +1,7 @@ +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 \ No newline at end of file diff --git a/webpack/react_app/components/FeaturesDropdown/index.js b/webpack/react_app/components/FeaturesDropdown/index.js index 82f0cc490..2c444984b 100644 --- a/webpack/react_app/components/FeaturesDropdown/index.js +++ b/webpack/react_app/components/FeaturesDropdown/index.js @@ -31,9 +31,11 @@ const FeaturesDropdown = ({ hostId, hostSearch, selectedCount }) => { : ALL_REX_FEATURES_URL; const { response, status } = useAPI('get', foremanUrl(rexFeaturesUrl)); const dispatch = useDispatch(); - // eslint-disable-next-line camelcase - const canRunJob = response?.permissions?.can_run_job; - if (isSingleHost && !canRunJob) { + const canRunJob = isSingleHost + ? // eslint-disable-next-line camelcase + response?.permissions?.can_run_job + : response?.results?.some(result => result.can_create_job_invocations); + if (!canRunJob) { return null; }