FEATURE: Staff only poll results (PR #7984)

These changes allow only staff to see the results of a poll.

Non-staff users will be shown a screen like this:

https://aws1.discourse-cdn.com/review/original/1X/1b8bd76013363860f2bc455049cf35e69ef44e0a.png

The “Votes are public” message has been removed from the info section, and the button to show the votes has been replaced with a message stating the results will only be shown to staff.

GitHub

You’ve signed the CLA, oblakeerickson. Thank you! This pull request is ready for review.

    const staffonly = poll.results === "staff_only";
1 Like
    const isStaff = this.get("currentUser.staff");
1 Like
    const isStaff = this.get("currentUser.staff");
1 Like
    const hideResultsDisabled = !staffOnly && (closed || topicArchived);
1 Like
      } else if (poll.results === "staffOnly" && !isStaff) {
1 Like
        isStaff) &&
1 Like
        isStaff) &&
1 Like
      (poll.results !== "on_close" &&
1 Like
        !(poll.results === "staff_only"));
1 Like
          if (this.get("currentUser.staff")) {
1 Like
          if (this.get("currentUser.staff")) {
1 Like
        if (attrs.poll.results === "staff_only") {
1 Like
    if (!attrs.isClosed && !attrs.showResults && poll.public && (poll.results !== "staff_only")) {
1 Like

Maybe “on_close” and “staff_only” would deserve a const in the js file.

const ON_CLOSE = "on_close";
const STAFF_ONLY = "staff_only";
          title: "Results are only shown to <strong>staff</strong> members."

Or something similar?

1 Like

If we only ever want staff member to see the results, we might want to rewrite this method like this

def can_see_results?(user)
  return true if always?
  return user&.staff? if staff_only?
  return has_voted?(user) if on_vote?
  is_closed?
end
1 Like

This showResults variable should be kept in sync with the can_see_results?(user) method.

1 Like

Since we want to return a boolean, we might want to change this line

    return !!user&.staff? if staff_only?
1 Like