Skip to content

WIP: feat: grades upload flow#8008

Open
YheChen wants to merge 3 commits into
MarkUsProject:masterfrom
YheChen:feat/upload-assignment-grades
Open

WIP: feat: grades upload flow#8008
YheChen wants to merge 3 commits into
MarkUsProject:masterfrom
YheChen:feat/upload-assignment-grades

Conversation

@YheChen

@YheChen YheChen commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

Adds CSV upload support for criterion marks from the assignment Grades tab.

This PR adds an Upload button for instructors on the assignment Grades tab. The upload flow accepts a CSV in the same general format as the existing Grades tab CSV export / grade entry form uploads, updates marks for matching assignment criteria, supports an overwrite option, and ignores total mark and bonus/deduction columns.

Also adds backend import handling, authorization, translations, and model/controller tests.

Fixes #7794

Screenshots of your changes (if applicable)

Add screenshots of:

  • the new Upload button in the Grades tab
  • the upload modal
Associated documentation repository pull request (if applicable)

N/A

Type of Change

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots) X
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

@coveralls

coveralls commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 27919845468

Coverage increased (+0.03%) to 90.291%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 5 uncovered changes across 4 files (172 of 177 lines covered, 97.18%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
app/javascript/Components/assignment_summary_table.jsx 3 1 33.33%
app/controllers/assignments_controller.rb 7 6 85.71%
app/javascript/Components/Modals/assignment_grades_upload_modal.jsx 4 3 75.0%
app/models/assignment.rb 67 66 98.51%
Total (8 files) 177 172 97.18%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 50615
Covered Lines: 46688
Line Coverage: 92.24%
Relevant Branches: 2313
Covered Branches: 1101
Branch Coverage: 47.6%
Branches in Coverage %: Yes
Coverage Strength: 127.09 hits per line

💛 - Coveralls

@YheChen YheChen requested a review from david-yz-liu June 22, 2026 21:36

@david-yz-liu david-yz-liu left a 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.

@YheChen nice work, I left a few comments. Please also make sure to update the screenshots in the PR description and the documentation Wiki.

class AssignmentPolicy < ApplicationPolicy
default_rule :manage?
alias_rule :summary?, to: :view?
alias_rule :upload_grades?, to: :manage?

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.

This isn't necessary because of the default_rule :manage? call

Comment thread app/models/assignment.rb
.joins(grouping: :group)
.includes(:marks, grouping: :group)
.index_by { |result| result.grouping.group.group_name }
results_by_user_name = current_results

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.

Don't include this. The group name is required; the list of users is optional, and should be ignored if it's in the CSV upload. There is no need to have a fallback query (see my further comment below on result_for_uploaded_marks_row)

Comment thread app/models/assignment.rb

raise CsvInvalidLineError if criterion_columns == :invalid

result = result_for_uploaded_marks_row(row, group_name_index, user_name_index,

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.

I wouldn't define a helper function here, it's not worth it. Do a lookup on row[group_name_index]. This will either be a Result or nil, and is the only thin you need to use.

Comment thread app/models/assignment.rb
mark = result.marks.find_or_initialize_by(criterion: criterion)
next if !overwrite && !mark.mark.nil?

mark_value = parse_uploaded_mark(row[column_index])

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.

No need to make this a helper function, inline the logic here

Comment thread app/models/assignment.rb
next if !overwrite && !mark.mark.nil?

mark_value = parse_uploaded_mark(row[column_index])
unless mark.update(mark: mark_value,

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.

Doing this one record at a time will be quite slow, even with the transaction. Modify the logic to accumulate a set of updates and use upsert_all

Comment thread app/models/assignment.rb
elsif criterion_columns.nil?
begin
criterion_columns = assignment_upload_criterion_columns(headers, row, criteria_by_name)
rescue CsvInvalidLineError

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.

I'm not sure what the purpose of this exception handling and re-raising is

Comment thread app/models/assignment.rb
next
elsif criterion_columns.nil?
begin
criterion_columns = assignment_upload_criterion_columns(headers, row, criteria_by_name)

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.

Similar to my above comment, I think this is overly complex and doesn't require a helper. Ignore the "totals" row; determine Criterion object based on the name, which is found only in the headers row.

You can ignore the "totals" row by skipping any row with a blank "group name" column, which I believe you already have some logic to do.

Comment thread app/models/assignment.rb
criteria.exists? ? criteria.last.position + 1 : 1
end

def criteria_by_upload_name

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.

This helper function isn't necessary; again, inline the code above.

First, to create a hash use the pattern of

ta_criteria.map do |criteria|
  ...

  # end with an array of [key, value]
end.to_h

Second, the most complex part of this logic is the conditional adding of "bonus". This appears elsewhere in the code for generating CSV files, so actually what I would suggest is to define a Criterion helper method called export_name that handles this logic, and then just call criterion.export_name here. Also modify the existing places in the CSV exporting to use this method.

The .to_s and strip calls are unnecessary. They are not found in the corresponding CSV export method.

upload_file_requirement: Filename %{file_name} is not allowed for this assignment.
upload_file_requirement_in_folder: Filename %{file_name} in %{file_path} is not allowed for this assignment.
upload_grades:
invalid_criteria: 'No matching criteria were found in the uploaded CSV. Unknown criteria: %{criteria}'

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.

Reword this message to "The following criteria were not found for this assignment: %{criteria}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the ability to upload grades directly to assignments

3 participants