mirror of https://github.com/jumpserver/jumpserver
修复用户组编辑导致该用户组都丢失问题
parent
f2487a22cd
commit
81a6f4841f
|
@ -6,7 +6,7 @@
|
||||||
# from Crypto.PublicKey import RSA
|
# from Crypto.PublicKey import RSA
|
||||||
import uuid
|
import uuid
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from juser.user_api import *
|
from juser.user_api import *
|
||||||
from jperm.perm_api import get_group_user_perm
|
from jperm.perm_api import get_group_user_perm
|
||||||
|
@ -111,22 +111,18 @@ def group_edit(request):
|
||||||
if len(UserGroup.objects.filter(name=group_name)) > 1:
|
if len(UserGroup.objects.filter(name=group_name)) > 1:
|
||||||
raise ServerError(u'%s 用户组已存在' % group_name)
|
raise ServerError(u'%s 用户组已存在' % group_name)
|
||||||
# add user group
|
# add user group
|
||||||
|
user_group = get_object_or_404(UserGroup, id=group_id)
|
||||||
|
user_group.user_set.clear()
|
||||||
|
|
||||||
for user in User.objects.filter(id__in=users_selected):
|
for user in User.objects.filter(id__in=users_selected):
|
||||||
user.group.add(UserGroup.objects.get(id=group_id))
|
user.group.add(UserGroup.objects.get(id=group_id))
|
||||||
# delete user group
|
|
||||||
user_group = UserGroup.objects.get(id=group_id)
|
|
||||||
for user in [user for user in User.objects.filter(group=user_group) if user not in User.objects.filter(id__in=users_selected)]:
|
|
||||||
user_group_all = user.group.all()
|
|
||||||
user.group.clear()
|
|
||||||
for g in user_group_all:
|
|
||||||
if g == user_group:
|
|
||||||
continue
|
|
||||||
user.group.add(g)
|
|
||||||
user_group.name = group_name
|
user_group.name = group_name
|
||||||
user_group.comment = comment
|
user_group.comment = comment
|
||||||
user_group.save()
|
user_group.save()
|
||||||
except ServerError, e:
|
except ServerError, e:
|
||||||
error = e
|
error = e
|
||||||
|
|
||||||
if not error:
|
if not error:
|
||||||
return HttpResponseRedirect(reverse('user_group_list'))
|
return HttpResponseRedirect(reverse('user_group_list'))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue