mirror of https://github.com/jumpserver/jumpserver
修改组信息
parent
c4196e7d5a
commit
5ddcdf99c1
|
@ -3,19 +3,9 @@ from juser.models import User, UserGroup
|
||||||
from jasset.models import Asset, BisGroup
|
from jasset.models import Asset, BisGroup
|
||||||
|
|
||||||
|
|
||||||
class PermUser(models.Model):
|
class Perm(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user_group = models.ForeignKey(UserGroup)
|
||||||
asset = models.ForeignKey(Asset)
|
|
||||||
asset_group = models.ForeignKey(BisGroup)
|
asset_group = models.ForeignKey(BisGroup)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '%s_%s' % (self.user.username, self.asset.ip)
|
return '%s_%s' % (self.user_group.name, self.asset_group.name)
|
||||||
|
|
||||||
|
|
||||||
class PermUserGroup(models.Model):
|
|
||||||
group = models.ForeignKey(UserGroup)
|
|
||||||
asset = models.ForeignKey(Asset)
|
|
||||||
asset_group = models.ForeignKey(BisGroup)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return '%s_%s' % (self.group.name, self.asset.ip)
|
|
|
@ -2,7 +2,13 @@ from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class UserGroup(models.Model):
|
class UserGroup(models.Model):
|
||||||
|
GROUP_TYPE_CHOICES = (
|
||||||
|
('U', 'UniqueUserGroup'),
|
||||||
|
('M', 'ManyUserGroup')
|
||||||
|
)
|
||||||
|
|
||||||
name = models.CharField(max_length=80, unique=True)
|
name = models.CharField(max_length=80, unique=True)
|
||||||
|
type = models.CharField(max_length=1, choices=GROUP_TYPE_CHOICES, default='U')
|
||||||
comment = models.CharField(max_length=160, blank=True, null=True)
|
comment = models.CharField(max_length=160, blank=True, null=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|
|
@ -113,6 +113,14 @@ def gen_sha512(salt, password):
|
||||||
return crypt.crypt(password, '$6$%s$' % salt)
|
return crypt.crypt(password, '$6$%s$' % salt)
|
||||||
|
|
||||||
|
|
||||||
|
def group_db_add(**kwargs):
|
||||||
|
group_name = kwargs.get('name')
|
||||||
|
group = UserGroup.objects.filter(name=group_name)
|
||||||
|
if group:
|
||||||
|
raise AddError
|
||||||
|
UserGroup.objects.create(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
def group_add(request):
|
def group_add(request):
|
||||||
error = ''
|
error = ''
|
||||||
msg = ''
|
msg = ''
|
||||||
|
@ -127,13 +135,8 @@ def group_add(request):
|
||||||
error = u'缁勫悕涓嶈兘涓虹┖'
|
error = u'缁勫悕涓嶈兘涓虹┖'
|
||||||
raise AddError
|
raise AddError
|
||||||
|
|
||||||
group = UserGroup.objects.filter(name=group_name)
|
group_db_add(name=group_name, comment=comment, type='M')
|
||||||
if group:
|
|
||||||
error = u'缁 %s 宸插瓨鍦' % group_name
|
|
||||||
raise AddError
|
|
||||||
|
|
||||||
group = UserGroup(name=group_name, comment=comment)
|
|
||||||
group.save()
|
|
||||||
except AddError:
|
except AddError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -148,7 +151,7 @@ def group_add(request):
|
||||||
|
|
||||||
def group_list(request):
|
def group_list(request):
|
||||||
header_title, path1, path2 = '鏌ョ湅灞炵粍 | Show Group', 'juser', 'group_list'
|
header_title, path1, path2 = '鏌ョ湅灞炵粍 | Show Group', 'juser', 'group_list'
|
||||||
groups = contact_list = UserGroup.objects.all().order_by('id')
|
groups = contact_list = UserGroup.objects.filter(type='M').order_by('id')
|
||||||
p = paginator = Paginator(contact_list, 10)
|
p = paginator = Paginator(contact_list, 10)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -418,7 +421,7 @@ def user_add(request):
|
||||||
msg = ''
|
msg = ''
|
||||||
header_title, path1, path2 = '娣诲姞鐢ㄦ埛 | Add User', 'juser', 'user_add'
|
header_title, path1, path2 = '娣诲姞鐢ㄦ埛 | Add User', 'juser', 'user_add'
|
||||||
user_role = {'SU': u'瓒呯骇绠$悊鍛', 'GA': u'缁勭鐞嗗憳', 'CU': u'鏅氱敤鎴'}
|
user_role = {'SU': u'瓒呯骇绠$悊鍛', 'GA': u'缁勭鐞嗗憳', 'CU': u'鏅氱敤鎴'}
|
||||||
all_group = UserGroup.objects.all()
|
all_group = UserGroup.objects.filter(type='M')
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.POST.get('username', None)
|
username = request.POST.get('username', None)
|
||||||
password = request.POST.get('password', None)
|
password = request.POST.get('password', None)
|
||||||
|
@ -457,10 +460,10 @@ def user_add(request):
|
||||||
date_joined=time_now)
|
date_joined=time_now)
|
||||||
|
|
||||||
server_add_user(username, password, ssh_key_pwd1)
|
server_add_user(username, password, ssh_key_pwd1)
|
||||||
|
group_db_add(name=username, comment=username, type='U')
|
||||||
if LDAP_ENABLE:
|
if LDAP_ENABLE:
|
||||||
ldap_add_user(username, ldap_pwd)
|
ldap_add_user(username, ldap_pwd)
|
||||||
msg = u'娣诲姞鐢ㄦ埛 %s 鎴愬姛锛' % username
|
msg = u'娣诲姞鐢ㄦ埛 %s 鎴愬姛锛' % username
|
||||||
# locals = lambda: {}
|
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
error = u'娣诲姞鐢ㄦ埛 %s 澶辫触 %s ' % (username, e)
|
error = u'娣诲姞鐢ㄦ埛 %s 澶辫触 %s ' % (username, e)
|
||||||
|
|
Loading鈥
Reference in New Issue