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

Issue 326 : Restrict organization creation : use Django permissions #327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pytition/petition/templates/layouts/nav-useractions.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
<span class="oi oi-plus"></span>
{% trans "New Petition" %}
</a>
{% if not settings.RESTRICT_ORG_CREATION or perms.petition.add_organization %}
<a class="dropdown-item" href="{% url "org_create" %}">
<span class="oi oi-plus"></span>
{% trans "New Organization" %}
</a>
{% endif %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url "account_settings" %}">
<span class="oi oi-cog"></span>
Expand Down
2 changes: 2 additions & 0 deletions pytition/petition/templates/petition/account_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ <h5 class="mt-2 mb-2"><a href="{% url 'org_dashboard' org.slugname %}">{{org.nam
{% else %}
<i>{% trans "You are not part of any organization" %}</i>
{% endif %}
{% if not settings.RESTRICT_ORG_CREATION or perms.petition.add_organization %}
<div class="text-center mt-5">
<a href="{% url 'org_create' %}" class="btn btn-primary">{% trans "Create an Organization" %}</a>
</div>
{% endif %}
</div>
<div class="tab-pane fade" id="delete_account_form" role="tabpanel"
aria-labelledby="delete-account-form-list">
Expand Down
5 changes: 4 additions & 1 deletion pytition/petition/templates/petition/user_org_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<div class="dashboard-nav-item py-3">
<div class="d-flex justify-content-between align-items-center flex-wrap">
<h4><span class="oi oi-people"></span>&nbsp;{% trans "Organizations" %}&nbsp;({{ user.organization_set.all.count }})</h4>
<a href="{% url "org_create" %}" class="btn btn-outline-primary btn-sm" data-toggle="tooltip" title="{% trans "Create a new organization" %}">{% trans "New organization" %}</a>
{% if not settings.RESTRICT_ORG_CREATION or perms.petition.add_organization %}
<a href="{% url "org_create" %}" class="btn btn-outline-primary btn-sm" data-toggle="tooltip"
title="{% trans "Create a new organization" %}">{% trans "New organization" %}</a>
{% endif %}
</div>
<ul class="dashboard-org-list">
{% for org in user.organization_set.all %}
Expand Down
2 changes: 1 addition & 1 deletion pytition/petition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ def account_settings(request):
# Create a new organization
@login_required
def org_create(request):
if settings.RESTRICT_ORG_CREATION and not request.user.is_superuser:
if settings.RESTRICT_ORG_CREATION and not request.user.has_perm('petition.add_organization'):
messages.error(request, _("Only super users can create an organization."))
return redirect("user_dashboard")
user = get_session_user(request)
Expand Down
1 change: 0 additions & 1 deletion pytition/pytition/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@
DISABLE_USER_PETITION = False

#:| If set to True, regular users won't be able to create new organizations.
#:| Only superusers will be allowed to
RESTRICT_ORG_CREATION = False

#:| Default address for 'Reply to' field in mail sent on account creation
Expand Down