Skip to content

Commit

Permalink
Add test for when checkbox is not checked
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Jun 26, 2024
1 parent 4c533ba commit c691500
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def show
private

def propagate_permissions_to_children
return unless params[:propagate_permissions]
return unless params[:propagate_permissions] == '1'

# Should only propagate permissions to child assays if the assay is an assay stream
return unless @assay.is_assay_stream?
Expand Down
68 changes: 50 additions & 18 deletions test/functional/assays_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1929,15 +1929,15 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
sample_collection_st = FactoryBot.create(:isa_sample_collection_sample_type, contributor: person, projects: [project],
linked_sample_type: source_st)

study = FactoryBot.create(:study, investigation: , contributor: person,
study = FactoryBot.create(:study, investigation:, contributor: person,
policy: FactoryBot.create(:private_policy, permissions: [FactoryBot.create(:permission, contributor: person, access_type: Policy::MANAGING)]),
sops: [FactoryBot.create(:sop, policy: FactoryBot.create(:public_policy))],
sample_types: [source_st, sample_collection_st])
assay_stream = FactoryBot.create(:assay_stream, study: , contributor: person)
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person)
assay_sample_type = FactoryBot.create :isa_assay_material_sample_type, linked_sample_type: sample_collection_st,
contributor: person, isa_template: FactoryBot.build(:isa_assay_material_template)
assay = FactoryBot.create(:assay,
study: ,
study:,
policy: FactoryBot.create(:private_policy, permissions:[FactoryBot.create(:permission,contributor: person, access_type:Policy::EDITING)]),
sample_type: assay_sample_type,
contributor: person,
Expand Down Expand Up @@ -1983,8 +1983,8 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
sops: [FactoryBot.create(:sop, policy: FactoryBot.create(:public_policy))],
sample_types: [source_st, sample_collection_st])

assay_stream = FactoryBot.create(:assay_stream, study: , contributor: person)
assay1 = FactoryBot.create(:assay, study: , contributor: person, sample_type: assay_st1,
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person)
assay1 = FactoryBot.create(:assay, study:, contributor: person, sample_type: assay_st1,
policy: FactoryBot.create(:private_policy, permissions: [FactoryBot.create(:permission, contributor: person, access_type: Policy::MANAGING)]),
position: 0, assay_stream: )
assay2 = FactoryBot.create(:assay, study: study, contributor: person, sample_type: assay_st2,
Expand Down Expand Up @@ -2036,15 +2036,15 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
login_as(current_user)
investigation = FactoryBot.create(:investigation, is_isa_json_compliant: true, contributor: current_user.person)
study = FactoryBot.create(:isa_json_compliant_study, investigation: )
assay_stream = FactoryBot.create(:assay_stream, study: , contributor: current_user.person)
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: current_user.person)
get :show, params: { id: assay_stream }
assert_response :success

# If stream has no assays, it should say 'Design Assay'
assert_select 'a', text: /Design #{I18n.t('assay')}/i, count: 1

assay_sample_type1 = FactoryBot.create(:isa_assay_material_sample_type, linked_sample_type: study.sample_types.second)
assay1 = FactoryBot.create(:assay, contributor: current_user.person, study: , assay_stream:, sample_type: assay_sample_type1)
assay1 = FactoryBot.create(:assay, contributor: current_user.person, study:, assay_stream:, sample_type: assay_sample_type1)

assert_equal assay_stream.study, assay1.study

Expand All @@ -2061,7 +2061,7 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
assert_select 'a', text: /Design the next #{I18n.t('assay')}/i, count: 1

assay_sample_type2 = FactoryBot.create(:isa_assay_material_sample_type, linked_sample_type: assay_sample_type1)
assay2 = FactoryBot.create(:assay, contributor: current_user.person, study: , assay_stream:, sample_type: assay_sample_type2)
assay2 = FactoryBot.create(:assay, contributor: current_user.person, study:, assay_stream:, sample_type: assay_sample_type2)

get :show, params: { id: assay1 }
assert_response :success
Expand Down Expand Up @@ -2137,16 +2137,16 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
login_as(person)
investigation = FactoryBot.create(:investigation, is_isa_json_compliant: true, contributor: person)
study = FactoryBot.create(:isa_json_compliant_study, investigation: )
assay_stream = FactoryBot.create(:assay_stream, study: , contributor: person, position: 0)
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person, position: 0)

begin_assay_sample_type = FactoryBot.create(:isa_assay_material_sample_type, linked_sample_type: study.sample_types.second, projects: [project], contributor: person)
begin_assay = FactoryBot.create(:assay, contributor: person, study: , assay_stream:, sample_type: begin_assay_sample_type, position: 0)
begin_assay = FactoryBot.create(:assay, contributor: person, study:, assay_stream:, sample_type: begin_assay_sample_type, position: 0)

