mirror of https://github.com/jumpserver/jumpserver
[Update] 删掉集群等等
parent
759760e7d9
commit
fe1862120f
|
@ -10,7 +10,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
from ..const import ASSET_ADMIN_CONN_CACHE_KEY
|
from ..const import ASSET_ADMIN_CONN_CACHE_KEY
|
||||||
from .cluster import Cluster
|
|
||||||
from .group import AssetGroup
|
from .group import AssetGroup
|
||||||
from .user import AdminUser, SystemUser
|
from .user import AdminUser, SystemUser
|
||||||
|
|
||||||
|
@ -168,7 +167,6 @@ class Asset(models.Model):
|
||||||
try:
|
try:
|
||||||
asset.save()
|
asset.save()
|
||||||
asset.system_users = [choice(SystemUser.objects.all()) for i in range(3)]
|
asset.system_users = [choice(SystemUser.objects.all()) for i in range(3)]
|
||||||
asset.groups = [choice(AssetGroup.objects.all()) for i in range(3)]
|
|
||||||
logger.debug('Generate fake asset : %s' % asset.ip)
|
logger.debug('Generate fake asset : %s' % asset.ip)
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
print('Error continue')
|
print('Error continue')
|
||||||
|
|
|
@ -10,15 +10,15 @@ __all__ = ['init_model', 'generate_fake']
|
||||||
|
|
||||||
|
|
||||||
def init_model():
|
def init_model():
|
||||||
from . import Cluster, SystemUser, AdminUser, AssetGroup, Asset
|
from . import SystemUser, AdminUser, Asset
|
||||||
for cls in [Cluster, SystemUser, AdminUser, AssetGroup, Asset]:
|
for cls in [SystemUser, AdminUser, Asset]:
|
||||||
if hasattr(cls, 'initial'):
|
if hasattr(cls, 'initial'):
|
||||||
cls.initial()
|
cls.initial()
|
||||||
|
|
||||||
|
|
||||||
def generate_fake():
|
def generate_fake():
|
||||||
from . import Cluster, SystemUser, AdminUser, AssetGroup, Asset
|
from . import SystemUser, AdminUser, Asset
|
||||||
for cls in [Cluster, SystemUser, AdminUser, AssetGroup, Asset]:
|
for cls in [SystemUser, AdminUser, Asset]:
|
||||||
if hasattr(cls, 'generate_fake'):
|
if hasattr(cls, 'generate_fake'):
|
||||||
cls.generate_fake()
|
cls.generate_fake()
|
||||||
|
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
|
|
||||||
from rest_framework import serializers
|
|
||||||
from common.mixins import BulkSerializerMixin
|
|
||||||
from ..models import Asset, Cluster
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterUpdateAssetsSerializer(serializers.ModelSerializer):
|
|
||||||
"""
|
|
||||||
集群更新资产数据结构
|
|
||||||
"""
|
|
||||||
assets = serializers.PrimaryKeyRelatedField(many=True, queryset=Asset.objects.all())
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Cluster
|
|
||||||
fields = ['id', 'assets']
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
|
||||||
"""
|
|
||||||
cluster
|
|
||||||
"""
|
|
||||||
assets_amount = serializers.SerializerMethodField()
|
|
||||||
admin_user_name = serializers.SerializerMethodField()
|
|
||||||
assets = serializers.PrimaryKeyRelatedField(many=True, queryset=Asset.objects.all())
|
|
||||||
system_users = serializers.SerializerMethodField()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Cluster
|
|
||||||
fields = '__all__'
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_assets_amount(obj):
|
|
||||||
return obj.assets.count()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_admin_user_name(obj):
|
|
||||||
try:
|
|
||||||
return obj.admin_user.name
|
|
||||||
except AttributeError:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_system_users(obj):
|
|
||||||
return ', '.join(obj.name for obj in obj.systemuser_set.all())
|
|
|
@ -12,7 +12,7 @@ from common.utils import get_object_or_none, capacity_convert, \
|
||||||
from common.celery import register_as_period_task, after_app_shutdown_clean, \
|
from common.celery import register_as_period_task, after_app_shutdown_clean, \
|
||||||
after_app_ready_start, app as celery_app
|
after_app_ready_start, app as celery_app
|
||||||
|
|
||||||
from .models import SystemUser, AdminUser, Asset, Cluster
|
from .models import SystemUser, AdminUser, Asset
|
||||||
from . import const
|
from . import const
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block custom_foot_js %}
|
{% block custom_foot_js %}
|
||||||
<script>
|
<script>
|
||||||
function updateSystemUserCluster(nodes) {
|
function updateSystemUserNode(nodes) {
|
||||||
var the_url = "{% url 'api-assets:system-user-detail' pk=system_user.id %}";
|
var the_url = "{% url 'api-assets:system-user-detail' pk=system_user.id %}";
|
||||||
var body = {
|
var body = {
|
||||||
nodes: Object.assign([], nodes)
|
nodes: Object.assign([], nodes)
|
||||||
|
@ -267,7 +267,7 @@ $(document).ready(function () {
|
||||||
$.map(jumpserver.nodes_selected, function(value, index) {
|
$.map(jumpserver.nodes_selected, function(value, index) {
|
||||||
nodes.push(index);
|
nodes.push(index);
|
||||||
});
|
});
|
||||||
updateSystemUserCluster(nodes);
|
updateSystemUserNode(nodes);
|
||||||
})
|
})
|
||||||
.on('click', '.btn-remove-from-node', function() {
|
.on('click', '.btn-remove-from-node', function() {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
|
@ -282,7 +282,7 @@ $(document).ready(function () {
|
||||||
var nodes = $('.bdg_node').map(function () {
|
var nodes = $('.bdg_node').map(function () {
|
||||||
return $(this).data('gid');
|
return $(this).data('gid');
|
||||||
}).get();
|
}).get();
|
||||||
updateSystemUserCluster(nodes);
|
updateSystemUserNode(nodes);
|
||||||
}).on('click', '.btn-del', function () {
|
}).on('click', '.btn-del', function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var name = "{{ system_user.name}}";
|
var name = "{{ system_user.name}}";
|
||||||
|
|
|
@ -27,7 +27,7 @@ from common.mixins import JSONResponseMixin
|
||||||
from common.utils import get_object_or_none, get_logger, is_uuid
|
from common.utils import get_object_or_none, get_logger, is_uuid
|
||||||
from common.const import create_success_msg, update_success_msg
|
from common.const import create_success_msg, update_success_msg
|
||||||
from .. import forms
|
from .. import forms
|
||||||
from ..models import Asset, AssetGroup, AdminUser, Cluster, SystemUser, Label, Node
|
from ..models import Asset, AdminUser, SystemUser, Label, Node
|
||||||
from ..hands import AdminUserRequiredMixin
|
from ..hands import AdminUserRequiredMixin
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from users.utils import AdminUserRequiredMixin
|
from users.utils import AdminUserRequiredMixin
|
||||||
from users.models import User, UserGroup
|
from users.models import User, UserGroup
|
||||||
from assets.models import Asset, AssetGroup, SystemUser, Node
|
from assets.models import Asset, SystemUser, Node
|
||||||
from assets.serializers import AssetGrantedSerializer, NodeGrantedSerializer, NodeSerializer
|
from assets.serializers import AssetGrantedSerializer, NodeGrantedSerializer, NodeSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue