[Update] 完成基本框架

This commit is contained in:
ibuler
2018-07-13 15:05:46 +08:00
parent d6ec92d82d
commit 7412bdcba7
11 changed files with 96 additions and 28 deletions

View File

@@ -6,7 +6,7 @@ from collections import OrderedDict
from django.conf import settings
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import AbstractUser, UserManager
from django.core import signing
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -15,6 +15,7 @@ from django.shortcuts import reverse
from common.utils import get_signer, date_expired_default
from common.models import Setting
from orgs.utils import get_current_org
__all__ = ['User']
@@ -186,6 +187,18 @@ class User(AbstractUser):
else:
self.role = 'User'
@property
def admin_orgs(self):
from orgs.models import Organization
return Organization.get_user_admin_orgs(self)
@property
def is_org_admin(self):
if self.is_superuser or self.admin_orgs:
return True
else:
return False
@property
def is_app(self):
return self.role == 'App'
@@ -207,8 +220,11 @@ class User(AbstractUser):
if self.username == 'admin':
self.role = 'Admin'
self.is_active = True
super().save(*args, **kwargs)
instance = super().save(*args, **kwargs)
current_org = get_current_org()
if current_org and current_org.is_real():
instance.orgs.add(current_org)
return instance
@property
def private_token(self):