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
df281def
Commit
df281def
authored
Sep 17, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish user detail asset grant ..
parent
7d3474ae
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
12 deletions
+21
-12
utils.py
apps/perms/utils.py
+6
-1
user_granted_asset.html
apps/users/templates/users/user_granted_asset.html
+6
-7
views.py
apps/users/views.py
+9
-4
No files found.
apps/perms/utils.py
View file @
df281def
...
...
@@ -7,7 +7,7 @@ def get_user_group_granted_asset_groups(user_group):
"""Return asset groups granted of the user group
:param user_group: Instance of :class: ``UserGroup``
:return: {asset
_group1: {system_user1, }, asset_group2
: {system_user1, system_user2]}
:return: {asset
1: {system_user1, }, asset1
: {system_user1, system_user2]}
"""
asset_groups
=
{}
asset_permissions
=
user_group
.
asset_permissions
.
all
()
...
...
@@ -61,6 +61,7 @@ def get_user_granted_asset_groups_direct(user):
if
asset_group
in
asset_groups
:
asset_groups
[
asset_group
]
|=
set
(
asset_permission
.
system_users
.
all
())
else
:
setattr
(
asset_group
,
'is_inherit_from_user_group'
,
False
)
asset_groups
[
asset_group
]
=
set
(
asset_permission
.
system_users
.
all
())
return
asset_groups
...
...
@@ -88,6 +89,7 @@ def get_user_granted_asset_groups_inherit_from_user_groups(user):
if
asset_group
in
asset_groups
:
asset_groups
[
asset_group
]
|=
set
(
asset_permission
.
system_users
.
all
())
else
:
setattr
(
asset_group
,
'is_inherit_from_user_group'
,
True
)
asset_groups
[
asset_group
]
=
set
(
asset_permission
.
system_users
.
all
())
return
asset_groups
...
...
@@ -130,6 +132,8 @@ def get_user_granted_assets_direct(user):
if
asset
in
assets
:
assets
[
asset
]
|=
set
(
asset_permission
.
system_users
.
all
())
else
:
setattr
(
asset
,
'is_inherit_from_user_groups'
,
False
)
setattr
(
asset
,
'is_inherit_from_user_groups'
,
False
)
assets
[
asset
]
=
set
(
asset_permission
.
system_users
.
all
())
return
assets
...
...
@@ -150,6 +154,7 @@ def get_user_granted_assets_inherit_from_user_groups(user):
if
asset
in
assets
:
assets
[
asset
]
|=
assets_inherited
[
asset
]
else
:
setattr
(
asset
,
'is_inherit_from_user_groups'
,
True
)
assets
[
asset
]
=
assets_inherited
[
asset
]
return
assets
...
...
apps/users/templates/users/user_granted_asset.html
View file @
df281def
...
...
@@ -74,7 +74,7 @@
</tr>
</thead>
<tbody>
{% for asset in object_list %}
{% for asset
, system_users
in object_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-detail' pk=asset.id %}"
>
...
...
@@ -83,7 +83,7 @@
</td>
<td
class=
"text-center"
>
{{ asset.ip }}
</td>
<td
class=
"text-center"
>
{{ asset.port }}
</td>
<td
class=
"text-center"
>
{{
assets.asset
}}
</td>
<td
class=
"text-center"
>
{{
system_users|join_attr:"name"
}}
</td>
<td
class=
"text-center"
>
{% if asset.is_valid %}
<i
class=
"fa fa-check text-navy"
></i>
...
...
@@ -92,8 +92,7 @@
{% endif %}
</td>
<td>
<button
class=
"btn btn-danger btn-xs btn_delete_user_group {% if not asset.is_valid %} disabled {% endif %}"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
<button
class=
"btn btn-danger btn-xs btn_delete_user_group {% if asset.is_inherit_from_user_groups or asset.is_inherit_from_asset_groups %} disabled {% endif %}"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
...
...
@@ -134,7 +133,7 @@
</tr>
</thead>
<tbody>
{% for asset_group in asset_groups %}
{% for asset_group
, system_users
in asset_groups %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-group-detail' pk=asset_group.id %}"
>
...
...
@@ -142,9 +141,9 @@
</a>
</td>
<td
class=
"text-center"
>
{{ asset_group.assets.count }}
</td>
<td
class=
"text-center"
>
{{
asset_group.name
}}
</td>
<td
class=
"text-center"
>
{{
system_users|join_attr:"name"
}}
</td>
<td>
<button
class=
"btn btn-danger btn-xs btn_delete_user_group {% if not asset
.is_valid
%} disabled {% endif %}"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
<button
class=
"btn btn-danger btn-xs btn_delete_user_group {% if not asset
_group.is_inherit_from_user_groups
%} disabled {% endif %}"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
...
...
apps/users/views.py
View file @
df281def
...
...
@@ -427,15 +427,20 @@ class UserGrantedAssetView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
return
super
(
UserGrantedAssetView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
self
.
assets_granted
=
get_user_granted_assets
(
self
.
object
)
return
self
.
assets_granted
.
keys
()
# Convert format from {'asset': ['system_users'], ..} to
# [('asset', ['system_users']), ('asset', ['system_users']))
assets_granted
=
[(
asset
,
system_users
)
for
asset
,
system_users
in
get_user_granted_assets
(
self
.
object
)
.
items
()]
return
assets_granted
def
get_context_data
(
self
,
**
kwargs
):
asset_groups
=
[(
asset_group
,
system_users
)
for
asset_group
,
system_users
in
get_user_granted_asset_groups
(
self
.
object
)
.
items
()]
context
=
{
'app'
:
'User'
,
'action'
:
'User granted asset'
,
'asset_groups'
:
get_user_granted_asset_groups
(
self
.
object
),
'assets'
:
self
.
assets_granted
,
'asset_groups'
:
asset_groups
,
}
kwargs
.
update
(
context
)
return
super
(
UserGrantedAssetView
,
self
)
.
get_context_data
(
**
kwargs
)
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