Skip to content

Commit

Permalink
Don't allow admins to submit to invalid exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Dec 10, 2024
1 parent 7909495 commit 73307f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/policies/activity_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def media?
def submit?
return false if record.removed?
return false if user.blank?
return false if record.not_valid?
return true if user.admin?
return true if record.ok?

Expand Down
20 changes: 20 additions & 0 deletions test/controllers/submissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,24 @@ def expected_score_string(*args)

assert_response :ok
end

test 'should not be able to submit to invalid exercise' do
attrs = generate_attr_hash
exercise = Exercise.find(attrs[:exercise_id])
exercise.update!(status: :not_valid)

sign_in create(:staff)
create_request(attr_hash: attrs)

assert_response :unprocessable_entity
end

test 'should not be able to submit to valid exercise' do
attrs = generate_attr_hash

sign_in create(:staff)
create_request(attr_hash: attrs)

assert_response :success
end
end
7 changes: 7 additions & 0 deletions test/system/activities_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ class ActivitiesTest < ApplicationSystemTestCase

assert_text '`<script>alert("😀\\n")</script>\\n\n\\0`'
end

test 'should not be able to submit to invalid exercise' do
@instance.update!(status: :not_valid)
visit exercise_path(id: @instance.id)

assert_no_selector '#editor-process-btn'
end
end

0 comments on commit 73307f8

Please sign in to comment.