fix: 修复系统组件绑定角色bug (#7962)

Co-authored-by: feng626 <1304903146@qq.com>
pull/7971/head
fit2bot 2022-03-23 10:56:23 +08:00 committed by GitHub
parent 6bde31cdd0
commit 9b73727bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -8,20 +8,21 @@ import random
import datetime
from typing import Callable
from django.db import models
from django.conf import settings
from django.utils import timezone
from django.core.cache import cache
from django.shortcuts import reverse
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.hashers import check_password
from django.core.cache import cache
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django.shortcuts import reverse
from orgs.utils import current_org
from orgs.models import Organization
from common.utils import date_expired_default, get_logger, lazyproperty, random_string
from rbac.const import Scope
from common import fields
from django.db.models import TextChoices
from common.utils import date_expired_default, get_logger, lazyproperty, random_string
from ..signals import post_user_change_password, post_user_leave_org, pre_user_leave_org
__all__ = ['User', 'UserPasswordHistory']
@ -177,14 +178,14 @@ class RoleManager(models.Manager):
def get_role_binding_cls(self):
from rbac.models import SystemRoleBinding, OrgRoleBinding
if self.scope == 'org':
if self.scope == Scope.org:
return OrgRoleBinding
else:
return SystemRoleBinding
def get_role_cls(self):
from rbac.models import SystemRole, OrgRole
if self.scope == 'org':
if self.scope == Scope.org:
return OrgRole
else:
return SystemRole
@ -244,7 +245,7 @@ class RoleManager(models.Manager):
'user': self.user,
'scope': self.scope
}
if not current_org.is_root():
if self.scope == Scope.org and not current_org.is_root():
kwargs['org_id'] = current_org.id
items.append(self.role_binding_cls(**kwargs))
@ -615,7 +616,7 @@ class MFAMixin:
class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
class Source(TextChoices):
class Source(models.TextChoices):
local = 'local', _('Local')
ldap = 'ldap', 'LDAP/AD'
openid = 'openid', 'OpenID'