Skip to content

Commit

Permalink
Merge pull request #2145 from seek4science/remove-redundant-ab-cwl
Browse files Browse the repository at this point in the history
Don't allow abstract CWL path to be set to same as main workflow path
  • Loading branch information
fbacall authored Feb 26, 2025
2 parents ab74356 + 5ff5f57 commit cd83dca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def initialize(*args)

acts_as_doi_mintable(proxy: :parent, general_type: 'Workflow')

before_validation :remove_redundant_abstract_cwl_annotation
before_save :refresh_internals, if: -> { main_workflow_path_changed? && main_workflow_blob && !main_workflow_blob.empty? }
after_save :clear_cached_diagram, if: -> { diagram_path_changed? }
after_commit :submit_to_life_monitor, on: [:create, :update], if: :should_submit_to_life_monitor?
Expand Down Expand Up @@ -97,6 +98,10 @@ def should_submit_to_life_monitor?
def sync_test_status
parent.update_column(:test_status, Workflow::TEST_STATUS_INV[test_status]) if latest_git_version?
end

def remove_redundant_abstract_cwl_annotation
abstract_cwl_annotation.mark_for_destruction if abstract_cwl_path && abstract_cwl_path == main_workflow_path
end
end

explicit_versioning(version_column: 'version', sync_ignore_columns: ['doi', 'test_status']) do
Expand Down
35 changes: 35 additions & 0 deletions test/integration/git_workflow_creation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,41 @@ class GitWorkflowCreationTest < ActionDispatch::IntegrationTest
assert_equal annotation_count + 2, Git::Annotation.count
end

test 'cannot set abstract cwl path to same as main workflow path' do
person = FactoryBot.create(:person)
cwl = WorkflowClass.find_by_key('cwl') || FactoryBot.create(:cwl_workflow_class)
login_as(person.user)

repo = FactoryBot.create(:unlinked_local_repository)

assert_difference('Workflow.count', 1) do
assert_difference('Git::Version.count', 1) do
# 2 annotations = Main WF path, diagram path
assert_difference('Git::Annotation.count', 2) do
post create_metadata_workflows_path, params: {
workflow: {
workflow_class_id: cwl.id,
title: 'blabla',
project_ids: [person.projects.first.id],
git_version_attributes: {
root_path: '/',
git_repository_id: repo.id,
ref: 'refs/heads/master',
main_workflow_path: 'Concat_two_files.cwl',
diagram_path: 'diagram.png',
abstract_cwl_path: 'Concat_two_files.cwl'
}
}
}
end
end
end

assert_redirected_to workflow_path(assigns(:workflow))
assert_equal 'Concat_two_files.cwl', assigns(:workflow).main_workflow_path
assert_nil assigns(:workflow).abstract_cwl_path
end

private

def login_as(user)
Expand Down

0 comments on commit cd83dca

Please sign in to comment.