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
AO3-5603 Revise WorksController to eliminate set_instance_variables. #3517
AO3-5603 Revise WorksController to eliminate set_instance_variables. #3517
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of initial comments/questions, no rush -- I still need to look at the works_controller more thoroughly.
|
||
@work.preview_mode = !!(params[:preview_button] || params[:edit_button] || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double !!
is throwing me off here -- could you translate this from code to English for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically a type-conversion to ensure that @work.preview_mode
is true or false instead of "Preview"
, "Edit"
, "Cancel"
, or nil
. A single !
acts as negation and forces the results to be either true or false, so a double-negation cancels out the negation and just converts to a boolean. I'm pretty sure it would work without the double negation -- I only added it because at one point I tried to print out @work.preview_mode
and found the fact that it held a string confusing.
# prompter notification (separate from the recipient notification) ensuring | ||
# that anonymous prompters are notified, and (b) if the prompter is not | ||
# anonymous, they'll receive two notifications with roughly the same info | ||
# (gift notification + prompter notification). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was never called before, so having it now would likely fix AO3-3556 as well, we'll see.
Notes for me: @sarken said we handle prompter notification at:
Lines 100 to 109 in bd4f323
# notify prompters of response to their prompt | |
def notify_prompters | |
if !self.challenge_claims.empty? && !self.unrevealed? | |
if self.collections.first.nil? | |
UserMailer.prompter_notification(self.id,).deliver | |
else | |
UserMailer.prompter_notification(self.id, self.collections.first.id).deliver | |
end | |
end | |
end |
and also (for unrevealed works specifically):
otwarchive/app/models/collection_item.rb
Lines 310 to 313 in 5954492
# also notify prompters of responses to their prompt | |
if item_type == "Work" && !item.challenge_claims.blank? | |
UserMailer.prompter_notification(self.item.id, self.collection.id).deliver | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, though I'll leave the green label to the next reviewer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neglected to put my green check on it! Like red said, reviewer number 3 can flip the label.
Issue
https://otwarchive.atlassian.net/browse/AO3-5603
Purpose
set_instance_variables
.#new
, the code to build an item from params into#create
, and the code to modify an existing item into#update
.load_pseuds
(for the ChaptersController) andset_work_form_fields
(for the WorksController).WorksController#set_instance_variables_tags
.params[:cancel_button]
to the very beginning of the function, before assigning to attributes. Because some attribute assignment is written to the database immediately (e.g. tags), I figured that that was contrary to the purpose of the button.set_challenge_claim_info
. This means that it can be used alongsideset_challenge_info
(which works only for the work's assignments).Work#check_for_invalid_tags
into a validation. (It used to be a before_save callback that aborted in case of error, which meant that it would only display an error to the user ifWork#save
was called. Hence the complicated code in theWorksController#preview_mode
function to try to catch invalid tags on preview.)WorksController#work_tag_params
to make sure that it only allows the tags (and the language) to be changed, and not any of the other fields that are available inWorksController#work_params
.Testing
See Slack. In addition, it would be good to check that the refactored code behaves as expected.