Skip to content

Commit

Permalink
disabling the edit link for disabled automated workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ksierks committed Oct 30, 2024
1 parent 04de08e commit d9bf81e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ def new
end
end

def edit
def edit # rubocop:disable Metrics/MethodLength
authorize! @namespace, to: :update_automated_workflow_executions?
@workflow = Irida::Pipelines.instance.find_pipeline_by(@automated_workflow_execution.metadata['workflow_name'],
@automated_workflow_execution.metadata['workflow_version'],
'available')
render turbo_stream: turbo_stream.update('automated_workflow_execution_modal',
partial: 'edit_dialog',
locals: {
open: true
}), status: :ok

respond_to do |format|
format.turbo_stream do
if @automated_workflow_execution.disabled
render status: :unprocessable_entity,
locals: {
type: 'alert', message: t('.error',
workflow_name: @automated_workflow_execution.id)
}
else
render status: :ok
end
end
end
end

def create # rubocop:disable Metrics/MethodLength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer",
) %>
<%= link_to t(:"projects.automated_workflow_executions.actions.edit_button"),
<%= link_to_if !automated_workflow_execution.disabled,
t(:"projects.automated_workflow_executions.actions.edit_button"),
edit_namespace_project_automated_workflow_execution_path(
@project.parent,
@project,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% if @automated_workflow_execution.disabled %>
<%= turbo_stream.append "flashes" do %>
<%= viral_flash(type:, data: message) %>
<% end %>
<% else %>
<%= turbo_stream.update(
"automated_workflow_execution_modal",
partial: "edit_dialog",
locals: {
open: true,
},
) %>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,8 @@ en:
destroy:
error: Could not delete automated pipeline for %{workflow_name}
success: Automated pipeline for %{workflow_name} was successfully deleted
edit:
error: Cannot edit automated pipeline %{workflow_name}
edit_dialog:
title: 'Editing Automated Pipeline: %{workflow_name}'
index:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,8 @@ fr:
destroy:
error: Could not delete automated pipeline for %{workflow_name}
success: Automated pipeline for %{workflow_name} was successfully deleted
edit:
error: Cannot edit automated pipeline %{workflow_name}
edit_dialog:
title: 'Editing Automated Pipeline: %{workflow_name}'
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ class AutomatedWorkflowExecutionsControllerTest < ActionDispatch::IntegrationTes
end

test 'can destroy a automated workflow execution for a project' do
assert_equal 2, @project.namespace.automated_workflow_executions.count
assert_equal 3, @project.namespace.automated_workflow_executions.count

automated_workflow_execution = automated_workflow_executions(:valid_automated_workflow_execution)

delete namespace_project_automated_workflow_execution_path(@namespace, @project, automated_workflow_execution,
format: :turbo_stream)

assert_equal 1, @project.namespace.automated_workflow_executions.count
assert_equal 2, @project.namespace.automated_workflow_executions.count

assert_response :success
end
Expand Down Expand Up @@ -141,22 +141,35 @@ class AutomatedWorkflowExecutionsControllerTest < ActionDispatch::IntegrationTes
assert_response :unauthorized
end

test 'can get the edit page to update a automated workflow execution for a project' do
test 'can get the edit page to update an automated workflow execution for a project' do
sign_in users(:john_doe)

automated_workflow_execution = automated_workflow_executions(:valid_automated_workflow_execution)

get edit_namespace_project_automated_workflow_execution_path(@namespace, @project, automated_workflow_execution)
get edit_namespace_project_automated_workflow_execution_path(@namespace, @project, automated_workflow_execution,
params: { format: :turbo_stream })

assert_response :success
end

test 'cannot access the edit page to update a automated workflow execution with incorrect permissions' do
test 'cannot access the edit page to update a disabled automated workflow execution' do
sign_in users(:john_doe)

automated_workflow_execution = automated_workflow_executions(:disabled_automated_workflow_execution)

get edit_namespace_project_automated_workflow_execution_path(@namespace, @project, automated_workflow_execution,
params: { format: :turbo_stream })

assert_response :unprocessable_entity
end

test 'cannot access the edit page to update an automated workflow execution with incorrect permissions' do
sign_in users(:ryan_doe)

automated_workflow_execution = automated_workflow_executions(:valid_automated_workflow_execution)

get edit_namespace_project_automated_workflow_execution_path(@namespace, @project, automated_workflow_execution)
get edit_namespace_project_automated_workflow_execution_path(@namespace, @project, automated_workflow_execution,
params: { format: :turbo_stream })

assert_response :unauthorized
end
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/automated_workflow_executions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ invalid_metadata_automated_workflow_execution:
email_notification: true
update_samples: false

disabled_automated_workflow_execution:
name: "Disabled Automated Workflow Execution"
namespace_id: <%= ActiveRecord::FixtureSet.identify(:project1_namespace, :uuid) %>
created_by_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %>
metadata:
{
"workflow_name": "phac-nml/iridanextexample",
"workflow_version": "1.0.2",
}
workflow_params: { "assembler": "stub" }
email_notification: true
update_samples: false
disabled: true

projectA_automated_workflow_execution_one:
namespace_id: <%= ActiveRecord::FixtureSet.identify(:projectA_namespace, :uuid) %>
created_by_id: <%= ActiveRecord::FixtureSet.identify(:jeff_doe, :uuid) %>
Expand Down
2 changes: 1 addition & 1 deletion test/system/projects/automated_workflow_executions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup
assert_selector 'h1', text: I18n.t(:'projects.automated_workflow_executions.index.title')
assert_selector 'p', text: I18n.t(:'projects.automated_workflow_executions.index.subtitle')

assert_selector 'tr', count: 2 + header_row_count
assert_selector 'tr', count: 3 + header_row_count
end

test 'can see an empty state for table listing of automated workflow executions for a project' do
Expand Down

0 comments on commit d9bf81e

Please sign in to comment.