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
1e835d2f
Commit
1e835d2f
authored
Nov 20, 2016
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[future] 增加503和501的自定义异常
parent
76f72dfb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
exc.py
apps/ops/api/exc.py
+16
-0
permissions.py
apps/ops/api/permissions.py
+19
-0
No files found.
apps/ops/api/exc.py
0 → 100644
View file @
1e835d2f
# ~*~ coding: utf-8 ~*~
from
__future__
import
unicode_literals
,
print_function
from
rest_framework.exceptions
import
APIException
from
django.utils.translation
import
ugettext
as
_
class
ServiceUnavailable
(
APIException
):
status_code
=
default_code
=
503
default_detail
=
_
(
'Service temporarily unavailable, try again later.'
)
class
ServiceNotImplemented
(
APIException
):
status_code
=
default_code
=
501
default_detail
=
_
(
'This service maybe implemented in the future, but now not implemented!'
)
apps/ops/api/permissions.py
0 → 100644
View file @
1e835d2f
# ~*~ coding: utf-8 ~*~
from
__future__
import
unicode_literals
from
rest_framework
import
permissions
class
AdminUserRequired
(
permissions
.
BasePermission
):
"""
Custom permission to only allow admin user to access the resource.
"""
def
has_object_permission
(
self
,
request
,
view
,
obj
):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
if
request
.
method
in
permissions
.
SAFE_METHODS
:
return
True
# Write permissions are only allowed to the admin role.
return
request
.
user
.
is_staff
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