Beispiel #1
0
def admin_userpermission_change(token, u_id, permission_id):
    global my_users
    user = get_user_from_token(token)

    if (user_valid_uid(u_id)):
        if (user_valid_permission_id(permission_id)):
            if (user.get_permission_id() == 1):
                get_user_from_id(u_id).set_permission_id(permission_id)
                if permission_id == 1 or permission_id == 2:
                    make_user_owner_in_all_channels(u_id)
                return True
            if (user.get_permission_id() == 2):
                if (permission_id == 1):
                    raise AccessError(
                        "As an Admin, You Can Not Change Other Users to Owners"
                    )
                if (user_is_not_an_owner(u_id)):
                    get_user_from_id(u_id).set_permission_id(permission_id)
                    if permission_id == 2:
                        make_user_owner_in_all_channels(u_id)
                    return True
                else:
                    raise AccessError(
                        "As An Admin, You Can Not Change An Owner's Privileges"
                    )
            else:
                raise AccessError(
                    "As a Member, You Can Not Change Anyone's Privileges")
        else:
            raise ValueError("Your Permission ID is Invalid")
    else:
        raise ValueError("Invalid User ID")
Beispiel #2
0
def message_edit(token, message_id, message_str):

    if not user_valid_token(token):
        raise AccessError("User is not a valid user")

    user_id = get_user_from_token(token).get_uid()
    message = get_message_from_m_id(message_id)
    channel = get_verified_channel_from_id(
        get_channel_from_message(message_id), get_channel_list())

    if not channel_owner(user_id, channel):
        if not message_poster(user_id, message):
            raise AccessError("Not authorized user of message")

    message.change_content(message_str)
    return {}
Beispiel #3
0
def standup_send(token, channel_id, message):
    global list_of_messages
    global end_time

    curr_user = get_user_from_token(token)

    try:
        curr_channel = get_verified_channel_from_id(channel_id,
                                                    get_channel_list())
    except:
        raise ValueError("Channel ID is not a valid channel")

    if curr_user.get_uid() in curr_channel.get_mem_list():
        if (len(message) <= 1000):
            if curr_channel.get_active_standup():
                list_of_messages.append({
                    "handle_str":
                    curr_user.get_handle_str(),
                    "message":
                    message
                })
                return {}
            else:
                raise ValueError("Standup is not active at the moment")
        else:
            raise ValueError("Message is more that 1000 characters")
    else:
        raise AccessError("The user is not a valid user")
Beispiel #4
0
def standup_start(token, channel_id, length):
    global end_time

    sender = get_user_from_token(token)
    sender_uid = sender.get_uid()
    try:
        curr_channel = get_verified_channel_from_id(channel_id,
                                                    get_channel_list())
    except:
        raise ValueError("Channel ID is not a valid channel")

    if sender_uid in curr_channel.get_mem_list():
        if not curr_channel.get_active_standup():

            curr_channel.set_active_standup(True)
            start_time = datetime.now()
            t = Timer(length, standup_output_message, [token, channel_id], {})
            t.start()

            end_time = start_time + timedelta(seconds=length)
            return {'time_finish': int(end_time.timestamp())}
        else:
            raise ValueError("Standup is already running.")
    else:
        raise AccessError("Authorised user is not a member of the channel.")
Beispiel #5
0
def message_send(token, channel_id, message):

    if not authorized_user(token, channel_id):
        raise AccessError("User has not joined the channel")

    time_created = datetime.now()

    return append_message(channel_id, token, set_global_message_id(), message,
                          time_created)
Beispiel #6
0
def standup_active(token, channel_id):
    global end_time

    if user_valid_token(token) is False:
        raise AccessError("Invalid User Token")

    if get_verified_channel_from_id(channel_id,
                                    get_channel_list()).get_active_standup():
        return {"is_active": True, "time_finish": int(end_time.timestamp())}
    else:
        return {"is_active": False, "time_finish": None}
Beispiel #7
0
def message_unpin(token, message_id):
    user_id = get_user_from_token(token).get_uid()

    message = get_message_from_m_id(message_id)
    channel = get_verified_channel_from_id(
        get_channel_from_message(message_id), get_channel_list())

    if not authorized_user(token, channel.get_channel_id()):
        raise AccessError("User is not a member of the channel")

    if not user_valid_token(token):
        raise AccessError("User is not a valid user")

    if not channel_owner(user_id, channel):
        raise ValueError("The user is not an admin")

    if not message.pinned():
        raise ValueError("Message is already unpinned")

    message.unpin_message()
    return {}
Beispiel #8
0
def message_remove(token, message_id):

    user_id = get_user_from_token(token).get_uid()

    message = get_message_from_m_id(message_id)
    channel = get_verified_channel_from_id(
        get_channel_from_message(message_id), get_channel_list())

    if not channel_owner(user_id, channel):
        if not message_poster(user_id, message):
            raise AccessError("Not authorized user of message")

    channel.get_mess().remove(message)
    return {}