middle_assay_sample_type = FactoryBot.create(:isa_assay_material_sample_type, linked_sample_type: begin_assay_sample_type, projects: [project], contributor: person)
middle_assay = FactoryBot.create(:assay, contributor: person, study: , assay_stream:, sample_type: middle_assay_sample_type, position: 1)
middle_assay = FactoryBot.create(:assay, contributor: person, study:, assay_stream:, sample_type: middle_assay_sample_type, position: 1)

end_assay_sample_type = FactoryBot.create(:isa_assay_data_file_sample_type, linked_sample_type: middle_assay_sample_type, projects: [project], contributor: person)
end_assay = FactoryBot.create(:assay, contributor: person, study: , assay_stream:, sample_type: end_assay_sample_type, position: 2)
end_assay = FactoryBot.create(:assay, contributor: person, study:, assay_stream:, sample_type: end_assay_sample_type, position: 2)

assert_difference('Assay.count', -1) do
assert_difference('SampleType.count', -1) do
Expand All @@ -2166,8 +2166,8 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
login_as(person)
investigation = FactoryBot.create(:investigation, is_isa_json_compliant: true, contributor: person)
study = FactoryBot.create(:isa_json_compliant_study, investigation: )
assay_stream = FactoryBot.create(:assay_stream, study: , contributor: person, position: 0)
experimental_assay = FactoryBot.create(:assay, contributor: person, study: , assay_stream:, position: 0)
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person, position: 0)
experimental_assay = FactoryBot.create(:assay, contributor: person, study:, assay_stream:, position: 0)

get :manage, params: { id: assay_stream }
assert_response :success
Expand All @@ -2185,9 +2185,9 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
other_person = FactoryBot.create(:person)
investigation = FactoryBot.create(:investigation, is_isa_json_compliant: true, contributor: person)
study = FactoryBot.create(:isa_json_compliant_study, investigation: )
assay_stream = FactoryBot.create(:assay_stream, study: , contributor: person, position: 0)
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person, position: 0)

authorized_child_assay = FactoryBot.create(:assay, contributor: person, study: , assay_stream:, position: 0)
authorized_child_assay = FactoryBot.create(:assay, contributor: person, study:, assay_stream:, position: 0)

login_as(person)
refute authorized_child_assay.can_manage?(other_person)
Expand All @@ -2210,8 +2210,8 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links

investigation = FactoryBot.create(:investigation, is_isa_json_compliant: true, contributor: person)
study = FactoryBot.create(:isa_json_compliant_study, investigation: )
assay_stream = FactoryBot.create(:assay_stream, study: , contributor: person, position: 0)
unauthorized_child_assay = FactoryBot.create(:assay, contributor: second_person, study: , assay_stream:, position: 0)
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person, position: 0)
unauthorized_child_assay = FactoryBot.create(:assay, contributor: second_person, study:, assay_stream:, position: 0)

login_as(person)
patch :manage_update, params: { id: assay_stream, propagate_permissions: '1', assay: {creator_ids: [third_person.id]}, policy_attributes: {access_type: Policy::NO_ACCESS, permissions_attributes: {'1' => {contributor_type: 'Person', contributor_id: third_person.id, access_type: Policy::MANAGING}}}}
Expand All @@ -2228,5 +2228,37 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
refute unauthorized_child_assay.can_manage?(third_person)
end
end

test 'Should not propagate assay stream permissions when propagate_permissions param is not true' do
with_config_value(:isa_json_compliance_enabled, true) do
person = FactoryBot.create(:person)
other_person = FactoryBot.create(:person)
investigation = FactoryBot.create(:investigation, is_isa_json_compliant: true, contributor: person)
study = FactoryBot.create(:isa_json_compliant_study, investigation: )
assay_stream = FactoryBot.create(:assay_stream, study:, contributor: person, position: 0)
authorized_child_assay = FactoryBot.create(:assay, contributor: person, study:, assay_stream:, position: 0)

login_as(person)
refute authorized_child_assay.can_manage?(other_person)
patch :manage_update, params: { id: assay_stream, assay: {creator_ids: [other_person.id] }, policy_attributes: {access_type: Policy::NO_ACCESS, permissions_attributes: {'1' => {contributor_type: 'Person', contributor_id: other_person.id, access_type: Policy::MANAGING}}}}

assert flash[:error].nil?

# assert that the permissions of the authorized assay were not propagated
# other_person should not see the authorized assay
authorized_child_assay.reload
refute authorized_child_assay.can_manage?(other_person)

patch :manage_update, params: { id: assay_stream, propagate_permissions: '0', assay: {creator_ids: [other_person.id] }, policy_attributes: {access_type: Policy::NO_ACCESS, permissions_attributes: {'1' => {contributor_type: 'Person', contributor_id: other_person.id, access_type: Policy::MANAGING}}}}

assert flash[:error].nil?

# assert that the permissions of the authorized assay were not propagated
# other_person should not see the authorized assay
authorized_child_assay.reload
refute authorized_child_assay.can_manage?(other_person)

end
end

end

0 comments on commit c691500

Please sign in to comment.