Row selection for peer reviewer unassigning bypasses current unassign method#7274
Conversation
…imilar logic to Graders tab
| end | ||
| end | ||
| end | ||
| selected_reviewee_group_ids = [] # prevent whole row from being deleted |
There was a problem hiding this comment.
I'm pretty sure selected_reviewee_group_ids can be removed from the PeerReview.unassign() call.
…ixed case of row selction and individual reviewer selection
Pull Request Test Coverage Report for Build 12104886027Details
💛 - Coveralls |
| when 'unassign' | ||
| deleted_count, undeleted_reviews = PeerReview.unassign(selected_reviewee_group_ids, | ||
| reviewers_to_remove_from_reviewees_map) | ||
| unless selected_reviewee_group_ids.empty? # if a row was selected |
There was a problem hiding this comment.
This check isn't necessary (the .each below will not execute if selected_reviewee_group_ids is empty)
|
|
||
| context 'when applicable reviewers are selected' do | ||
| before do | ||
| @selected_reviewee_group_ids.each do |reviewee_id| |
There was a problem hiding this comment.
this block shouldn't be what you want (it doesn't make sense to mix reviewer group ids with reviewee group ids)
spec/models/peer_review_spec.rb
Outdated
| end | ||
|
|
||
| describe '#has_marks_or_annotations?' do | ||
| describe 'has_marks_or_annotations?' do |
There was a problem hiding this comment.
This change isn't correct; the # indicates that this is an instance method, as a Ruby convention
There was a problem hiding this comment.
self.get_num_marked and self.get_num_collected are marked with self., which from my knowledge, makes them class methods rather than instance methods. However, their corresponding test cases are also prefixed with #. Which naming convention should these test cases follow?
| deleted_count, undeleted_reviews = PeerReview.unassign(selected_reviewee_group_ids, | ||
| reviewers_to_remove_from_reviewees_map) | ||
| unless selected_reviewee_group_ids.empty? # if a row was selected | ||
| selected_reviewee_group_ids.each do |reviewee_id| # row selected reviewee |
There was a problem hiding this comment.
This algorithm is correct but pretty inefficient, as it involves a triply-nested loop.
You can improve this in a few ways:
- First, by joining on relevant
PeerReviewassociations, which in this case are:reviewerandreviewee(both of these refer toGroupings, but Rails will handle the SQL generation to avoid name conflicts---inspect the logged SQL query for more information) - You can use
whereon those associations, e.g..where(reviewer: { id: ... })and again Rails will produce the correct query - You can pass in an array of ids to a
wherecondition, and the resulting SQL query become anINoperation
As usual for complex queries, I recommend experimenting in the Rails console first before writing code to modify this method.
…justed controller tests for row selection case to correctly map reviewer ids based on the assigned reviewers through a database lookup
…justed controller tests for row selection case to correctly map reviewer ids based on the assigned reviewers through a database lookup
… peer-review-unassign-row-selection
|
Marking as "ready for review" to see how ci/cd tests run, still not 100% on these changes. Will re-request a review once I am ready for your review :) |
… peer-review-unassign-row-selection
david-yz-liu
left a comment
There was a problem hiding this comment.
@hemmatio nice work. I left a few comments for further improvement, but I think you're quite close. Also make sure to update the Changelog (this is indicated in the PR template checklist, which you should remember to fill out)
| @assignment = Assignment.find(params[:assignment_id]) | ||
| selected_reviewer_group_ids = params[:selectedReviewerGroupIds] || [] | ||
| selected_reviewee_group_ids = params[:selectedRevieweeGroupIds] || [] | ||
| selected_reviewer_group_ids = Array(params[:selectedReviewerGroupIds]) || [] |
There was a problem hiding this comment.
I'm not sure why adding Array is needed here, as this PR isn't changing the front-end at all? If you're having trouble with the tests you've added, you can call Array in the tests themselves.
| reviewers_to_remove_from_reviewees_map) | ||
| peer_reviews_filtered = PeerReview.joins(:reviewer, :reviewee) | ||
| .where(reviewer: { id: selected_reviewer_group_ids }) | ||
| .where(reviewee: { id: selected_reviewee_group_ids }) |
There was a problem hiding this comment.
Also, these don't need to be separate where clauses, as .where takes an arbitrary number of arguments and treats them as an AND, which is what you want in this case
… peer-review-unassign-row-selection
… as their respective tests
david-yz-liu
left a comment
There was a problem hiding this comment.
@hemmatio great work!
By the way, I missed your earlier question about naming conventions for tests: the # symbol is used to prefix instance method names; the . is used to prefix class method names. Somewhat confusingly, class methods are defined using "self":
class A:
def my_instance_method # no "self"
...
end
def self.my_class_method # "self" indicates this is a class method
...
end
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.)
When selecting an entire row, the necessary checks from #7263 are being bypassed. For reference, an image of "row selection":
Proposed fix: make the row-selected behaviour consistent with the behaviour from the Graders tab.
An image of the Graders tab is as follows:

...
Screenshots of your changes (if applicable)
Examples of acceptable selections for unassignment:Associated documentation repository pull request (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)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:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)
14/11/24: I've gone through and replicated the Graders tab logic for the row selection case. I still need to add tests.
19/11/24: Tests have been added for various row selection cases. I have removed the method
delete_all_reviews_for()in thePeerReviewclass, as well as all calls for it within the peer review unassign logic, as it is not useful.