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

Enable the deletion of Grade Entry Forms that have no grades #6915

Merged
merged 12 commits into from
Feb 26, 2024

Conversation

Bruce-8
Copy link
Contributor

@Bruce-8 Bruce-8 commented Jan 26, 2024

Motivation and Context

Currently, there is no destroy option for marks spreadsheets (aka grade entry forms). This pull request adds both a web UI feature and new API routes for the deletion of marks spreadsheets, under the condition that there are no non-nil grades for that marks spreadsheet.

Your Changes

Description:

  • Added a new destroy action method to grade_entry_forms_controller for both the regular and API version.
  • Modified routes.rb to include routes for the added action methods.
  • Added a new HTML/ERB button that allows users to delete a grade entry form in the web UI.

Type of change (select all that apply):

  • New feature (non-breaking change which adds functionality)

Testing

  • Manually tested the button feature in the web UI.
  • Added Rspec unit tests for valid http responses, successful deletion, and other forms of correctness for this feature.

Questions and Comments (if applicable)

Checklist

  • I have performed a self-review of my own code.
  • 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 on Coveralls.
  • I have added tests for my changes.
  • I have updated the Changelog.md file.

@Bruce-8 Bruce-8 marked this pull request as draft January 26, 2024 09:58
@Bruce-8 Bruce-8 requested a review from david-yz-liu January 26, 2024 09:59
@Bruce-8 Bruce-8 removed the request for review from david-yz-liu February 8, 2024 19:15
@Bruce-8 Bruce-8 marked this pull request as ready for review February 8, 2024 19:27
@Bruce-8 Bruce-8 requested a review from david-yz-liu February 8, 2024 21:34
Changelog.md Outdated Show resolved Hide resolved
config/locales/views/grade_entry_forms/en.yml Outdated Show resolved Hide resolved
app/views/grade_entry_forms/_form.html.erb Outdated Show resolved Hide resolved
app/controllers/grade_entry_forms_controller.rb Outdated Show resolved Hide resolved
spec/controllers/api/grade_entry_forms_controller_spec.rb Outdated Show resolved Hide resolved
@Bruce-8 Bruce-8 requested a review from david-yz-liu February 23, 2024 16:43
@Bruce-8 Bruce-8 changed the title Enable the deletion of Grade Entry Forms Enable the deletion of Grade Entry Forms that have no grades Feb 23, 2024
@@ -5,7 +5,7 @@ class GradeEntryItem < ApplicationRecord

has_one :course, through: :grade_entry_form

has_many :grades, dependent: :delete_all
has_many :grades, dependent: :destroy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay I realized after reviewing again that this change will also change what happens when the user tries to destroy a single column (on the grade entry form "update" page). Previously, we actually did allow the user to delete the column even if that would result in non-nil grades being deleted.

I don't want to change that existing behaviour in this PR. So, please revert the added Grade destroy callback and this line, and instead add a callback to GradeEntryForm itself to check for non-nil grades. See also my comment on the form below about how I want you to check for this.

Sorry for the change of plans!

@@ -89,3 +89,12 @@
data: { disable_with: t('working') } %>
</p>
<% end %>

<% if @grade_entry_form.id != nil %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

use .nil? and an unless

@@ -89,3 +89,12 @@
data: { disable_with: t('working') } %>
</p>
<% end %>

<% if @grade_entry_form.id != nil %>
<% deletable = @grade_entry_form.count_non_nil == 0 %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I like that you tried to use an existing method, that particular method does a lot more work than necessary. I encourage you to use an association and a query directly; note that @grade_entry_form already has a grades association, and you can filter out the non-nil grades, and use exists? to check whether there are any results. You can do this both for this disabling check and for the actual before_destroy callback itself (see my above comment).

<%= button_to t(:delete),
course_grade_entry_form_path(@current_course.id, @grade_entry_form.id),
method: :delete,
disabled: !deletable
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good, but please also add a tooltip with a message explains why the button is disabled (see Mimis' PR for assignment button deletion).

@Bruce-8 Bruce-8 requested a review from david-yz-liu February 25, 2024 01:47
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@Bruce-8 good work. I just left one more comment.

Regarding the failing test: I don't believe it's related to your pull request, but you should be able to fix it here by passing ignore_query: true to the have_current_path method. Please do that in this PR.

@@ -89,3 +89,13 @@
data: { disable_with: t('working') } %>
</p>
<% end %>

<% unless @grade_entry_form.id.nil? %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh after you modified this I realized exactly what you were checking; use the new_record? method instead to check whether a model has been saved or not.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 8040446126

Details

  • -2 of 67 (97.01%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.008%) to 91.756%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/controllers/api/grade_entry_forms_controller.rb 7 9 77.78%
Totals Coverage Status
Change from base Build 8031400082: 0.008%
Covered Lines: 39090
Relevant Lines: 41980

💛 - Coveralls

@Bruce-8 Bruce-8 requested a review from david-yz-liu February 25, 2024 20:42
@david-yz-liu david-yz-liu merged commit 49a93d7 into MarkUsProject:master Feb 26, 2024
6 checks passed
@Bruce-8 Bruce-8 deleted the delete-mark-spreadsheet branch March 4, 2024 22:41
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.

3 participants