jumpserver/apps/assets/views/system_user.py

112 lines
3.6 KiB
Python
Raw Normal View History

2017-04-04 03:37:52 +00:00
# ~*~ coding: utf-8 ~*~
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
2017-07-24 14:42:01 +00:00
from django.views.generic.edit import CreateView, DeleteView, UpdateView
2017-04-04 03:37:52 +00:00
from django.urls import reverse_lazy
from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic.detail import DetailView
2017-04-04 03:37:52 +00:00
from common.const import create_success_msg, update_success_msg
2018-01-30 08:12:33 +00:00
from ..forms import SystemUserForm
2018-10-10 07:37:20 +00:00
from ..models import SystemUser, Node, CommandFilter
from common.permissions import PermissionsMixin, IsOrgAdmin
2017-07-19 23:55:24 +00:00
2017-04-04 03:37:52 +00:00
__all__ = [
'SystemUserCreateView', 'SystemUserUpdateView',
'SystemUserDetailView', 'SystemUserDeleteView',
'SystemUserAssetView', 'SystemUserListView',
]
2017-04-04 03:37:52 +00:00
class SystemUserListView(PermissionsMixin, TemplateView):
2017-04-04 03:37:52 +00:00
template_name = 'assets/system_user_list.html'
permission_classes = [IsOrgAdmin]
2017-04-04 03:37:52 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('System user list'),
}
kwargs.update(context)
2017-12-13 09:21:08 +00:00
return super().get_context_data(**kwargs)
2017-04-04 03:37:52 +00:00
class SystemUserCreateView(PermissionsMixin, SuccessMessageMixin, CreateView):
2017-04-04 03:37:52 +00:00
model = SystemUser
form_class = SystemUserForm
2017-04-04 03:37:52 +00:00
template_name = 'assets/system_user_create.html'
success_url = reverse_lazy('assets:system-user-list')
success_message = create_success_msg
permission_classes = [IsOrgAdmin]
2017-04-04 03:37:52 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Create system user'),
}
kwargs.update(context)
2017-12-13 09:21:08 +00:00
return super().get_context_data(**kwargs)
2017-04-04 03:37:52 +00:00
class SystemUserUpdateView(PermissionsMixin, SuccessMessageMixin, UpdateView):
2017-04-04 03:37:52 +00:00
model = SystemUser
2018-01-30 08:12:33 +00:00
form_class = SystemUserForm
2017-04-04 03:37:52 +00:00
template_name = 'assets/system_user_update.html'
success_url = reverse_lazy('assets:system-user-list')
success_message = update_success_msg
permission_classes = [IsOrgAdmin]
2017-04-04 03:37:52 +00:00
def get_context_data(self, **kwargs):
context = {
'app': _('Assets'),
'action': _('Update system user')
}
kwargs.update(context)
2017-12-13 09:21:08 +00:00
return super().get_context_data(**kwargs)
2017-07-19 23:55:24 +00:00
2017-04-04 03:37:52 +00:00
class SystemUserDetailView(PermissionsMixin, DetailView):
2017-04-04 03:37:52 +00:00
template_name = 'assets/system_user_detail.html'
context_object_name = 'system_user'
model = SystemUser
permission_classes = [IsOrgAdmin]
2017-04-04 03:37:52 +00:00
def get_context_data(self, **kwargs):
2019-07-04 08:41:38 +00:00
cmd_filters_remain = CommandFilter.objects.exclude(system_users=self.object)
2017-04-04 03:37:52 +00:00
context = {
'app': _('Assets'),
2017-12-13 09:21:08 +00:00
'action': _('System user detail'),
2019-07-04 08:41:38 +00:00
'cmd_filters_remain': cmd_filters_remain,
2017-04-04 03:37:52 +00:00
}
kwargs.update(context)
2017-12-13 09:21:08 +00:00
return super().get_context_data(**kwargs)
2017-04-04 03:37:52 +00:00
class SystemUserDeleteView(PermissionsMixin, DeleteView):
2017-04-04 03:37:52 +00:00
model = SystemUser
template_name = 'delete_confirm.html'
2017-04-04 03:37:52 +00:00
success_url = reverse_lazy('assets:system-user-list')
permission_classes = [IsOrgAdmin]
2017-04-04 03:37:52 +00:00
class SystemUserAssetView(PermissionsMixin, DetailView):
model = SystemUser
template_name = 'assets/system_user_assets.html'
2017-04-04 03:37:52 +00:00
context_object_name = 'system_user'
permission_classes = [IsOrgAdmin]
2017-04-04 03:37:52 +00:00
def get_context_data(self, **kwargs):
2019-07-04 07:36:57 +00:00
from ..utils import NodeUtil
nodes_remain = Node.objects.exclude(systemuser=self.object)
util = NodeUtil()
nodes_remain = util.get_nodes_by_queryset(nodes_remain)
2017-04-04 03:37:52 +00:00
context = {
2018-01-05 09:57:02 +00:00
'app': _('assets'),
'action': _('System user asset'),
2018-10-10 11:29:53 +00:00
'nodes_remain': nodes_remain
2017-04-04 03:37:52 +00:00
}
kwargs.update(context)
2017-12-13 09:21:08 +00:00
return super().get_context_data(**kwargs)