fix(access): use getattr instead as attribute may exist as None
ref: #789
This commit is contained in:
@ -52,7 +52,7 @@ class TenancyManager(models.Manager):
|
||||
user_organizations: list(str()) = []
|
||||
|
||||
has_tenant_field = False
|
||||
if hasattr(self.model, 'organization'):
|
||||
if getattr(self.model, 'organization', None) is not None:
|
||||
has_tenant_field = True
|
||||
|
||||
|
||||
@ -82,38 +82,38 @@ class TenancyManager(models.Manager):
|
||||
|
||||
if len(user_organizations) > 0 and not user.is_superuser:
|
||||
|
||||
if getattr(self.model, 'is_global', False) is True:
|
||||
# if getattr(self.model, 'is_global', False) is True:
|
||||
|
||||
if has_tenant_field:
|
||||
# if has_tenant_field:
|
||||
|
||||
return super().get_queryset().select_related('organization').filter(
|
||||
models.Q(organization__in=user_organizations)
|
||||
|
|
||||
models.Q(is_global = True)
|
||||
)
|
||||
# return super().get_queryset().select_related('organization').filter(
|
||||
# models.Q(organization__in=user_organizations)
|
||||
# # |
|
||||
# # models.Q(is_global = True)
|
||||
# )
|
||||
|
||||
else:
|
||||
# else:
|
||||
|
||||
return super().get_queryset().filter(
|
||||
models.Q(organization__in=user_organizations)
|
||||
|
|
||||
models.Q(is_global = True)
|
||||
)
|
||||
# return super().get_queryset().filter(
|
||||
# models.Q(organization__in=user_organizations)
|
||||
# # |
|
||||
# # models.Q(is_global = True)
|
||||
# )
|
||||
|
||||
|
||||
# else:
|
||||
|
||||
if has_tenant_field:
|
||||
|
||||
return super().get_queryset().select_related('organization').filter(
|
||||
models.Q(organization__in=user_organizations)
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
if has_tenant_field:
|
||||
|
||||
return super().get_queryset().select_related('organization').filter(
|
||||
models.Q(organization__in=user_organizations)
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
return super().get_queryset().filter(
|
||||
models.Q(organization__in=user_organizations)
|
||||
)
|
||||
return super().get_queryset().filter(
|
||||
models.Q(organization__in=user_organizations)
|
||||
)
|
||||
|
||||
|
||||
if has_tenant_field:
|
||||
|
@ -37,7 +37,7 @@ class TenancyManager(
|
||||
|
||||
|
||||
has_tenant_field = False
|
||||
if hasattr(self.model, 'organization'):
|
||||
if getattr(self.model, 'organization', None) is not None:
|
||||
has_tenant_field = True
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user