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
ca178c53
Commit
ca178c53
authored
Nov 01, 2019
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修复初始化 Default 节点的 Bug(原因:在其他组织下 Default 节点默认的 key 1 已经存在)4
parent
d7948425
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
node.py
apps/assets/models/node.py
+20
-16
No files found.
apps/assets/models/node.py
View file @
ca178c53
...
...
@@ -391,9 +391,16 @@ class SomeNodesMixin:
def
default_node
(
cls
):
with
tmp_to_org
(
Organization
.
default
()):
defaults
=
{
'value'
:
cls
.
default_value
}
obj
,
created
=
cls
.
objects
.
get_or_create
(
defaults
=
defaults
,
key
=
cls
.
default_key
,
)
try
:
obj
,
created
=
cls
.
objects
.
get_or_create
(
defaults
=
defaults
,
key
=
cls
.
default_key
,
)
except
IntegrityError
as
e
:
logger
.
error
(
"Create default node failed: {}"
.
format
(
e
))
cls
.
modify_other_org_root_node_key
()
obj
,
created
=
cls
.
objects
.
get_or_create
(
defaults
=
defaults
,
key
=
cls
.
default_key
,
)
return
obj
@classmethod
...
...
@@ -407,12 +414,7 @@ class SomeNodesMixin:
@classmethod
def
initial_some_nodes
(
cls
):
try
:
cls
.
default_node
()
except
IntegrityError
as
e
:
logger
.
error
(
"Create default node failed: {}"
.
format
(
e
))
cls
.
modify_other_org_root_node_key
()
cls
.
default_node
()
cls
.
default_node
()
cls
.
empty_node
()
cls
.
ungrouped_node
()
cls
.
favorite_node
()
...
...
@@ -424,20 +426,22 @@ class SomeNodesMixin:
因为在其他组织下存在 default 节点,故在 DEFAULT 组织下 get 不到 create 失败
"""
logger
.
info
(
"Modify other org root node key"
)
with
transaction
.
atomic
():
with
tmp_to_org
(
Organization
.
root
()):
node
=
cls
.
objects
.
filter
(
key
=
'1'
)
.
first
()
if
not
node
:
with
tmp_to_org
(
Organization
.
root
()):
node_key1
=
cls
.
objects
.
filter
(
key
=
'1'
)
.
first
()
if
not
node
_key1
:
logger
.
info
(
"Not found node that `key` = 1"
)
return
if
not
node
.
org
.
is_real
():
if
not
node
_key1
.
org
.
is_real
():
logger
.
info
(
"Org is not real for node that `key` = 1"
)
return
with
tmp_to_org
(
node
.
org
):
with
transaction
.
atomic
():
with
tmp_to_org
(
node_key1
.
org
):
org_root_node_new_key
=
cls
.
get_next_org_root_node_key
()
for
n
in
cls
.
objects
.
all
():
old_key
=
n
.
key
key_list
=
n
.
key
.
split
(
':'
)
org_root_node_new_key
=
cls
.
get_next_org_root_node_key
()
key_list
[
0
]
=
org_root_node_new_key
new_key
=
':'
.
join
(
key_list
)
n
.
key
=
new_key
...
...
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