Changing category settings would not always unhide the like button
because the model would not be updated on the client side until a full
page refresh.
The `Topic#update_vote_count` method should be concurrency-safe to prevent unique constraint violation errors when multiple processes try to insert a topic_votes_count record for the same topic simultaneously.
Signed-off-by: OsamaSayegh <asooomaasoooma90@gmail.com>
`/voting/who` path has `ensure_logged_in` so clicking the vote count to see who voted triggered http requests that ended with 403 error. Now, users are asked to log in, just like when clicking the "vote" button.
Was able to reproduce a bug where votes were not properly moved when merging two topics together. We were only checking duplicate votes if either both votes were either active or archived, and not a mix of the two. As a result, there were cases where the plugin was trying to move votes that already existed on an open topic, causing the merge to partially fail with a duplicate index error.
What this commit does is as follows:
- Cleaned up the logic so it's more readable. Previously it was duplicative and difficult to read.
- We're now checking if a user has a vote on Topic A (active or archived) and Topic B (active or archived) that we're properly deleting the origin vote and keeping the destination vote instead of trying to merge in a duplicate. (This caused the original bug described above).
- Per the specs on meta, topic merges move all votes to the destination topic, and if this causes a user to go over the limit, they'll have to wait until enough votes are released.
- If the destination topic is closed, the votes will be archived; if the destination topic is open, those votes will be active. This is regardless of origin vote state.
Also, the Gemfile was missing a source declaration to allow installation of gems/dependencies, so I've added that.
Problem was that we are adding `hidden` class to popup and jQuery `toggle()` function is not handling that properly. Therefore I decided to use `toggleClass` in that case and it works pretty well.
The bug was mentioned here - https://meta.discourse.org/t/voting-plugin/157676/8
The fix is pretty simple
result = result.select("*, ... AS current_user_voted")
become
result = result.select("topics.*, ... AS current_user_voted")
I also merged all 3 'TopicQuery.results_filter_callbacks' into one and did
some slight refactoring on the 'add_to_serializer'.
We are trying to avoid custom tables. Changes:
CategoryCustomField -> DiscourseVoting::CategorySetting # contains infromation if voting is enabled for category
UserCustomField -> DiscourseVoting::Vote # user's votes
TopicCustomField -> DiscourseVoting::VoteCounter # cache count for topics