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) post_user_create.send(self.__class__, user=user)
@staticmethod @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(): if not current_org or not current_org.is_real():
return return
for user, roles in zip(users, org_roles): for user, roles in zip(users, org_roles):
if update and roles is None:
continue
if not roles: if not roles:
# 当前组织创建的用户,至少是该组织的`User` # 当前组织创建的用户,至少是该组织的`User`
roles = [ORG_ROLE.USER] roles = [ORG_ROLE.USER]
@ -107,7 +109,7 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
users = serializer.save() users = serializer.save()
if isinstance(users, User): if isinstance(users, User):
users = [users] 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): def perform_bulk_update(self, serializer):
# TODO: 需要测试 # TODO: 需要测试

Loading…
Cancel
Save