Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check to prevent soft deleted subject added to subject set #4355

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading