mirror of https://github.com/jumpserver/jumpserver
用户修改完毕
parent
b4006d3d36
commit
d25a3ce17c
|
@ -34,7 +34,10 @@ def groups_str(username):
|
||||||
user = User.objects.get(username=username)
|
user = User.objects.get(username=username)
|
||||||
for group in user.user_group.filter(Q(type='A') | Q(type='M')):
|
for group in user.user_group.filter(Q(type='A') | Q(type='M')):
|
||||||
groups.append(group.name)
|
groups.append(group.name)
|
||||||
return ' '.join(groups)
|
if len(groups) < 4:
|
||||||
|
return ' '.join(groups)
|
||||||
|
else:
|
||||||
|
return "%s ..." % ' '.join(groups[0:3])
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name='get_item')
|
@register.filter(name='get_item')
|
||||||
|
|
|
@ -16,6 +16,7 @@ from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from juser.models import UserGroup, User
|
from juser.models import UserGroup, User
|
||||||
from connect import PyCrypt, KEY
|
from connect import PyCrypt, KEY
|
||||||
|
@ -135,6 +136,14 @@ def group_add_user(group_name, user_id=None, username=None):
|
||||||
group.user_set.add(user)
|
group.user_set.add(user)
|
||||||
|
|
||||||
|
|
||||||
|
def group_update_user(group_id, users_id):
|
||||||
|
group = UserGroup.objects.get(id=group_id)
|
||||||
|
group.user_set.clear()
|
||||||
|
for user_id in users_id:
|
||||||
|
user = User.objects.get(id=user_id)
|
||||||
|
group.user_set.add(user)
|
||||||
|
|
||||||
|
|
||||||
def db_add_user(**kwargs):
|
def db_add_user(**kwargs):
|
||||||
groups_post = kwargs.pop('groups')
|
groups_post = kwargs.pop('groups')
|
||||||
user = User(**kwargs)
|
user = User(**kwargs)
|
||||||
|
@ -253,7 +262,7 @@ def group_add(request):
|
||||||
msg = ''
|
msg = ''
|
||||||
header_title, path1, path2 = '娣诲姞灞炵粍 | Add Group', 'juser', 'group_add'
|
header_title, path1, path2 = '娣诲姞灞炵粍 | Add Group', 'juser', 'group_add'
|
||||||
group_types = {
|
group_types = {
|
||||||
'P': '绉佹湁缁',
|
# 'P': '绉佹湁缁',
|
||||||
'M': '绠$悊缁',
|
'M': '绠$悊缁',
|
||||||
'A': '鎺堟潈缁',
|
'A': '鎺堟潈缁',
|
||||||
}
|
}
|
||||||
|
@ -321,19 +330,32 @@ def group_edit(request):
|
||||||
error = ''
|
error = ''
|
||||||
msg = ''
|
msg = ''
|
||||||
header_title, path1, path2 = '淇敼灞炵粍 | Edit Group', 'juser', 'group_edit'
|
header_title, path1, path2 = '淇敼灞炵粍 | Edit Group', 'juser', 'group_edit'
|
||||||
|
group_types = {
|
||||||
|
# 'P': '绉佹湁缁',
|
||||||
|
'M': '绠$悊缁',
|
||||||
|
'A': '鎺堟潈缁',
|
||||||
|
}
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
group_id = request.GET.get('id', None)
|
group_id = request.GET.get('id', None)
|
||||||
group = UserGroup.objects.get(id=group_id)
|
group = UserGroup.objects.get(id=group_id)
|
||||||
group_name = group.name
|
group_name = group.name
|
||||||
comment = group.comment
|
comment = group.comment
|
||||||
|
group_type = group.type
|
||||||
|
users_all = User.objects.all()
|
||||||
|
users_selected = group.user_set.all()
|
||||||
|
users = [user for user in users_all if user not in users_selected]
|
||||||
|
|
||||||
return render_to_response('juser/group_add.html', locals())
|
return render_to_response('juser/group_add.html', locals())
|
||||||
else:
|
else:
|
||||||
group_id = request.POST.get('group_id', None)
|
group_id = request.POST.get('group_id', None)
|
||||||
group_name = request.POST.get('group_name', None)
|
group_name = request.POST.get('group_name', None)
|
||||||
comment = request.POST.get('comment', '')
|
comment = request.POST.get('comment', '')
|
||||||
|
users_selected = request.POST.getlist('users_selected')
|
||||||
|
group_type = request.POST.get('group_type')
|
||||||
group = UserGroup.objects.filter(id=group_id)
|
group = UserGroup.objects.filter(id=group_id)
|
||||||
group.update(name=group_name, comment=comment)
|
# return HttpResponse(group_type)
|
||||||
|
group.update(name=group_name, comment=comment, type=group_type)
|
||||||
|
group_update_user(group_id, users_selected)
|
||||||
|
|
||||||
return HttpResponseRedirect('/juser/group_list/')
|
return HttpResponseRedirect('/juser/group_list/')
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<select id="group_type" name="group_type" class="form-control m-b">
|
<select id="group_type" name="group_type" class="form-control m-b">
|
||||||
{% for t, type_name in group_types.items %}
|
{% for t, type_name in group_types.items %}
|
||||||
{% ifequal t type_name %}
|
{% ifequal t group_type %}
|
||||||
<option value="{{ t }}" selected>{{ type_name }}</option>
|
<option value="{{ t }}" selected>{{ type_name }}</option>
|
||||||
{% else %}
|
{% else %}
|
||||||
<option value="{{ t }}">{{ type_name }}</option>
|
<option value="{{ t }}">{{ type_name }}</option>
|
||||||
|
@ -80,6 +80,9 @@
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<div>
|
<div>
|
||||||
<select id="users_selected" name="users_selected" class="form-control m-b" size="12" multiple>
|
<select id="users_selected" name="users_selected" class="form-control m-b" size="12" multiple>
|
||||||
|
{% for user in users_selected %}
|
||||||
|
<option value="{{ user.id }}">{{ user.name }}</option>
|
||||||
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -96,7 +99,7 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-sm-4 col-sm-offset-2">
|
<div class="col-sm-4 col-sm-offset-2">
|
||||||
<button class="btn btn-white" type="submit">鍙栨秷</button>
|
<button class="btn btn-white" type="submit">鍙栨秷</button>
|
||||||
<button class="btn btn-primary" type="submit">纭淇濆瓨</button>
|
<button class="btn btn-primary" type="submit" onclick="javascript: (function(){$('#users_selected option').each(function(){$(this).prop('selected', true)})})()">纭淇濆瓨</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -43,7 +43,11 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="gradeX">
|
<tr class="gradeX">
|
||||||
<td class="text-center">灞炵粍</td>
|
<td class="text-center">灞炵粍</td>
|
||||||
<td class="text-center">{{ user.username|groups_str }}</td>
|
<td class="text-center">
|
||||||
|
{% for group in user.user_group.all %}
|
||||||
|
{{ group.name }}
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="gradeX">
|
<tr class="gradeX">
|
||||||
<td class="text-center">Email</td>
|
<td class="text-center">Email</td>
|
||||||
|
|
Loading鈥
Reference in New Issue