Skip to content

Commit

Permalink
Merge pull request #152 from fsinfuhh/poll_creation_requires_login
Browse files Browse the repository at this point in the history
Add configuration that requires login for poll creation
  • Loading branch information
timonegk authored Jan 12, 2024
2 parents 81fe0d9 + 17f99e5 commit 3f8640c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
10 changes: 10 additions & 0 deletions bitpoll/base/templates/base/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
<section class="section create-poll">
<div class="container">
<div class="halfsize">
{% value_from_settings POLL_CREATION_REQUIRES_LOGIN as requires_login %}
{% value_from_settings POLL_CREATION_ACCOUNT_WEBSITE as account_website %}
{% value_from_settings POLL_CREATION_ACCOUNT_NAME as account_name %}
{% if requires_login and request.user.is_anonymous %}
<h1>{% trans 'Login required to create polls' %}</h1>
<hr/>
<p class="lead">{% blocktrans %}This instance is reserved for users of <a href="{{ account_website }}">{{ account_name }}</a>.
If you do not have an account there, please use the public version at <a href="https://bitpoll.de">bitpoll.de</a>.{% endblocktrans %}</p>
{% else %}
<h1>{% trans 'Create a poll' %}</h1>
<hr/>
<form method="POST" class="form" action="{% url 'index' %}">
Expand Down Expand Up @@ -190,6 +199,7 @@ <h1>{% trans 'Create a poll' %}</h1>
<input type="submit" value="{% trans 'Create' %}" class="action primary"/>
</div>
</form>
{% endif %}
</div>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion bitpoll/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def index(request):
"""
public_polls = Poll.objects.filter(public_listening=True) # TODO: limit & sotierung & pagination oder so?
randomize_url = settings.DEFAULT_RANDOM_SLUG == 'true' # this settings value is a javascript true/false
if request.method == 'POST':
if request.method == 'POST' and (request.user.is_authenticated or not settings.POLL_CREATION_REQUIRES_LOGIN):
randomize_url = 'random_slug' in request.POST
post_data = request.POST.copy()
if randomize_url and request.POST.get('url', '') == '':
Expand Down
6 changes: 6 additions & 0 deletions bitpoll/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
'GROUP_MANAGEMENT',
'PUBLIC_POLLS',
'CALENDAR_ENABLED',
'POLL_CREATION_REQUIRES_LOGIN',
'POLL_CREATION_ACCOUNT_WEBSITE',
'POLL_CREATION_ACCOUNT_NAME',
]

LOGIN_REDIRECT_URL = "/"
Expand Down Expand Up @@ -332,6 +335,9 @@

REGISTER_ENABLED = True
GROUP_MANAGEMENT = REGISTER_ENABLED
POLL_CREATION_REQUIRES_LOGIN = False
POLL_CREATION_ACCOUNT_WEBSITE = "https://example.org"
POLL_CREATION_ACCOUNT_NAME = "Example"

CSP_REPORT_ONLY = True
CSP_REPORT_URL = ""
Expand Down
18 changes: 17 additions & 1 deletion locale/de_DE/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-04 00:45+0200\n"
"POT-Creation-Date: 2023-12-15 15:58+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Timon Engelke <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -238,6 +238,22 @@ msgstr ""
"Wenn du mithelfen möchtest, kannst du dies bei <a href=\"https://github.com/"
"fsinfuhh/BitPoll\">GitHub</a> tun."

#: bitpoll/base/templates/base/index.html:21
msgid "Login required to create polls"
msgstr "Zum Erstellen von Umfragen wird ein Account benötigt"

#: bitpoll/base/templates/base/index.html:23
msgid ""
"This instance is reserved for users of <a "
"href=\"%(account_website)s\">%(account_name)s</a>.\n"
" If you do not have an account there, please use the public "
"version at <a href=\"https://bitpoll.de\">bitpoll.de</a>."
msgstr ""
"Diese Seite kann nur von <a href=\"%(account_website)s\">%(account_name)s-"
"Nutzern</a> genutzt werden.\n"
" Wenn du keinen %(account_name)s-Account hast, nutze bitte "
"die öffentliche Version auf <a href=\"https://bitpoll.de\">bitpoll.de</a>."

#: bitpoll/base/templates/base/index.html:19
msgid "Create a poll"
msgstr "Erstelle eine Umfrage"
Expand Down
18 changes: 16 additions & 2 deletions locale/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-04 00:45+0200\n"
"POT-Creation-Date: 2023-12-15 15:58+0100\n"
"PO-Revision-Date: 2022-07-04 00:46+0200\n"
"Last-Translator: Timon Engelke <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -200,7 +200,21 @@ msgid ""
"a>."
msgstr ""

#: bitpoll/base/templates/base/index.html:19
#: bitpoll/base/templates/base/index.html:21
#, fuzzy
#| msgid "Login required to vote."
msgid "Login required to create polls"
msgstr "Login required to vote."

#: bitpoll/base/templates/base/index.html:23
msgid ""
"This instance is reserved for users of <a "
"href=\"%(account_website)s\">%(account_name)s</a>.\n"
" If you do not have an account there, please use the public "
"version at <a href=\"https://bitpoll.de\">bitpoll.de</a>."
msgstr ""

#: bitpoll/base/templates/base/index.html:26
msgid "Create a poll"
msgstr "Create a poll"

Expand Down
19 changes: 18 additions & 1 deletion locale/it_IT/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,24 @@ msgstr ""
" <a href=\"https://github.com/fsinfuhh/BitPoll\">GitHub</"
"a>."

#: bitpoll/base/templates/base/index.html:19
#: bitpoll/base/templates/base/index.html:23
msgid "Login required to create polls"
msgstr "Accesso richiesto per creare sondaggi"

#: bitpoll/base/templates/base/index.html:25
#, python-format
msgid ""
"This instance is reserved for users of <a "
"href=\"%(account_website)s\">%(account_name)s</a>.\n"
" If you do not have an account there, please use the public "
"version at <a href=\"https://bitpoll.de\">bitpoll.de</a>."
msgstr ""
"Questa istanza è riservata agli utenti di <a "
"href=\"%(account_website)s\">%(account_name)s</a>.\n"
"Se non si dispone di un account, utilizzare la versione pubblica su <a "
"href=\"https://bitpoll.de\">bitpoll.de</a>."

#: bitpoll/base/templates/base/index.html:28
msgid "Create a poll"
msgstr "Crea un sondaggio"

Expand Down

0 comments on commit 3f8640c

Please sign in to comment.