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
1af40b6c
Commit
1af40b6c
authored
Jul 17, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 支持etag
parent
8ed3bb85
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
12 deletions
+27
-12
cmd_filter.py
apps/assets/serializers/cmd_filter.py
+9
-9
mixin.py
apps/perms/api/mixin.py
+15
-1
user_permission.py
apps/perms/api/user_permission.py
+1
-0
jumpserver.js
apps/static/js/jumpserver.js
+2
-2
No files found.
apps/assets/serializers/cmd_filter.py
View file @
1af40b6c
...
...
@@ -35,12 +35,12 @@ class CommandFilterRuleSerializer(BulkOrgResourceModelSerializer):
fields
=
'__all__'
list_serializer_class
=
AdaptedBulkListSerializer
def
validate_content
(
self
,
content
):
tp
=
self
.
initial_data
.
get
(
"type"
)
if
tp
==
CommandFilterRule
.
TYPE_REGEX
:
return
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
#
def validate_content(self, content):
#
tp = self.initial_data.get("type")
#
if tp == CommandFilterRule.TYPE_REGEX:
#
return 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/perms/api/mixin.py
View file @
1af40b6c
...
...
@@ -6,6 +6,8 @@ from django.core.cache import cache
from
django.db.models
import
Q
from
django.conf
import
settings
from
rest_framework.views
import
Response
from
django.utils.decorators
import
method_decorator
from
django.views.decorators.http
import
condition
from
django.utils.translation
import
ugettext
as
_
from
common.utils
import
get_logger
...
...
@@ -14,7 +16,7 @@ from ..utils import (
AssetPermissionUtil
)
from
..
import
const
from
..hands
import
Asset
,
Node
,
SystemUser
,
Label
from
..hands
import
Asset
,
Node
,
SystemUser
from
..
import
serializers
logger
=
get_logger
(
__name__
)
...
...
@@ -22,6 +24,17 @@ logger = get_logger(__name__)
__all__
=
[
'UserPermissionCacheMixin'
,
'GrantAssetsMixin'
,
'NodesWithUngroupMixin'
]
def
get_etag
(
request
,
*
args
,
**
kwargs
):
cache_policy
=
request
.
GET
.
get
(
"cache_policy"
)
if
cache_policy
!=
'1'
:
return
None
view
=
request
.
parser_context
.
get
(
"view"
)
if
not
view
:
return
None
etag
=
view
.
get_meta_cache_id
()
return
etag
class
UserPermissionCacheMixin
:
cache_policy
=
'0'
RESP_CACHE_KEY
=
'_PERMISSION_RESPONSE_CACHE_V2_{}'
...
...
@@ -96,6 +109,7 @@ class UserPermissionCacheMixin:
cache
.
set
(
key
,
response
.
data
,
self
.
CACHE_TIME
)
logger
.
debug
(
"Set response to cache: {}"
.
format
(
key
))
@method_decorator
(
condition
(
etag_func
=
get_etag
))
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
cache_policy
=
request
.
GET
.
get
(
'cache_policy'
,
'0'
)
...
...
apps/perms/api/user_permission.py
View file @
1af40b6c
...
...
@@ -3,6 +3,7 @@
import
uuid
from
django.shortcuts
import
get_object_or_404
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.generics
import
(
ListAPIView
,
get_object_or_404
,
RetrieveAPIView
)
...
...
apps/static/js/jumpserver.js
View file @
1af40b6c
...
...
@@ -223,7 +223,7 @@ function formSubmit(props) {
return
}
$
.
each
(
errors
,
function
(
k
,
v
)
{
var
fieldRef
=
props
.
form
.
find
(
'
input
[name="'
+
k
+
'"]'
);
var
fieldRef
=
props
.
form
.
find
(
'[name="'
+
k
+
'"]'
);
var
formGroupRef
=
fieldRef
.
parents
(
'.form-group'
);
var
parentRef
=
fieldRef
.
parent
();
var
helpBlockRef
=
parentRef
.
children
(
'.help-block.error'
);
...
...
@@ -237,7 +237,7 @@ function formSubmit(props) {
helpBlockRef
.
html
(
help_msg
);
}
else
{
$
.
each
(
v
,
function
(
kk
,
vv
)
{
if
(
typeof
errors
===
"object"
)
{
if
(
typeof
vv
===
"object"
)
{
$
.
each
(
vv
,
function
(
kkk
,
vvv
)
{
noneFieldErrorMsg
+=
" "
+
vvv
+
'<br/>'
;
})
...
...
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