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
627a5825
Commit
627a5825
authored
Sep 10, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user perm
parent
89923333
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
159 additions
and
10 deletions
+159
-10
utils.py
apps/common/utils.py
+10
-0
forms.py
apps/perms/forms.py
+17
-0
hands.py
apps/perms/hands.py
+11
-0
models.py
apps/perms/models.py
+20
-2
views.py
apps/perms/views.py
+99
-2
hands.py
apps/users/hands.py
+1
-1
models.py
apps/users/models.py
+1
-5
No files found.
apps/common/utils.py
View file @
627a5825
...
@@ -6,6 +6,7 @@ from __future__ import unicode_literals
...
@@ -6,6 +6,7 @@ from __future__ import unicode_literals
from
django.shortcuts
import
reverse
as
dj_reverse
from
django.shortcuts
import
reverse
as
dj_reverse
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core
import
signing
from
django.core
import
signing
from
django.utils
import
timezone
def
reverse
(
viewname
,
urlconf
=
None
,
args
=
None
,
kwargs
=
None
,
current_app
=
None
,
external
=
False
):
def
reverse
(
viewname
,
urlconf
=
None
,
args
=
None
,
kwargs
=
None
,
current_app
=
None
,
external
=
False
):
...
@@ -31,3 +32,11 @@ def encrypt(*args, **kwargs):
...
@@ -31,3 +32,11 @@ def encrypt(*args, **kwargs):
def
decrypt
(
*
args
,
**
kwargs
):
def
decrypt
(
*
args
,
**
kwargs
):
return
signing
.
loads
(
*
args
,
**
kwargs
)
return
signing
.
loads
(
*
args
,
**
kwargs
)
def
date_expired_default
():
try
:
years
=
int
(
settings
.
CONFIG
.
DEFAULT_EXPIRED_YEARS
)
except
TypeError
:
years
=
70
return
timezone
.
now
()
+
timezone
.
timedelta
(
days
=
365
*
years
)
\ No newline at end of file
apps/perms/forms.py
0 → 100644
View file @
627a5825
# ~*~ coding: utf-8 ~*~
from
__future__
import
absolute_import
,
unicode_literals
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
from
users.models
import
User
,
UserGroup
from
assets.models
import
Asset
,
AssetGroup
,
SystemUser
from
.models
import
UserAssetPerm
class
UserAssetPermForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
UserAssetPerm
fields
=
[
'assets'
,
'asset_groups'
,
'system_users'
,
'date_expired'
,
'comment'
]
apps/perms/hands.py
0 → 100644
View file @
627a5825
# ~*~ coding: utf-8 ~*~
#
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
apps/perms/models.py
View file @
627a5825
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
,
absolute_import
from
django.db
import
models
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
# Create your models here.
from
users.models
import
User
,
UserGroup
from
assets.models
import
Asset
,
AssetGroup
,
SystemUser
from
common.utils
import
date_expired_default
class
UserAssetPerm
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'asset_perm'
,
on_delete
=
models
.
CASCADE
)
assets
=
models
.
ManyToManyField
(
Asset
,
related_name
=
'user_perms'
,
blank
=
True
)
asset_groups
=
models
.
ManyToManyField
(
AssetGroup
,
related_name
=
'user_perm'
,
blank
=
True
)
system_users
=
models
.
ManyToManyField
(
SystemUser
,
related_name
=
'user_perm'
,
blank
=
True
)
date_expired
=
models
.
DateTimeField
(
default
=
date_expired_default
,
verbose_name
=
_
(
'Date expired'
))
created_by
=
models
.
CharField
(
max_length
=
128
)
date_created
=
models
.
DateTimeField
(
auto_now
=
True
)
comment
=
models
.
TextField
(
verbose_name
=
_
(
'Comment'
))
class
UserGroupAssetPerm
(
models
.
Model
):
pass
apps/perms/views.py
View file @
627a5825
from
django.shortcuts
import
render
# ~*~ coding: utf-8 ~*~
# Create your views here.
from
__future__
import
unicode_literals
,
absolute_import
from
django.views.generic.list
import
ListView
from
django.conf
import
settings
from
.hands
import
AdminUserRequiredMixin
from
.models
import
UserAssetPerm
,
UserGroupAssetPerm
class
SystemUserListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
UserAssetPerm
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'system_user_list'
template_name
=
'assets/system_user_list.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'System user list'
),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
}
kwargs
.
update
(
context
)
return
super
(
SystemUserListView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_queryset
(
self
):
# Todo: Default order by lose asset connection num
self
.
queryset
=
super
(
SystemUserListView
,
self
)
.
get_queryset
()
self
.
keyword
=
keyword
=
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_created'
)
if
keyword
:
self
.
queryset
=
self
.
queryset
.
filter
(
Q
(
name__icontains
=
keyword
)
|
Q
(
comment__icontains
=
keyword
))
if
sort
:
self
.
queryset
=
self
.
queryset
.
order_by
(
sort
)
return
self
.
queryset
class
SystemUserCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
SystemUser
form_class
=
SystemUserForm
template_name
=
'assets/system_user_create_update.html'
success_url
=
reverse_lazy
(
'assets:system-user-list'
)
success_message
=
_
(
'Create system user <a href="
%
s">
%
s</a> successfully.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Create system user'
),
}
kwargs
.
update
(
context
)
return
super
(
SystemUserCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
return
self
.
success_message
%
(
reverse_lazy
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}),
self
.
object
.
name
,
)
class
SystemUserUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
SystemUser
form_class
=
SystemUserForm
template_name
=
'assets/system_user_create_update.html'
success_message
=
_
(
'Update system user <a href="
%
s">
%
s</a> successfully.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Update system user'
)
}
kwargs
.
update
(
context
)
return
super
(
SystemUserUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:system-user-detail'
,
pk
=
self
.
object
.
pk
)
return
success_url
class
SystemUserDetailView
(
AdminUserRequiredMixin
,
DetailView
):
template_name
=
'assets/system_user_detail.html'
context_object_name
=
'system_user'
model
=
SystemUser
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'System user detail'
)
}
kwargs
.
update
(
context
)
return
super
(
SystemUserDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
SystemUserDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
model
=
SystemUser
template_name
=
'assets/delete_confirm.html'
success_url
=
'assets:system-user-list'
apps/users/hands.py
View file @
627a5825
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
:license: GPL v2, see LICENSE for more details.
:license: GPL v2, see LICENSE for more details.
"""
"""
from
users.utils
import
AdminUserRequiredMixin
apps/users/models.py
View file @
627a5825
...
@@ -14,7 +14,7 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -14,7 +14,7 @@ from django.utils.translation import ugettext_lazy as _
from
rest_framework.authtoken.models
import
Token
from
rest_framework.authtoken.models
import
Token
from
common.utils
import
encrypt
,
decrypt
from
common.utils
import
encrypt
,
decrypt
,
date_expired_default
class
UserGroup
(
models
.
Model
):
class
UserGroup
(
models
.
Model
):
...
@@ -58,10 +58,6 @@ class UserGroup(models.Model):
...
@@ -58,10 +58,6 @@ class UserGroup(models.Model):
continue
continue
def
date_expired_default
():
return
timezone
.
now
()
+
timezone
.
timedelta
(
days
=
365
*
70
)
class
User
(
AbstractUser
):
class
User
(
AbstractUser
):
ROLE_CHOICES
=
(
ROLE_CHOICES
=
(
(
'Admin'
,
_
(
'Administrator'
)),
(
'Admin'
,
_
(
'Administrator'
)),
...
...
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