Skip to content
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Added term-based suffixes to course names created via LTI to ensure uniqueness across academic years (#7881)
- Added `db:populate_course_dates` rake task to backfill `start_at`/`end_at` for existing courses, and permit those fields when creating courses through the admin UI (#7925)
- Sync due date when creating or updating LTI gradebook line items, and re-sync automatically when an assessment is edited (#7872)
- Added GET and PATCH /overall_comment API routes (#7963)

### 🐛 Bug fixes
- Prevent "No rows found" message from displaying in tables when data is loading (#7790)
Expand Down
28 changes: 28 additions & 0 deletions app/controllers/api/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,34 @@ def add_test_run
end
end

def overall_comment
result = grouping&.current_result
return page_not_found('No submission exists for that group') if result.nil?

case request.method
when 'GET'
respond_to do |format|
format.xml do
render xml: { overall_comment: result.overall_comment }.to_xml(root: 'result', skip_types: 'true')
end
format.json { render json: { overall_comment: result.overall_comment } }
end
when 'PATCH'
if has_missing_params?([:overall_comment])
render 'shared/http_status', locals: { code: '422', message:
HttpStatusHelper::ERROR_CODE['message']['422'] }, status: :unprocessable_content
return
end
if result.update(overall_comment: params[:overall_comment])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should check whether :overall_comment is present in the params first. If it isn't, render the 422 error response (similar to how we do this in update_marking_state).

Separately, when reviewing this I realized that we should not allow the overall_comment field to be updated if the result is released. This should actually be controlled by a model validation (i.e., within the Result class). There's already a validation but it's only checking a change to the marking_state status, so please add to that validation to detect a change to the overall_comment field.

Copy link
Copy Markdown
Contributor Author

@philipkukulak philipkukulak May 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you David. I've updated the overall_comment method to validate the existence of :overall_comment when a PATCH is received since no parameter is sent for GET requests.

I've also added a case to the check_for_released method in the Result model.

Tests updated accordingly, and Changelog has been updated as well. I'll work on documentation shortly.

head :ok
else
render 'shared/http_status',
locals: { code: '422', message: result.errors.full_messages.first },
status: :unprocessable_content
end
end
end

private

def assignment
Expand Down
14 changes: 10 additions & 4 deletions app/models/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,17 @@ def print_pdf_filename

private

# Do not allow the marking state to be changed to incomplete if the result is released
# Do not allow certain fields to be changed when the result is released
def check_for_released
if released_to_students && marking_state_changed?(to: Result::MARKING_STATES[:incomplete])
errors.add(:base, :marks_released)
throw(:abort)
if released_to_students
if marking_state_changed?(to: Result::MARKING_STATES[:incomplete])
errors.add(:base, :marks_released)
throw(:abort)
end
if overall_comment_changed?
errors.add(:overall_comment, :marks_released)
throw(:abort)
end
end
true
end
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
# PATCH /api/courses/:course_id/assignments/:assignment_id/groups/:group_id/feedback_files/:id(.:format) api/feedback_files#update
# PUT /api/courses/:course_id/assignments/:assignment_id/groups/:group_id/feedback_files/:id(.:format) api/feedback_files#update
# DELETE /api/courses/:course_id/assignments/:assignment_id/groups/:group_id/feedback_files/:id(.:format) api/feedback_files#destroy
# overall_comment_api_course_assignment_group GET /api/courses/:course_id/assignments/:assignment_id/groups/:id/overall_comment(.:format) api/groups#overall_comment
# PATCH /api/courses/:course_id/assignments/:assignment_id/groups/:id/overall_comment(.:format) api/groups#overall_comment
# annotations_api_course_assignment_group GET /api/courses/:course_id/assignments/:assignment_id/groups/:id/annotations(.:format) api/groups#annotations
# add_annotations_api_course_assignment_group POST /api/courses/:course_id/assignments/:assignment_id/groups/:id/add_annotations(.:format) api/groups#add_annotations
# add_members_api_course_assignment_group POST /api/courses/:course_id/assignments/:assignment_id/groups/:id/add_members(.:format) api/groups#add_members
Expand Down Expand Up @@ -620,6 +622,10 @@
patch 'extension'
delete 'extension'
end
member do
get 'overall_comment'
patch 'overall_comment'
end
end
resources :starter_file_groups, only: [:index, :create]
member do
Expand Down
116 changes: 116 additions & 0 deletions spec/controllers/api/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
params: { assignment_id: assignment.id, course_id: course.id, id: group.id, extension: extension_params }
expect(response).to have_http_status(:forbidden)
end

it 'should fail to authenticate a GET overall_comment request' do
get :overall_comment, params: { assignment_id: assignment.id, id: group.id, course_id: course.id }
expect(response).to have_http_status(:forbidden)
end

it 'should fail to authenticate a PATCH overall_comment request' do
patch :overall_comment, params: { assignment_id: assignment.id, id: group.id, course_id: course.id }
expect(response).to have_http_status(:forbidden)
end
end

context 'An authenticated request requesting' do
Expand Down Expand Up @@ -1460,5 +1470,111 @@
end
end
end

context 'Overall Comment' do
let!(:grouping) { create(:grouping, group: group, assignment: assignment) }

before { request.env['HTTP_ACCEPT'] = 'application/json' }

context 'when no submission/result exists' do
it 'GET returns 404' do
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
expect(response).to have_http_status(:not_found)
end

it 'PATCH returns 404' do
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id,
id: group.id, overall_comment: 'hello' }
expect(response).to have_http_status(:not_found)
end
end

context 'when a result exists' do
let(:submission) { create(:version_used_submission, grouping: grouping) }

before { submission }

context 'expecting a json response' do
it 'GET returns 200 with the overall_comment' do
grouping.current_result.update!(overall_comment: 'existing comment')
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
expect(response).to have_http_status(:ok)
expect(response.parsed_body['overall_comment']).to eq('existing comment')
end

it 'GET returns 200 with null overall_comment when none set' do
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
expect(response).to have_http_status(:ok)
expect(response.parsed_body['overall_comment']).to be_nil
end

it_behaves_like 'for a different course' do
before do
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
end
end
end

context 'expecting an xml response' do
before { request.env['HTTP_ACCEPT'] = 'application/xml' }

it 'GET returns 200' do
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
expect(response).to have_http_status(:ok)
end

it 'GET returns overall_comment nested under a result root element' do
grouping.current_result.update!(overall_comment: 'xml comment')
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
parsed = Hash.from_xml(response.body)
expect(parsed.dig('result', 'overall_comment')).to eq('xml comment')
end

it 'GET returns null overall_comment as empty element when none set' do
get :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
parsed = Hash.from_xml(response.body)
expect(parsed.dig('result', 'overall_comment')).to be_nil
end
end

it 'PATCH updates overall_comment and returns 200' do
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id,
id: group.id, overall_comment: 'new comment' }
expect(response).to have_http_status(:ok)
expect(grouping.current_result.reload.overall_comment).to eq('new comment')
end

it 'PATCH returns 422 when result is released' do
grouping.current_result.update!(released_to_students: true)
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id,
id: group.id, overall_comment: 'blocked' }
expect(response).to have_http_status(:unprocessable_content)
end

it 'PATCH returns 422 when overall_comment param is missing' do
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id, id: group.id }
expect(response).to have_http_status(:unprocessable_content)
end

it 'PATCH returns 422 when overall_comment param is nil' do
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id,
id: group.id, overall_comment: nil }
expect(response).to have_http_status(:unprocessable_content)
end

it 'PATCH returns 422 when overall_comment param is empty string' do
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id,
id: group.id, overall_comment: '' }
expect(response).to have_http_status(:unprocessable_content)
end

it_behaves_like 'for a different course' do
before do
patch :overall_comment, params: { course_id: course.id, assignment_id: assignment.id,
id: group.id, overall_comment: 'hello' }
end
end
end
end
end
end
20 changes: 20 additions & 0 deletions spec/models/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@
end
end
end

context 'check_for_released' do
before { result.update!(released_to_students: true) }

it 'does not allow marking_state to be changed to incomplete' do
result.marking_state = Result::MARKING_STATES[:incomplete]
expect(result.save).to be false
expect(result.errors[:base]).to be_present
end

it 'does not allow overall_comment to be changed' do
result.overall_comment = 'new comment'
expect(result.save).to be false
expect(result.errors[:overall_comment]).to be_present
end

it 'allows other fields to be updated' do
expect { result.regenerate_view_token }.not_to raise_error
end
end
end

shared_context 'get subtotal context' do
Expand Down
Loading