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
fde87029
Commit
fde87029
authored
Nov 01, 2019
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修复初始化 Default 节点的 Bug(原因:在其他组织下 Default 节点默认的 key 1 已经存在)
parent
3dfb2d6a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
7 deletions
+40
-7
node.py
apps/assets/models/node.py
+40
-7
No files found.
apps/assets/models/node.py
View file @
fde87029
...
...
@@ -6,6 +6,7 @@ import time
from
django.db
import
models
,
transaction
from
django.db.models
import
Q
from
django.db.utils
import
IntegrityError
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext
from
django.core.cache
import
cache
...
...
@@ -336,6 +337,17 @@ class SomeNodesMixin:
else
:
return
False
@classmethod
def
get_next_org_root_node_key
(
cls
):
with
tmp_to_org
(
Organization
.
root
()):
org_nodes_roots
=
cls
.
objects
.
filter
(
key__regex
=
r'^[0-9]+$'
)
org_nodes_roots_keys
=
org_nodes_roots
.
values_list
(
'key'
,
flat
=
True
)
if
not
org_nodes_roots_keys
:
org_nodes_roots_keys
=
[
'1'
]
max_key
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
key
=
str
(
max_key
+
1
)
if
max_key
!=
0
else
'2'
return
key
@classmethod
def
create_org_root_node
(
cls
):
# 如果使用current_org 在set_current_org时会死循环
...
...
@@ -344,12 +356,7 @@ class SomeNodesMixin:
if
not
ori_org
.
is_real
():
return
cls
.
default_node
()
set_current_org
(
Organization
.
root
())
org_nodes_roots
=
cls
.
objects
.
filter
(
key__regex
=
r'^[0-9]+$'
)
org_nodes_roots_keys
=
org_nodes_roots
.
values_list
(
'key'
,
flat
=
True
)
if
not
org_nodes_roots_keys
:
org_nodes_roots_keys
=
[
'1'
]
key
=
max
([
int
(
k
)
for
k
in
org_nodes_roots_keys
])
key
=
str
(
key
+
1
)
if
key
!=
0
else
'2'
key
=
cls
.
get_next_org_root_node_key
()
set_current_org
(
ori_org
)
root
=
cls
.
objects
.
create
(
key
=
key
,
value
=
ori_org
.
name
)
return
root
...
...
@@ -400,11 +407,37 @@ class SomeNodesMixin:
@classmethod
def
initial_some_nodes
(
cls
):
cls
.
default_node
()
try
:
cls
.
default_node
()
except
IntegrityError
as
e
:
logger
.
error
(
"Create default node failed"
)
cls
.
modify_other_org_root_node_key
()
cls
.
default_node
()
cls
.
empty_node
()
cls
.
ungrouped_node
()
cls
.
favorite_node
()
@classmethod
def
modify_other_org_root_node_key
(
cls
):
"""
解决创建 default 节点失败的问题,
因为在其他组织下存在 default 节点,故在 DEFAULT 组织下 get 不到 create 失败
"""
logger
.
info
(
"Modify other org root node key"
)
with
transaction
.
atomic
():
with
tmp_to_org
(
Organization
.
root
()):
node
=
cls
.
objects
.
get
(
key
=
'1'
)
with
tmp_to_org
(
node
.
org
):
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
n
.
save
()
logger
.
info
(
'Modify key ( {} > {} )'
.
format
(
old_key
,
new_key
))
class
Node
(
OrgModelMixin
,
SomeNodesMixin
,
TreeMixin
,
FamilyMixin
,
FullValueMixin
,
NodeAssetsMixin
):
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
...
...
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