mirror of https://github.com/jumpserver/jumpserver
Tmp org (#1583)
* [Update] 修改一些内容 * [Update] 修改datatable 支持process * [Bugfix] 修复asset queryset 没有valid方法的bugpull/1584/head
parent
e7c530d8e6
commit
36f1165d1b
|
@ -42,37 +42,40 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
|
||||||
pagination_class = LimitOffsetPagination
|
pagination_class = LimitOffsetPagination
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
|
|
||||||
def get_queryset(self):
|
def filter_node(self):
|
||||||
time.sleep(3)
|
|
||||||
queryset = super().get_queryset()\
|
|
||||||
.prefetch_related('labels', 'nodes')\
|
|
||||||
.select_related('admin_user')
|
|
||||||
admin_user_id = self.request.query_params.get('admin_user_id')
|
|
||||||
node_id = self.request.query_params.get("node_id")
|
node_id = self.request.query_params.get("node_id")
|
||||||
|
if not node_id:
|
||||||
|
return
|
||||||
|
|
||||||
|
node = get_object_or_404(Node, id=node_id)
|
||||||
show_current_asset = self.request.query_params.get("show_current_asset")
|
show_current_asset = self.request.query_params.get("show_current_asset")
|
||||||
|
|
||||||
if admin_user_id:
|
if node.is_root():
|
||||||
admin_user = get_object_or_404(AdminUser, id=admin_user_id)
|
if show_current_asset:
|
||||||
queryset = queryset.filter(admin_user=admin_user)
|
self.queryset = self.queryset.filter(
|
||||||
|
|
||||||
if node_id and show_current_asset:
|
|
||||||
node = get_object_or_404(Node, id=node_id)
|
|
||||||
if node.is_root():
|
|
||||||
queryset = queryset.filter(
|
|
||||||
Q(nodes=node_id) | Q(nodes__isnull=True)
|
Q(nodes=node_id) | Q(nodes__isnull=True)
|
||||||
).distinct()
|
).distinct()
|
||||||
else:
|
return
|
||||||
queryset = queryset.filter(nodes=node).distinct()
|
if show_current_asset:
|
||||||
|
self.queryset = self.queryset.filter(nodes=node).distinct()
|
||||||
|
else:
|
||||||
|
self.queryset = self.queryset.filter(
|
||||||
|
nodes__key__regex='^{}(:[0-9]+)*$'.format(node.key),
|
||||||
|
).distinct()
|
||||||
|
|
||||||
if node_id and not show_current_asset:
|
def filter_admin_user_id(self):
|
||||||
node = get_object_or_404(Node, id=node_id)
|
admin_user_id = self.request.query_params.get('admin_user_id')
|
||||||
if node.is_root():
|
if admin_user_id:
|
||||||
queryset = Asset.objects.all()
|
admin_user = get_object_or_404(AdminUser, id=admin_user_id)
|
||||||
else:
|
self.queryset = self.queryset.filter(admin_user=admin_user)
|
||||||
queryset = queryset.filter(
|
|
||||||
nodes__key__regex='^{}(:[0-9]+)*$'.format(node.key),
|
def get_queryset(self):
|
||||||
).distinct()
|
self.queryset = super().get_queryset()\
|
||||||
return queryset
|
.prefetch_related('labels', 'nodes')\
|
||||||
|
.select_related('admin_user')
|
||||||
|
self.filter_admin_user_id()
|
||||||
|
self.filter_node()
|
||||||
|
return self.queryset
|
||||||
|
|
||||||
|
|
||||||
class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
|
class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
|
||||||
|
|
|
@ -45,10 +45,6 @@ class AssetQuerySet(models.QuerySet):
|
||||||
return self.active()
|
return self.active()
|
||||||
|
|
||||||
|
|
||||||
class AssetManager(OrgManager):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Asset(OrgModelMixin):
|
class Asset(OrgModelMixin):
|
||||||
# Important
|
# Important
|
||||||
PLATFORM_CHOICES = (
|
PLATFORM_CHOICES = (
|
||||||
|
@ -131,7 +127,7 @@ class Asset(OrgModelMixin):
|
||||||
comment = models.TextField(max_length=128, default='', blank=True,
|
comment = models.TextField(max_length=128, default='', blank=True,
|
||||||
verbose_name=_('Comment'))
|
verbose_name=_('Comment'))
|
||||||
|
|
||||||
objects = AssetManager()
|
objects = OrgManager.from_queryset(AssetQuerySet)()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{0.hostname}({0.ip})'.format(self)
|
return '{0.hostname}({0.ip})'.format(self)
|
||||||
|
|
|
@ -20,7 +20,7 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
||||||
model = Asset
|
model = Asset
|
||||||
list_serializer_class = BulkListSerializer
|
list_serializer_class = BulkListSerializer
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
validators = [] # If not set to [], partial bulk update will be error
|
# validators = [] # If not set to [], partial bulk update will be error
|
||||||
|
|
||||||
def get_field_names(self, declared_fields, info):
|
def get_field_names(self, declared_fields, info):
|
||||||
fields = super().get_field_names(declared_fields, info)
|
fields = super().get_field_names(declared_fields, info)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
{% block custom_head_css_js %}
|
{% block custom_head_css_js %}
|
||||||
<link href="{% static 'css/plugins/ztree/awesomeStyle/awesome.css' %}" rel="stylesheet">
|
<link href="{% static 'css/plugins/ztree/awesomeStyle/awesome.css' %}" rel="stylesheet">
|
||||||
|
{# <link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet">#}
|
||||||
<script type="text/javascript" src="{% static 'js/plugins/ztree/jquery.ztree.all.min.js' %}"></script>
|
<script type="text/javascript" src="{% static 'js/plugins/ztree/jquery.ztree.all.min.js' %}"></script>
|
||||||
<script src="{% static 'js/jquery.form.min.js' %}"></script>
|
<script src="{% static 'js/jquery.form.min.js' %}"></script>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
@ -27,6 +28,10 @@
|
||||||
list-style: none;
|
list-style: none;
|
||||||
background-clip: padding-box;
|
background-clip: padding-box;
|
||||||
}
|
}
|
||||||
|
.dataTables_wrapper .dataTables_processing {
|
||||||
|
opacity: .9;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
div#rMenu li{
|
div#rMenu li{
|
||||||
margin: 1px 0;
|
margin: 1px 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -35,20 +40,6 @@
|
||||||
.dropdown a:hover {
|
.dropdown a:hover {
|
||||||
background-color: #f1f1f1
|
background-color: #f1f1f1
|
||||||
}
|
}
|
||||||
|
|
||||||
.dataTables_wrapper .dataTables_processing {
|
|
||||||
position: absolute;
|
|
||||||
top: 30%;
|
|
||||||
left: 50%;
|
|
||||||
width: 30%;
|
|
||||||
height: 40px;
|
|
||||||
margin-left: -20%;
|
|
||||||
margin-top: -25px;
|
|
||||||
padding-top: 20px;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 1.2em;
|
|
||||||
background: none;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,8 +3,10 @@ import uuid
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from orgs.mixins import OrgModelMixin
|
||||||
|
|
||||||
class FTPLog(models.Model):
|
|
||||||
|
class FTPLog(OrgModelMixin):
|
||||||
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
||||||
user = models.CharField(max_length=128, verbose_name=_('User'))
|
user = models.CharField(max_length=128, verbose_name=_('User'))
|
||||||
remote_addr = models.CharField(max_length=15, verbose_name=_("Remote addr"), blank=True, null=True)
|
remote_addr = models.CharField(max_length=15, verbose_name=_("Remote addr"), blank=True, null=True)
|
||||||
|
|
|
@ -80,6 +80,9 @@ class AdminUserRequiredMixin(UserPassesTestMixin):
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
print("Current org: {}".format(current_org))
|
print("Current org: {}".format(current_org))
|
||||||
|
if not request.user.is_authenticated:
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
if not current_org:
|
if not current_org:
|
||||||
return redirect('orgs:switch-a-org')
|
return redirect('orgs:switch-a-org')
|
||||||
|
|
||||||
|
|
|
@ -175,4 +175,7 @@ class LunaView(View):
|
||||||
Luna是单独部署的一个程序,你需要部署luna,coco,配置nginx做url分发,
|
Luna是单独部署的一个程序,你需要部署luna,coco,配置nginx做url分发,
|
||||||
如果你看到了这个页面,证明你访问的不是nginx监听的端口,祝你好运
|
如果你看到了这个页面,证明你访问的不是nginx监听的端口,祝你好运
|
||||||
"""
|
"""
|
||||||
return HttpResponse(msg)
|
return HttpResponse(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
from common.permissions import IsOrgAdminOrAppUser
|
from common.permissions import IsSuperUserOrAppUser
|
||||||
from .models import Organization
|
from .models import Organization
|
||||||
from .serializers import OrgSerializer
|
from .serializers import OrgSerializer
|
||||||
|
|
||||||
|
@ -11,4 +11,4 @@ from .serializers import OrgSerializer
|
||||||
class OrgViewSet(viewsets.ModelViewSet):
|
class OrgViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Organization.objects.all()
|
queryset = Organization.objects.all()
|
||||||
serializer_class = OrgSerializer
|
serializer_class = OrgSerializer
|
||||||
permission_classes = (IsOrgAdminOrAppUser,)
|
permission_classes = (IsSuperUserOrAppUser,)
|
||||||
|
|
|
@ -23,10 +23,10 @@ __all__ = [
|
||||||
class OrgManager(models.Manager):
|
class OrgManager(models.Manager):
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
queryset = super(OrgManager, self).get_queryset()
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if not hasattr(tl, 'times'):
|
if not hasattr(tl, 'times'):
|
||||||
tl.times = 0
|
tl.times = 0
|
||||||
|
|
||||||
print("[{}]>>>>>>>>>> Get query set".format(tl.times))
|
print("[{}]>>>>>>>>>> Get query set".format(tl.times))
|
||||||
print(current_org)
|
print(current_org)
|
||||||
if not current_org:
|
if not current_org:
|
||||||
|
@ -34,11 +34,8 @@ class OrgManager(models.Manager):
|
||||||
elif current_org.is_real():
|
elif current_org.is_real():
|
||||||
kwargs['org_id'] = current_org.id
|
kwargs['org_id'] = current_org.id
|
||||||
elif current_org.is_default():
|
elif current_org.is_default():
|
||||||
kwargs['org_id'] = None
|
queryset = queryset.filter(org_id="").filter(org_id__isnull=True)
|
||||||
queryset = super(OrgManager, self).get_queryset()
|
|
||||||
queryset = queryset.filter(**kwargs)
|
queryset = queryset.filter(**kwargs)
|
||||||
# print(kwargs)
|
|
||||||
# print(queryset.query)
|
|
||||||
tl.times += 1
|
tl.times += 1
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
|
@ -386,11 +386,10 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||||
selector: 'td:first-child'
|
selector: 'td:first-child'
|
||||||
};
|
};
|
||||||
var table = ele.DataTable({
|
var table = ele.DataTable({
|
||||||
// pageLength: options.pageLength || 15,
|
pageLength: options.pageLength || 15,
|
||||||
// dom: options.dom || '<"#uc.pull-left">flt<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
|
dom: options.dom || '<"#uc.pull-left">fltr<"row m-t"<"col-md-8"<"#op.col-md-6"><"col-md-6 text-center"i>><"col-md-4"p>>',
|
||||||
// order: options.order || [],
|
order: options.order || [],
|
||||||
// select: options.select || 'multi',
|
buttons: [],
|
||||||
// buttons: [],
|
|
||||||
columnDefs: columnDefs,
|
columnDefs: columnDefs,
|
||||||
serverSide: true,
|
serverSide: true,
|
||||||
processing: true,
|
processing: true,
|
||||||
|
@ -475,8 +474,7 @@ jumpserver.initServerSideDataTable = function (options) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}).
|
}).on('draw', function(){
|
||||||
on('draw', function(){
|
|
||||||
$('#op').html(options.op_html || '');
|
$('#op').html(options.op_html || '');
|
||||||
$('#uc').html(options.uc_html || '');
|
$('#uc').html(options.uc_html || '');
|
||||||
var table_data = [];
|
var table_data = [];
|
||||||
|
|
Loading…
Reference in New Issue