Skip to content
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

Can't unwatch a poll under certain conditions #134

Open
MarkusNeblung opened this issue Feb 17, 2023 · 0 comments
Open

Can't unwatch a poll under certain conditions #134

MarkusNeblung opened this issue Feb 17, 2023 · 0 comments

Comments

@MarkusNeblung
Copy link
Contributor

I recognized it with following workflow: create a poll with "show complete results" -> watch the poll -> change poll settings to " never show results". Now I get the error message "You are not allowed to watch this poll.", if I try to unwatch the poll.

I see 2 possible solutions:

def can_watch(self, user: AbstractUser) -> bool:
if self.can_vote(user) and self.show_results not in ('never', 'summary after vote', 'complete after vote'):
# If the user can vote and the results are not restricted
return True
if self.has_voted(user) and self.show_results not in ('never', ):
# If the user has voted and can view the results
return True
return False

Change the return False to return self.is_ower(user). This will fix the problem only for the owners. But it's possible that other users have the same problem.

@require_POST
@login_required
def watch(request, poll_url):
current_poll = get_object_or_404(Poll, url=poll_url)
if not current_poll.can_watch(request.user):
messages.error(
request, _("You are not allowed to watch this poll.")
)
return redirect('poll', poll_url)
if current_poll.user_watches(request.user):
poll_watch = PollWatch.objects.get(poll=current_poll, user=request.user)
poll_watch.delete()
else:
poll_watch = PollWatch(poll=current_poll, user=request.user)
poll_watch.save()
return redirect('poll', poll_url)

Rearrange this method so that it only throws the error if the user try to watch the poll. This allows to always unwatch to poll.

Beside that it would be helpful if owners always can watch a poll (they can always see the results, so why not allow them always to watch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant