Skip to content

Commit

Permalink
fix: prevent new attempt if last is incomplete or passed
Browse files Browse the repository at this point in the history
  • Loading branch information
satikaj committed Jun 11, 2024
1 parent 176ff7f commit b912e3f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/api/test_attempts_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class TestAttemptsApi < Grape::API
else
logger.debug "Request to review test attempt #{params[:id]}"
test.review
# TODO: add review permission flag to taskdef
end
present test, with: Entities::TestAttemptEntity
end
Expand All @@ -118,6 +117,18 @@ class TestAttemptsApi < Grape::API

attempts = TestAttempt.where("task_id = ?", task.id)

# check if last attempt is complete
last_attempt = attempts.order(id: :desc).first
if last_attempt.completion_status == false
error!({ message: 'An attempt is still ongoing. Cannot initiate new attempt.' }, 400)
return
end

# check if last attempt is a pass
if last_attempt.success_status == true
error!({ message: 'User has passed the SCORM test. Cannot initiate more attempts.' }, 400)
end

# check attempt limit
test_count = attempts.count
limit = task.task_definition.scorm_attempt_limit + task.scorm_extensions
Expand Down

0 comments on commit b912e3f

Please sign in to comment.