Skip to content

Commit

Permalink
Change to after_action
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Jun 26, 2024
1 parent 0c6ce36 commit 8843ffa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AssaysController < ApplicationController
# => Rearrange positions
after_action :rearrange_assay_positions_at_destroy, only: :destroy

before_action :propagate_permissions_to_children, only: :manage_update
after_action :propagate_permissions_to_children, only: :manage_update

include Seek::Publishing::PublishingCommon

Expand Down Expand Up @@ -165,7 +165,8 @@ def show
def propagate_permissions_to_children
return unless params[:propagate_permissions]

# flash[:error] = 'You do not have the necessary permissions to propagate permissions to children'
# Should only propagate permissions to child assays if the assay is an assay stream
return unless @assay.is_assay_stream?

errors = []
@assay.child_assays.map do |assay|
Expand All @@ -175,7 +176,10 @@ def propagate_permissions_to_children
next
end

assay.update(assay_params)
current_assay_policy = assay.policy
# Clone the policy from the parent assay
assay.update(policy: @assay.policy.deep_copy)
current_assay_policy.destroy if current_assay_policy
update_sharing_policies assay
end
# Add an error message to the flash
Expand Down
4 changes: 2 additions & 2 deletions test/functional/assays_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,7 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
end
end

test 'assay stream permissions propagation' do
test 'Should propagate assay stream permissions' do
with_config_value(:isa_json_compliance_enabled, true) do
person = FactoryBot.create(:person)
other_person = FactoryBot.create(:person)
Expand All @@ -2175,7 +2175,7 @@ def check_fixtures_for_authorization_of_sops_and_datafiles_links
login_as(person)
refute unauthorized_child_assay.can_manage?
refute authorized_child_assay.can_manage?(other_person)
patch :manage_update, params: { id: assay_stream, propagate_permissions: '1', assay: {creator_ids: [other_person.id]}, policy_attributes: {access_type: Policy::VISIBLE, permissions_attributes: {'1' => {contributor_type: 'Person', contributor_id: other_person.id, access_type: Policy::MANAGING}}}}
patch :manage_update, params: { id: assay_stream, propagate_permissions: '1', 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 the flash[:error] text. The permissions of the unauthorized assay should not be propagated
assert flash[:error], "<ul><li>You do not have the necessary permissions to propagate permissions to #{t('assay').downcase} [#{unauthorized_child_assay.id}]: '#{unauthorized_child_assay.title}'</li></ul>"
Expand Down

0 comments on commit 8843ffa

Please sign in to comment.