From 6873b0bfe997497e7c6669b9df3a71815a316e78 Mon Sep 17 00:00:00 2001 From: Danyal Faheem <138459282+Danyal-Faheem@users.noreply.github.com> Date: Thu, 23 Nov 2023 17:33:50 +0500 Subject: [PATCH] Don't display submissions count and max submissions to anonymous users (#3) * feat: unauthenticated users can now vote and see results of polls * refactor: Add function to check if current user is anonymous user * refactor: Change anonymous user vote to a service call * fix: render max_submissions correctly after user votes * refactor: add function to get anonymous user poll service * fix: don't display submissions_count to anonymous user --- poll/poll.py | 3 +-- poll/public/html/poll.html | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/poll/poll.py b/poll/poll.py index c14d81e..0b81849 100644 --- a/poll/poll.py +++ b/poll/poll.py @@ -576,6 +576,7 @@ def student_view(self, context=None): 'can_view_private_results': self.can_view_private_results(), # a11y: Transfer block ID to enable creating unique ids for questions and answers in the template 'block_id': self._get_block_id(), + 'is_anonymous_user': self.is_anonymous_user(), }) if self.choice: @@ -762,8 +763,6 @@ def is_anonymous_user(self): user_service = self.runtime.service(self, 'user') user = user_service.get_current_user() return not user.opt_attrs.get('edx-platform.is_authenticated') - - @XBlock.json_handler def studio_submit(self, data, suffix=''): diff --git a/poll/public/html/poll.html b/poll/public/html/poll.html index 627be0f..fc54eb0 100644 --- a/poll/public/html/poll.html +++ b/poll/public/html/poll.html @@ -40,11 +40,13 @@

{{ display_name }}

{% trans 'Thank you.' %} + {% if not is_anonymous_user %}
{% blocktrans with submissions_count_s='{{ submissions_count }}' max_submissions_s='{{ max_submissions }}' %} You have used {{ submissions_count_s }} out of {{ max_submissions_s }} submissions. {% endblocktrans %}
+ {% endif %} {% if feedback %}