Ejemplo n.º 1
0
 def add_role_user(cls, role_id: int, user_id: int, creator: str)->tuple:
     """
     add role's user
     新增角色用户
     :param role_id:
     :param user_id:
     :param creator:
     :return:
     """
     # 去重下
     role_user_queryset = LoonUserRole.objects.filter(user_id=user_id, role_id=role_id, is_deleted=0)
     if role_user_queryset:
         return False, 'user has been existed in this role'
     role_user_obj = LoonUserRole(user_id=user_id, role_id=role_id, creator=creator)
     role_user_obj.save()
     return True, dict(role_user_id=role_user_obj.id)
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        """
        新增用户对应的角色

        入参:
        user_id
        role_id

        :param request:
        :param args:
        :param kwargs:
        :return:
        """
        json_str = request.body.decode('utf-8')
        if not json_str:
            return api_response(-1, 'post参数为空', {})
        request_data_dict = json.loads(json_str)
        user_id = request_data_dict.get('user_id', '')
        role_id = request_data_dict.get('role_id', '')

        LoonUserRole().create_user_role(user_id, role_id)

        return api_response(0, '')