Skip to content

Commit

Permalink
Refs #36887 - hide dropdown based on permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Nov 6, 2023
1 parent 31e8636 commit 290e13f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/views/api/v2/host/main.rabl
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
attributes :cockpit_url

extends "api/v2/host/permissions"

Check failure on line 3 in app/views/api/v2/host/main.rabl

View workflow job for this annotation

GitHub Actions / rubocop

Layout/TrailingEmptyLines: Final newline missing.
7 changes: 7 additions & 0 deletions app/views/api/v2/host/permissions.rabl
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 7 in app/views/api/v2/host/permissions.rabl

View workflow job for this annotation

GitHub Actions / rubocop

Layout/TrailingEmptyLines: Final newline missing.
8 changes: 5 additions & 3 deletions webpack/react_app/components/FeaturesDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 290e13f

Please sign in to comment.