Beispiel #1
0
    def post(self, req, team_id, user_id):
        serializer = CreateTeamUserReqSerializer(data=req.data)
        serializer.is_valid(raise_exception=True)

        try:
            team = team_services.get_team_by_team_id(team_id)
        except Tenants.DoesNotExist:
            raise exceptions.NotFound()

        role_ids = req.data["role_ids"].replace(" ", "").split(",")
        roleids = team_services.get_all_team_role_id(tenant_name=team_id,
                                                     allow_owner=True)
        for role_id in role_ids:
            if int(role_id) not in roleids:
                raise serializers.ValidationError("角色{}不存在".format(role_id),
                                                  status.HTTP_404_NOT_FOUND)

        flag = team_services.user_is_exist_in_team(user_list=[user_id],
                                                   tenant_name=team_id)
        if flag:
            user_obj = user_services.get_user_by_user_id(user_id=user_id)
            raise serializers.ValidationError(
                "用户{}已经存在".format(user_obj.nick_name),
                status.HTTP_400_BAD_REQUEST)

        team_services.add_user_role_to_team(tenant=team,
                                            user_ids=[user_id],
                                            role_ids=role_ids)

        return Response(None, status.HTTP_201_CREATED)
Beispiel #2
0
    def put(self, req, team_id, user_id):
        if req.user.user_id == user_id:
            raise serializers.ValidationError(
                "您不能修改自己的权限!", status=status.HTTP_400_BAD_REQUEST)

        serializer = CreateTeamUserReqSerializer(data=req.data)
        serializer.is_valid(raise_exception=True)

        role_ids = req.data["role_ids"].replace(" ", "").split(",")
        roleids = team_services.get_all_team_role_id(tenant_name=team_id,
                                                     allow_owner=True)
        for role_id in role_ids:
            if int(role_id) not in roleids:
                raise serializers.ValidationError("角色{}不存在".format(role_id),
                                                  status.HTTP_404_NOT_FOUND)

        try:
            user_services.get_user_by_tenant_id(team_id, user_id)
        except UserNotExistError as e:
            return Response({"msg": e.message}, status.HTTP_404_NOT_FOUND)

        team_services.change_tenant_role(user_id=user_id,
                                         tenant_name=team_id,
                                         role_id_list=role_ids)

        return Response(None, status.HTTP_200_OK)
 def post(self, req, team_id, user_id):
     serializer = CreateTeamUserReqSerializer(data=req.data)
     serializer.is_valid(raise_exception=True)
     role_ids = req.data["role_ids"].replace(" ", "").split(",")
     team_services.add_user_role_to_team(tenant=self.team,
                                         user_ids=[user_id],
                                         role_ids=role_ids)
     return Response(None, status.HTTP_201_CREATED)
Beispiel #4
0
    def put(self, req, team_id, user_id):
        if req.user.user_id == user_id:
            raise serializers.ValidationError("您不能修改自己的权限!", status.HTTP_400_BAD_REQUEST)

        serializer = CreateTeamUserReqSerializer(data=req.data)
        serializer.is_valid(raise_exception=True)

        role_ids = req.data["role_ids"].replace(" ", "").split(",")
        user = user_repo.get_by_user_id(user_id)
        user_kind_role_service.update_user_roles(kind="team", kind_id=self.team.tenant_id, user=user, role_ids=role_ids)
        return Response(None, status.HTTP_200_OK)