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
324bb686
Commit
324bb686
authored
Sep 11, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user-pserm
parent
70cae93a
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
223 additions
and
69 deletions
+223
-69
urls.py
apps/jumpserver/urls.py
+1
-0
forms.py
apps/perms/forms.py
+15
-6
hands.py
apps/perms/hands.py
+3
-2
models.py
apps/perms/models.py
+1
-1
perm_user_asset_create_update.html
.../perms/templates/perms/perm_user_asset_create_update.html
+81
-0
perm_user_asset_list.html
apps/perms/templates/perms/perm_user_asset_list.html
+66
-0
perm_user_list.html
apps/perms/templates/perms/perm_user_list.html
+8
-14
urls.py
apps/perms/urls.py
+4
-3
views.py
apps/perms/views.py
+42
-41
_nav.html
apps/templates/_nav.html
+1
-1
hands.py
apps/users/hands.py
+1
-1
No files found.
apps/jumpserver/urls.py
View file @
324bb686
...
...
@@ -25,6 +25,7 @@ urlpatterns = [
url
(
r'^$'
,
TemplateView
.
as_view
(
template_name
=
'base.html'
),
name
=
'index'
),
url
(
r'^(api/)?users/'
,
include
(
'users.urls'
)),
url
(
r'^assets/'
,
include
(
'assets.urls'
)),
url
(
r'^perms/'
,
include
(
'perms.urls'
)),
url
(
r'^terminal/'
,
include
(
'webterminal.urls'
)),
]
...
...
apps/perms/forms.py
View file @
324bb686
...
...
@@ -4,14 +4,23 @@ 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
from
.hands
import
User
,
UserGroup
,
Asset
,
AssetGroup
,
SystemUser
from
.models
import
PermUserAsset
class
UserAssetPerm
Form
(
forms
.
ModelForm
):
class
PermUserAsset
Form
(
forms
.
ModelForm
):
class
Meta
:
model
=
UserAssetPerm
model
=
PermUserAsset
fields
=
[
'assets'
,
'asset_groups'
,
'system_users'
,
'date_expired'
,
'comment'
'
user'
,
'action'
,
'
assets'
,
'asset_groups'
,
'system_users'
,
'date_expired'
,
'comment'
]
widgets
=
{
'user'
:
forms
.
HiddenInput
(
attrs
=
{
'style'
:
'display: none'
}),
'assets'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select assets'
)}),
'asset_groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'system_users'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select system users'
)}),
}
apps/perms/hands.py
View file @
324bb686
...
...
@@ -5,7 +5,8 @@ from django.db import models
from
django.utils.translation
import
ugettext_lazy
as
_
from
users.utils
import
AdminUserRequiredMixin
from
users.models
import
User
,
UserGroup
from
assets.models
import
Asset
,
AssetGroup
,
SystemUser
apps/perms/models.py
View file @
324bb686
...
...
@@ -23,7 +23,7 @@ class PermUserAsset(models.Model):
date_expired
=
models
.
DateTimeField
(
default
=
date_expired_default
,
verbose_name
=
_
(
'Date expired'
))
created_by
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
)
date_created
=
models
.
DateTimeField
(
auto_now
=
True
)
comment
=
models
.
TextField
(
verbose_name
=
_
(
'Comment'
))
comment
=
models
.
TextField
(
verbose_name
=
_
(
'Comment'
)
,
blank
=
True
)
def
__unicode__
(
self
):
return
'
%(id)
s:
%(user)
s
%(action)
s'
%
{
...
...
apps/perms/templates/perms/perm_user_asset_create_update.html
0 → 100644
View file @
324bb686
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2
.
min
.
css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2
.
full
.
min
.
js
"
%}"
></script>
<link
href=
"{% static "
css
/
plugins
/
datepicker
/
datepicker3
.
css
"
%}"
rel=
"stylesheet"
>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
{% trans 'Create asset perm for ' %}
<b>
{{ user.name }}
</b></h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
{% csrf_token %}
<input
name=
"{{ form.user.html_name }}"
hidden=
"hidden"
style=
"display: none"
value=
"{{ user.id }}"
>
{{ form.action|bootstrap_horizontal }}
{{ form.assets|bootstrap_horizontal }}
{{ form.asset_groups|bootstrap_horizontal }}
{{ form.system_users |bootstrap_horizontal }}
<div
class=
"form-group {% if form.date_expired.errors %} has-error {% endif %}"
id=
"date_5"
>
<label
for=
"{{ form.date_expired.id_for_label }}"
class=
"col-sm-2 control-label"
>
{{ form.date_expired.label }}
</label>
<div
class=
"col-sm-9"
>
<div
class=
"input-group date"
>
<span
class=
"input-group-addon"
><i
class=
"fa fa-calendar"
></i></span>
<input
id=
"{{ form.date_expired.id_for_label }}"
name=
"{{ form.date_expired.html_name }}"
type=
"text"
class=
"form-control"
value=
"{{ form.date_expired.value|date:'Y-m-d' }}"
>
</div>
<span
class=
"help-block "
>
{{ form.date_expired.errors }}
</span>
</div>
</div>
{{ form.comment|bootstrap_horizontal }}
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script
src=
"{% static 'js/plugins/datapicker/bootstrap-datepicker.js' %}"
></script>
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.input-group.date'
).
datepicker
({
format
:
"yyyy-mm-dd"
,
todayBtn
:
"linked"
,
keyboardNavigation
:
false
,
forceParse
:
false
,
calendarWeeks
:
true
,
autoclose
:
true
})
})
</script>
{% endblock %}
\ No newline at end of file
apps/perms/templates/perms/perm_user_asset_list.html
0 → 100644
View file @
324bb686
{% extends '_list_base.html' %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'users:user-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create perm " %}
</a>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user-list' %}?sort=username"
>
{% trans 'Username' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Role' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset group' %}
</th>
<th
class=
"text-center"
>
{% trans 'System user' %}
</th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user-list' %}?sort=date_expired"
>
{% trans 'Active' %}
</a></th>
<th
class=
"text-center"
></th>
{% endblock %}
{% block table_body %}
{% for perm in page_obj %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ user.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'users:user-detail' pk=user.id %}"
>
{{ user.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ user.username }}
</td>
<td
class=
"text-center"
>
{{ user.get_role_display }}
</td>
<th
class=
"text-center"
>
35/40
</th>
<th
class=
"text-center"
>
20
</th>
<th
class=
"text-center"
>
3
</th>
<td
class=
"text-center"
>
<a
href=
"{% url 'perms:perm-user-asset-create' pk=user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Create perm' %}
</a>
<a
href=
"{% url 'users:user-delete' pk=user.id %}"
class=
"btn btn-xs btn-danger del {% if user.id == request.user.id or user.username == 'admin' %} disabled {% endif %}"
>
{% trans 'Flush' %}
</a>
</td>
</tr>
{% endfor %}
{% endblock %}
{% block content_bottom_left %}
<form
id=
""
method=
"get"
action=
""
class=
" mail-search"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
>
<option>
{% trans 'Delete selected' %}
</option>
<option>
{% trans 'Update selected' %}
</option>
<option>
{% trans 'Deactive selected' %}
</option>
<option>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'search_btn'
type=
"submit"
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
apps/perms/templates/perms/perm_user_list.html
View file @
324bb686
...
...
@@ -2,6 +2,7 @@
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'users:user-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Batch create perm " %}
</a>
{% endblock %}
{% block table_head %}
...
...
@@ -10,9 +11,8 @@
</th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user-list' %}?sort=username"
>
{% trans 'Username' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'User group' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset available' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset unavailable' %}
</th>
<th
class=
"text-center"
>
{% trans 'Role' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset group' %}
</th>
<th
class=
"text-center"
>
{% trans 'System user' %}
</th>
<th
class=
"text-center"
><a
href=
"{% url 'users:user-list' %}?sort=date_expired"
>
{% trans 'Active' %}
</a></th>
...
...
@@ -32,18 +32,12 @@
</td>
<td
class=
"text-center"
>
{{ user.username }}
</td>
<td
class=
"text-center"
>
{{ user.get_role_display }}
</td>
<td
class=
"text-center"
title=
"{% for user_group in user.group.all %} {{ user_group.name }} {% endfor %}"
>
{{ user.groups.all|join_queryset_attr:"name" }}
</td>
<th
class=
"text-center"
>
{{ user.name }}
</th>
<th
class=
"text-center"
>
35/40
</th>
<th
class=
"text-center"
>
20
</th>
<th
class=
"text-center"
>
3
</th>
<td
class=
"text-center"
>
{% if user.is_expired and user.is_active %}
<i
class=
"fa fa-times text-danger"
></i>
{% else %}
<i
class=
"fa fa-check text-navy"
></i>
{% endif %}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'users:user-update' pk=user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
href=
"{% url 'users:user-delete' pk=user.id %}"
class=
"btn btn-xs btn-danger del {% if user.id == request.user.id or user.username == 'admin' %} disabled {% endif %}"
>
{% trans 'Delete' %}
</a>
<a
href=
"{% url 'perms:perm-user-asset-create' pk=user.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Create perm' %}
</a>
<a
href=
"{% url 'users:user-delete' pk=user.id %}"
class=
"btn btn-xs btn-danger del {% if user.id == request.user.id or user.username == 'admin' %} disabled {% endif %}"
>
{% trans 'Flush' %}
</a>
</td>
</tr>
{% endfor %}
...
...
apps/perms/urls.py
View file @
324bb686
...
...
@@ -7,9 +7,10 @@ app_name = 'perms'
urlpatterns
=
[
# Resource asset url
url
(
r'^user$'
,
views
.
PermUserAssetListView
.
as_view
(),
name
=
'perm-user-list'
),
# url(r'^user/(?P<user>[0-9]+)/perm-asset/$', views.AssetListView.as_view(), name='perm-user-asset-list'),
# url(r'^user/(?P<user>[0-9]+)/perm-asset/$', views.AssetListView.as_view(), name='perm-user-asset-list'),
url
(
r'^user$'
,
views
.
PermUserListView
.
as_view
(),
name
=
'perm-user-list'
),
url
(
r'^user/(?P<pk>[0-9]+)/perm-asset/$'
,
views
.
PermUserAssetListView
.
as_view
(),
name
=
'perm-user-asset-list'
),
url
(
r'^user/(?P<pk>[0-9]+)/perm-asset/create$'
,
views
.
PermUserAssetCreateView
.
as_view
(),
name
=
'perm-user-asset-create'
),
# url(r'^user/(?P<user>[0-9]+)$', views.AssetListView.as_view(), name='asset-list'),
# url(r'^asset/create$', views.AssetCreateView.as_view(), name='asset-create'),
# url(r'^asset/(?P<pk>[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'),
...
...
apps/perms/views.py
View file @
324bb686
...
...
@@ -13,7 +13,7 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
from
.hands
import
AdminUserRequiredMixin
,
User
,
UserGroup
from
.models
import
PermUserAsset
,
PermUserGroupAsset
from
.forms
import
UserAssetPerm
Form
from
.forms
import
PermUserAsset
Form
class
PermUserListView
(
AdminUserRequiredMixin
,
ListView
):
...
...
@@ -35,7 +35,7 @@ class PermUserListView(AdminUserRequiredMixin, ListView):
# Todo: Default order by lose asset connection num
self
.
queryset
=
super
(
PermUserListView
,
self
)
.
get_queryset
()
self
.
keyword
=
keyword
=
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_
creat
ed'
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_
join
ed'
)
if
keyword
:
self
.
queryset
=
self
.
queryset
.
filter
(
Q
(
name__icontains
=
keyword
)
|
...
...
@@ -46,58 +46,59 @@ class PermUserListView(AdminUserRequiredMixin, ListView):
return
self
.
queryset
class
PermUserAssetListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
PermUserAsset
class
PermUserAssetListView
(
AdminUserRequiredMixin
,
SingleObjectMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'system_user_list'
template_name
=
'assets/system_user_list.html'
context_object_name
=
'perm_user_asset_list'
template_name
=
'perms/perm_user_asset_list.html'
model
=
User
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
User
.
objects
.
all
())
return
super
(
PermUserAssetListView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'
System user
list'
),
'action'
:
_
(
'
User perm asset
list'
),
'keyword'
:
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
}
kwargs
.
update
(
context
)
return
super
(
PermUserAssetListView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_queryset
(
self
):
# Todo: Default order by lose asset connection num
self
.
queryset
=
super
(
PermUserAssetListView
,
self
)
.
get_queryset
()
self
.
keyword
=
keyword
=
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_created'
)
self
.
queryset
=
self
.
object
.
permuserasset_set
.
all
()
return
self
.
queryset
class
PermUserAssetCreateView
(
AdminUserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
model
=
PermUserAsset
form_class
=
PermUserAssetForm
template_name
=
'perms/perm_user_asset_create_update.html'
success_url
=
reverse_lazy
(
'perms:perm-user-list'
)
success_message
=
_
(
'Create user asset perm <a href="
%
s">
%
s</a> successfully.'
)
def
get_initial
(
self
):
return
{
'user'
:
self
.
get_object
(
queryset
=
User
.
objects
.
all
())}
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
PermUserAssetCreateView
,
self
)
.
form_invalid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Perms'
),
'action'
:
_
(
'Create user asset perm'
),
'user'
:
self
.
get_object
(
queryset
=
User
.
objects
.
all
()),
}
kwargs
.
update
(
context
)
return
super
(
PermUserAssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_success_message
(
self
,
cleaned_data
):
return
self
.
success_message
%
(
reverse_lazy
(
'perms:perm-user-asset-list'
,
kwargs
=
{
'pk'
:
self
.
object
.
user
.
id
})
)
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 PermUserAssetCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
# model = PermUserAsset
# form_class = PermUserAssetForm
# 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(PermUserAssetCreateView, 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 PermUserAssetUpdateView(AdminUserRequiredMixin, UpdateView):
# model = PermUserAsset
# form_class = PermUserAssetForm
...
...
apps/templates/_nav.html
View file @
324bb686
...
...
@@ -30,7 +30,7 @@
<a
href=
"#"
><i
class=
"fa fa-edit"
></i>
<span
class=
"nav-label"
>
{% trans 'Perms' %}
</span><span
class=
"fa arrow"
></span></a>
<ul
class=
"nav nav-second-level"
>
<li
id=
"sudo"
>
<a
class=
"sudo"
href=
""
>
{% trans 'User perm' %}
</a>
<a
class=
"sudo"
href=
"
{% url 'perms:perm-user-list' %}
"
>
{% trans 'User perm' %}
</a>
</li>
<li
id=
"role"
>
<a
href=
""
>
{% trans 'User group perm' %}
</a>
...
...
apps/users/hands.py
View file @
324bb686
...
...
@@ -10,5 +10,5 @@
:license: GPL v2, see LICENSE for more details.
"""
from
users.utils
import
AdminUserRequiredMixin
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