FEATURE: Show votes in an "on voted" poll to the creator

This required properly plumbing the guardian into the serializer.

Notably, the default state in the client was not changed - if you haven't voted in
the poll, you need to click the button to view the results instead of the results
being immediately visible on page load.

Implements https://meta.discourse.org/t/-/138108
This commit is contained in:
Kane York
2020-03-20 11:29:00 -07:00
committed by Kane York
parent 0d3386d255
commit 330102fd20
6 changed files with 30 additions and 11 deletions

View File

@ -678,6 +678,7 @@ createWidget("discourse-poll-buttons", {
const staffOnly = poll.results === "staff_only";
const isStaff = this.currentUser && this.currentUser.staff;
const isAdmin = this.currentUser && this.currentUser.admin;
const isMe = this.currentUser && post.user_id === this.currentUser.id;
const dataExplorerEnabled = this.siteSettings.data_explorer_enabled;
const hideResultsDisabled = !staffOnly && (closed || topicArchived);
const exportQueryID = this.siteSettings.poll_export_data_explorer_query_id;
@ -710,7 +711,7 @@ createWidget("discourse-poll-buttons", {
})
);
} else {
if (poll.get("results") === "on_vote" && !attrs.hasVoted) {
if (poll.get("results") === "on_vote" && !attrs.hasVoted && !isMe) {
contents.push(infoTextHtml(I18n.t("poll.results.vote.title")));
} else if (poll.get("results") === "on_close" && !closed) {
contents.push(infoTextHtml(I18n.t("poll.results.closed.title")));