jumpserver/apps/perms/views.py

80 lines
2.5 KiB
Python
Raw Normal View History

2016-09-10 13:08:10 +00:00
# ~*~ coding: utf-8 ~*~
2016-08-08 16:43:11 +00:00
2016-09-10 13:08:10 +00:00
from __future__ import unicode_literals, absolute_import
2017-03-09 06:55:33 +00:00
2016-09-11 01:50:42 +00:00
from django.utils.translation import ugettext as _
from django.views.generic import ListView, CreateView, UpdateView
2018-02-01 09:14:15 +00:00
from django.views.generic.edit import DeleteView
2016-09-11 01:50:42 +00:00
from django.urls import reverse_lazy
2016-09-10 13:08:10 +00:00
from common.utils import get_object_or_none
from .hands import AdminUserRequiredMixin, Node
2018-02-01 09:14:15 +00:00
from .models import AssetPermission, NodePermission
2016-09-11 14:45:24 +00:00
from .forms import AssetPermissionForm
2016-09-10 13:08:10 +00:00
2016-09-11 15:20:14 +00:00
class AssetPermissionListView(AdminUserRequiredMixin, ListView):
2018-02-01 09:14:15 +00:00
model = NodePermission
2016-09-11 14:45:24 +00:00
context_object_name = 'asset_permission_list'
template_name = 'perms/asset_permission_list.html'
2016-09-10 13:08:10 +00:00
def get_context_data(self, **kwargs):
context = {
2016-09-11 01:50:42 +00:00
'app': _('Perms'),
2016-09-11 14:45:24 +00:00
'action': _('Asset permission list'),
2016-09-10 13:08:10 +00:00
}
kwargs.update(context)
return super().get_context_data(**kwargs)
2018-02-01 09:14:15 +00:00
class AssetPermissionCreateView(AdminUserRequiredMixin, CreateView):
model = NodePermission
2016-09-11 14:45:24 +00:00
form_class = AssetPermissionForm
2016-09-11 15:20:14 +00:00
template_name = 'perms/asset_permission_create_update.html'
2016-09-11 14:45:24 +00:00
success_url = reverse_lazy('perms:asset-permission-list')
2017-03-09 06:55:33 +00:00
def get_form(self, form_class=None):
form = super().get_form(form_class=form_class)
node_id = self.request.GET.get("node_id")
node = get_object_or_none(Node, id=node_id)
if not node:
node = Node.root()
form['node'].initial = node
return form
2016-09-11 08:59:19 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Perms'),
2016-09-11 14:45:24 +00:00
'action': _('Create asset permission'),
2016-09-11 08:59:19 +00:00
}
kwargs.update(context)
return super().get_context_data(**kwargs)
2016-09-11 15:20:14 +00:00
2018-02-01 09:14:15 +00:00
class AssetPermissionUpdateView(AdminUserRequiredMixin, UpdateView):
model = NodePermission
2016-09-11 15:20:14 +00:00
form_class = AssetPermissionForm
template_name = 'perms/asset_permission_create_update.html'
2017-05-15 15:39:54 +00:00
success_url = reverse_lazy("perms:asset-permission-list")
2016-09-11 15:20:14 +00:00
2018-02-02 10:52:09 +00:00
def get_form(self, form_class=None):
form = super().get_form(form_class=form_class)
form['node'].initial = form.instance.node
return form
2016-09-11 15:20:14 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Perms'),
'action': _('Update asset permission')
}
kwargs.update(context)
return super().get_context_data(**kwargs)
2016-09-11 15:20:14 +00:00
class AssetPermissionDeleteView(AdminUserRequiredMixin, DeleteView):
model = AssetPermission
template_name = 'delete_confirm.html'
2016-09-11 15:20:14 +00:00
success_url = reverse_lazy('perms:asset-permission-list')