mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-14 15:00:16 +02:00
Grant srp.add_srpfleetmain access to create SRP request
See merge request allianceauth/allianceauth!1098
This commit is contained in:
commit
d429c8b59a
@ -1,4 +1,6 @@
|
||||
from django.conf.urls import include
|
||||
from django.contrib.auth.decorators import user_passes_test
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from functools import wraps
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib import messages
|
||||
@ -35,3 +37,32 @@ def main_character_required(view_func):
|
||||
messages.error(request, _('A main character is required to perform that action. Add one below.'))
|
||||
return redirect('authentication:dashboard')
|
||||
return login_required(_wrapped_view)
|
||||
|
||||
|
||||
def permissions_required(perm, login_url=None, raise_exception=False):
|
||||
"""
|
||||
Decorator for views that checks whether a user has a particular permission
|
||||
enabled, redirecting to the log-in page if necessary.
|
||||
If the raise_exception parameter is given the PermissionDenied exception
|
||||
is raised.
|
||||
|
||||
This decorator is identical to the django permission_required except it
|
||||
allows for passing a tuple/list of perms that will return true if any one
|
||||
of them is present.
|
||||
"""
|
||||
def check_perms(user):
|
||||
if isinstance(perm, str):
|
||||
perms = (perm,)
|
||||
else:
|
||||
perms = perm
|
||||
# First check if the user has the permission (even anon users)
|
||||
for perm_ in perms:
|
||||
perm_ = (perm_,)
|
||||
if user.has_perms(perm_):
|
||||
return True
|
||||
# In case the 403 handler should be called raise the exception
|
||||
if raise_exception:
|
||||
raise PermissionDenied
|
||||
# As the last resort, show the login form
|
||||
return False
|
||||
return user_passes_test(check_perms, login_url=login_url)
|
||||
|
@ -17,6 +17,8 @@
|
||||
<a href="{% url 'srp:all' %}" class="btn btn-primary">
|
||||
{% trans "View All" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if perms.srp.add_srpfleetmain or perms.auth.srp_management %}
|
||||
<a href="{% url 'srp:add' %}" class="btn btn-success">
|
||||
{% trans "Add SRP Fleet" %}
|
||||
</a>
|
||||
|
@ -10,6 +10,7 @@ from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db.models import Sum
|
||||
from allianceauth.authentication.decorators import permissions_required
|
||||
from allianceauth.eveonline.providers import provider
|
||||
from allianceauth.notifications import notify
|
||||
from .form import SrpFleetMainForm
|
||||
@ -59,7 +60,7 @@ def srp_fleet_view(request, fleet_id):
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required('auth.srp_management')
|
||||
@permissions_required(('auth.srp_management', 'srp.add_srpfleetmain'))
|
||||
def srp_fleet_add_view(request):
|
||||
logger.debug("srp_fleet_add_view called by user %s" % request.user)
|
||||
completed = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user