diff --git a/apps/dashboard/app/controllers/projects_controller.rb b/apps/dashboard/app/controllers/projects_controller.rb index bf029d032e..1db4279ef2 100644 --- a/apps/dashboard/app/controllers/projects_controller.rb +++ b/apps/dashboard/app/controllers/projects_controller.rb @@ -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 diff --git a/apps/dashboard/app/models/script.rb b/apps/dashboard/app/models/script.rb index 15e678c295..ce7157d740 100644 --- a/apps/dashboard/app/models/script.rb +++ b/apps/dashboard/app/models/script.rb @@ -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 = {}) diff --git a/apps/dashboard/app/views/projects/show.html.erb b/apps/dashboard/app/views/projects/show.html.erb index ad565cd661..9b7c13e6e2 100644 --- a/apps/dashboard/app/views/projects/show.html.erb +++ b/apps/dashboard/app/views/projects/show.html.erb @@ -1,4 +1,8 @@ <%= javascript_include_tag 'projects', nonce: true %> +<%- + disabled = !@valid_project + disabled_class = disabled ? 'disabled' : '' +-%> diff --git a/apps/dashboard/config/locales/en.yml b/apps/dashboard/config/locales/en.yml index cec98ab4f2..9f9149b3cc 100644 --- a/apps/dashboard/config/locales/en.yml +++ b/apps/dashboard/config/locales/en.yml @@ -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!" diff --git a/apps/dashboard/test/models/script_test.rb b/apps/dashboard/test/models/script_test.rb index 087ff02bc2..efcdf548c2 100644 --- a/apps/dashboard/test/models/script_test.rb +++ b/apps/dashboard/test/models/script_test.rb @@ -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)