Skip to content

Commit

Permalink
Don't display submissions count and max submissions to anonymous users (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
Danyal-Faheem committed Nov 23, 2023
1 parent 1d40d2d commit 6873b0b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions poll/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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=''):
Expand Down
2 changes: 2 additions & 0 deletions poll/public/html/poll.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ <h3 class="poll-header">{{ display_name }}</h3>
<span>{% trans 'Thank you.' %}</span>
</div>

{% if not is_anonymous_user %}
<div class="poll-submissions-count poll-hidden">
{% blocktrans with submissions_count_s='<span class="poll-current-count">{{ submissions_count }}</span>' max_submissions_s='<span class="poll-max-submissions">{{ max_submissions }}</span>' %}
You have used {{ submissions_count_s }} out of {{ max_submissions_s }} submissions.
{% endblocktrans %}
</div>
{% endif %}

{% if feedback %}
<div class="poll-feedback-container{% if not choice %} poll-hidden{% endif %}">
Expand Down

0 comments on commit 6873b0b

Please sign in to comment.