-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow unauthenticated users to vote and see results of polls #2
Conversation
poll/poll.py
Outdated
@@ -662,6 +664,12 @@ def get_results(self, data, suffix=''): | |||
if self.private_results and not self.can_view_private_results(): | |||
detail, total = {}, None | |||
else: | |||
# Get tally from the db directly | |||
tally = self.get_tally() | |||
if not self.runtime._services['user'].get_current_user().opt_attrs['edx-platform.is_authenticated'] and tally: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code readability could be improved by converting first condition into a function.
if not self.runtime._services['user'].get_current_user().opt_attrs['edx-platform.is_authenticated'] and tally: | |
if self.is_anonymous_user() and tally: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Changes
Service
A service was necessary as the
FieldDataCache
object was being used by the xblocks to store and update data.FieldDataCache
was not storing or fetching cache for anonymous users. As the cache was not present in the case of anonymous users, the ORM would try to add a new entry for the poll with the same primary key, thereby resulting in an integrity error.To get around this and not having to change the
FieldDataCache
class, we decided to create a service and then update the tally in the database ourselves rather than let the LMS handle it in the case of an anonymous users vote.IP Hashing
IP hashing was not done as xblocks in openedx have a
student_module
table where they store every interaction of the student with every single xblock. Each vote of the poll by an authenticated user is stored there. Xblocks manage this data themselves and they do not keep a similar record for unauthenticated users.Unauthenticated users have their state managed for the session by the LMS itself and then the data is deleted. To store IP hash, we will need to keep track of unauthenticated users ourselves. For that reason, we would have had to create a new model and store the IP hash there. To avoid the scenario of running migrations, we did not go through with this idea.
Authenticated users flow
Authenticated users have no difference in the experience from before.
Fixes