Skip to content

Commit

Permalink
add check to prevent soft deleted subject added to subject set (#4355)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tooyosi authored Jul 9, 2024
1 parent faf9756 commit 115e6de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/subject_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def add_relation(resource, relation, value)
if relation == :subjects && value.is_a?(Array)
#ids is returning duplicates even though the AR Relations were uniq
subject_ids_to_link = new_items(resource, relation, value).distinct.ids
unless Subject.where(id: subject_ids_to_link).count == value.count
unless Subject.where(id: subject_ids_to_link, activated_state: 'active').count == value.count
raise BadLinkParams.new("Error: check the subject set and all the subjects exist.")
end
new_sms_values = subject_ids_to_link.map do |subject_id|
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/api/v1/subject_sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@
expect(response).to have_http_status(:ok)
end
end

context 'when a linking resource has been soft deleted' do
it 'returns a 422 with a missing subject' do
last_subject = subjects.last
last_subject.update(activated_state: 'inactive')
run_update_links
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

context 'with illegal link properties' do
Expand Down

0 comments on commit 115e6de

Please sign in to comment.