mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 11:10:43 +01:00
More granular site perms, including hiding the Add/Delete buttons when not permitted
This commit is contained in:
parent
776e3c4c7a
commit
f4afab58d6
@ -15,7 +15,11 @@
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.port %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.root_page %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=form.is_default_site %}
|
||||
<li><input type="submit" value="{% trans 'Save' %}" /><a href="{% url 'wagtailsites_delete' site.id %}" class="button button-secondary no">{% trans "Delete site" %}</a></li>
|
||||
<li><input type="submit" value="{% trans 'Save' %}" />
|
||||
{% if perms.site.delete_site %}
|
||||
<a href="{% url 'wagtailsites_delete' site.id %}" class="button button-secondary no">{% trans "Delete site" %}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -3,8 +3,12 @@
|
||||
{% block titletag %}{% trans "Sites" %}{% endblock %}
|
||||
{% block content %}
|
||||
{% trans "Sites" as sites_str %}
|
||||
{% trans "Add a site" as add_a_site_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=sites_str add_link="wagtailsites_create" add_text=add_a_site_str icon="radio-empty" %}
|
||||
{% if perms.site.add_site %}
|
||||
{% trans "Add a site" as add_a_site_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=sites_str add_link="wagtailsites_create" add_text=add_a_site_str icon="radio-empty" %}
|
||||
{% else %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=sites_str icon="radio-empty" %}
|
||||
{% endif %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<div id="sites-list">
|
||||
|
@ -1,13 +1,20 @@
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from django.contrib.auth.decorators import permission_required, user_passes_test
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from wagtail.wagtailcore.models import Site
|
||||
from wagtail.wagtailsites.forms import SiteForm
|
||||
|
||||
|
||||
@permission_required('site.change_site')
|
||||
def user_has_site_model_perm(user):
|
||||
for verb in ['add', 'change', 'delete']:
|
||||
if user.has_perm('site.%s_site' % verb):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@user_passes_test(user_has_site_model_perm)
|
||||
def index(request):
|
||||
sites = Site.objects.all()
|
||||
return render(request, 'wagtailsites/index.html', {
|
||||
|
Loading…
Reference in New Issue
Block a user