Unverified Commit 36f1165d authored by 老广's avatar 老广 Committed by GitHub

Tmp org (#1583)

* [Update] 修改一些内容

* [Update] 修改datatable 支持process

* [Bugfix] 修复asset queryset 没有valid方法的bug
parent e7c530d8
...@@ -42,37 +42,40 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet): ...@@ -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 node.is_root():
if show_current_asset:
self.queryset = self.queryset.filter(
Q(nodes=node_id) | Q(nodes__isnull=True)
).distinct()
return
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()
def filter_admin_user_id(self):
admin_user_id = self.request.query_params.get('admin_user_id')
if admin_user_id: if admin_user_id:
admin_user = get_object_or_404(AdminUser, id=admin_user_id) admin_user = get_object_or_404(AdminUser, id=admin_user_id)
queryset = queryset.filter(admin_user=admin_user) self.queryset = self.queryset.filter(admin_user=admin_user)
if node_id and show_current_asset: def get_queryset(self):
node = get_object_or_404(Node, id=node_id) self.queryset = super().get_queryset()\
if node.is_root(): .prefetch_related('labels', 'nodes')\
queryset = queryset.filter( .select_related('admin_user')
Q(nodes=node_id) | Q(nodes__isnull=True) self.filter_admin_user_id()
).distinct() self.filter_node()
else: return self.queryset
queryset = queryset.filter(nodes=node).distinct()
if node_id and not show_current_asset:
node = get_object_or_404(Node, id=node_id)
if node.is_root():
queryset = Asset.objects.all()
else:
queryset = queryset.filter(
nodes__key__regex='^{}(:[0-9]+)*$'.format(node.key),
).distinct()
return queryset
class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView): class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
......
...@@ -45,10 +45,6 @@ class AssetQuerySet(models.QuerySet): ...@@ -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): ...@@ -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): ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 ...@@ -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): ...@@ -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): ...@@ -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)
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -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 ...@@ -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__ = [ ...@@ -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): ...@@ -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) { ...@@ -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) { ...@@ -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 = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment