[Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题2 (#3919)

* [Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题2

* [Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题3

* [Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题4
pull/3922/head
BaiJiangJie 2020-04-18 23:14:25 +08:00 committed by GitHub
parent 386ce629ac
commit 0379e5160c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -72,7 +72,8 @@ class Organization(models.Model):
org = cls.default() if default else None
return org
@lazyproperty
# @lazyproperty
# lazyproperty 导致用户列表中角色显示出现不稳定的情况, 如果不加会导致数据库操作次数太多
def org_users(self):
from users.models import User
if self.is_real():
@ -83,9 +84,9 @@ class Organization(models.Model):
return users
def get_org_users(self):
return self.org_users
return self.org_users()
@lazyproperty
# @lazyproperty
def org_admins(self):
from users.models import User
if self.is_real():
@ -93,7 +94,7 @@ class Organization(models.Model):
return User.objects.filter(role=User.ROLE_ADMIN)
def get_org_admins(self):
return self.org_admins
return self.org_admins()
def org_id(self):
if self.is_real():
@ -103,7 +104,7 @@ class Organization(models.Model):
else:
return ''
@lazyproperty
# @lazyproperty
def org_auditors(self):
from users.models import User
if self.is_real():
@ -111,7 +112,7 @@ class Organization(models.Model):
return User.objects.filter(role=User.ROLE_AUDITOR)
def get_org_auditors(self):
return self.org_auditors
return self.org_auditors()
def get_org_members(self, exclude=()):
from users.models import User

View File

@ -49,12 +49,7 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
if isinstance(users, User):
users = [users]
if current_org and current_org.is_real():
# current_org.users.add(*users)
# 如果在真实组织下创建用户,使用上面的语句会出现用户角色显示不稳定的问题
# 可能是current_org的users add操作是进程不安全的
# User Model 中的 remove 操作没有出现问题,暂时不做更改
for user in users:
user.related_user_orgs.add(current_org.id)
current_org.users.add(*users)
self.send_created_signal(users)
def get_permissions(self):