Unverified Commit 3451c2b4 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

[Update] 解决授权资产显示禁用资产的问题 (#2975)

* [Update] 解决授权资产显示禁用资产的问题

* [Bugfix] 解决资产更新页面取消激活失败的问题

* [Bugfix] 解决资产详情页面禁用资产时会清除协议的问题

* [Bugfix] 解决创建/更新管理用户、系统用户提交密钥错误时报错的问题
parent 1c7a09c9
...@@ -112,7 +112,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer): ...@@ -112,7 +112,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
protocol = protocols_data[0].split('/') protocol = protocols_data[0].split('/')
validated_data["protocol"] = protocol[0] validated_data["protocol"] = protocol[0]
validated_data["port"] = int(protocol[1]) validated_data["port"] = int(protocol[1])
if validated_data: if protocols_data:
validated_data["protocols"] = ' '.join(protocols_data) validated_data["protocols"] = ' '.join(protocols_data)
def create(self, validated_data): def create(self, validated_data):
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from django.utils.translation import ugettext as _
from rest_framework import serializers from rest_framework import serializers
from common.utils import ssh_pubkey_gen, validate_ssh_private_key from common.utils import ssh_pubkey_gen, validate_ssh_private_key
......
...@@ -216,6 +216,8 @@ $(document).ready(function () { ...@@ -216,6 +216,8 @@ $(document).ready(function () {
var form = $("form"); var form = $("form");
var protocols = {}; var protocols = {};
var data = form.serializeObject(); var data = form.serializeObject();
objectAttrsIsBool(data, ['is_active']);
objectAttrsIsList(data, ['nodes', 'labels']);
$.each(data, function (k, v) { $.each(data, function (k, v) {
if (k.startsWith("form")){ if (k.startsWith("form")){
delete data[k]; delete data[k];
...@@ -233,12 +235,6 @@ $(document).ready(function () { ...@@ -233,12 +235,6 @@ $(document).ready(function () {
return v.name + '/' + v.port return v.name + '/' + v.port
}); });
data["protocols"] = protocols; data["protocols"] = protocols;
if (typeof data.labels === "string") {
data["labels"] = [data["labels"]];
}
if (typeof data["nodes"] == "string") {
data["nodes"] = [data["nodes"]]
}
var props = { var props = {
url: the_url, url: the_url,
data: data, data: data,
......
...@@ -499,7 +499,7 @@ class AssetPermissionUtil(AssetPermissionCacheMixin): ...@@ -499,7 +499,7 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
if pattern: if pattern:
assets_ids = Asset.objects.filter( assets_ids = Asset.objects.filter(
nodes__key__regex=pattern nodes__key__regex=pattern
).values_list("id", flat=True).distinct() ).valid().values_list("id", flat=True).distinct()
else: else:
assets_ids = [] assets_ids = []
self.tree.add_assets_without_system_users(assets_ids) self.tree.add_assets_without_system_users(assets_ids)
...@@ -523,8 +523,8 @@ class AssetPermissionUtil(AssetPermissionCacheMixin): ...@@ -523,8 +523,8 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
assets_ids = defaultdict(lambda: defaultdict(int)) assets_ids = defaultdict(lambda: defaultdict(int))
for perm in self.permissions: for perm in self.permissions:
actions = [perm.actions] actions = [perm.actions]
_assets_ids = [a.id for a in perm.assets.all()] _assets_ids = perm.assets.valid().values_list("id", flat=True)
system_users_ids = [s.id for s in perm.system_users.all()] system_users_ids = perm.system_users.values_list("id", flat=True)
iterable = itertools.product(_assets_ids, system_users_ids, actions) iterable = itertools.product(_assets_ids, system_users_ids, actions)
for asset_id, sys_id, action in iterable: for asset_id, sys_id, action in iterable:
assets_ids[asset_id][sys_id] |= action assets_ids[asset_id][sys_id] |= action
......
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