From 98afa032a77ab4313980a9991fd9e43c9f4ec7ab Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 17 Apr 2020 16:32:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Update]=20=E4=BF=AE=E5=A4=8D=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E9=A1=B5=E9=9D=A2=E5=8F=AF=E8=BF=9E=E6=8E=A5=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/assets/models/utils.py b/apps/assets/models/utils.py index d010f95f2..90c203e81 100644 --- a/apps/assets/models/utils.py +++ b/apps/assets/models/utils.py @@ -77,7 +77,7 @@ class Connectivity: return cls(cls.UNKNOWN, timezone.now()) @classmethod - def set(cls, key, value, ttl=0): + def set(cls, key, value, ttl=None): cache.set(key, value, ttl) @classmethod From 0379e5160c208c5122837cfddc58411bb6952e8d Mon Sep 17 00:00:00 2001 From: BaiJiangJie <32935519+BaiJiangJie@users.noreply.github.com> Date: Sat, 18 Apr 2020 23:14:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E7=9C=9F?= =?UTF-8?q?=E5=AE=9E=E7=BB=84=E7=BB=87=E4=B8=8B=EF=BC=8C=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8D=E7=A8=B3=E5=AE=9A=E7=9A=84=E9=97=AE=E9=A2=982=20(#391?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题2 * [Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题3 * [Bugfix] 修复真实组织下,新建的用户角色显示不稳定的问题4 --- apps/orgs/models.py | 13 +++++++------ apps/users/api/user.py | 7 +------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/orgs/models.py b/apps/orgs/models.py index bae5c408c..6e6e6dfd6 100644 --- a/apps/orgs/models.py +++ b/apps/orgs/models.py @@ -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 diff --git a/apps/users/api/user.py b/apps/users/api/user.py index 2670eb014..fac0fabca 100644 --- a/apps/users/api/user.py +++ b/apps/users/api/user.py @@ -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):