Exemplo n.º 1
0
def http_standup_start():
    """
    http_standup_start:
    For a given channel, start the stand up period whereby for the next "length" seconds if someone calls "standup_send" with a message, it is buffered during the X second window then at the end of the X second window a message will be added to the message queue in the channel from the user who started the standup. X is an integer that denotes the number of seconds that the standup occurs for

    Input:
    - (JSON) {token, channel_id, length}
    Output:
    - (JSON) {time_finish}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])
    length = input_handle_ids(input_data["length"])
    output = standup_start(server_data, input_data["token"], channel_id,
                           length)

    #create a multithread on the standup
    thread = threading.Thread(target=standup_handler,
                              args=(channel_id, int(output["time_finish"])))
    thread.start()

    return dumps(output)
Exemplo n.º 2
0
def http_message_sendlater():
    """
    http_message_sendlater:
    Send a message from authorized_user to the channel specified by channel_id automatically at a secified time in the future

    Input:
    - (JSON) {token, channel_id, message, time_sent}
    Output:
    - (JSON) {message_id}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])

    # Construct the necessary information here
    message_info = process_message_infos(server_data, input_data["token"],
                                         channel_id, input_data["message"],
                                         int(input_data["time_sent"]))

    queue = get_message_queue()
    queue.append(message_info)

    return dumps({"message_id": message_info["message_id"]})
Exemplo n.º 3
0
def http_admin_userpermission_change():
    """
    http_admin_userpermission_change:
    Given a user by their u_id, set their permission to new permissions described by permission_id

    Input:
    - (JSON) {token, u_id, permission_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    u_id = input_handle_ids(input_data["u_id"])
    permission_id = input_handle_ids(input_data["permission_id"])
    output_data = admin_userpermission_change(server_data, input_data["token"],
                                              u_id, permission_id)

    return dumps(output_data)
Exemplo n.º 4
0
def http_message_unreact():
    """
    http_message_unreact:
    Given a message within a channel the authorized user is a part of, remove a react to that particular message

    Input:
    - (JSON) {token, message_id, react_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    message_id = input_handle_ids(input_data["message_id"])
    react_id = input_handle_ids(input_data["react_id"])

    output_data = message_unreact(server_data, input_data["token"], message_id,
                                  react_id)
    return dumps(output_data)
Exemplo n.º 5
0
def http_channel_removeowner():
    """
    http_channel_removeowner:
    Remove user with u_id an owner of this channel

    Input:
    - (JSON) {token, channel_id, u_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])
    u_id = input_handle_ids(input_data["u_id"])

    output_data = channel_removeowner(server_data, input_data["token"],
                                      channel_id, u_id)
    return dumps(output_data)
Exemplo n.º 6
0
def http_channel_messages():
    """
    http_channel_messages:
    Given a channel with channel_id that the user is a part of, return up to 50 messages between index start and start+50 exclusive. 0 is the most recent message

    Input:
    - (URL) {token, channel_id, start}
    Output:
    - (JSON) {message, start, end}
    """

    # Get input and server data
    input_token = request.args.get("token")
    input_channel_id = input_handle_ids(request.args.get("channel_id"))
    input_start = input_handle_ids(request.args.get("start"))
    server_data = get_server_data_obj()

    output_data = channel_messages(server_data, input_token, input_channel_id,
                                   input_start)
    return dumps(output_data)
Exemplo n.º 7
0
def http_channel_invite():
    """
    http_channel_invite:
    Invites a user to join a channel with channel_id. Once invited the user is added to the channel immediately

    Input:
    - (JSON) {token, channel_id, u_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    channel_id = -1
    u_id = -1

    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])
    u_id = input_handle_ids(input_data["u_id"])

    output_data = channel_invite(server_data, input_data["token"], channel_id,
                                 u_id)
    return dumps(output_data)
Exemplo n.º 8
0
def http_admin_remove_user():
    """
    http_admin_remove_user:
    Remove the user from the server

    Input:
    - (JSON) {token, u_id}
    Output:
    - (JSON) {}
    """
    server_data = get_server_data_obj()
    input_data = request.get_json()
    u_id = input_handle_ids(input_data["u_id"])
    remove_user(server_data, input_data["token"], u_id)

    return dumps({})
