Esempio n. 1
0
def message_react(token, message_id, react_id):
    """
    Given a message within a channel the authorised user is part of,
    add a "react" to that particular message.
    """

    u_id = get_current_user(token)

    # React_id check
    if react_id != 1:
        raise InputError(description='react_id is not a valid React ID.' +
                         'The only valid react ID the frontend has is 1')

    # Check user is in channel they are reacting in and if they are,
    # execute.
    if user_in_message_channel(message_id, u_id) is True:
        message_file = get_message(message_id)
        u_id_to_react = next(
            (i for i in message_file['reacts'][0]['u_ids'] if u_id == i),
            False)

        if u_id_to_react is not False:
            # This user has already reacted.
            raise InputError(description='Message with ID message_id already' +
                             'contains an active React with ID react_id')
        else:
            # User has not already reacted.
            message_file['reacts'][0]['u_ids'].append(u_id)

    return {}
Esempio n. 2
0
def test_hangmne_normal():
    """
    Test if hangman can start with correct input
    """
    user_infor = auth_register("*****@*****.**", "ccc337992611", "Min",
                               "Li")
    channel_infor = channels_create(user_infor['token'], 'test_one', True)
    time_create_date = datetime.datetime.now().replace(microsecond=0)
    time_create = time_create_date.timestamp()
    message_id = message_send(user_infor['token'], channel_infor['channel_id'],
                              "/hangman")
    assert search(BOT_TOKEN,
                  "A game of hangman has been started in this channel") == {
                      "messages": [{
                          'message_id': message_id["message_id"] + 1,
                          'u_id': -1,
                          'message':
                          "A game of hangman has been started in this channel",
                          'time_created': time_create,
                          'reacts': [set_reacts()],
                          'is_pinned': False
                      }]
                  }

    auth_logout(BOT_TOKEN)
    message_id = message_send(user_infor['token'], channel_infor['channel_id'],
                              "/guess e")

    assert database.get_current_user(BOT_TOKEN) == -1
