From e7c530d8e6a6ee22ae95093720b4cb253e742fe4 Mon Sep 17 00:00:00 2001 From: BaiJiangJie <32935519+BaiJiangJie@users.noreply.github.com> Date: Wed, 25 Jul 2018 11:28:20 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E6=B7=BB=E5=8A=A0=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=A7=84=E5=88=99org=20(#1580)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 修复创建授权规则,显示org_name不是有效UUID的bug * [Update] 更新org之间隔离授权规则,解决QuerySet与Manager问题;修复创建用户,显示org_name不是有效UUID之bug; --- apps/orgs/mixins.py | 2 +- apps/perms/forms.py | 5 +++-- apps/perms/models.py | 13 ++++++------- apps/users/forms.py | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/orgs/mixins.py b/apps/orgs/mixins.py index 244eebdb9..873b25fa3 100644 --- a/apps/orgs/mixins.py +++ b/apps/orgs/mixins.py @@ -58,7 +58,7 @@ class OrgManager(models.Manager): class OrgModelMixin(models.Model): - org_id = models.CharField(max_length=36, null=True) + org_id = models.CharField(max_length=36, null=True, blank=True) objects = OrgManager() def save(self, *args, **kwargs): diff --git a/apps/perms/forms.py b/apps/perms/forms.py index a71b25765..3ce3db6c5 100644 --- a/apps/perms/forms.py +++ b/apps/perms/forms.py @@ -29,12 +29,13 @@ class AssetPermissionForm(OrgModelForm): return users_field = self.fields.get('users') if hasattr(users_field, 'queryset'): - users_field.queryset = User.objects.filter(orgs=current_org) + # users_field.queryset = User.objects.filter(orgs=current_org) + users_field.queryset = current_org.get_org_users().exclude(role=User.ROLE_APP) class Meta: model = AssetPermission exclude = ( - 'id', 'date_created', 'created_by' + 'id', 'date_created', 'created_by', 'org_id' ) widgets = { 'users': forms.SelectMultiple( diff --git a/apps/perms/models.py b/apps/perms/models.py index 581b552b4..1c3a67d8e 100644 --- a/apps/perms/models.py +++ b/apps/perms/models.py @@ -6,6 +6,8 @@ from django.utils import timezone from common.utils import date_expired_default, set_or_append_attr_bulk +from orgs.mixins import OrgModelMixin, OrgManager + class AssetPermissionQuerySet(models.QuerySet): def active(self): @@ -16,15 +18,12 @@ class AssetPermissionQuerySet(models.QuerySet): .filter(date_expired__gt=timezone.now()) -class AssetPermissionManager(models.Manager): - def get_queryset(self): - return AssetPermissionQuerySet(self.model, using=self._db) - +class AssetPermissionManager(OrgManager): def valid(self): return self.get_queryset().valid() -class AssetPermission(models.Model): +class AssetPermission(OrgModelMixin): id = models.UUIDField(default=uuid.uuid4, primary_key=True) name = models.CharField(max_length=128, unique=True, verbose_name=_('Name')) users = models.ManyToManyField('users.User', related_name='asset_permissions', blank=True, verbose_name=_("User")) @@ -39,7 +38,7 @@ class AssetPermission(models.Model): date_created = models.DateTimeField(auto_now_add=True, verbose_name=_('Date created')) comment = models.TextField(verbose_name=_('Comment'), blank=True) - objects = AssetPermissionManager() + objects = AssetPermissionManager.from_queryset(AssetPermissionQuerySet)() def __str__(self): return self.name @@ -71,7 +70,7 @@ class AssetPermission(models.Model): return assets -class NodePermission(models.Model): +class NodePermission(OrgModelMixin): id = models.UUIDField(default=uuid.uuid4, primary_key=True) node = models.ForeignKey('assets.Node', on_delete=models.CASCADE, verbose_name=_("Node")) user_group = models.ForeignKey('users.UserGroup', on_delete=models.CASCADE, verbose_name=_("User group")) diff --git a/apps/users/forms.py b/apps/users/forms.py index e0f7ea283..2ffc11b68 100644 --- a/apps/users/forms.py +++ b/apps/users/forms.py @@ -332,6 +332,5 @@ class OrgUserField(forms.ModelMultipleChoiceField): return {"orgs"} - class FileForm(forms.Form): file = forms.FileField()