2020-05-16 18:55:59 +01:00
|
|
|
"""passbook PolicyBinding administration"""
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.contrib.auth.mixins import (
|
|
|
|
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
|
|
|
)
|
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.utils.translation import ugettext as _
|
2020-07-01 23:13:33 +01:00
|
|
|
from django.views.generic import ListView, UpdateView
|
2020-05-16 18:55:59 +01:00
|
|
|
from guardian.mixins import PermissionListMixin, PermissionRequiredMixin
|
|
|
|
|
2020-07-01 23:13:33 +01:00
|
|
|
from passbook.admin.views.utils import DeleteMessageView
|
2020-05-16 18:55:59 +01:00
|
|
|
from passbook.lib.views import CreateAssignPermView
|
|
|
|
from passbook.policies.forms import PolicyBindingForm
|
|
|
|
from passbook.policies.models import PolicyBinding
|
|
|
|
|
|
|
|
|
|
|
|
class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView):
|
|
|
|
"""Show list of all policies"""
|
|
|
|
|
|
|
|
model = PolicyBinding
|
|
|
|
permission_required = "passbook_policies.view_policybinding"
|
|
|
|
paginate_by = 10
|
2020-05-19 19:29:02 +01:00
|
|
|
ordering = ["order", "target"]
|
2020-05-16 18:55:59 +01:00
|
|
|
template_name = "administration/policybinding/list.html"
|
|
|
|
|
|
|
|
|
|
|
|
class PolicyBindingCreateView(
|
|
|
|
SuccessMessageMixin,
|
|
|
|
LoginRequiredMixin,
|
|
|
|
DjangoPermissionRequiredMixin,
|
|
|
|
CreateAssignPermView,
|
|
|
|
):
|
|
|
|
"""Create new PolicyBinding"""
|
|
|
|
|
|
|
|
model = PolicyBinding
|
|
|
|
permission_required = "passbook_policies.add_policybinding"
|
|
|
|
form_class = PolicyBindingForm
|
|
|
|
|
|
|
|
template_name = "generic/create.html"
|
2020-05-20 08:17:06 +01:00
|
|
|
success_url = reverse_lazy("passbook_admin:policies-bindings")
|
2020-05-16 18:55:59 +01:00
|
|
|
success_message = _("Successfully created PolicyBinding")
|
|
|
|
|
|
|
|
|
|
|
|
class PolicyBindingUpdateView(
|
|
|
|
SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView
|
|
|
|
):
|
|
|
|
"""Update policybinding"""
|
|
|
|
|
|
|
|
model = PolicyBinding
|
|
|
|
permission_required = "passbook_policies.change_policybinding"
|
|
|
|
form_class = PolicyBindingForm
|
|
|
|
|
|
|
|
template_name = "generic/update.html"
|
2020-05-20 08:17:06 +01:00
|
|
|
success_url = reverse_lazy("passbook_admin:policies-bindings")
|
2020-05-16 18:55:59 +01:00
|
|
|
success_message = _("Successfully updated PolicyBinding")
|
|
|
|
|
|
|
|
|
|
|
|
class PolicyBindingDeleteView(
|
2020-07-01 23:13:33 +01:00
|
|
|
LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageView
|
2020-05-16 18:55:59 +01:00
|
|
|
):
|
|
|
|
"""Delete policybinding"""
|
|
|
|
|
|
|
|
model = PolicyBinding
|
|
|
|
permission_required = "passbook_policies.delete_policybinding"
|
|
|
|
|
|
|
|
template_name = "generic/delete.html"
|
2020-05-20 08:17:06 +01:00
|
|
|
success_url = reverse_lazy("passbook_admin:policies-bindings")
|
2020-05-16 18:55:59 +01:00
|
|
|
success_message = _("Successfully deleted PolicyBinding")
|