|
|
@ -112,7 +112,8 @@ class Organization(models.Model):
|
|
|
|
role_id = role.id
|
|
|
|
role_id = role.id
|
|
|
|
with tmp_to_org(self):
|
|
|
|
with tmp_to_org(self):
|
|
|
|
defaults = {
|
|
|
|
defaults = {
|
|
|
|
'user': user, 'role_id': role_id, 'org_id': self.id, 'scope': 'org'
|
|
|
|
'user': user, 'role_id': role_id,
|
|
|
|
|
|
|
|
'org_id': self.id, 'scope': 'org'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.members.through.objects.update_or_create(**defaults, defaults=defaults)
|
|
|
|
self.members.through.objects.update_or_create(**defaults, defaults=defaults)
|
|
|
|
|
|
|
|
|
|
|
@ -162,25 +163,19 @@ class Organization(models.Model):
|
|
|
|
self.delete_related_models()
|
|
|
|
self.delete_related_models()
|
|
|
|
return super().delete(*args, **kwargs)
|
|
|
|
return super().delete(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def admin(self):
|
|
|
|
|
|
|
|
from rbac.models import OrgRoleBinding
|
|
|
|
|
|
|
|
from users.models import User
|
|
|
|
|
|
|
|
from rbac.builtin import BuiltinRole
|
|
|
|
|
|
|
|
from .utils import tmp_to_org
|
|
|
|
|
|
|
|
|
|
|
|
# class OrgMemberManager(models.Manager):
|
|
|
|
role_org_admin = BuiltinRole.org_admin.get_role()
|
|
|
|
# def remove_users(self, org, users):
|
|
|
|
with tmp_to_org(self):
|
|
|
|
# from users.models import User
|
|
|
|
org_admins = OrgRoleBinding.get_role_users(role_org_admin)
|
|
|
|
# pk_set = []
|
|
|
|
if not org_admins:
|
|
|
|
# for user in users:
|
|
|
|
org_admins = User.objects.filter(username='admin')
|
|
|
|
# if hasattr(user, 'pk'):
|
|
|
|
return org_admins
|
|
|
|
# pk_set.append(user.pk)
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# pk_set.append(user)
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# send = partial(
|
|
|
|
|
|
|
|
# signals.m2m_changed.send, sender=self.model,
|
|
|
|
|
|
|
|
# instance=org, reverse=False, model=User,
|
|
|
|
|
|
|
|
# pk_set=pk_set, using=self.db
|
|
|
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
# send(action="pre_remove")
|
|
|
|
|
|
|
|
# self.filter(org_id=org.id, user_id__in=pk_set).delete()
|
|
|
|
|
|
|
|
# send(action="post_remove")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OrganizationMember(models.Model):
|
|
|
|
class OrganizationMember(models.Model):
|
|
|
|