Beispiel #1
0
def standup_send(token, channel_id, message):
    '''Sending a message to get buffered in the standup queue,
    assuming a standup is currently active'''
    data = getData()
    user_id = getUserFromToken(token)
    user = data['users'][user_id]
    right_channel_index = find_channel(channel_id)

    if right_channel_index is None:
        raise Value_Error(f"Channel ID: {channel_id} is not a valid channel")

    right_channel = data['channels_list'][right_channel_index]

    if len(message) > 1000:
        raise Value_Error("Message is more than 1000 characters")

    if right_channel['standup']['finish_time'] < dt.utcnow():
        raise Value_Error(
            'An active standup is not currently running in this channel')

    if not inChannel(token, channel_id):
        raise AccessError(
            'The authorised user is not a member of the channel that the message is within'
        )

    message_id = right_channel['standup']['message_id']
    msg_id = find_message(message_id)
    old_message = data['messages'][msg_id]['message']
    old_message += str(user['handle']) + ': ' + message + ' '
    edit(token, message_id, old_message)

    # update data after edit
    data = getData()
    save(data)
    return {}
Beispiel #2
0
def unpin(token, message_id):
    ''' Given a message within a channel, remove it's mark as unpinned '''
    data = getData()
    user_id = getUserFromToken(token)
    user_dict = data['users'][user_id]
    msg_id = find_message(message_id)

    if msg_id is None:
        raise Value_Error("Message_Id is not a valid message")

    msg_dict = data['messages'][msg_id]

    if user_dict['permission'] is 3:
        raise Value_Error(
            "Message with message_id was not sent by the authorised user making this request and The authorised user is not an admin or owner of this channel or the slackr"
        )

    if not inChannel(token, msg_dict['channel_id']):
        raise AccessError("you need to be in the channel to pin the message")

    if msg_dict['is_pinned'] is False:
        raise Value_Error(
            f"Message with ID message_id: {message_id} already unpinned")

    msg_dict['is_pinned'] = False
    save(data)
    return {}
Beispiel #3
0
def pin(token, message_id):
    ''' Given a message within a channel, mark it as "pinned" to
    be given special display treatment by the frontend '''
    data = getData()
    user_id = getUserFromToken(token)
    user_dict = data['users'][user_id]
    msg_id = find_message(message_id)

    if msg_id is None:
        raise Value_Error("Message_Id is not a valid message")

    msg_dict = data['messages'][msg_id]

    if user_dict['permission'] == 3:
        raise Value_Error("The authorised user is not an admin")

    if not inChannel(token, msg_dict['channel_id']):
        raise AccessError(
            "The authorised user is not a member of the channel that the message is within"
        )

    if msg_dict['is_pinned'] is True:
        raise Value_Error(
            f"Message with ID message_id: {message_id} already pinned")

    msg_dict['is_pinned'] = True
    save(data)
    return {}
Beispiel #4
0
def unreact(token, message_id, react_id):
    ''' Given a message within a channel the authorised user is
    part of, remove a "react" to that particular message '''
    data = getData()
    user_id = getUserFromToken(token)
    user_dict = data['users'][user_id]
    msg_dict = data['messages'][find_message(message_id)]
    reacts_list = msg_dict['reacts']
    channel_id = msg_dict['channel_id']
    '''Check if the user is in this particular channel_id of the message '''
    user_channel_list = user_dict['user_channel']
    error_flag = 1
    for i in user_channel_list:
        if i['channel_id'] == channel_id:
            error_flag = 0

    if error_flag == 1:
        raise Value_Error(
            "Not a valid message within a channel that the authorised user has joined"
        )

    if react_id != 1:
        raise Value_Error("Not a valid react_id")

    reacts_list = msg_dict['reacts']

    if user_id not in reacts_list[int(react_id) - 1]['u_ids']:
        raise Value_Error(
            "Message with ID message_id does not contain an active React with ID react_id"
        )

    reacts_list[int(react_id) - 1]['u_ids'].remove(user_id)
    save(data)
    return {}
Beispiel #5
0
def edit(token, message_id, message):
    ''' Given a message, update it's text with new text '''
    data = getData()
    user_dict = data['users'][getUserFromToken(token)]
    msg_dict = data['messages'][find_message(message_id)]

    if msg_dict['u_id'] != user_dict['u_id'] and user_dict[
            'permission'] != 1 and user_dict['permission'] != 2:
        raise AccessError("Unauthorised user making edit request")

    msg_dict['message'] = message
    save(data)
    return {}
Beispiel #6
0
def remove(token, message_id):
    ''' Given a message_id for a message, this
    message is removed from the channel '''
    data = getData()
    user_id = getUserFromToken(token)
    user = data['users'][user_id]
    message_index = find_message(message_id)

    if message_index is None:
        raise Value_Error(f"Message (based on ID) no longer exists")
    message = data['messages'][message_index]

    if user['u_id'] != message['u_id'] and int(
            user['permission']) not in range(1, 3):
        raise Value_Error(
            "Message with message_id was not sent by the authorised user making this request and The authorised user is not an admin or owner of this channel or the slackr"
        )

    data['messages'].remove(message)
    save(data)
    return {}