AO3-3176 Prevent 500 error when editing chapter you didn't coauthor #2627
Conversation
sarken
added some commits
Aug 21, 2016
sarken
added the
Awaiting review
label
Nov 23, 2016
| + if item_type == "chapter" && @chapter.posted? | ||
| + to_select = @to_select.select { |pseud| pseud.user.id == current_user.id } | ||
| + pseuds = to_select.empty? ? @work.pseuds : to_select | ||
| + pseuds.collect { |pseud| pseud.id.to_i } |
| @@ -1,3 +1,3 @@ | ||
| module ChaptersHelper | ||
| - | ||
| + |
| - @selected_pseuds = to_select.collect {|pseud| pseud.id.to_i } | ||
| + @coauthors = @allpseuds.select{ |p| p.user.id != current_user.id } | ||
| + @to_select = @chapter.authors.blank? ? @chapter.pseuds.blank? ? @work.pseuds : @chapter.pseuds : @chapter.authors | ||
| + @selected_pseuds = @to_select.collect { |pseud| pseud.id.to_i } |
| - to_select = @chapter.authors.blank? ? @chapter.pseuds.blank? ? @work.pseuds : @chapter.pseuds : @chapter.authors | ||
| - @selected_pseuds = to_select.collect {|pseud| pseud.id.to_i } | ||
| + @coauthors = @allpseuds.select{ |p| p.user.id != current_user.id } | ||
| + @to_select = @chapter.authors.blank? ? @chapter.pseuds.blank? ? @work.pseuds : @chapter.pseuds : @chapter.authors |
houndci-bot
Nov 23, 2016
Ternary operators must not be nested. Prefer if or else constructs instead.
sarken
Nov 23, 2016
Owner
Yeah, so do I -- it took me hours to figure out what it was doing. However, I'm not too keen on refactoring it here, partially because I'd have to update two or three other pull requests, and partially because the corresponding code in the works controller should also be updated if we change this, and that's getting beyond the scope of this issue.
| - @coauthors = @allpseuds.select{ |p| p.user.id != current_user.id} | ||
| - to_select = @chapter.authors.blank? ? @chapter.pseuds.blank? ? @work.pseuds : @chapter.pseuds : @chapter.authors | ||
| - @selected_pseuds = to_select.collect {|pseud| pseud.id.to_i } | ||
| + @coauthors = @allpseuds.select{ |p| p.user.id != current_user.id } |
sarken
referenced
this pull request
Nov 23, 2016
Merged
AO3-4999 Chapter: Make it easier to see and add co-authors who are already on the work #2515
sarken
changed the title from
AO3-3176 Let co-authors edit all chapters to AO3-3176 Prevent 500 error when editing chapter you didn't coauthor
Nov 23, 2016
|
This has gone grey btw. |
sarken
added some commits
May 2, 2017
| - @selected_pseuds = to_select.collect {|pseud| pseud.id.to_i } | ||
| + @coauthors = @allpseuds.select{ |p| p.user.id != current_user.id } | ||
| + @to_select = @chapter.authors.blank? ? @chapter.pseuds.blank? ? @work.pseuds : @chapter.pseuds : @chapter.authors | ||
| + @selected_pseuds = @to_select.collect { |pseud| pseud.id.to_i } |
| + # Controls which of current_user's pseuds is selected when posting or editing | ||
| + # an item. It used to be handled with just @selected_pseuds from the item | ||
| + # type's controller (chapter, series, work), but needs a special case when | ||
| + # current_user is editing a chapter they didn't co-author. When that happens, # we want to select all pseuds current_user has listed on the work itself. |
sarken
May 8, 2017
Owner
I'll probably need to update this once we merge #2515 -- will fix this then!
| + if item_type == "chapter" && @chapter.posted? | ||
| + to_select = @to_select.select { |pseud| pseud.user.id == current_user.id } | ||
| + pseuds = to_select.empty? ? @work.pseuds : to_select | ||
| + pseuds.collect { |pseud| pseud.id.to_i } |
| - options_from_collection_for_select(@pseuds, :id, :name, @selected_pseuds), :multiple => true %> | ||
| + options_from_collection_for_select(@pseuds, :id, :name, | ||
| + selected_pseuds(type)), | ||
| + multiple: true %> |
| + if item_type == "chapter" && @chapter.posted? | ||
| + to_select = @to_select.select { |pseud| pseud.user.id == current_user.id } | ||
| + pseuds = to_select.empty? ? @work.pseuds : to_select | ||
| + pseuds.collect { |pseud| pseud.id } |
houndci-bot
May 9, 2017
Prefer map over collect.
Pass &:id as an argument to collect instead of a block.
bingeling
added Reviewed: Ready to Merge and removed Awaiting review
labels
May 10, 2017
bingeling
merged commit adf5f9d
into otwcode:master
May 10, 2017
2 checks passed
Scrutinizer
1 updated code elements
Details
hound
6 violations found.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sarken commentedNov 23, 2016
Issue
https://otwarchive.atlassian.net/browse/AO3-3176
Purpose
Prevents a 500 error that happens when trying to edit a chapter you didn't co-author on a work you did co-author.
The problem here is you have to include a pseud when posting or editing a chapter. If you're posting a new chapter or editing a chapter you're already a co-author of, one or more pseuds are selected for you and everything works smoothly. However, when you're editing a chapter you're not already a co-author of, none of your pseuds are selected. (If you had multiple pseuds and knew the cause of the error, this wasn't a huge problem: there was a visible field to select the pseuds you wanted to add to the chapter. Once you chose one or more pseuds, everything worked great! But if you only had a default pseud, the field was hidden.)
So what we're doing here is saying, "Okay, if we're editing a chapter this person's not already a co-author on, select and add all the pseuds they have used on this work so far."
References
Starts with #2515 to avoid merge conflicts and take advantage of test changes. 2666aca is the commit with the relevant changes.
This should be merged with the other two chapter co-authoring pull requests, #2515 and #2518.