Fix possible discrepancy in author search with ignored authors #532
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #273.
The issue was that, in some cases, it was possible to add the same author more than once. Even though it was already a co-author of the post, it would still show up in search and be available for another addition - here, the last suggestion is the same user who is already an author of the post:
tl;dr - the issue was due to JS referencing existing authors by
user_nicename
while PHP byuser_login
.Getting a peak at what happened when a post is saved, it was clear that there was some mismatch between the newly-added coauthors and the already present ones. It looked like some case issue:
I expected this to be an issue with
search_authors()
- in particular, something to do with$ignored_authors
. Indeed, diving into the JS and PHP, I found out it was an issue with how ignored authors are handled by the two sides.JS takes care of making the AJAX request to
ajax_suggest()
, which in turn callssearch_authors()
. It sendsexisting_authors
as parameter, populating it with current authorsuser_nicename
s.But on the other side, PHP was deciding whether an author should be excluded from search comparing
user_login
s with the AJAX-supplied list ofuser_nicename
s. This would work fine in several situations - basically, all the timesuser_login
did not have any special chars or uppercase letters. But whenuser_nicename
was different fromuser_login
, this was clearly an issue.I thus changed
user_login
withuser_nicename
in the PHP bit. After this edit, the issue has gone! :)This edit does not affect anything else, as far as I am been able to check. All PHPUnit tests still succeed as they did before. Also,
search_authors()
is only called byajax_suggest()
, so it should really only affect its behavior (and that's what my tests have confirmed) :)