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
70713af9
Commit
70713af9
authored
Oct 12, 2019
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 限制组织名称中使用的特殊字符
parent
2f2b0b28
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
9 deletions
+37
-9
const.py
apps/assets/const.py
+14
-0
asset.py
apps/assets/forms/asset.py
+3
-6
asset.py
apps/assets/serializers/asset.py
+6
-2
serializers.py
apps/orgs/serializers.py
+14
-1
No files found.
apps/assets/const.py
0 → 100644
View file @
70713af9
# -*- coding: utf-8 -*-
#
from
django.utils.translation
import
ugettext_lazy
as
_
GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT
=
_
(
'Only Numbers、letters、 chinese and characters ( {} ) are allowed'
)
.
format
(
" "
.
join
([
'.'
,
'_'
,
'@'
,
'-'
]))
GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN
=
r"^[\._@\w-]+$"
GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG
=
\
_
(
"* The contains characters that are not allowed"
)
apps/assets/forms/asset.py
View file @
70713af9
...
...
@@ -7,6 +7,7 @@ from common.utils import get_logger
from
orgs.mixins.forms
import
OrgModelForm
from
..models
import
Asset
,
Node
from
..const
import
GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT
logger
=
get_logger
(
__file__
)
...
...
@@ -14,10 +15,6 @@ __all__ = [
'AssetCreateForm'
,
'AssetUpdateForm'
,
'AssetBulkUpdateForm'
,
'ProtocolForm'
,
]
HELP_TEXTS_ASSET_HOSTNAME
=
_
(
'Only Numbers、letters、 chinese and characters ( {} ) are allowed'
)
.
format
(
" "
.
join
([
'.'
,
'_'
,
'@'
]))
class
ProtocolForm
(
forms
.
Form
):
name
=
forms
.
ChoiceField
(
...
...
@@ -72,7 +69,7 @@ class AssetCreateForm(OrgModelForm):
'nodes'
:
_
(
"Node"
),
}
help_texts
=
{
'hostname'
:
HELP_TEXTS_ASSET_HOSTNAME
,
'hostname'
:
GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT
,
'admin_user'
:
_
(
'root or other NOPASSWD sudo privilege user existed in asset,'
'If asset is windows or other set any one, more see admin user left menu'
...
...
@@ -119,7 +116,7 @@ class AssetUpdateForm(OrgModelForm):
'nodes'
:
_
(
"Node"
),
}
help_texts
=
{
'hostname'
:
HELP_TEXTS_ASSET_HOSTNAME
,
'hostname'
:
GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT
,
'admin_user'
:
_
(
'root or other NOPASSWD sudo privilege user existed in asset,'
'If asset is windows or other set any one, more see admin user left menu'
...
...
apps/assets/serializers/asset.py
View file @
70713af9
...
...
@@ -8,6 +8,10 @@ from django.utils.translation import ugettext_lazy as _
from
orgs.mixins.serializers
import
BulkOrgResourceModelSerializer
from
common.serializers
import
AdaptedBulkListSerializer
from
..models
import
Asset
,
Node
,
Label
from
..const
import
(
GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN
,
GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG
)
from
.base
import
ConnectivitySerializer
__all__
=
[
...
...
@@ -94,10 +98,10 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
@staticmethod
def
validate_hostname
(
hostname
):
pattern
=
r"^[\._@\w-]+$"
pattern
=
GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN
res
=
re
.
match
(
pattern
,
hostname
)
if
res
is
None
:
msg
=
_
(
"* The hostname contains characters that are not allowed"
)
msg
=
GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG
raise
serializers
.
ValidationError
(
msg
)
return
hostname
...
...
apps/orgs/serializers.py
View file @
70713af9
import
re
from
rest_framework.serializers
import
ModelSerializer
from
rest_framework
import
serializers
from
users.models
import
User
,
UserGroup
from
assets.models
import
Asset
,
Domain
,
AdminUser
,
SystemUser
,
Label
from
assets.const
import
(
GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN
,
GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG
)
from
perms.models
import
AssetPermission
from
common.serializers
import
AdaptedBulkListSerializer
from
.utils
import
set_current_org
,
get_current_org
...
...
@@ -18,6 +22,15 @@ class OrgSerializer(ModelSerializer):
fields
=
'__all__'
read_only_fields
=
[
'created_by'
,
'date_created'
]
@staticmethod
def
validate_name
(
name
):
pattern
=
GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN
res
=
re
.
match
(
pattern
,
name
)
if
res
is
None
:
msg
=
GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG
raise
serializers
.
ValidationError
(
msg
)
return
name
class
OrgReadSerializer
(
ModelSerializer
):
admins
=
serializers
.
SlugRelatedField
(
slug_field
=
'name'
,
many
=
True
,
read_only
=
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