mirror of https://github.com/jumpserver/jumpserver
add user-list-delete support for user-group detail page
parent
74cdd2d0f3
commit
49f007601f
|
@ -3,7 +3,10 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from rest_framework import generics
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
|
from rest_framework import generics, status
|
||||||
|
from rest_framework.response import Response
|
||||||
from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
|
from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
|
||||||
|
|
||||||
from .serializers import UserSerializer, UserGroupSerializer, UserAttributeSerializer, UserGroupEditSerializer, \
|
from .serializers import UserSerializer, UserGroupSerializer, UserAttributeSerializer, UserGroupEditSerializer, \
|
||||||
|
@ -27,11 +30,6 @@ class UserDetailDeleteUpdateApi(generics.RetrieveUpdateDestroyAPIView):
|
||||||
print(self.request.data)
|
print(self.request.data)
|
||||||
return super(UserDetailDeleteUpdateApi, self).delete(request, *args, **kwargs)
|
return super(UserDetailDeleteUpdateApi, self).delete(request, *args, **kwargs)
|
||||||
|
|
||||||
# def get(self, request, *args, **kwargs):
|
|
||||||
# print("hello world")
|
|
||||||
# print(request.user)
|
|
||||||
# return super(UserDetailDeleteUpdateApi, self).get(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class UserGroupListAddApi(generics.ListCreateAPIView):
|
class UserGroupListAddApi(generics.ListCreateAPIView):
|
||||||
queryset = UserGroup.objects.all()
|
queryset = UserGroup.objects.all()
|
||||||
|
@ -111,3 +109,18 @@ class UserBulkUpdateApi(ListBulkCreateUpdateDestroyAPIView):
|
||||||
if isinstance(ids, list):
|
if isinstance(ids, list):
|
||||||
queryset = queryset.filter(id__in=ids)
|
queryset = queryset.filter(id__in=ids)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteUserFromGroupApi(generics.DestroyAPIView):
|
||||||
|
queryset = UserGroup.objects.all()
|
||||||
|
serializer_class = GroupEditSerializer
|
||||||
|
|
||||||
|
def destroy(self, request, *args, **kwargs):
|
||||||
|
group = self.get_object()
|
||||||
|
self.perform_destroy(group, **kwargs)
|
||||||
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
def perform_destroy(self, instance, **kwargs):
|
||||||
|
user_id = kwargs.get('uid')
|
||||||
|
user = get_object_or_404(User, id=user_id)
|
||||||
|
instance.users.remove(user)
|
||||||
|
|
|
@ -4,14 +4,14 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.hashers import make_password
|
from django.contrib.auth.hashers import make_password
|
||||||
from django.utils import timezone
|
|
||||||
from django.db import models
|
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
from django.core import signing
|
||||||
|
from django.db import models, IntegrityError
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.db import IntegrityError
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core import signing
|
from django.utils import timezone
|
||||||
|
from django.shortcuts import reverse
|
||||||
|
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
|
@ -102,6 +102,9 @@ class User(AbstractUser):
|
||||||
def password_raw(self, password_raw_):
|
def password_raw(self, password_raw_):
|
||||||
self.set_password(password_raw_)
|
self.set_password(password_raw_)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('users:user-detail', args=(self.id,))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_expired(self):
|
def is_expired(self):
|
||||||
if self.date_expired > timezone.now():
|
if self.date_expired > timezone.now():
|
||||||
|
|
|
@ -7,6 +7,18 @@
|
||||||
<link href="{% static "css/plugins/sweetalert/sweetalert.css" %}" rel="stylesheet">
|
<link href="{% static "css/plugins/sweetalert/sweetalert.css" %}" rel="stylesheet">
|
||||||
<script src="{% static "js/plugins/select2/select2.full.min.js" %}"></script>
|
<script src="{% static "js/plugins/select2/select2.full.min.js" %}"></script>
|
||||||
<script src="{% static "js/plugins/sweetalert/sweetalert.min.js" %}"></script>
|
<script src="{% static "js/plugins/sweetalert/sweetalert.min.js" %}"></script>
|
||||||
|
<style>
|
||||||
|
.label {
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 2.5;
|
||||||
|
}
|
||||||
|
.label .remove {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.label span {
|
||||||
|
color: #5e5e5e;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="wrapper wrapper-content animated fadeInRight">
|
<div class="wrapper wrapper-content animated fadeInRight">
|
||||||
|
@ -46,9 +58,17 @@
|
||||||
<td><b>{{ object.comment }}</b></td>
|
<td><b>{{ object.comment }}</b></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Created at:' %}:</td>
|
<td>{% trans 'Created at' %}:</td>
|
||||||
<td><b>{{ object.date_created }}</b></td>
|
<td><b>{{ object.date_created }}</b></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{% trans 'Users' %}:</td>
|
||||||
|
<td style="line-height: 2">
|
||||||
|
{% for user in object.users.all %}
|
||||||
|
<span class="label m-l-xs"><a href="{{ user.get_absolute_url }}"><span>{{ user.name }}</span></a><a data-uid="{{ user.id }}" class="btn_remove"><i class="remove fa fa-times-circle"></i></a></span>
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -109,3 +129,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% block custom_foot_js %}
|
||||||
|
<script>
|
||||||
|
$(document).on('click', '.btn_remove', function(){
|
||||||
|
var $this = $(this);
|
||||||
|
var uid = $this.data('uid');
|
||||||
|
var the_url = '{% url "users:delete-user-from-group-api" pk=object.id uid=99991937 %}'.replace('99991937', uid);
|
||||||
|
var success = function(){
|
||||||
|
$this.closest('.label').remove();
|
||||||
|
};
|
||||||
|
var error = function(){};
|
||||||
|
APIUpdateAttr({url: the_url, body: "{}", method: "DELETE", success: success, error: error});
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -46,6 +46,8 @@ urlpatterns += [
|
||||||
url(r'^v1/user-groups$', api.UserGroupListAddApi.as_view(), name='user-group-list-api'),
|
url(r'^v1/user-groups$', api.UserGroupListAddApi.as_view(), name='user-group-list-api'),
|
||||||
url(r'^v1/user-groups/(?P<pk>[0-9]+)$',
|
url(r'^v1/user-groups/(?P<pk>[0-9]+)$',
|
||||||
api.UserGroupDetailDeleteUpdateApi.as_view(), name='user-group-detail-api'),
|
api.UserGroupDetailDeleteUpdateApi.as_view(), name='user-group-detail-api'),
|
||||||
|
url(r'^v1/user-groups/group/(?P<pk>\d+)/user/(?P<uid>\d+)/$',
|
||||||
|
api.DeleteUserFromGroupApi.as_view(), name='delete-user-from-group-api'),
|
||||||
url(r'^v1/user-groups/(?P<pk>[0-9]+)/edit$',
|
url(r'^v1/user-groups/(?P<pk>[0-9]+)/edit$',
|
||||||
api.UserGroupEditApi.as_view(), name='user-group-edit-api'),
|
api.UserGroupEditApi.as_view(), name='user-group-edit-api'),
|
||||||
url(r'^v1/user-groups/(?P<pk>[0-9]+)/delete/$', api.GroupDeleteApi.as_view(),
|
url(r'^v1/user-groups/(?P<pk>[0-9]+)/delete/$', api.GroupDeleteApi.as_view(),
|
||||||
|
|
Loading…
Reference in New Issue