|
|
|
@ -55,11 +55,13 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
|
|
|
|
|
post_user_create.send(self.__class__, user=user) |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def set_users_to_org(users, org_roles): |
|
|
|
|
def set_users_to_org(users, org_roles, update=False): |
|
|
|
|
# 只有真实存在的组织才真正关联用户 |
|
|
|
|
if not current_org or not current_org.is_real(): |
|
|
|
|
return |
|
|
|
|
for user, roles in zip(users, org_roles): |
|
|
|
|
if update and roles is None: |
|
|
|
|
continue |
|
|
|
|
if not roles: |
|
|
|
|
# 当前组织创建的用户,至少是该组织的`User` |
|
|
|
|
roles = [ORG_ROLE.USER] |
|
|
|
@ -107,7 +109,7 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
|
|
|
|
|
users = serializer.save() |
|
|
|
|
if isinstance(users, User): |
|
|
|
|
users = [users] |
|
|
|
|
self.set_users_to_org(users, org_roles) |
|
|
|
|
self.set_users_to_org(users, org_roles, update=True) |
|
|
|
|
|
|
|
|
|
def perform_bulk_update(self, serializer): |
|
|
|
|
# TODO: 需要测试 |
|
|
|
|