Skip to content

Commit

Permalink
Added cluster validation to projects.show page to disable script acti…
Browse files Browse the repository at this point in the history
…ons (#3257)

* Added cluster validation to projects.show page to disable script actions

* Improved check for empty clusters in script validation
  • Loading branch information
abujeda authored Dec 20, 2023
1 parent d0c3788 commit ef3dd02
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions apps/dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def show
redirect_to(projects_path, alert: I18n.t('dashboard.jobs_project_not_found', project_id: project_id))
else
@scripts = Script.all(@project.directory)
@valid_project = Script.clusters?
flash.now[:alert] = I18n.t("dashboard.jobs_project_invalid_configuration_clusters") unless @valid_project
end
end

Expand Down
5 changes: 5 additions & 0 deletions apps/dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def from_yaml(file, project_dir)
def next_id
SecureRandom.alphanumeric(8).downcase
end

def clusters?
cluster_attribute = SmartAttributes::AttributeFactory.build('auto_batch_clusters', {})
cluster_attribute.select_choices(hide_excludable: false).any?
end
end

def initialize(opts = {})
Expand Down
17 changes: 11 additions & 6 deletions apps/dashboard/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<%= javascript_include_tag 'projects', nonce: true %>
<%-
disabled = !@valid_project
disabled_class = disabled ? 'disabled' : ''
-%>

<div class='page-header text-center'>
<h1 class="my-2"><%= @project.title %></h1>
Expand Down Expand Up @@ -48,21 +52,21 @@
<%= link_to(
t('dashboard.show'),
project_script_path(@project.id, script.id),
class: 'btn btn-success mx-1'
class: "btn btn-success mx-1 #{disabled_class}"
)
%>

<%= link_to(
t('dashboard.edit'),
edit_project_script_path(@project.id, script.id),
class: 'btn btn-primary mx-1',
class: "btn btn-primary mx-1 #{disabled_class}",
)
%>

<%= link_to(
t('dashboard.delete'),
project_script_path(@project.id, script.id),
class: 'btn btn-danger mx-1',
class: "btn btn-danger mx-1 #{disabled_class}",
method: 'delete',
data: { confirm: I18n.t('dashboard.jobs_scripts_delete_script_confirmation') },
)
Expand All @@ -75,9 +79,10 @@
<%= button_to(
t('dashboard.batch_connect_form_launch'),
submit_project_script_path(@project.id, script.id),
class: 'btn btn-secondary mx-1',
class: "btn btn-secondary mx-1",
title: 'Launch script with cached values',
data: {:method => "post"},
disabled: disabled,
params: params
)
%>
Expand All @@ -88,9 +93,9 @@
</tbody>
</table>

<%= link_to('New Script',
<%= link_to('New Script',
new_project_script_path(@project.id),
class: 'btn btn-info',
class: "btn btn-info #{disabled_class}",
title: I18n.t('dashboard.jobs_project_create_new_project_directory'))
%>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ en:
jobs_project_validation_error: "Invalid Request. Please review the errors below"
jobs_project_save_error: "Cannot save manifest to %{path}"
jobs_project_generic_error: "There was an error processing your request: %{error}"
jobs_project_invalid_configuration_clusters: "An HPC cluster is required. Contact your administrator to add one to the system."

jobs_scripts_created: "Script successfully created!"
jobs_scripts_updated: "Script manifest updated!"
Expand Down
13 changes: 13 additions & 0 deletions apps/dashboard/test/models/script_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ class ScriptTest < ActiveSupport::TestCase
assert target.send('attribute_parameter?', 'account_exclude')
assert target.send('attribute_parameter?', 'account_fixed')
end

test 'clusters? return false when auto_batch_clusters returns no clusters' do
Configuration.stubs(:job_clusters).returns([])

assert_equal false, Script.clusters?
end

test 'clusters? return true when auto_batch_clusters returns clusters' do
Configuration.stubs(:job_clusters).returns(OodCore::Clusters.load_file('test/fixtures/config/clusters.d'))

assert_equal true, Script.clusters?
end

test 'creates script' do
Dir.mktmpdir do |tmp|
projects_path = Pathname.new(tmp)
Expand Down

0 comments on commit ef3dd02

Please sign in to comment.