Skip to content

v1.45.0 - Topic polls

Latest

Choose a tag to compare

@leafo leafo released this 08 Oct 20:19
· 2 commits to master since this release
v1.45.0

Migrate:

require("community.schema").run_migrations(45)

Additions

  • Add polls to topics. A topic can have one poll with a question, a set of choices, single or multiple choice voting, anonymous or named voters, and results that are either public or only visible to the topic author and moderators. Polls open when created and close at an end date (default one day, max 30 days).

Polls are off by default. Override Categories\allowed_to_create_poll(user) to enable them.

TopicPolls

  • Models: TopicPolls, PollChoices, PollVotes, with Topics getting a poll relation
  • vote_type enum: single, multiple
  • anonymous hides voter names from everyone but moderators, hide_results hides vote counts from everyone but the author and moderators
  • version is incremented when the question or choices change so a stale vote form is rejected
  • allowed_to_vote, allowed_to_view_results, allowed_to_view_voters, is_open, is_closed, has_votes, total_vote_count, reset_votes
  • TopicPolls\filter_text(text) is called on the question, choices and descriptions before saving. Override it to filter or reject text, like Posts\filter_body
  • PollChoices\vote(user) creates a vote, replacing the user's existing vote for single polls. Whether the vote is counted comes from CommunityUsers\count_poll_vote_for(poll_choice), an override point that defaults to true
  • PollChoices\preload_recent_votes(choices) loads the newest voters on each choice

TopicPollsFlow (community.flows.topic_polls)

  • vote with choice_id, action (create or delete) and poll_version. Sets @poll, @choice and @vote
  • choice_voters paginates the voters of a choice, sets @votes and @next_page
  • close_poll for the topic author or a moderator. A moderator closing someone else's poll writes a topic.close_poll moderation log
  • delete_poll and reset_poll_votes for moderators, logged as topic.delete_poll and topic.reset_poll_votes

Posting with polls

  • new_topic accepts topic[poll] with poll_question, description, vote_type, anonymous, hide_results, end_date (UTC YYYY-MM-DD HH:MM:SS) and choices[n][choice_text], choices[n][description]. A poll on a topic that goes to the pending queue is created when the pending post is promoted, with the duration measured from promotion
  • edit_post on a topic post accepts the same fields as post[poll], with choices[n][id] to keep an existing choice. Choices not submitted are deleted along with their votes. Once a poll has votes the question, vote type and existing choices are locked for the author, a moderator can still change them and the edit is logged as topic.edit_poll. The end date can be changed while the poll is open, a closed poll can't be reopened
  • BrowsingFlow\topic_posts preloads the topic's poll, choices and the viewing user's votes. preload_poll_voters is opt-in for views that list voters

Other

  • shapes.utc_timestamp for validating a YYYY-MM-DD HH:MM:SS string
  • AsyncCounter\sync returns the number of counters synced
  • Spec factories for TopicPolls and PollChoices

Changes

  • Moderating a pending post from CategoriesFlow\edit_pending_post or PendingPostsFlow now writes a moderation log for every action: post.approve_pending on promote and pending_post.status(...) otherwise, with the user and topic as log objects. edit_pending_post accepts the ignored status. ModerationLogs has a pending_post object type
  • ModerationLogs\get_action_text covers the poll actions
  • Blocks no longer prevent admins or moderators from replying to the user who blocked them
  • Posts\pin_to refuses to pin a reply above the topic post, and unpin puts the post back in date order instead of one position early
  • Posts\hard_delete uses Model.delete