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
0a9e4a5e
Commit
0a9e4a5e
authored
Aug 25, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify urls.conf: Merge to single
parent
8aa92bb6
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
16 deletions
+29
-16
settings.py
apps/jumpserver/settings.py
+1
-0
urls.py
apps/jumpserver/urls.py
+8
-10
api_urls.py
apps/users/api_urls.py
+3
-2
models.py
apps/users/models.py
+2
-2
serializers.py
apps/users/serializers.py
+4
-0
usergroup_list.html
apps/users/templates/users/usergroup_list.html
+1
-1
urls.py
apps/users/urls.py
+9
-0
views.py
apps/users/views.py
+1
-1
No files found.
apps/jumpserver/settings.py
View file @
0a9e4a5e
...
...
@@ -182,6 +182,7 @@ WSGI_APPLICATION = 'ws4redis.django_runserver.application'
# URL that distinguishes websocket connections from normal requests
WEBSOCKET_URL
=
'/ws/'
# WebSocket Redis
WS4REDIS_CONNECTION
=
{
'host'
:
'127.0.0.1'
,
...
...
apps/jumpserver/urls.py
View file @
0a9e4a5e
...
...
@@ -20,24 +20,22 @@ from django.views.generic.base import TemplateView
from
django.http
import
HttpResponseRedirect
def
view
(
request
,
**
kwargs
):
if
kwargs
:
print
kwargs
return
HttpResponseRedirect
(
'/'
+
kwargs
[
"module"
]
+
'/'
+
kwargs
[
"version"
]
+
'/'
+
kwargs
[
"api"
])
#
def view(request, **kwargs):
#
if kwargs:
#
print kwargs
#
return HttpResponseRedirect('/' + kwargs["module"] + '/' + kwargs["version"] + '/' + kwargs["api"])
urlpatterns
=
[
url
(
r'^$'
,
TemplateView
.
as_view
(
template_name
=
'base.html'
)),
url
(
r'^users/'
,
include
(
'users.urls'
)),
url
(
r'^
(api/)?
users/'
,
include
(
'users.urls'
)),
url
(
r'^assets/'
,
include
(
'assets.urls'
)),
url
(
r'^terminal/'
,
include
(
'webterminal.urls'
)),
# url(r'^api/(?P<version>.*)/(?P<module>.*)/(?P<api>.*)', view),
# url(r'^admin/', admin.site.urls),
]
urlpatterns
+=
[
url
(
r'^api/users/'
,
include
(
'users.api_urls'
)),
]
#
urlpatterns += [
#
url(r'^api/users/', include('users.api_urls')),
#
]
if
settings
.
DEBUG
:
urlpatterns
+=
static
(
settings
.
MEDIA_URL
,
document_root
=
settings
.
MEDIA_ROOT
)
...
...
apps/users/api_urls.py
View file @
0a9e4a5e
...
...
@@ -4,10 +4,11 @@
from
django.conf.urls
import
url
,
include
import
api
app_name
=
'users'
urlpatterns
=
[
url
(
r'^v1/users/$'
,
api
.
UserListAddApi
.
as_view
(),
name
=
'user-list-api'
),
url
(
r'^v1/users/(?P<pk>[0-9]+)/$'
,
api
.
UserDetailDeleteUpdateApi
.
as_view
(),
name
=
'user-detail-api'
),
url
(
r'^v1/usergroups/$'
,
api
.
UserGroupListAddApi
.
as_view
(),
name
=
'usergroup-list-api'
),
url
(
r'^v1/usergroups/(?P<pk>[0-9]+)/$'
,
api
.
UserGroupDetailDeleteUpdateApi
.
as_view
(),
name
=
'usergroup-detail-api'
),
url
(
r'^v1/usergroups/(?P<pk>[0-9]+)/$'
,
api
.
UserGroupDetailDeleteUpdateApi
.
as_view
(),
name
=
'usergroup-detail-api'
),
]
apps/users/models.py
View file @
0a9e4a5e
...
...
@@ -25,7 +25,7 @@ from django.db import OperationalError
# return self.name
#
# def delete(self, using=None, keep_parents=False):
# if self.user
_set
.all().count() > 0:
# if self.user
s
.all().count() > 0:
# raise OperationalError('Role %s has some member, should not be delete.' % self.name)
# else:
# return super(Role, self).delete(using=using, keep_parents=keep_parents)
...
...
@@ -99,7 +99,7 @@ class User(AbstractUser):
username
=
models
.
CharField
(
max_length
=
20
,
unique
=
True
,
verbose_name
=
'用户名'
)
name
=
models
.
CharField
(
max_length
=
20
,
blank
=
True
,
verbose_name
=
'姓名'
)
email
=
models
.
EmailField
(
max_length
=
30
,
unique
=
True
,
verbose_name
=
'邮件'
)
groups
=
models
.
ManyToManyField
(
UserGroup
,
blank
=
True
,
verbose_name
=
'用户组'
)
groups
=
models
.
ManyToManyField
(
UserGroup
,
related_name
=
'users'
,
blank
=
True
,
verbose_name
=
'用户组'
)
role
=
models
.
CharField
(
choices
=
ROLE_CHOICES
,
default
=
'User'
,
max_length
=
10
,
blank
=
True
,
verbose_name
=
'角色'
)
avatar
=
models
.
ImageField
(
upload_to
=
"avatar"
,
verbose_name
=
'头像'
)
wechat
=
models
.
CharField
(
max_length
=
30
,
blank
=
True
,
verbose_name
=
'微信'
)
...
...
apps/users/serializers.py
View file @
0a9e4a5e
...
...
@@ -7,6 +7,8 @@ from .models import User, UserGroup
class
UserSerializer
(
serializers
.
ModelSerializer
):
groups
=
serializers
.
HyperlinkedRelatedField
(
many
=
True
,
read_only
=
True
,
view_name
=
'users:usergroup-detail-api'
)
class
Meta
:
model
=
User
exclude
=
[
...
...
@@ -16,6 +18,8 @@ class UserSerializer(serializers.ModelSerializer):
class
UserGroupSerializer
(
serializers
.
ModelSerializer
):
users
=
serializers
.
HyperlinkedRelatedField
(
many
=
True
,
read_only
=
True
,
view_name
=
'users:user-detail-api'
)
class
Meta
:
model
=
UserGroup
fields
=
'__all__'
...
...
apps/users/templates/users/usergroup_list.html
View file @
0a9e4a5e
...
...
@@ -26,7 +26,7 @@
{{ usergroup.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ usergroup.user
_set
.all|length }}
</td>
<td
class=
"text-center"
>
{{ usergroup.user
s
.all|length }}
</td>
<td
class=
"text-center"
>
数量
</td>
<th
class=
"text-center"
>
{{ usergroup.comment|truncatewords:8 }}
</th>
<td
class=
"text-center"
>
...
...
apps/users/urls.py
View file @
0a9e4a5e
...
...
@@ -2,6 +2,7 @@ from django.conf.urls import url
from
.views
import
UserListView
,
UserAddView
,
UserUpdateView
,
UserDeleteView
,
UserDetailView
from
.views
import
UserGroupListView
,
UserGroupAddView
,
UserGroupUpdateView
,
UserGroupDeleteView
,
UserGroupDetailView
import
api
app_name
=
'users'
...
...
@@ -17,3 +18,11 @@ urlpatterns = [
url
(
r'^usergroup/(?P<pk>[0-9]+)/edit/$'
,
UserGroupUpdateView
.
as_view
(),
name
=
'usergroup-edit'
),
url
(
r'^usergroup/(?P<pk>[0-9]+)/delete/$'
,
UserGroupDeleteView
.
as_view
(),
name
=
'usergroup-delete'
),
]
urlpatterns
+=
[
url
(
r'^v1/users/$'
,
api
.
UserListAddApi
.
as_view
(),
name
=
'user-list-api'
),
url
(
r'^v1/users/(?P<pk>[0-9]+)/$'
,
api
.
UserDetailDeleteUpdateApi
.
as_view
(),
name
=
'user-detail-api'
),
url
(
r'^v1/usergroups/$'
,
api
.
UserGroupListAddApi
.
as_view
(),
name
=
'usergroup-list-api'
),
url
(
r'^v1/usergroups/(?P<pk>[0-9]+)/$'
,
api
.
UserGroupDetailDeleteUpdateApi
.
as_view
(),
name
=
'usergroup-detail-api'
),
]
apps/users/views.py
View file @
0a9e4a5e
...
...
@@ -147,7 +147,7 @@ class UserGroupAddView(CreateView):
users_id_list
=
self
.
request
.
POST
.
getlist
(
'users'
,
[])
users
=
[
get_object_or_404
(
User
,
id
=
user_id
)
for
user_id
in
users_id_list
]
usergroup
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
usergroup
.
user
_set
.
add
(
*
tuple
(
users
))
usergroup
.
user
s
.
add
(
*
tuple
(
users
))
usergroup
.
save
()
return
super
(
UserGroupAddView
,
self
)
.
form_valid
(
form
)
...
...
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