diff --git a/adhocracy4/polls/serializers.py b/adhocracy4/polls/serializers.py index e178f3e21..bdee39a6d 100644 --- a/adhocracy4/polls/serializers.py +++ b/adhocracy4/polls/serializers.py @@ -1,3 +1,4 @@ +from django.conf import settings from rest_framework import serializers from adhocracy4.dashboard import components @@ -153,7 +154,12 @@ def get_has_user_vote(self, poll): return False def update(self, instance, data): - instance.allow_unregistered_users = data.get("allow_unregistered_users", False) + if getattr(settings, "A4_POLL_ENABLE_UNREGISTERED_USERS", False): + instance.allow_unregistered_users = data.get( + "allow_unregistered_users", False + ) + else: + instance.allow_unregistered_users = False instance.save() # Delete removed questions from the database instance.questions.exclude( diff --git a/adhocracy4/polls/static/PollDashboard/EditPollManagement.jsx b/adhocracy4/polls/static/PollDashboard/EditPollManagement.jsx index 4dba1e1cf..a9bf96585 100644 --- a/adhocracy4/polls/static/PollDashboard/EditPollManagement.jsx +++ b/adhocracy4/polls/static/PollDashboard/EditPollManagement.jsx @@ -208,10 +208,11 @@ export const EditPollManagement = (props) => { onSubmit={(e) => handleSubmit(e)} onChange={() => removeAlert()} className="editpoll__questions" > -
- - setAllowUnregisteredUsers((state) => !state)} checked={allowUnregisteredUsers} /> -
+ {props.enableUnregisteredUsers && +
+ + setAllowUnregisteredUsers((state) => !state)} checked={allowUnregisteredUsers} /> +
} { questions.map((question, index, arr) => { diff --git a/adhocracy4/polls/static/react_poll_management.jsx b/adhocracy4/polls/static/react_poll_management.jsx index 41b1566d8..9ed9fe43b 100644 --- a/adhocracy4/polls/static/react_poll_management.jsx +++ b/adhocracy4/polls/static/react_poll_management.jsx @@ -7,13 +7,11 @@ import { EditPollManagement } from './PollDashboard/EditPollManagement' function init () { ReactWidgetInit('a4', 'poll-management', function (el) { - const pollId = el.dataset.pollId + const props = JSON.parse(el.dataset.attributes) const root = createRoot(el) - const reloadOnSuccess = JSON.parse(el.getAttribute('data-reloadOnSuccess')) - root.render( - + ) } ) diff --git a/adhocracy4/polls/templatetags/react_polls.py b/adhocracy4/polls/templatetags/react_polls.py index 420475f20..41f90e3c5 100644 --- a/adhocracy4/polls/templatetags/react_polls.py +++ b/adhocracy4/polls/templatetags/react_polls.py @@ -21,14 +21,16 @@ def react_polls(poll: Poll): @register.simple_tag def react_poll_form(poll, reload_on_success=False): + attributes = { + "pollId": poll.pk, + "reloadOnSuccess": reload_on_success, + "enableUnregisteredUsers": getattr( + settings, "A4_POLL_ENABLE_UNREGISTERED_USERS", False + ), + } reload_on_success = json.dumps(reload_on_success) return format_html( - ( - '
' - "
" - ), - pollId=poll.pk, - reload_on_success=reload_on_success, + '
', + attributes=json.dumps(attributes), ) diff --git a/changelog/8381.md b/changelog/8381.md new file mode 100644 index 000000000..f7fcfb633 --- /dev/null +++ b/changelog/8381.md @@ -0,0 +1,6 @@ +### Added + +- add option to allow unregistered users to vote in a poll: + - the feature is controlled via a new django setting `A4_POLL_ENABLE_UNREGISTERED_USERS` to enable or disable it +- add a new captcha react component to integrate the captcha in the poll +