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

Prevent deletion of graded peer reviews #7263

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

hemmatio
Copy link
Member

@hemmatio hemmatio commented Oct 10, 2024

Proposed Changes

(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)
This PR aims to fix #7119. Currently, instructors are able to unassign peer reviewers no matter the situation. This PR prevents peer reviewers from being unassigned in the case that grade data exists, annotations exist, or the peer review is set to complete.

Screenshots of your changes (if applicable) Case 1: Successfully unassigned all image

Case 2: Could not unassign any
image

Case 3: Unassigned some, could not unassign rest (less than 5)
image

Case 4: Unassigned some, could not unassign rest (more than 5)
image

Associated documentation repository pull request (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

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

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

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

(Include any questions or comments you have regarding your changes.)
09/10/24: This is still a WIP, I just wanted to save my work on GitHub.

15/10/24: Added more error/success flashes, moved flash messages to locale file, modified logic of mark checking to check for non-nil mark criteron

22/10/24: Updated error messages to include reviewer and reviewee pairs to prevent any confusion in the case that the same reviewer cannot be unassigned in multiple different cases. Updated error flashes to be truncated when more than 5 reviewers could not be unassigned. Updated the exclamation mark in error flashes to be centred when the message is more than one line long. Added testcase which mocks that has_marks_or_annotations? returns true, then ensures that no peer reviews are deleted in that case.
Also: Is it necessary to update the project documentation for this? I see that the peer review wiki does not have anything yet, which I believe would be the related documentation.

23/10/24: Added more comprehensive testcases to cover all written lines of code. Mocks behaviour for each flashed message, and fully covers logic of has_marks_or_annotations? checking each criterion for a non-nil mark.

24/10/24: When selecting an entire row, the necessary checks were being bypassed. To fix this, I processed each row selection to be treated as if individual reviewers were selected.
For reference, an image of "row selection": image

…r and reviewee pairs. Updated css stylesheet to centre the exclamation mark in error flashes when the error message is multiple lines. Added testcase to ensure that has_marks_or_annotations? works as expected, and prevents peer reviewers from being unassigned
@hemmatio hemmatio marked this pull request as ready for review October 23, 2024 21:36
@hemmatio
Copy link
Member Author

Sorry, I requested a review prematurely. I'll re-request once I am fully prepared for a review.

@hemmatio hemmatio marked this pull request as draft October 23, 2024 21:48
@hemmatio hemmatio marked this pull request as ready for review October 23, 2024 21:48
@hemmatio hemmatio removed the request for review from david-yz-liu October 23, 2024 21:49
@coveralls
Copy link
Collaborator

coveralls commented Oct 23, 2024

Pull Request Test Coverage Report for Build 11493476708

Details

  • 80 of 80 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 91.665%

Totals Coverage Status
Change from base Build 11452193434: 0.01%
Covered Lines: 40733
Relevant Lines: 43764

💛 - Coveralls

@hemmatio hemmatio marked this pull request as draft October 23, 2024 22:13
@hemmatio hemmatio marked this pull request as ready for review October 24, 2024 03:19
…ections (Previously row selections bypassed the necessary checks)
unless reviewee_group.nil? || reviewer_group.nil?
peer_review = reviewer_group.review_for(reviewee_group)
unless peer_review.nil?
if peer_review.has_marks_or_annotations?
Copy link
Contributor

Choose a reason for hiding this comment

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

This check (peer_review.has_marks_or_annotations?) is good, but you should reorganize as follows: instead of adding it here, add it as a before_destroy callback. The delete_peer_review_between method calls destroy, and will trigger the callback. This is more robust because it will affect everywhere that a peer review is attempted to be destroyed, not just this particular method.

(It's possible to also skip callbacks, in case we ever want to enable that in the future.)

unless peer_review.nil?
if peer_review.has_marks_or_annotations?
delete_all_reviews = false
undeleted_reviews.append(reviewer_group.get_all_students_in_group +
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Use the group name rather than the students (the latter will make the message look weird when students are working in groups)
  2. Make this entire string internationalized

def has_marks_or_annotations?
result = self.result
marks_not_nil = false
result.marks.each do |mark|
Copy link
Contributor

Choose a reason for hiding this comment

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

This is inefficient, and can be simplified into a single query with exists?

deleted_count = 0
undeleted_reviews = []

# When an entire row is selected for unassignment
Copy link
Contributor

Choose a reason for hiding this comment

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

This is interesting, it's seems you're actually fixing a separate bug here; please pull this out and make into into a new pull request with a description of just this bug.

PeerReview.unassign(selected_reviewee_group_ids, reviewers_to_remove_from_reviewees_map)
reviews_deleted, deleted_count, undeleted_reviews = PeerReview.unassign(selected_reviewee_group_ids,
reviewers_to_remove_from_reviewees_map)
if !reviews_deleted && deleted_count == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this case needs a separate message, you can merge it with the next one (length <= 5). See also my suggestion for rewording the message down below.

@@ -498,6 +498,8 @@ option.uncollected {
.flash-content {
display: inline-block;
padding-left: 5pt;
vertical-align: middle;
max-width: calc(100% - 3em);
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep all rules alphabetically ordered (I'm surprised the pre-commit hooks didn't pick up on this, but that's something I'll look into separately!)

@@ -9,6 +9,9 @@ en:
assigned_reviewers_header: Reviewers
errors:
cannot_allow_reviewer_to_be_reviewee: A student cannot be a reviewer and reviewee
cannot_unassign_all_reviewers: 'Cannot unassign all selected peer reviewers due to existing marks or annotations. %{deleted_count} peer reviewer(s) were unassigned, but the following could not be: %{undeleted_reviews}.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Reword to "Successfully unassigned %{deleted_count} peer reviewer(s), but could not unassign the following due to existing marks or annotations: ..."

@reviewer = Grouping.find_by(id: @selected_reviewer_group_ids[0])
@reviewee = Grouping.find_by(id: @selected_reviewee_group_ids[1])
allow_any_instance_of(PeerReview).to receive(:has_marks_or_annotations?).and_return(true)
selected_group = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really necessary to create separate hash variables like this, you can define it inline as { @reviewee.id => { @reviewer.id => true } } or something similar

end
end

it 'does not delete the peer review' do
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to be testing whether or not the database was actually changed here, and you should be doing it in the other tests as well

@@ -88,4 +88,23 @@
end
end
end

describe '#has_marks_or_annotations?' do
Copy link
Contributor

Choose a reason for hiding this comment

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

This set of test cases is incomplete, you should be adding more cases (don't just rely on code coverage to tell you whether the tests are complete or not)

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.

Prevent deletion of graded peer reviews
3 participants