示例#1
0
def delete_channel(channel_id: str, request: Request, response: Response):

    # Clean delete channel
    Channel.objects(_id=channel_id).update(set__status='deleted')

    # Return response
    return {"msg": "deleted!"}
示例#2
0
def update_channel(channel_payload: ChannelType, channel_id: str,
                   request: Request, response: Response, action: str):

    # Get logged in user
    user = auth_module.get_me(request=request)

    if user is None:
        response.status_code = status.HTTP_401_UNAUTHORIZED
        return util_module.generate_response_context(status=403,
                                                     error='access denied!',
                                                     data=None)

    if action == 'update':

        # Check ownership
        if not Channel.objects(pk=channel_id,
                               admins__contains=user.get("_id")):
            response.status_code = status.HTTP_403_FORBIDDEN
            return util_module.generate_response_context(
                status=403, error='access denied! now owner', data=None)

        # Update
        Channel.objects(_id=channel_id).update(
            set__name=channel_payload.name,
            set__summary=channel_payload.summary,
            set__tags=channel_payload.tags)

        # Retrun success response
        return {"msg": 'updated'}

    if action == 'follow':

        # Add new follower
        Channel.objects(pk=channel_id).update(
            add_to_set__followers=[user.get("_id")])

        return {"msg": "follow channel"}

    if action == 'unfollow':

        # Add new follower
        Channel.objects(pk=channel_id).update(pull__followers=user.get("_id"))

        return {"msg": "unfollow channel"}

    if action == 'delete':

        # Clean delete channel
        Channel.objects(_id=channel_id).update(set__status='deleted')

        # Return response
        return {"msg": "deleted!"}

    if action == 'add-admin':

        return {"case": "assign admin to channel"}

    # No action was provided
    return {"msg": "provide action query parameter!"}