Flowr: Return empty array if no submission was found

This commit is contained in:
Sebastian Serth
2018-11-28 23:42:37 +01:00
parent 64d5a0f9b2
commit 8ccdb79fef

View File

@ -6,6 +6,14 @@ class FlowrController < ApplicationController
submission = Submission.joins(:testruns) submission = Submission.joins(:testruns)
.where(submissions: {user_id: current_user.id, user_type: current_user.class.name}) .where(submissions: {user_id: current_user.id, user_type: current_user.class.name})
.order('testruns.created_at DESC').first .order('testruns.created_at DESC').first
# Return if no submission was found
if submission.blank?
skip_authorization
render json: [], status: :ok
return
end
# verify authorization for the submission, as all queried errors are generated by this submission anyway # verify authorization for the submission, as all queried errors are generated by this submission anyway
# and structured_errors don't have a policy yet # and structured_errors don't have a policy yet
authorize(submission) authorize(submission)