Skip to content

Commit

Permalink
Display used grace credits in student assignment list (#7226)
Browse files Browse the repository at this point in the history
Resolves #2118.
  • Loading branch information
hemmatio authored Oct 3, 2024
1 parent 1df895e commit 5849875
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### ✨ New features and improvements

- Add visual indicator on a per-assignment basis for used grace credits (#7226)

### 🐛 Bug fixes

- Fix incorrect calculation of token penalties when submissions are on time (#7216)
Expand Down
6 changes: 6 additions & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ def released_result_for?(assessment)
end
end

def grace_credits_used_for(assessment)
grouping = accepted_grouping_for(assessment.id)
return 0 if grouping.nil? # Return 0 if no grouping exists
grouping.grace_period_deduction_single
end

# Determine what assessments are visible to the role.
# By default, returns all assessments visible to the role for the current course.
# Optional parameter assessment_type takes values "Assignment" or "GradeEntryForm". If passed one of these options,
Expand Down
4 changes: 4 additions & 0 deletions app/views/assignments/_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<% route = course_assignment_path(@current_course, assignment.id) %>
<% assignment_text = "#{h(assignment.short_identifier)}: #{h(assignment.description)}" %>
<% grace_credits_used = @current_role.grace_credits_used_for(assignment) %>
<tr>
<td>
<%= link_to assignment_text, route %>
</td>
<td>
<%= render partial: 'assignments/assignment_date',
locals: { assignment: assignment } %>
<% if grace_credits_used > 0 %>
<span><%= t('assignments.grace_credits_used_html', grace_credits_used: grace_credits_used)%></span>
<% end %>
</td>
<% unless upcoming %>
<td>
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/assignments/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ en:
required_files_by_student: You may specify file(s) that students are required to submit.
section_due_dates_info_html: "<strong>Important</strong> The global due date and start time need to be filled in. If a section has no due date specified, the global due date will be used instead. If a section has no start time specified, the global start time will be used instead. Students not assigned to any section will only be allowed to form groups with other students not assigned to any section."
section_due_dates_option: If the section-specific settings option is checked, students can only form groups within their section.
grace_credits_used_html: 'Grace Credits Used: <strong>%{grace_credits_used}</strong>'
help:
edit:
assignment_type_html: 'Persist Groups/Properties from ___: use the same groups and repositories from previous assignment. If selected, assignment folders will be created for every group immediately, rather than when a student clicks on the assignment for the first time.<br />If students can form their own groups, group names are always autogenerated. You can also create groups manually or by uploading a file.'
Expand Down
28 changes: 28 additions & 0 deletions spec/models/student_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,34 @@
end
end

context 'where there is a grace deduction' do
before do
# setting up an assignment to use grace credits on
@assignment = create(:assignment)
@grouping = create(:grouping, assignment: @assignment)
@student1 = create(:student)
@student2 = create(:student)
@membership1 = create(:student_membership, role: @student1, grouping: @grouping,
membership_status: StudentMembership::STATUSES[:accepted])
@membership2 = create(:student_membership, role: @student2, grouping: @grouping,
membership_status: StudentMembership::STATUSES[:inviter])
memberships = @grouping.accepted_student_memberships
memberships.each do |membership| # mimics behaviour from grace_period_submission_rule.rb
create(:grace_period_deduction, membership: membership, deduction: 2)
end
end

it 'returns the correct value of used credits per assessment' do
expect(@student1.grace_credits_used_for(@assignment)).to eq(2)
expect(@student2.grace_credits_used_for(@assignment)).to eq(2)
end

it 'deducts grace credits from each group member' do
expect(@student1.remaining_grace_credits).to eq(3)
expect(@student2.remaining_grace_credits).to eq(3)
end
end

context 'as a noteable' do
it 'display for note without seeing an exception' do
expect(@student.display_for_note).not_to be_nil
Expand Down

0 comments on commit 5849875

Please sign in to comment.