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
930eb1d2
Commit
930eb1d2
authored
Jul 02, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修正migrations
parent
79554b47
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
52 additions
and
91 deletions
+52
-91
cmd_filter.py
apps/assets/forms/cmd_filter.py
+12
-0
cmd_filter.py
apps/assets/serializers/cmd_filter.py
+9
-0
django.po
apps/locale/zh/LC_MESSAGES/django.po
+0
-0
asset_permission.py
apps/perms/api/asset_permission.py
+1
-1
user_permission.py
apps/perms/api/user_permission.py
+2
-2
const.py
apps/perms/const.py
+1
-21
asset_permission.py
apps/perms/forms/asset_permission.py
+5
-5
0003_action.py
apps/perms/migrations/0003_action.py
+0
-9
0004_assetpermission_actions.py
apps/perms/migrations/0004_assetpermission_actions.py
+0
-13
0006_auto_20190628_1921.py
apps/perms/migrations/0006_auto_20190628_1921.py
+7
-6
0007_remove_assetpermission_actions.py
apps/perms/migrations/0007_remove_assetpermission_actions.py
+1
-0
asset_permission.py
apps/perms/models/asset_permission.py
+4
-23
asset_permission.py
apps/perms/serializers/asset_permission.py
+5
-5
signals_handler.py
apps/perms/signals_handler.py
+1
-1
asset_permission.py
apps/perms/utils/asset_permission.py
+2
-2
asset_permission.py
apps/perms/views/asset_permission.py
+2
-3
No files found.
apps/assets/forms/cmd_filter.py
View file @
930eb1d2
# -*- coding: utf-8 -*-
#
from
django
import
forms
from
django.core.exceptions
import
ValidationError
import
re
from
orgs.mixins
import
OrgModelForm
from
..models
import
CommandFilter
,
CommandFilterRule
...
...
@@ -15,6 +17,8 @@ class CommandFilterForm(OrgModelForm):
class
CommandFilterRuleForm
(
OrgModelForm
):
invalid_pattern
=
re
.
compile
(
r'[\.\*\+\[\\\?\{\}\^\$\|\(\)\#\<\>]'
)
class
Meta
:
model
=
CommandFilterRule
fields
=
[
...
...
@@ -25,3 +29,11 @@ class CommandFilterRuleForm(OrgModelForm):
'placeholder'
:
'eg:
\r\n
reboot
\r\n
rm -rf'
}),
}
def
clean_content
(
self
):
content
=
self
.
cleaned_data
.
get
(
"content"
)
if
self
.
invalid_pattern
.
search
(
content
):
invalid_char
=
self
.
invalid_pattern
.
pattern
.
replace
(
'
\\
'
,
''
)
msg
=
_
(
"Content should not be contain: {}"
)
.
format
(
invalid_char
)
raise
ValidationError
(
msg
)
return
content
apps/assets/serializers/cmd_filter.py
View file @
930eb1d2
# -*- coding: utf-8 -*-
#
import
re
from
rest_framework
import
serializers
from
common.fields
import
ChoiceDisplayField
...
...
@@ -20,8 +21,16 @@ class CommandFilterSerializer(BulkOrgResourceModelSerializer):
class
CommandFilterRuleSerializer
(
BulkOrgResourceModelSerializer
):
serializer_choice_field
=
ChoiceDisplayField
invalid_pattern
=
re
.
compile
(
r'[\.\*\+\[\\\?\{\}\^\$\|\(\)\#\<\>]'
)
class
Meta
:
model
=
CommandFilterRule
fields
=
'__all__'
list_serializer_class
=
AdaptedBulkListSerializer
def
validate_content
(
self
,
content
):
if
self
.
invalid_pattern
.
search
(
content
):
invalid_char
=
self
.
invalid_pattern
.
pattern
.
replace
(
'
\\
'
,
''
)
msg
=
_
(
"Content should not be contain: {}"
)
.
format
(
invalid_char
)
raise
serializers
.
ValidationError
(
msg
)
return
content
apps/locale/zh/LC_MESSAGES/django.po
View file @
930eb1d2
This diff is collapsed.
Click to expand it.
apps/perms/api/asset_permission.py
View file @
930eb1d2
...
...
@@ -10,7 +10,7 @@ from rest_framework.pagination import LimitOffsetPagination
from
common.permissions
import
IsOrgAdmin
from
common.utils
import
get_object_or_none
from
..models
import
AssetPermission
,
Action
from
..models
import
AssetPermission
from
..hands
import
(
User
,
UserGroup
,
Asset
,
Node
,
SystemUser
,
)
...
...
apps/perms/api/user_permission.py
View file @
930eb1d2
...
...
@@ -21,7 +21,7 @@ from ..utils import (
from
..hands
import
User
,
Asset
,
Node
,
SystemUser
,
NodeSerializer
from
..
import
serializers
,
const
from
..mixins
import
AssetsFilterMixin
from
..models
import
Action
Flag
from
..models
import
Action
logger
=
get_logger
(
__name__
)
...
...
@@ -423,7 +423,7 @@ class ValidateUserAssetPermissionApi(UserPermissionCacheMixin, APIView):
return
Response
({
'msg'
:
False
},
status
=
403
)
action
=
granted_system_users
[
su
]
choices
=
Action
Flag
.
value_to_choices
(
action
)
choices
=
Action
.
value_to_choices
(
action
)
if
action_name
not
in
choices
:
return
Response
({
'msg'
:
False
},
status
=
403
)
...
...
apps/perms/const.py
View file @
930eb1d2
# -*- coding: utf-8 -*-
#
from
django.utils.translation
import
ugettext_lazy
as
_
__all__
=
[
'PERMS_ACTION_NAME_ALL'
,
'PERMS_ACTION_NAME_CONNECT'
,
'PERMS_ACTION_NAME_DOWNLOAD_FILE'
,
'PERMS_ACTION_NAME_UPLOAD_FILE'
,
'PERMS_ACTION_NAME_CHOICES'
]
PERMS_ACTION_NAME_ALL
=
'all'
PERMS_ACTION_NAME_CONNECT
=
'connect'
PERMS_ACTION_NAME_UPLOAD_FILE
=
'upload_file'
PERMS_ACTION_NAME_DOWNLOAD_FILE
=
'download_file'
PERMS_ACTION_NAME_CHOICES
=
(
(
PERMS_ACTION_NAME_ALL
,
_
(
'All'
)),
(
PERMS_ACTION_NAME_CONNECT
,
_
(
'Connect'
)),
(
PERMS_ACTION_NAME_UPLOAD_FILE
,
_
(
'Upload file'
)),
(
PERMS_ACTION_NAME_DOWNLOAD_FILE
,
_
(
'Download file'
)),
)
UNGROUPED_NODE_ID
=
"00000000-0000-0000-0000-000000000000"
UNGROUPED_NODE_ID
=
"00000000-0000-0000-0000-000000000002"
apps/perms/forms/asset_permission.py
View file @
930eb1d2
...
...
@@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _
from
orgs.mixins
import
OrgModelForm
from
orgs.utils
import
current_org
from
assets.models
import
Asset
,
Node
from
..models
import
AssetPermission
,
Action
Flag
from
..models
import
AssetPermission
,
Action
__all__
=
[
'AssetPermissionForm'
,
...
...
@@ -16,20 +16,20 @@ __all__ = [
class
ActionField
(
forms
.
MultipleChoiceField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
kwargs
[
'choices'
]
=
Action
Flag
.
CHOICES
kwargs
[
'initial'
]
=
Action
Flag
.
ALL
kwargs
[
'choices'
]
=
Action
.
CHOICES
kwargs
[
'initial'
]
=
Action
.
ALL
kwargs
[
'label'
]
=
_
(
"Action"
)
kwargs
[
'widget'
]
=
forms
.
CheckboxSelectMultiple
()
super
()
.
__init__
(
*
args
,
**
kwargs
)
def
to_python
(
self
,
value
):
value
=
super
()
.
to_python
(
value
)
return
Action
Flag
.
choices_to_value
(
value
)
return
Action
.
choices_to_value
(
value
)
def
prepare_value
(
self
,
value
):
if
value
is
None
:
return
value
value
=
Action
Flag
.
value_to_choices
(
value
)
value
=
Action
.
value_to_choices
(
value
)
return
value
...
...
apps/perms/migrations/0003_action.py
View file @
930eb1d2
...
...
@@ -4,14 +4,6 @@ from django.db import migrations, models
import
uuid
def
add_default_actions
(
apps
,
schema_editor
):
from
..const
import
PERMS_ACTION_NAME_CHOICES
action_model
=
apps
.
get_model
(
'perms'
,
'Action'
)
db_alias
=
schema_editor
.
connection
.
alias
for
action
,
_
in
PERMS_ACTION_NAME_CHOICES
:
action_model
.
objects
.
using
(
db_alias
)
.
update_or_create
(
name
=
action
)
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
...
...
@@ -29,5 +21,4 @@ class Migration(migrations.Migration):
'verbose_name'
:
'Action'
,
},
),
migrations
.
RunPython
(
add_default_actions
)
]
apps/perms/migrations/0004_assetpermission_actions.py
View file @
930eb1d2
...
...
@@ -3,18 +3,6 @@
from
django.db
import
migrations
,
models
def
set_default_action_to_existing_perms
(
apps
,
schema_editor
):
from
orgs.utils
import
set_to_root_org
from
..models
import
Action
set_to_root_org
()
perm_model
=
apps
.
get_model
(
'perms'
,
'AssetPermission'
)
db_alias
=
schema_editor
.
connection
.
alias
perms
=
perm_model
.
objects
.
using
(
db_alias
)
.
all
()
default_action
=
Action
.
get_action_all
()
for
perm
in
perms
:
perm
.
actions
.
add
(
default_action
.
id
)
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
...
...
@@ -27,5 +15,4 @@ class Migration(migrations.Migration):
name
=
'actions'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
related_name
=
'permissions'
,
to
=
'perms.Action'
,
verbose_name
=
'Action'
),
),
migrations
.
RunPython
(
set_default_action_to_existing_perms
)
]
apps/perms/migrations/0006_auto_20190628_1921.py
View file @
930eb1d2
...
...
@@ -6,21 +6,22 @@ from functools import reduce
def
migrate_old_actions
(
apps
,
schema_editor
):
from
orgs.utils
import
set_to_root_org
from
..models
import
ActionFlag
set_to_root_org
()
perm_model
=
apps
.
get_model
(
'perms'
,
'AssetPermission'
)
db_alias
=
schema_editor
.
connection
.
alias
perms
=
perm_model
.
objects
.
using
(
db_alias
)
.
all
()
actions_map
=
{
"all"
:
ActionFlag
.
ALL
,
"connect"
:
ActionFlag
.
CONNECT
,
"upload_file"
:
ActionFlag
.
UPLOAD
,
"download_file"
:
ActionFlag
.
DOWNLOAD
,
"all"
:
0
b11111111
,
"connect"
:
0
b00000001
,
"upload_file"
:
0
b00000010
,
"download_file"
:
0
b00000100
,
}
for
perm
in
perms
:
actions
=
perm
.
actions
.
all
()
new_actions
=
[
actions_map
.
get
(
action
.
name
,
ActionFlag
.
ALL
)
for
action
in
actions
]
if
not
actions
:
continue
new_actions
=
[
actions_map
.
get
(
action
.
name
,
0
b11111111
)
for
action
in
actions
]
new_action
=
reduce
(
lambda
x
,
y
:
x
|
y
,
new_actions
)
perm
.
action
=
new_action
perm
.
save
()
...
...
apps/perms/migrations/0007_remove_assetpermission_actions.py
View file @
930eb1d2
...
...
@@ -19,4 +19,5 @@ class Migration(migrations.Migration):
old_name
=
'action'
,
new_name
=
'actions'
,
),
migrations
.
DeleteModel
(
name
=
'Action'
),
]
apps/perms/models/asset_permission.py
View file @
930eb1d2
...
...
@@ -4,37 +4,18 @@ from functools import reduce
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
common.utils
import
date_expired_default
,
set_or_append_attr_bulk
from
common.utils
import
date_expired_default
from
orgs.mixins
import
OrgModelMixin
from
..const
import
PERMS_ACTION_NAME_CHOICES
,
PERMS_ACTION_NAME_ALL
from
.base
import
BasePermission
__all__
=
[
'A
ction'
,
'AssetPermission'
,
'NodePermission'
,
'ActionFlag'
'A
ssetPermission'
,
'NodePermission'
,
'Action'
,
]
class
Action
(
models
.
Model
):
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
name
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
choices
=
PERMS_ACTION_NAME_CHOICES
,
verbose_name
=
_
(
'Name'
)
)
class
Meta
:
verbose_name
=
_
(
'Action'
)
def
__str__
(
self
):
return
self
.
get_name_display
()
@classmethod
def
get_action_all
(
cls
):
return
cls
.
objects
.
get
(
name
=
PERMS_ACTION_NAME_ALL
)
class
ActionFlag
:
class
Action
:
CONNECT
=
0
b00000001
UPLOAD
=
0
b00000010
DOWNLOAD
=
0
b00000100
...
...
@@ -86,7 +67,7 @@ class AssetPermission(BasePermission):
nodes
=
models
.
ManyToManyField
(
'assets.Node'
,
related_name
=
'granted_by_permissions'
,
blank
=
True
,
verbose_name
=
_
(
"Nodes"
))
system_users
=
models
.
ManyToManyField
(
'assets.SystemUser'
,
related_name
=
'granted_by_permissions'
,
verbose_name
=
_
(
"System user"
))
# actions = models.ManyToManyField(Action, related_name='permissions', blank=True, verbose_name=_('Action'))
actions
=
models
.
IntegerField
(
choices
=
Action
Flag
.
DB_CHOICES
,
default
=
ActionFlag
.
ALL
,
verbose_name
=
_
(
"Actions"
))
actions
=
models
.
IntegerField
(
choices
=
Action
.
DB_CHOICES
,
default
=
Action
.
ALL
,
verbose_name
=
_
(
"Actions"
))
class
Meta
:
unique_together
=
[(
'org_id'
,
'name'
)]
...
...
apps/perms/serializers/asset_permission.py
View file @
930eb1d2
...
...
@@ -5,7 +5,7 @@ from rest_framework import serializers
from
common.fields
import
StringManyToManyField
from
orgs.mixins
import
BulkOrgResourceModelSerializer
from
perms.models
import
AssetPermission
,
Action
Flag
from
perms.models
import
AssetPermission
,
Action
__all__
=
[
'AssetPermissionCreateUpdateSerializer'
,
'AssetPermissionListSerializer'
,
...
...
@@ -16,20 +16,20 @@ __all__ = [
class
ActionField
(
serializers
.
MultipleChoiceField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
kwargs
[
'choices'
]
=
Action
Flag
.
CHOICES
kwargs
[
'choices'
]
=
Action
.
CHOICES
super
()
.
__init__
(
*
args
,
**
kwargs
)
def
to_representation
(
self
,
value
):
return
Action
Flag
.
value_to_choices
(
value
)
return
Action
.
value_to_choices
(
value
)
def
to_internal_value
(
self
,
data
):
return
Action
Flag
.
choices_to_value
(
data
)
return
Action
.
choices_to_value
(
data
)
class
ActionDisplayField
(
ActionField
):
def
to_representation
(
self
,
value
):
values
=
super
()
.
to_representation
(
value
)
choices
=
dict
(
Action
Flag
.
CHOICES
)
choices
=
dict
(
Action
.
CHOICES
)
return
[
choices
.
get
(
i
)
for
i
in
values
]
...
...
apps/perms/signals_handler.py
View file @
930eb1d2
...
...
@@ -6,7 +6,7 @@ from django.db import transaction
from
common.utils
import
get_logger
from
.utils
import
AssetPermissionUtil
from
.models
import
AssetPermission
,
Action
from
.models
import
AssetPermission
logger
=
get_logger
(
__file__
)
...
...
apps/perms/utils/asset_permission.py
View file @
930eb1d2
...
...
@@ -17,7 +17,7 @@ from orgs.utils import set_to_root_org
from
common.utils
import
get_logger
from
common.tree
import
TreeNode
from
..
import
const
from
..models
import
AssetPermission
,
Action
,
ActionFlag
from
..models
import
AssetPermission
,
Action
from
..hands
import
Node
,
Asset
from
assets.utils
import
NodeUtil
...
...
@@ -569,7 +569,7 @@ def parse_asset_to_tree_node(node, asset, system_users):
'protocol'
:
system_user
.
protocol
,
'priority'
:
system_user
.
priority
,
'login_mode'
:
system_user
.
login_mode
,
'actions'
:
[
Action
Flag
.
value_to_choices
(
action
)],
'actions'
:
[
Action
.
value_to_choices
(
action
)],
})
data
=
{
'id'
:
str
(
asset
.
id
),
...
...
apps/perms/views/asset_permission.py
View file @
930eb1d2
...
...
@@ -10,10 +10,9 @@ from django.conf import settings
from
common.permissions
import
PermissionsMixin
,
IsOrgAdmin
from
orgs.utils
import
current_org
from
perms.hands
import
Node
,
Asset
,
SystemUser
,
User
,
User
Group
from
perms.models
import
AssetPermission
,
Action
from
perms.hands
import
Node
,
Asset
,
SystemUser
,
UserGroup
from
perms.models
import
AssetPermission
from
perms.forms
import
AssetPermissionForm
from
perms.const
import
PERMS_ACTION_NAME_ALL
__all__
=
[
...
...
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