authentic/src/authentic2/apps/authenticators/manager_urls.py

76 lines
2.4 KiB
Python

# authentic2 - versatile identity manager
# Copyright (C) 2010-2022 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.auth.decorators import user_passes_test
from django.core.exceptions import PermissionDenied
from django.urls import path
from django.utils.functional import lazy
from authentic2.decorators import required
from authentic2.utils import misc as utils_misc
from . import views
def superuser_required(function, login_url):
def check_superuser(user):
if user and user.is_superuser:
return True
if user and not user.is_anonymous:
raise PermissionDenied()
return False
actual_decorator = user_passes_test(check_superuser, login_url=login_url)
return actual_decorator(function)
def superuser_login_required(func):
return superuser_required(func, login_url=lazy(utils_misc.get_manager_login_url, str)())
urlpatterns = required(
superuser_login_required,
[
# Authenticators
path('authenticators/', views.authenticators, name='a2-manager-authenticators'),
path(
'authenticators/add/',
views.add,
name='a2-manager-authenticator-add',
),
path(
'authenticators/<int:pk>/detail/',
views.detail,
name='a2-manager-authenticator-detail',
),
path(
'authenticators/<int:pk>/edit/',
views.edit,
name='a2-manager-authenticator-edit',
),
path(
'authenticators/<int:pk>/delete/',
views.delete,
name='a2-manager-authenticator-delete',
),
path(
'authenticators/<int:pk>/toggle/',
views.toggle,
name='a2-manager-authenticator-toggle',
),
],
)