Exemplo n.º 9
0
def http_standup_active():
    """
    http_standup_active:
    For a given channel, return whether a standup is active in it, and what time the standup finishes. If no standup is active then time_finish returns None

    Input:
    - (URL) {token, channel_id}
    Output:
    - (JSON) {is_active, time_finish}
    """

    # Get input and server data
    input_token = request.args.get("token")
    input_channel_id = input_handle_ids(request.args.get("channel_id"))
    server_data = get_server_data_obj()
    output = standup_active(server_data, input_token, input_channel_id)

    return dumps(output)
Exemplo n.º 10
0
def http_message_remove():
    """
    http_message_remove:
    Given a message_id for a message, this message is removed from the channel

    Input:
    - (JSON) {token, message_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    message_id = input_handle_ids(input_data["message_id"])

    output_data = message_remove(server_data, input_data["token"], message_id)
    return dumps(output_data)
Exemplo n.º 11
0
def http_message_unpin():
    """
    http_message_unpin:
    Given a message within a channel, mark it as unpinned

    Input:
    - (JSON) {token, message_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    message_id = input_handle_ids(input_data["message_id"])

    output_data = message_unpin(server_data, input_data["token"], message_id)
    return dumps(output_data)
Exemplo n.º 12
0
def http_message_pin():
    """
    http_message_pin:
    Given a message within a channel, mark it as pinned to be given special display treatment by the front end

    Input:
    - (JSON) {token, message_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    message_id = input_handle_ids(input_data["message_id"])

    output_data = message_pin(server_data, input_data["token"], message_id)
    return dumps(output_data)
Exemplo n.º 13
0
def http_channel_join():
    """
    http_channel_join:
    Given a channel_id of a channel that the authorized user can join, adds them to that channel

    Input:
    - (JSON) {token, channel_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])

    output_data = channel_join(server_data, input_data["token"], channel_id)
    return dumps(output_data)
Exemplo n.º 14
0
def http_channel_leave():
    """
    http_channel_leave:
    Gievn a channel ID, the user removed as a member of this channel

    Input:
    - (JSON) {token, channel_id}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])

    output_data = channel_leave(server_data, input_data["token"], channel_id)
    return dumps(output_data)
Exemplo n.º 15
0
def http_standup_send():
    """
    http_standup_send:
    Sending a message to get buffered in the standup queue, assuming a standup is currently active

    Input:
    - (JSON) {token, channel_id, message}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])
    output = standup_send(server_data, input_data["token"], channel_id,
                          input_data["message"])

    return dumps(output)
Exemplo n.º 16
0
def http_user_profile():
    """
    http_user_profile:
    For a valid user, returns information about their user_id, email, first name, last name and handle

    Input:
    - (URL) {token, u_id}
    Output:
    - (JSON) {user}
    """

    # Get input and server data

    input_token = request.args.get("token")
    input_u_id = input_handle_ids(request.args.get("u_id"))
    server_data = get_server_data_obj()

    output_data = user_profile(server_data, input_token, input_u_id)
    return dumps(output_data)
Exemplo n.º 17
0
def http_message_send():
    """
    http_message_send:
    Send a message from authorised_user to the channel specified by channel_id

    Input:
    - (JSON) {token, channel_id, message}
    Output:
    - (JSON) {message_id}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    channel_id = input_handle_ids(input_data["channel_id"])

    output_data = message_send(server_data, input_data["token"], channel_id,
                               input_data["message"])
    return dumps(output_data)
Exemplo n.º 18
0
def http_channel_details():
    """
    http_channel_details:
    Given a channel with channel_id that the authorized user is a part of, provide basic details about the channel

    Input:
    - (URL) {token, channel_id}
    Output:
    - (JSON) {name, owner_members, all_members}
    """

    # Get input and server data
    input_token = request.args.get("token")
    input_channel_id = input_handle_ids(request.args.get("channel_id"))
    server_data = get_server_data_obj()

    output_data = channel_details(server_data, input_token, input_channel_id)

    return dumps(output_data)
Exemplo n.º 19
0
def http_message_edit():
    """
    http_message_edit:
    Given a message, update it's text with new text. If new message is an empty string, the message is deleted.

    Input:
    - (JSON) {token, message_id, message}
    Output:
    - (JSON) {}
    """

    # Get input and server data
    input_data = request.get_json()
    server_data = get_server_data_obj()
    message_id = input_handle_ids(input_data["message_id"])

    if not input_data["message"]:
        output_data = message_remove(server_data, input_data["token"],
                                     message_id)
    else:
        output_data = message_edit(server_data, input_data["token"],
                                   message_id, input_data["message"])

    return dumps(output_data)