diff --git a/Changelog.md b/Changelog.md index da42888226..0691d550f1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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) diff --git a/app/models/student.rb b/app/models/student.rb index 19ceca9346..d42ff2c96c 100644 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -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, diff --git a/app/views/assignments/_row.html.erb b/app/views/assignments/_row.html.erb index 33e530139f..40051e716c 100644 --- a/app/views/assignments/_row.html.erb +++ b/app/views/assignments/_row.html.erb @@ -1,5 +1,6 @@ <% 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) %> <%= link_to assignment_text, route %> @@ -7,6 +8,9 @@ <%= render partial: 'assignments/assignment_date', locals: { assignment: assignment } %> + <% if grace_credits_used > 0 %> + <%= t('assignments.grace_credits_used_html', grace_credits_used: grace_credits_used)%> + <% end %> <% unless upcoming %> diff --git a/config/locales/views/assignments/en.yml b/config/locales/views/assignments/en.yml index 40b65a0f1a..d84eb714c0 100644 --- a/config/locales/views/assignments/en.yml +++ b/config/locales/views/assignments/en.yml @@ -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: "Important 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: %{grace_credits_used}' 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.
If students can form their own groups, group names are always autogenerated. You can also create groups manually or by uploading a file.' diff --git a/spec/models/student_spec.rb b/spec/models/student_spec.rb index 7bb1be97e3..63851a3bba 100644 --- a/spec/models/student_spec.rb +++ b/spec/models/student_spec.rb @@ -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