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
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
|
||||
def get_queryset(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')
|
||||
def filter_node(self):
|
||||
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")
|
||||
|
||||
if admin_user_id:
|
||||
admin_user = get_object_or_404(AdminUser, id=admin_user_id)
|
||||
queryset = queryset.filter(admin_user=admin_user)
|
||||
|
||||
if node_id and show_current_asset:
|
||||
node = get_object_or_404(Node, id=node_id)
|
||||
if node.is_root():
|
||||
queryset = queryset.filter(
|
||||
if node.is_root():
|
||||
if show_current_asset:
|
||||
self.queryset = self.queryset.filter(
|
||||
Q(nodes=node_id) | Q(nodes__isnull=True)
|
||||
).distinct()
|
||||
else:
|
||||
queryset = queryset.filter(nodes=node).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()
|
||||
|
||||
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
|
||||
def filter_admin_user_id(self):
|
||||
admin_user_id = self.request.query_params.get('admin_user_id')
|
||||
if admin_user_id:
|
||||
admin_user = get_object_or_404(AdminUser, id=admin_user_id)
|
||||
self.queryset = self.queryset.filter(admin_user=admin_user)
|
||||
|
||||
def get_queryset(self):
|
||||
self.queryset = super().get_queryset()\
|
||||
.prefetch_related('labels', 'nodes')\
|
||||
.select_related('admin_user')
|
||||
self.filter_admin_user_id()
|
||||
self.filter_node()
|
||||
return self.queryset
|
||||
|
||||
|
||||
class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
|
||||
|
|
|
@ -45,10 +45,6 @@ class AssetQuerySet(models.QuerySet):
|
|||
return self.active()
|
||||
|
||||
|
||||
class AssetManager(OrgManager):
|
||||
pass
|
||||
|
||||
|
||||
class Asset(OrgModelMixin):
|
||||
# Important
|
||||
PLATFORM_CHOICES = (
|
||||
|
@ -131,7 +127,7 @@ class Asset(OrgModelMixin):
|
|||
comment = models.TextField(max_length=128, default='', blank=True,
|
||||
verbose_name=_('Comment'))
|
||||
|
||||
objects = AssetManager()
|
||||
objects = OrgManager.from_queryset(AssetQuerySet)()
|
||||
|
||||
def __str__(self):
|
||||
return '{0.hostname}({0.ip})'.format(self)
|
||||
|
|
|
@ -20,7 +20,7 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
|||
model = Asset
|
||||
list_serializer_class = BulkListSerializer
|
||||
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):
|
||||
fields = super().get_field_names(declared_fields, info)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
{% block custom_head_css_js %}
|
||||
<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 src="{% static 'js/jquery.form.min.js' %}"></script>
|
||||
<style type="text/css">
|
||||
|
@ -27,6 +28,10 @@
|
|||
list-style: none;
|
||||
background-clip: padding-box;
|
||||
}
|
||||
.dataTables_wrapper .dataTables_processing {
|
||||
opacity: .9;
|
||||
border: none;
|
||||
}
|
||||
div#rMenu li{
|
||||
margin: 1px 0;
|
||||
cursor: pointer;
|
||||
|
@ -35,20 +40,6 @@
|
|||
.dropdown a:hover {
|
||||
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>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,8 +3,10 @@ import uuid
|
|||
from django.db import models
|
||||
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)
|
||||
user = models.CharField(max_length=128, verbose_name=_('User'))
|
||||
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):
|
||||
print("Current org: {}".format(current_org))
|
||||
if not request.user.is_authenticated:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
if not current_org:
|
||||
return redirect('orgs:switch-a-org')
|
||||
|
||||
|
|
|
@ -175,4 +175,7 @@ class LunaView(View):
|
|||
Luna是单独部署的一个程序,你需要部署luna,coco,配置nginx做url分发,
|
||||
如果你看到了这个页面,证明你访问的不是nginx监听的端口,祝你好运
|
||||
"""
|
||||
return HttpResponse(msg)
|
||||
return HttpResponse(msg)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
from rest_framework import viewsets
|
||||
|
||||
from common.permissions import IsOrgAdminOrAppUser
|
||||
from common.permissions import IsSuperUserOrAppUser
|
||||
from .models import Organization
|
||||
from .serializers import OrgSerializer
|
||||
|
||||
|
@ -11,4 +11,4 @@ from .serializers import OrgSerializer
|
|||
class OrgViewSet(viewsets.ModelViewSet):
|
||||
queryset = Organization.objects.all()
|
||||
serializer_class = OrgSerializer
|
||||
permission_classes = (IsOrgAdminOrAppUser,)
|
||||
permission_classes = (IsSuperUserOrAppUser,)
|
||||
|
|
|
@ -23,10 +23,10 @@ __all__ = [
|
|||
class OrgManager(models.Manager):
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super(OrgManager, self).get_queryset()
|
||||
kwargs = {}
|
||||
if not hasattr(tl, 'times'):
|
||||
tl.times = 0
|
||||
|
||||
print("[{}]>>>>>>>>>> Get query set".format(tl.times))
|
||||
print(current_org)
|
||||
if not current_org:
|
||||
|
@ -34,11 +34,8 @@ class OrgManager(models.Manager):
|
|||
elif current_org.is_real():
|
||||
kwargs['org_id'] = current_org.id
|
||||
elif current_org.is_default():
|
||||
kwargs['org_id'] = None
|
||||
queryset = super(OrgManager, self).get_queryset()
|
||||
queryset = queryset.filter(org_id="").filter(org_id__isnull=True)
|
||||
queryset = queryset.filter(**kwargs)
|
||||
# print(kwargs)
|
||||
# print(queryset.query)
|
||||
tl.times += 1
|
||||
return queryset
|
||||
|
||||
|
|
|
@ -386,11 +386,10 @@ jumpserver.initServerSideDataTable = function (options) {
|
|||
selector: 'td:first-child'
|
||||
};
|
||||
var table = ele.DataTable({
|
||||
// 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>>',
|
||||
// order: options.order || [],
|
||||
// select: options.select || 'multi',
|
||||
// buttons: [],
|
||||
pageLength: options.pageLength || 15,
|
||||
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 || [],
|
||||
buttons: [],
|
||||
columnDefs: columnDefs,
|
||||
serverSide: true,
|
||||
processing: true,
|
||||
|
@ -475,8 +474,7 @@ jumpserver.initServerSideDataTable = function (options) {
|
|||
}
|
||||
})
|
||||
}
|
||||
}).
|
||||
on('draw', function(){
|
||||
}).on('draw', function(){
|
||||
$('#op').html(options.op_html || '');
|
||||
$('#uc').html(options.uc_html || '');
|
||||
var table_data = [];
|
||||
|
|
Loading…
Reference in New Issue