Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
cbc4a0a9
Commit
cbc4a0a9
authored
May 11, 2018
by
BaiJiangjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 资产树节点Node Value值校验修改异常抛出为400
parent
4c53eebd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
node.py
apps/assets/api/node.py
+4
-1
node.py
apps/assets/serializers/node.py
+7
-4
No files found.
apps/assets/api/node.py
View file @
cbc4a0a9
...
...
@@ -14,6 +14,7 @@
# limitations under the License.
from
rest_framework
import
generics
,
mixins
from
rest_framework.serializers
import
ValidationError
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework_bulk
import
BulkModelViewSet
...
...
@@ -110,7 +111,9 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
value
=
request
.
data
.
get
(
"value"
)
values
=
[
child
.
value
for
child
in
instance
.
get_children
()]
if
value
in
values
:
raise
AssertionError
(
'The same level node name cannot be the same'
)
raise
ValidationError
(
'The same level node name cannot be the same'
)
node
=
instance
.
create_child
(
value
=
value
)
return
Response
(
{
"id"
:
node
.
id
,
"key"
:
node
.
key
,
"value"
:
node
.
value
},
...
...
apps/assets/serializers/node.py
View file @
cbc4a0a9
...
...
@@ -51,14 +51,17 @@ class NodeSerializer(serializers.ModelSerializer):
fields
=
[
'id'
,
'key'
,
'value'
,
'parent'
,
'assets_amount'
,
'is_node'
]
list_serializer_class
=
BulkListSerializer
def
update
(
self
,
instance
,
validated_data
):
value
=
validated_data
.
get
(
'value'
)
def
validate
(
self
,
data
):
value
=
data
.
get
(
'value'
)
instance
=
self
.
instance
if
not
instance
.
is_root
():
children
=
instance
.
parent
.
get_children
()
.
exclude
(
key
=
instance
.
key
)
values
=
[
child
.
value
for
child
in
children
]
if
value
in
values
:
raise
AssertionError
(
'The same level node name cannot be the same'
)
return
super
()
.
update
(
instance
,
validated_data
)
raise
serializers
.
ValidationError
(
'The same level node name cannot be the same'
)
return
data
@staticmethod
def
get_parent
(
obj
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment