Browse Source

fix(orgs): 更新用户时`org_roles`参数为`None`时不更新组织角色

pull/4805/head
xinwen 4 years ago committed by 老广
parent
commit
b1ac3fa94f
  1. 6
      apps/users/api/user.py

6
apps/users/api/user.py

@ -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: 需要测试

Loading…
Cancel
Save