Esempio n. 3
0
def message_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.
    """
    # Token check
    u_id = get_current_user(token)

    # React_id check
    if react_id != 1:
        raise InputError(description='react_id is not a valid React ID.' +
                         'The only valid react ID the frontend has is 1')

    # Check user is in channel they are reacting in and if they are,
    # execute.
    if user_in_message_channel(message_id, u_id) is True:
        message_file = get_message(message_id)
        u_id_to_unreact = next(
            (i for i in message_file['reacts'][0]['u_ids'] if u_id == i), None)

        if u_id_to_unreact is not None:
            # If there was a react from the user.
            message_file['reacts'][0]['u_ids'].remove(u_id)
        else:
            # If there wasn't a react from the user.
            raise InputError(
                description='Message with ID message_id does not' +
                'contain an active React with ID react_id')

    return {}
def change_user_permission(token, u_id, permission_id):
    """
    Given a User by their user ID, set their permissions
    to new permissions described by permission_id
    """
    # Store u_id of person running command
    user_from_token = database.get_current_user(token)

    if permission_id not in VALID_PERMISSION_IDS.values():
        raise error.InputError(description="permission_id does not refer to a value permission")
    if (database.get_permission_dict(user_from_token).get("permission_id")
            != VALID_PERMISSION_IDS['owner']):
        # User is not a global owner.
        raise error.AccessError(description="The authorised user is not an owner")

    number_of_owners = 0
    for member in database.get_permissions_list():
        if member.get('permission_id') == VALID_PERMISSION_IDS['owner']:
            number_of_owners += 1

    if (u_id == user_from_token and number_of_owners == 1):
        # i.e. Owner calling this function is only owner.
        raise error.AccessError(description="Owner cannot remove" +
                                " permissions when he is the only owner")


    # Now, having checked for all errors, run function:
    database.set_permissions(u_id, permission_id)
Esempio n. 5
0
def message_sendlater(token, channel_id, message, time_sent):
    """
    Send a message from authorised_user to the channel specified by
    channel_id automatically at a specified time in the future.
    """
    u_id = get_current_user(token)

    if is_user_channel_member(channel_id, u_id) is False:
        raise AccessError(description='The authorised user has not ' +
                          'joined the channel they are trying to post to')

    # raise error if the message is longer than 1000 or empty string is given.
    if len(message) > 1000:
        raise InputError(description='Message is more than 1000 characters')

    if message == '':
        raise InputError(description='Cannot send an empty message')

    time_now_datetime = datetime.now().replace(microsecond=0)
    time_now = time_now_datetime.timestamp()
    if time_now > time_sent:
        raise InputError(description='Time sent is a time in the past')
    else:
        # Run sendlater
        time_diff = time_sent - time_now

        time.sleep(time_diff)
        return message_send(token, channel_id, message)
def standup_send(token, channel_id, message):
    """ Add a message to standup queue """

    # If token is valid, take u_id which is used to look through users
    u_id = database.get_current_user(token)

    # Check if user is member of channel that message is within
    # if not then raise an AccessError
    channel_data = database.get_channel_data(channel_id)
    if u_id not in channel_data['member_ids']:
        raise error.AccessError(
            description="You are not a member of this channel")

    # Check if message if more than 1000 characters long and raise InputError if that is the case
    if len(message) > 1000:
        raise error.InputError(
            description="The message entered is more than 1000 characters long"
        )

    # Check if standup is currently active in channel, raise InputError if not
    if standup_active(token, channel_id)['is_active'] is False:
        raise error.InputError(
            description="There are no standups active in this channel")

    # Format message to "handle_str: message"
    handle_str = database.get_user_data(u_id)['handle_str']
    string = handle_str + ": " + message

    # Now add string to the appropriate list in queues
    QUEUES[str(channel_id)].append(string)

    return {}
Esempio n. 7
0
def message_remove(token, message_id):
    """
    Given a message_id for a message, this message is removed from the channel.
    """
    u_id = get_current_user(token)

    message_location = get_message_location(message_id)

    channel_id = message_location["channel_id"]
    channel_data = get_channel_data(channel_id)

    if u_id not in channel_data['member_ids']:
        raise AccessError(
            description="User must be a member of the channel they are trying"
            + " to access.")

    # Find the message to be deleted. At this point
    #   The message definitely exists and the user is definitely a member of the channel
    #   it exists in.
    for message in channel_data["messages"]:
        if message['message_id'] == message_id:
            if message["u_id"] != u_id and get_permission_dict(u_id).get(
                    'permission_id') != 1:
                raise AccessError(
                    description="Authorised user did not send the message " +
                    "and is not a server/channel owner.")
            else:
                remove_message(message_id)

    return {}
Esempio n. 8
0
def message_send(token, channel_id, message):
    """
    Grab information from the frontend chat bar and send it.
    """

    u_id = get_current_user(token)

    if is_user_channel_member(channel_id, u_id) is False:
        raise AccessError(description='The authorised user has not ' +
                          'joined the channel they are trying to post to')

    # raise error if the message is longer than 1000 or empty string is given.
    if len(message) > 1000:
        raise InputError(description='Message is more than 1000 characters')

    if message == '':
        raise InputError(description='Cannot send an empty message')

    # Now parse the message
    message_id = message_parser.parse_message(u_id, channel_id, message)
    check_command(channel_id, message)

    return {
        "message_id": message_id,
    }
Esempio n. 9
0
def message_unpin(token, message_id):
    """
    Given a message within a channel, remove it's mark as unpinned.
    """
    u_id = get_current_user(token)
    message_location = get_message_location(message_id)
    message_file = get_message(message_id)

    ################### START ERROR CHECKS ############################

    channel_data = get_channel_data(message_location['channel_id'])

    check = next((i for i in channel_data['member_ids'] if i == u_id), False)

    if check is False:
        raise AccessError(description='The authorised user is not ' +
                          'a member of the channel that the message is within')

    if u_id not in channel_data['owner_ids']:
        raise AccessError(description='The authorised user is not an owner')

    ##################### END ERROR CHECKS ########################

    if message_file['is_pinned'] is False:
        raise InputError(
            description='Message with ID message_id is already unpinned')
    else:
        message_file['is_pinned'] = False
    return {}
Esempio n. 10
0
def user_profile_setemail(token, email):
    """
    Given input for email sets user's email if valid and not taken
    """
    users = database.get_users()
    for user in users:
        if user['email'] is email:
            raise error.InputError(description="This email is already taken")
    u_id = database.get_current_user(token)
    user = database.get_user_data(u_id)
    user['email'] = email
    database.set_user_data(user)
Esempio n. 11
0
def user_profile_sethandle(token, handle_str):
    """
    given input for a handle name set user's handle
    """
    if (len(handle_str) > 20 or len(handle_str) < 2):
        raise error.InputError(
            description="Handle is not within 2-20 characters")
    users = database.get_users()
    for user in users:
        if user['handle_str'] is handle_str:
            raise error.InputError(description="Handle is already taken")
    u_id = database.get_current_user(token)
    user = database.get_user_data(u_id)
    user['handle_str'] = handle_str
    database.set_user_data(user)
Esempio n. 12
0
def user_profile_uploadphoto(token, img_url, x_start, y_start, x_end, y_end):
    """
    given url of image on the internet, crops it within bounds.
    """
    # pylint: disable=too-many-arguments
    # This pylint warning is supressed because the function requires 6 arguments

    # Get the image from img_url and check if HTTP status of 200 returned
    try:
        req = urllib.request.Request(img_url,
                                     headers={'User-Agent': 'Mozilla/5.0'})
        response = urllib.request.urlopen(req)
    except:
        raise error.InputError(
            description="The image could not be opened from the given url")

    # Open the image, check if x and y are within dimensions of the image
    img = Image.open(response)
    width, height = img.size
    if x_start < 0 or y_start < 0 or x_end > width or y_end > height:
        raise error.InputError(
            description="Bounds given exceed the dimensions of the image")

    # Check if image type if a JPG
    if img.format != "JPEG":
        raise error.InputError(description="Image given is not of JPG type")

    # Crop the image to the correct dimensions
    img = img.crop((x_start, y_start, x_end, y_end))

    # Get u_id from token
    u_id = database.get_current_user(token)
    img_path = os.path.join(os.path.dirname(__file__), f"static/{u_id}.jpg")

    # Save the image in the static directory
    # image saved as {u_id}.jpg
    img.save(img_path)

    # serve image from file

    profile_img_url = url_for('static', filename=f"{u_id}.jpg", _external=True)

    # Add profile_img_url to database
    user = database.get_user_data(u_id)
    user['profile_img_url'] = profile_img_url
    database.set_user_data(user)

    return {}
def channels_list(token):
    """ Returns {channels}, where channels is a list of channels that the user is part of.
    i.e. {'channels': [{channel_id, name}, {channel_id, name}]} """

    u_id = database.get_current_user(token)

    output = {'channels': []}

    # obtain channels so that I can see lists of members
    # insert channel into the output list if user is a member
    for channel in database.get_channels():
        channeldata = database.get_channel_data(channel['channel_id'])
        if u_id in channeldata['member_ids']:
            output['channels'].append(channel)

    return output
Esempio n. 14
0
 def wrapper_func(*args, **kwargs):
     """ Wrapper function """
     try:
         token_arg_index = argspec.args.index("token")
         # Check the token is valid.
         if database.get_current_user(args[token_arg_index]) is None:
             # Token is invalid
             raise error.AccessError(
                 description="Current token is not valid.")
         else:
             return func(*args, **kwargs)
     except ValueError:
         print("\033[93m" +
               "WARNING: Token arg not found - running function " +
               f"{func.__name__} without token check." + "\033[0m")
         return func(*args, **kwargs)
Esempio n. 15
0
def user_profile_setname(token, name_first, name_last):
    """
    Given input for first and last name sets user's firtname and lastname if within character limit
    """
    if (len(name_first) > 50 or name_first == ""):
        raise error.InputError(
            description="First name is not within 1-50 characters")

    if (len(name_last) > 50 or name_last == ""):
        raise error.InputError(
            description="Last name is not within 1-50 characters")

    u_id = database.get_current_user(token)
    user = database.get_user_data(u_id)
    user['name_first'] = name_first
    user['name_last'] = name_last
    database.set_user_data(user)
Esempio n. 16
0
def channel_addowner(token, channel_id, u_id):
    """
    This function intakes the token of current authorised (auth) user, channel_id and a user u_id
    It then adds the user u_id as an owner of the channel,
    as long as the current auth user is an owner of slackr/channel
    """
    # Check if token is valid and raise AccessError if not
    curr_id = database.get_current_user(token)
    # gets current channel data
    curr_channel = database.get_channel_data(channel_id)
    # gets the permissions of current user from database
    user_perms = database.get_permission_dict(curr_id)

    # check if user u_id is already an owner of the channel and raise InputError if so
    # also checks to see if current auth user is a owner of channel

    # a counter to check if user is a member of the channel
    is_curr_owner = False
    for owner_id in curr_channel["owner_ids"]:
        if u_id == owner_id:
            raise error.InputError(description="user u_id is already an owner of this channel")
        # checks if curr_id is an owner of channel
        if curr_id == owner_id:
            is_curr_owner = True

    # checks if the user u_id is a member of the channel already
    is_u_member = False
    for member_id in curr_channel["member_ids"]:
        if u_id == member_id:
            is_u_member = True


    # if the auth user is an owner of the slackr, allow him to add u_id as owner of channel
    if is_u_member is True:
        if user_perms["permission_id"] == 1:
            # adds the user into channel_owner
            curr_channel["owner_ids"].append(u_id)
        # if the auth user is an owner of the channel, allow him to add u_id as owner of channel
        elif is_curr_owner is True:
            # adds the user into channel_owner
            curr_channel["owner_ids"].append(u_id)
        # else the auth user is not an owner and thus cannot use addowner
        else:
            raise error.AccessError(description="""current user is not an owner of the channel,
                                    or of the slackr""")
def remove_user(token, u_id):
    """ Given a u_id, remove the user from the Slackr. """

    # we get the current user data
    terminator = database.get_current_user(token)

    # Raise AccessError if user is not an owner of the Slackr
    terminator_perm = database.get_permission_dict(terminator)
    if terminator_perm['permission_id'] != 1:
        raise error.AccessError(description="""Action cannot be performed
                                               because you are not a Slackr owner.""")

    # Do a soft remove
    # they stay a part of everything, but they are removed from owner/memberID
    # in channels, and they are also banned from ever logging in again.

    # we get the token of the user to be removed

    # introduce a new permission ID 66:
    # terminated and set the user to be removed to perm_id 66: terminated
    terminated_id = 66
    database.set_permissions(u_id, terminated_id)

    # remove the user from every channel's member_id and owner_id
    #first we call a list of every channel
    all_channels = database.get_channels()
    # we then get the data for each channel
    for each_channel in all_channels:
        channel_data = database.get_channel_data(each_channel["channel_id"])

        # remove user u_id from owner_ids
        for owner_id in channel_data['owner_ids']:
            if u_id == owner_id:
                channel.channel_removeowner(token, channel_data["channel_id"], u_id)

        # remove user u_id from member_ids
        if u_id in channel_data['member_ids']:
            channel_data['member_ids'].remove(u_id)
        database.set_channel_data(channel_data)

    # finally we log the user out of the session (invalidating terminated token)
    terminated_token = database.get_token_from_user(u_id)
    if terminated_token is not None:
        auth.auth_logout(terminated_token)
Esempio n. 18
0
def channel_details(token, channel_id):
    """
    This function is given a valid token and channel_id.
    It then returns the name, owners and members of the channel
    """
    # Check if token is valid and raise AccessError if not
    curr_id = database.get_current_user(token)

    # check if user is a member of channel with channel_ID and return AccessError if not
    if is_user_channel_member(channel_id, curr_id) is False:
        raise error.AccessError(description="""You must be a member of the channel to view its
                                details.""")

    # now we return the name, owners and members of the channel
    details = {"name": "", "owner_members": [], "all_members": []}
    # for owner/all_members we need a list of dictionaries containing u_id, first name and last name
    # {"u_id": [], "name_first": "", "name_last": ""}

    channel = database.get_channel(channel_id)
    members = database.get_channel_data(channel_id)

    details["name"] = channel["name"]
    for user_id in members["owner_ids"]:

        owner_id = user_id
        user_data = database.get_user_data(owner_id)
        name_first = user_data["name_first"]
        name_last = user_data["name_last"]
        profile_img_url = user_data['profile_img_url']
        details["owner_members"].append({"u_id": owner_id, "name_first": name_first,
                                         "name_last": name_last,
                                         "profile_img_url": profile_img_url})

    for user_id in members["member_ids"]:
        member_id = user_id
        user_data = database.get_user_data(member_id)
        name_first = user_data["name_first"]
        name_last = user_data["name_last"]
        profile_img_url = user_data['profile_img_url']
        details["all_members"].append({"u_id": member_id, "name_first": name_first,
                                       "name_last": name_last,
                                       "profile_img_url": profile_img_url})

    return details
Esempio n. 19
0
def channel_removeowner(token, channel_id, u_id):
    """
    This function intakes the token of current authorised (auth) user, channel_id and a user u_id
    It then removes the user u_id as an owner of the channel,
    as long as the current auth user is an owner of slackr/channel
    and the user u_id is an owner
    """
    # Check if token is valid and raise AccessError if not
    curr_id = database.get_current_user(token)
    # gets current channel data
    curr_channel = database.get_channel_data(channel_id)
    # gets the permissions of current user from database
    user_perms = database.get_permission_dict(curr_id)

    u_id_permission = database.get_permission_dict(u_id)
    if u_id_permission["permission_id"] == 1:
        raise error.AccessError(description="user being removed is the owner of the slackr")

    # checks if u_id is not an owner of the channel
    # also checks if current auth user is an owner of the channel
    is_u_owner = False
    is_curr_owner = False
    for owner_id in curr_channel["owner_ids"]:
        if u_id == owner_id:
            is_u_owner = True
        if curr_id == owner_id:
            is_curr_owner = True
    if is_u_owner is False:
        raise error.InputError(description="user being removed is not an owner of the channel")


    # if the auth user is owner of slackr, allows him to remove u_id as owner
    if user_perms["permission_id"] == 1:
        # removes the user from channel_owner
        curr_channel["owner_ids"].remove(u_id)
    # if the auth user is an owner of the channel, allow him to remove u_id as owner of channel
    elif is_curr_owner is True:
        # adds the user into channel_owner
        curr_channel["owner_ids"].remove(u_id)
    # else the auth user is not an owner and thus cannot use addowner
    else:
        raise error.AccessError(description="""Authorised user user is not an owner of the channel,
                                or of the slackr""")
Esempio n. 20
0
def message_edit(token, message_id, message):
    """
    Given a message, update it's text with new text.
    If the new message is an empty string, the message is deleted.
    """
    u_id = get_current_user(token)

    message_location = get_message_location(message_id)

    # if message is longer than 1000 an Inputerror should be raised.
    if len(message) > 1000:
        raise InputError(
            description=
            'Message is more than 1000 characters or try to send an empty message'
        )

    channel_id = message_location["channel_id"]
    channel_data = get_channel_data(channel_id)

    if u_id not in channel_data['member_ids']:
        raise AccessError(
            description="User must be a member of the channel they are trying"
            + " to access.")

    # Find the message to be deleted (assume it definitely exists)
    msg_to_edit = next(msg for msg in channel_data['messages']
                       if msg['message_id'] == message_id)

    if msg_to_edit['u_id'] != u_id and get_permission_dict(
            u_id)['permission_id'] != 1:
        raise AccessError(
            description="Authorised user did not send the message " +
            "and is not a server/channel owner.")

    if message == '':
        remove_message(message_id)
    else:
        msg_to_edit['message'] = message
        set_message(channel_id, msg_to_edit)

    return {}
Esempio n. 21
0
def channel_invite(token, channel_id, u_id):
    """
    Invites a user (with user id u_id) to join a channel with
    ID channel_id. Once invited the user is added to the channel immediately
    """

    if database.get_current_user(token) not in database.get_channel_data(channel_id)['member_ids']:
        raise error.AccessError(description="""Authorised user is not
                                a member of channel with that channel_id.""")
    if u_id in database.get_channel_data(channel_id).get('member_ids'):
        raise error.InputError(description="This user is already a part of the channel.")

    new_channel_data = database.get_channel_data(channel_id)

    new_channel_data['member_ids'].append(u_id)
    if database.get_permission_dict(u_id).get('permission_id') == 1:
        new_channel_data['owner_ids'].append(u_id)

    database.set_channel_data(new_channel_data)

    return {}
Esempio n. 22
0
def channel_join(token, channel_id):
    """
    this function is passed a valid token and channel_id.
    It adds the user associated with the token into the channel, unless the channel is private
    """

    # Check if token is valid and raise AccessError if not
    curr_id = database.get_current_user(token)

    # gets current channel data
    curr_channel = database.get_channel_data(channel_id)
    # gets the permissions of current user from database
    user_perms = database.get_permission_dict(curr_id)

    # checks if user is already a part of channel
    for user_id in curr_channel["member_ids"]:
        if curr_id == user_id:
            raise error.InputError(description="user is joining a channel user is already in")

    # this checks if the channel is empty (or new) in this case we make the new member an owner.
    if curr_channel["member_ids"] == []:
        # adds the user into channel_member
        curr_channel["member_ids"].append(curr_id)
        # adds the user into channel_owner
        curr_channel["owner_ids"].append(curr_id)
    # this checks if the user is an owner of the slacker
    # if they are they are given owner privelages in the channel
    # else they are a member
    elif user_perms["permission_id"] == 1:
        # adds the user into channel_member
        curr_channel["member_ids"].append(curr_id)
        # adds the user into channel_owner
        curr_channel["owner_ids"].append(curr_id)
    elif curr_channel["is_public"] is True:
        # adds the user into the channel_member
        curr_channel["member_ids"].append(curr_id)
    elif curr_channel["is_public"] is False:
        raise error.InputError(description="""channel_join recieved a channel_id
                               for a private channel""")
Esempio n. 23
0
def channel_leave(token, channel_id):
    """
    This function takes in a token and channel ID.
    if both are valid, it will then remove the member from channel
    """

    # Check if token is valid and raise AccessError if not
    curr_id = database.get_current_user(token)

    # check if user is a member of channel with channel_ID and return AccessError if not
    user_channel = is_user_channel_member(channel_id, curr_id)
    if user_channel is False:
        raise error.AccessError(description="user is not a member of this channel")

    # remove user with u_id from the channel (from member_ids)
    curr_channel = database.get_channel_data(channel_id)

    curr_channel["member_ids"].remove(curr_id)
    # if user is an owner it removes them as an owner as well
    for owner_id in curr_channel["owner_ids"]:
        if owner_id == curr_id:
            curr_channel["owner_ids"].remove(curr_id)

    database.set_channel_data(curr_channel)
Esempio n. 24
0
def channel_messages(token, channel_id, start):
    """
    Retrieve a set of 50 or less messages from the channel.
    Returns a {messages, start, end} dictionary.
    """
    # Check if token is valid and raise AccessError if not
    curr_id = database.get_current_user(token)

    # check if user is a member of channel with channel_ID and return AccessError if not
    if is_user_channel_member(channel_id, curr_id) is False:
        raise error.AccessError(description="user is not a member of this channel")

    #get channel data
    curr_channel = database.get_channel_data(channel_id)
    # find the length of messages
    messages_length = len(curr_channel["messages"])

    # if start is after the oldest message in messages InputError is raised
    # if messages is called and start is 0 on an empty channel, it returns an empty channel.
    # if start is after the oldest message in messages InputError is raised

    if messages_length <= start and (messages_length != 0 or start > 0):
        raise error.InputError(description="""The start value selected is
                               past the oldest message in the list""")

    if messages_length == 0 and start == 0:
        return {"messages": [], "start": start, "end": -1}

    # get the list of dictionaries 'message'
    curr_messages = curr_channel["messages"]
    messages_returned = []

    end = start + 50
    num_msgs_to_check = messages_length - start

    # If end is larger than the total no. of messages,
    # the function will print till end and return -1
    if num_msgs_to_check < 50:

        counter = 0
        while counter < num_msgs_to_check:
            target_message_index = start + counter
            messages_returned.append(curr_messages[target_message_index])
            counter += 1

        end = -1
    # else if end is within total no of messages,
    # function will print 50 messaages from start and return start + 50
    else:
        # loop to add each message to return up till 50 messages is returned
        counter = 0
        while counter < 50:
            target_message_index = start + counter
            messages_returned.append(curr_messages[target_message_index])
            counter += 1

    for msg in messages_returned:
        for react in msg['reacts']:
            react['is_this_user_reacted'] = curr_id in react['u_ids']

    return {"messages": messages_returned, "start": start, "end": end}
def test_remove_user():
    """
    Tests if user_remove correctly removes a user from the required parts of database:

    -retained in USERS, PASSWORD_DATA_LIST and in CHANNEL_DATA_LIST (for messages)
    -permission_id of user is now terminated (66)
    -removed from:
        CURRENT_USERS,
        CHANNELS[owner_id]/[member_ID],
    """

    # establish a test register
    test_dict = auth.auth_register("*****@*****.**", "password", "Bob", "Ross")

    # valid channel ID (assigned by channels_create)
    c_id_dict = channels.channels_create(test_dict["token"], "test rum ham", True)

    # create a second user and add them to the channel as an owner
    test_dict_2 = auth.auth_register("*****@*****.**", "password2", "James", "May")
    channel.channel_join(test_dict_2["token"], c_id_dict["channel_id"])
    channel.channel_addowner(test_dict["token"], c_id_dict["channel_id"], test_dict_2["u_id"])

    # store our details before the leave
    details_before = channel.channel_details(test_dict["token"], c_id_dict["channel_id"])
    # ensure there are two members: test_dict & test_dict_2
    assert len(details_before["all_members"]) == 2
    assert details_before["all_members"][0]["u_id"] == test_dict["u_id"]
    assert details_before["all_members"][1]["u_id"] == test_dict_2["u_id"]
    #ensure there are two owners: test_dict & test_dict_2
    assert len(details_before["owner_members"]) == 2
    assert details_before["owner_members"][0]["u_id"] == test_dict["u_id"]
    assert details_before["owner_members"][1]["u_id"] == test_dict_2["u_id"]

    # now we send a message to test rum ham
    message.message_send(test_dict_2["token"], c_id_dict["channel_id"], "hello world")
    # test that messages successfully returns the message
    sent_messages = channel.channel_messages(test_dict["token"], c_id_dict["channel_id"], 0)
    assert sent_messages["messages"][0]["message"] == "hello world"

    ######## Now we call the user_remove function:
    admin.remove_user(test_dict["token"], test_dict_2["u_id"])
    ########

    # we test that they still remain in user
    all_users = database.get_users()
    assert len(all_users) == 2
    assert all_users[0]["u_id"] == test_dict["u_id"]
    assert all_users[1]["u_id"] == test_dict_2["u_id"]

    # we test that their messages can still be printed
    messages_post_remove = channel.channel_messages(test_dict["token"], c_id_dict["channel_id"], 0)
    assert messages_post_remove["messages"][0]["message"] == "hello world"
    assert messages_post_remove["messages"][0]["u_id"] == test_dict_2["u_id"]

    # we test that their permission is changed to 66
    terminated_id = 66
    permissions_post_remove = database.get_permission_dict(test_dict_2["u_id"])
    assert permissions_post_remove["u_id"] == test_dict_2["u_id"]
    assert permissions_post_remove["permission_id"] == terminated_id

    # we test that they are no longer a part of CURRENT_USERS,
    assert database.get_current_user(test_dict_2["token"]) is None

    # we test that they are no longer a part of CHANNELS[owner_id]/[member_ID],
    details_after = channel.channel_details(test_dict["token"], c_id_dict["channel_id"])
    # ensure there is one member: test_dict
    assert len(details_after["all_members"]) == 1
    assert details_after["all_members"][0]["u_id"] == test_dict["u_id"]
    # ensure there is one owner: test_dict
    assert len(details_after["owner_members"]) == 1
    assert details_after["owner_members"][0]["u_id"] == test_dict["u_id"]

    # we test that they are unable to log in again
    password_test = "qwertyuiop"
    with pytest.raises(error.AccessError):
        auth.auth_login("*****@*****.**", "password2")

    # Test that the InputError raised when an unregistered email is entered
    # still takes priority over the AccessError of admin_user_remove.
    with pytest.raises(error.InputError):
        auth.auth_login("*****@*****.**", password_test)

    # Check incorrect password works stil
    with pytest.raises(error.AccessError):
        auth.auth_login("*****@*****.**", password_test)

    with pytest.raises(error.InputError):
        auth.auth_login("wrongemailformat", password_test)