Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics.
This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
Previously, we were deleting the `enable_topic_voting` custom field param
and doing the staff logging in this plugin. This has a problem though, it
was being done in the model's create/destroy hooks and was missing the
acting user (so the logs would report the change as `system`).
This PR keeps the custom field param and relies on core to do the staff
action logging. This change also results in the custom field being set
in the DB when it is enabled even though we don't use it in the serializer.
On the category settings page if the voting plugin is enabled and user
clicks “Save Category” button then the database record for the
`discourse_voting_category_settings` table is deleted and recreated
every time the button is pressed. This commit checks for existing record
and prevents creation of new database record
We shouldn't add vote fields for personal messages since users can't vote there. If we include then it's creating an N+1 issue in the `private-messages-all` endpoint.
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>
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
- Secure the vote / unvote paths
- Improve perf, only ask for voters on click
- Remove all concept of supervotes
- Limit voting to a much saner and smaller number
- Improve rendering