Browse Source

修改组信息

pull/6/head
guanghongwei 10 years ago
parent
commit
5ddcdf99c1
  1. 16
      jperm/models.py
  2. 6
      juser/models.py
  3. 21
      juser/views.py

16
jperm/models.py

@ -3,19 +3,9 @@ from juser.models import User, UserGroup
from jasset.models import Asset, BisGroup
class PermUser(models.Model):
user = models.ForeignKey(User)
asset = models.ForeignKey(Asset)
class Perm(models.Model):
user_group = models.ForeignKey(UserGroup)
asset_group = models.ForeignKey(BisGroup)
def __unicode__(self):
return '%s_%s' % (self.user.username, self.asset.ip)
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)
return '%s_%s' % (self.user_group.name, self.asset_group.name)

6
juser/models.py

@ -2,7 +2,13 @@ from django.db import models
class UserGroup(models.Model):
GROUP_TYPE_CHOICES = (
('U', 'UniqueUserGroup'),
('M', 'ManyUserGroup')
)
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)
def __unicode__(self):

21
juser/views.py

@ -113,6 +113,14 @@ def gen_sha512(salt, password):
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):
error = ''
msg = ''
@ -127,13 +135,8 @@ def group_add(request):
error = u'缁勫悕涓嶈兘涓虹┖'
raise AddError
group = UserGroup.objects.filter(name=group_name)
if group:
error = u'%s 宸插瓨鍦' % group_name
raise AddError
group_db_add(name=group_name, comment=comment, type='M')
group = UserGroup(name=group_name, comment=comment)
group.save()
except AddError:
pass
@ -148,7 +151,7 @@ def group_add(request):
def group_list(request):
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)
try:
@ -418,7 +421,7 @@ def user_add(request):
msg = ''
header_title, path1, path2 = '娣诲姞鐢ㄦ埛 | Add User', 'juser', 'user_add'
user_role = {'SU': u'瓒呯骇绠$悊鍛', 'GA': u'缁勭鐞嗗憳', 'CU': u'鏅氱敤鎴'}
all_group = UserGroup.objects.all()
all_group = UserGroup.objects.filter(type='M')
if request.method == 'POST':
username = request.POST.get('username', None)
password = request.POST.get('password', None)
@ -457,10 +460,10 @@ def user_add(request):
date_joined=time_now)
server_add_user(username, password, ssh_key_pwd1)
group_db_add(name=username, comment=username, type='U')
if LDAP_ENABLE:
ldap_add_user(username, ldap_pwd)
msg = u'娣诲姞鐢ㄦ埛 %s 鎴愬姛锛' % username
# locals = lambda: {}
except Exception, e:
error = u'娣诲姞鐢ㄦ埛 %s 澶辫触 %s ' % (username, e)

Loading鈥
Cancel
Save