Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36751 - check permissions for schedule job button #836

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def update
process_response @remote_execution_feature.update(remote_execution_feature_params)
end

api :GET, '/api/hosts/:id/available_remote_execution_features', N_('List available remote execution features for a host')
param :id, :identifier, :required => true
def available_remote_execution_features
host = Host.find(params[:id])
@remote_execution_features = resource_scope
@permissions = {:can_run_job => (authorized_for(controller: :job_invocations, action: :create) && (!host.infrastructure_host? || User.current.can?(:execute_jobs_on_infrastructure_hosts))) }
adamruzicka marked this conversation as resolved.
Show resolved Hide resolved
end

private

def parent_scope
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node :permissions do
@permissions
end
child @remote_execution_features do
extends 'api/v2/remote_execution_features/main'
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
resources :foreign_input_sets, :only => [:index, :show, :create, :destroy, :update]
end

get 'hosts/:id/available_remote_execution_features', to: 'remote_execution_features#available_remote_execution_features'

resources :remote_execution_features, :only => [:show, :index, :update]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/foreman_remote_execution/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Engine < ::Rails::Engine
:'api/v2/template_inputs' => [:create, :update, :destroy],
:'api/v2/foreign_input_sets' => [:create, :update, :destroy]}, :resource_type => 'JobTemplate'
permission :edit_remote_execution_features, { :remote_execution_features => [:index, :show, :update],
:'api/v2/remote_execution_features' => [:index, :show, :update]}, :resource_type => 'RemoteExecutionFeature'
:'api/v2/remote_execution_features' => [:index, :show, :update, :available_remote_execution_features]}, :resource_type => 'RemoteExecutionFeature'
permission :destroy_job_templates, { :job_templates => [:destroy],
:'api/v2/job_templates' => [:destroy] }, :resource_type => 'JobTemplate'
permission :lock_job_templates, { :job_templates => [:lock, :unlock] }, :resource_type => 'JobTemplate'
Expand Down
3 changes: 2 additions & 1 deletion webpack/react_app/components/FeaturesDropdown/constant.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const REX_FEATURES_API = '/api/remote_execution_features';
export const REX_FEATURES_API = host =>
`/api/v2/hosts/${host}/available_remote_execution_features`;
export const NEW_JOB_PAGE = '/job_invocations/new?host_ids%5B%5D';
16 changes: 11 additions & 5 deletions webpack/react_app/components/FeaturesDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ import { runFeature } from './actions';

const FeaturesDropdown = ({ hostId }) => {
const [isOpen, setIsOpen] = useState(false);
const {
response: { results: features },
status,
} = useAPI('get', foremanUrl(REX_FEATURES_API));

const { response, status } = useAPI(
'get',
foremanUrl(REX_FEATURES_API(hostId))
);
const dispatch = useDispatch();
// eslint-disable-next-line camelcase
const canRunJob = response?.permissions?.can_run_job;
if (!canRunJob) {
return null;
}
// eslint-disable-next-line camelcase
const features = response?.remote_execution_features;
const dropdownItems = features
?.filter(feature => feature.host_action_button)
?.map(({ name, label, id, description }) => (
Expand Down
Loading