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
b5abb175
Commit
b5abb175
authored
Sep 17, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Jiu zhe yang ba
parent
ab2eeb0d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
36 deletions
+59
-36
models.py
apps/perms/models.py
+2
-1
forms.py
apps/users/forms.py
+1
-6
user_asset_permission.html
apps/users/templates/users/user_asset_permission.html
+28
-24
urls.py
apps/users/urls.py
+2
-0
views.py
apps/users/views.py
+26
-5
No files found.
apps/perms/models.py
View file @
b5abb175
...
...
@@ -22,7 +22,8 @@ class AssetPermission(models.Model):
assets
=
models
.
ManyToManyField
(
Asset
,
related_name
=
'granted_by_permissions'
,
blank
=
True
)
asset_groups
=
models
.
ManyToManyField
(
AssetGroup
,
related_name
=
'granted_by_permissions'
,
blank
=
True
)
system_users
=
models
.
ManyToManyField
(
SystemUser
,
related_name
=
'granted_by_permissions'
)
private_for
=
models
.
CharField
(
choices
=
PRIVATE_FOR_CHOICE
,
max_length
=
1
,
default
=
'N'
,
verbose_name
=
_
(
'Private for'
))
private_for
=
models
.
CharField
(
choices
=
PRIVATE_FOR_CHOICE
,
max_length
=
1
,
default
=
'N'
,
blank
=
True
,
verbose_name
=
_
(
'Private for'
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Active'
))
date_expired
=
models
.
DateTimeField
(
default
=
date_expired_default
,
verbose_name
=
_
(
'Date expired'
))
created_by
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
...
...
apps/users/forms.py
View file @
b5abb175
...
...
@@ -88,14 +88,11 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
def
save
(
self
,
commit
=
True
):
self
.
instance
=
super
(
UserPrivateAssetPermissionForm
,
self
)
.
save
(
commit
=
commit
)
self
.
instance
.
private_for
=
'U'
self
.
instance
.
users
=
[
self
.
user
]
self
.
instance
.
name
=
'_Private for
%
s
%
s'
%
(
self
.
user
.
username
,
)
self
.
instance
.
save
()
return
self
.
instance
def
clean_private_for
(
self
):
return
'U'
class
Meta
:
model
=
AssetPermission
fields
=
[
...
...
@@ -110,5 +107,3 @@ class UserPrivateAssetPermissionForm(forms.ModelForm):
'data-placeholder'
:
_
(
'Select system users'
)}),
}
apps/users/templates/users/user_asset_permission.html
View file @
b5abb175
...
...
@@ -44,7 +44,7 @@
<div
class=
"col-sm-7"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
style=
"float: left"
>
{% trans 'Asset permission of ' %}
<b>
{{ user.name }}
</b></span>
<span
style=
"float: left"
>
{% trans 'Asset permission of ' %}
<b>
{{ user
_object
.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
...
...
@@ -115,31 +115,35 @@
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick create permission for user' %}
</div>
<div
class=
"panel-body"
>
<form>
<form
method=
"post"
action=
"{% url 'users:user-asset-permission-create' pk=user_object.id %}"
>
<table
class=
"table"
>
<tbody>
{% csrf_token %}
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.assets|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.asset_groups|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.system_users|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td>
<button
type=
"button"
class=
"btn btn-primary btn-sm"
>
{% trans 'Submit' %}
</button>
</td>
</tr>
{% csrf_token %}
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.name|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.assets|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.asset_groups|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"1"
style=
"padding-top: 0"
>
{{ form.system_users|bootstrap }}
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td>
<button
type=
"submit"
class=
"btn btn-primary btn-sm"
>
{% trans 'Submit' %}
</button>
</td>
</tr>
</tbody>
</table>
</form>
...
...
apps/users/urls.py
View file @
b5abb175
...
...
@@ -18,6 +18,8 @@ urlpatterns = [
url
(
r'^user/(?P<pk>[0-9]+)$'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-detail'
),
url
(
r'^user/(?P<pk>[0-9]+)/asset-permission$'
,
views
.
UserAssetPermissionView
.
as_view
(),
name
=
'user-asset-permission'
),
url
(
r'^user/(?P<pk>[0-9]+)/asset-permission/create$'
,
views
.
UserAssetPermissionCreateView
.
as_view
(),
name
=
'user-asset-permission-create'
),
url
(
r'^user/(?P<pk>[0-9]+)/asset-granted'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-granted-asset'
),
url
(
r'^user/(?P<pk>[0-9]+)/login-history'
,
views
.
UserDetailView
.
as_view
(),
name
=
'user-login-history'
),
url
(
r'^first-login/$'
,
views
.
UserFirstLoginView
.
as_view
(),
name
=
'user-first-login'
),
...
...
apps/users/views.py
View file @
b5abb175
...
...
@@ -18,18 +18,17 @@ from django.views.decorators.csrf import csrf_protect
from
django.views.decorators.debug
import
sensitive_post_parameters
from
django.views.generic.base
import
TemplateView
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
,
FormView
,
SingleObjectMixin
,
FormMixin
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
,
FormView
,
SingleObjectMixin
,
\
FormMixin
,
ModelFormMixin
,
ProcessFormView
,
BaseCreateView
from
django.views.generic.detail
import
DetailView
from
formtools.wizard.views
import
SessionWizardView
from
common.utils
import
get_object_or_none
,
get_logger
from
.models
import
User
,
UserGroup
from
.forms
import
UserCreateForm
,
UserUpdateForm
,
UserGroupForm
,
UserLoginForm
,
UserInfoForm
,
UserKeyForm
,
\
UserPrivateAssetPermissionForm
from
.utils
import
AdminUserRequiredMixin
,
user_add_success_next
,
send_reset_password_mail
from
.hands
import
AssetPermission
logger
=
get_logger
(
__name__
)
...
...
@@ -394,4 +393,26 @@ class UserAssetPermissionView(AdminUserRequiredMixin, FormMixin, SingleObjectMix
class
UserAssetPermissionCreateView
(
AdminUserRequiredMixin
,
CreateView
):
pass
form_class
=
UserPrivateAssetPermissionForm
model
=
AssetPermission
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
user_object
=
self
.
get_object
(
queryset
=
User
.
objects
.
all
())
return
redirect
(
reverse
(
'users:user-asset-permission'
,
kwargs
=
{
'pk'
:
user_object
.
id
}))
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
user_object
=
self
.
get_object
(
queryset
=
User
.
objects
.
all
())
return
super
(
UserAssetPermissionCreateView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
def
get_form
(
self
,
form_class
=
None
):
form
=
super
(
UserAssetPermissionCreateView
,
self
)
.
get_form
(
form_class
=
form_class
)
form
.
user
=
self
.
user_object
return
form
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
redirect
(
reverse
(
'users:user-asset-permission'
,
kwargs
=
{
'pk'
:
self
.
user_object
.
id
}))
def
get_success_url
(
self
):
return
reverse
(
'users:user-asset-permission'
,
kwargs
=
{
'pk'
:
self
.
user_object
.
id
})
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