0
0
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:
Nick Smith 2014-07-09 16:55:41 +01:00 committed by Matt Westcott
parent 776e3c4c7a
commit f4afab58d6
3 changed files with 20 additions and 5 deletions

View File

@ -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.port %}
{% include "wagtailadmin/shared/field_as_li.html" with field=form.root_page %} {% 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 %} {% 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> </ul>
</div> </div>
</form> </form>

View File

@ -3,8 +3,12 @@
{% block titletag %}{% trans "Sites" %}{% endblock %} {% block titletag %}{% trans "Sites" %}{% endblock %}
{% block content %} {% block content %}
{% trans "Sites" as sites_str %} {% trans "Sites" as sites_str %}
{% trans "Add a site" as add_a_site_str %} {% if perms.site.add_site %}
{% include "wagtailadmin/shared/header.html" with title=sites_str add_link="wagtailsites_create" add_text=add_a_site_str icon="radio-empty" %} {% 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 class="nice-padding">
<div id="sites-list"> <div id="sites-list">

View File

@ -1,13 +1,20 @@
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.contrib import messages 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 django.utils.translation import ugettext as _
from wagtail.wagtailcore.models import Site from wagtail.wagtailcore.models import Site
from wagtail.wagtailsites.forms import SiteForm 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): def index(request):
sites = Site.objects.all() sites = Site.objects.all()
return render(request, 'wagtailsites/index.html', { return render(request, 'wagtailsites/index.html', {