Beispiel #9
0
def channel_details(token, channel_id):
    global channel_list

    target_channel = get_verified_channel_from_id(channel_id, channel_list)
    user_id = get_verified_user_from_token(token).get_uid()

    if user_id not in target_channel.get_mem_list():
        raise AccessError("The user is not in the channel.")

    list_of_member = generate_list_of_members(target_channel)
    list_of_owner = generate_list_of_owners(target_channel)

    return {
        'name': target_channel.get_channel_name(),
        'owner_members': list_of_owner,
        'all_members': list_of_member
    }
Beispiel #10
0
def channel_addowner(token, channel_id, u_id):
    target_channel = get_verified_channel_from_id(channel_id, channel_list)

    if u_id in target_channel.get_owner_list():
        raise ValueError("This user is already an owner.")

    host_user = get_verified_user_from_token(token)
    host_id = host_user.get_uid()

    if host_id in target_channel.get_owner_list() or \
            (host_user.get_permission_id() == 2 or host_user.get_permission_id() == 1):

        (target_channel.get_owner_list()).append(u_id)

    else:
        raise AccessError("Host User is not authorised.")

    return {}
Beispiel #11
0
def message_unreact(token, message_id, react_id):

    user_id = get_user_from_token(token).get_uid()

    if not valid_message_in_channel(user_id, message_id):
        raise ValueError("Invalid message_id with in the user joined channel")

    message = get_message_from_m_id(message_id)

    if not already_reacted(user_id, message, react_id):
        raise ValueError("Does not contain an active react")

    if not user_valid_token(token):
        raise AccessError("User is not a valid user")

    react = get_react_from_id(message, react_id)
    react.user_unreact(user_id)

    return {}
Beispiel #12
0
def channel_invite(token, channel_id, u_id):
    global channel_list

    host_user = get_verified_user_from_token(token)
    recipient_user = get_user_from_id(u_id)

    inv_channel = get_verified_channel_from_id(channel_id, channel_list)

    if host_user.get_uid() not in inv_channel.get_mem_list():
        raise AccessError("The host is not in the channel.")

    if recipient_user is None:
        raise ValueError("Invalid Guest.")

    if recipient_user.get_uid() in inv_channel.get_mem_list():
        raise ValueError("The user is already in channel.")

    inv_channel.get_mem_list().append(u_id)

    return {}
Beispiel #13
0
def channel_join(token, channel_id):
    target_channel = get_verified_channel_from_id(channel_id, channel_list)

    user = get_verified_user_from_token(token)
    user_id = user.get_uid()

    if user_id in target_channel.get_mem_list():
        raise ValueError("User is already in the channel.")

    if user.get_permission_id() == 1 or user.get_permission_id() == 2:
        target_channel.get_mem_list().append(user_id)
        target_channel.get_owner_list().append(user_id)

    elif user.get_permission_id() == 3 and target_channel.get_is_pub() == True:
        target_channel.get_mem_list().append(user_id)

    else:
        raise AccessError("The Channel is Private.")

    return {}
Beispiel #14
0
def message_send_later(token, channel_id, message, time_sent):

    timestamp = float(time_sent)
    time = datetime.fromtimestamp(timestamp)

    if not channel_valid_id(channel_id):
        raise ValueError("Channel does not exist")

    if not valid_time(time_sent):
        raise ValueError("Time sent is in the past")

    if not authorized_user(token, channel_id):
        raise AccessError("User has not joined the channel")

    time_dif = (time - datetime.now()).total_seconds()
    t = Timer(time_dif,
              append_message,
              args=[channel_id, token,
                    set_global_message_id(), message, time])
    t.start()
    return {"message_id": get_global_message_id()}
Beispiel #15
0
def channel_messages(token, channel_id, start):

    global channel_list

    channel = get_verified_channel_from_id(channel_id, channel_list)
    u_id = get_verified_user_from_token(token).get_uid()
    user = get_verified_user_from_token(token)
    first_message = len(channel.get_mess()) - start

    if u_id in channel.get_mem_list():
        if start <= len(channel.get_mess()):
            if (len(channel.get_mess()) - start) - 50 >= 0:
                end = start + 50
                last_message = first_message - 50
            else:
                end = -1
                last_message = 0
            messages = generate_indexed_messages(user, channel, first_message,
                                                 last_message)
            return {"messages": messages, "start": start, "end": end}
        else:
            raise ValueError("The start is greater than cumulative messages")
    else:
        raise AccessError("The user is not in the channel")
Beispiel #16
0
 def wrapper(*args, **kwargs):
     argsList = list(args)
     if not user_valid_token(argsList[0]):
         raise AccessError("Invalid User Token")
     return function(*args, **kwargs)