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

Don't allow admins to submit to invalid exercises #5997

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading