2015-10-07 09:16:20 +00:00
|
|
|
|
# coding: utf-8
|
2015-08-20 15:42:27 +00:00
|
|
|
|
|
2015-04-20 02:12:11 +00:00
|
|
|
|
from django.db import models
|
2015-10-07 04:17:20 +00:00
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
2015-04-20 02:12:11 +00:00
|
|
|
|
|
2015-10-06 15:47:53 +00:00
|
|
|
|
from jasset.models import Asset, AssetGroup
|
|
|
|
|
|
2015-04-20 02:12:11 +00:00
|
|
|
|
|
|
|
|
|
class UserGroup(models.Model):
|
|
|
|
|
name = models.CharField(max_length=80, unique=True)
|
|
|
|
|
comment = models.CharField(max_length=160, blank=True, null=True)
|
2015-10-07 09:16:20 +00:00
|
|
|
|
asset = models.ManyToManyField(Asset)
|
|
|
|
|
asset_group = models.ManyToManyField(AssetGroup)
|
2015-04-20 02:12:11 +00:00
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.name
|
|
|
|
|
|
2015-08-27 16:33:54 +00:00
|
|
|
|
|
2015-10-03 16:53:01 +00:00
|
|
|
|
class User(AbstractUser):
|
2015-04-20 02:12:11 +00:00
|
|
|
|
USER_ROLE_CHOICES = (
|
|
|
|
|
('SU', 'SuperUser'),
|
2015-08-26 16:08:20 +00:00
|
|
|
|
('GA', 'GroupAdmin'),
|
2015-04-20 02:12:11 +00:00
|
|
|
|
('CU', 'CommonUser'),
|
|
|
|
|
)
|
|
|
|
|
name = models.CharField(max_length=80)
|
2015-08-31 15:04:53 +00:00
|
|
|
|
uuid = models.CharField(max_length=100)
|
2015-09-15 15:38:06 +00:00
|
|
|
|
role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU')
|
2015-04-20 02:12:11 +00:00
|
|
|
|
group = models.ManyToManyField(UserGroup)
|
2015-08-20 15:42:27 +00:00
|
|
|
|
ssh_key_pwd = models.CharField(max_length=200)
|
2015-04-20 02:12:11 +00:00
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.username
|
2015-08-20 15:42:27 +00:00
|
|
|
|
|
2015-08-28 16:09:36 +00:00
|
|
|
|
|
|
|
|
|
class AdminGroup(models.Model):
|
|
|
|
|
"""
|
|
|
|
|
under the user control group
|
|
|
|
|
用户可以管理的用户组,或组的管理员是该用户
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
user = models.ForeignKey(User)
|
2015-08-31 15:04:53 +00:00
|
|
|
|
group = models.ForeignKey(UserGroup)
|
|
|
|
|
|
2015-09-02 13:42:31 +00:00
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return '%s: %s' % (self.user.username, self.group.name)
|