Exemple #1
0
def validate_remove(data, token, messageId):
    if token in data['tokens']:
        pass
    else:
        raise ValueError("invalid token")
    u_id = getUserFromToken(token)
    userIsInChannel(data, channel_id, getUserFromToken(token))
    exists = False
    for channel in data['channels']:
        for message in channel['messages']:
            if message['u_id'] == u_id:
                if message['message_id'] == messageId:
                    exists = True
    if exists == False:
        raise ValueError("Invalid IDs")
Exemple #2
0
def listAll():
    # Returns a list of all the PUBLIC channels (as well as PRIVATE channels if the user is a member of any).
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)

    return sendSuccess({'channels': channelListAll(data, u_id)})
Exemple #3
0
def validate_remove(data, token, messageId):
    if token in data['tokens']:
        pass
    else:
        raise ValueError("invalid token")
    channel_id = 0
    messagereal = False
    for channel in data['channels']:
        for message in channel['messages']:
            if message['message_id'] == messageId:
                channel_id = channel['channel_id']
                messagereal = True
    if messagereal == False:
        raise ValueError("cant find message")
    u_id = getUserFromToken(token)
    #userIsInChannel(data, channel_id, getUserFromToken(token))
    if isUserinChannelbool(data, channel_id, u_id) == False:
        raise AccessError("User is not in that channel 184msg helper")
    exists = False
    ownmessage = False
    #adminCalling = False
    adminCalling = isAdminOrOwner(data, u_id)
    for channel in data['channels']:
        for message in channel['messages']:
            if message['message_id'] == messageId:
                exists = True
                if message['u_id'] == u_id:
                    ownmessage = True
    if exists == False:
        raise ValueError("Invalid IDs")
    if ownmessage == False:
        if adminCalling == False:
            raise AccessError("Not an admin or owner or own message")
Exemple #4
0
def list():
    # Returns a list of all the PUBLIC and PRIVATE channels that the user is a member of.
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)

    return sendSuccess({'channels': channelList(data, u_id)})
Exemple #5
0
def messageUnreact():
    token = request.form.get('token')
    checkTokenValidity(token, data)
    messageId, reactId = (request.form[x] for x in ('message_id', 'react_id'))
    u_id = getUserFromToken(token)
    unreactMessage(data, messageId, reactId, token)
    return dumps({})
Exemple #6
0
def user_profile_sethandle(data, token, handle_str):

    # Check if the handle is valid
    letter_number = True

    # Assumption: Has to be letter or number
    for i in handle_str:
        if not (i.isdigit() or i.isalpha()):
            letter_number = False

    if len(handle_str) > 20:
        raise ValueError("Should be no more than 20 characters")

    elif letter_number == False:
        raise ValueError("Handle can only be letters and digits")

    elif not handle_str:
        raise ValueError("Handle cannot be empty")

    # Reset it
    # Decode token to match user
    u_id = getUserFromToken(token)

    for user in data['users']:
        if user['handle'] == handle_str:
            raise ValueError("Handle is already being used")
        elif user['u_id'] == u_id:
            user['handle'] = handle_str
Exemple #7
0
def message_send(data, message, channelid, token):
    u_id = getUserFromToken(token)
    validate_message(data, message, channel_id, token, u_id)
    messageId = randrange(99999)
    for channel in data['channels']:
        while messageId in channel['messages']['message_id']:
            messageId = randrange(99999)
    data['channels']['messages'].append({
        'message_id':
        messageId,
        'u_id':
        u_id,
        'message':
        message,
        'time_created':
        time,
        'reacts': [{
            'react_id': 0,
            'u_id': u_id,
            'is_this_user_reacted': 0,
        }],
        'is_pinned':
        0,
    })
    return messageId
def admin_userpermission_change(data, token, u_id, permission_id):
    # Decode token to match user
    auth_u_id = getUserFromToken(token)

    # Check whether auth_u_id has the permission to change
    for auth_user in data['users']:
        if auth_user['u_id'] == auth_u_id:
            if not auth_user['is_admin'] == PERMISSION1 and \
                not auth_user['is_admin'] == PERMISSION2:

                raise AccessError(
                    'The authorised user is not an admin or owner')

    # Check permission_id
    if permission_id != PERMISSION1 and \
        permission_id != PERMISSION2 and \
        permission_id != PERMISSION3:

        raise ValueError('permission_id does not refer to a value permission')

    # Check if u_id (the one that needs to be modified) exists
    exist = False
    for user in data['users']:
        if user['u_id'] == u_id:
            exist = True
            user['is_admin'] = permission_id

    # Raise error if u_id does not exist
    if exist == False:
        raise ValueError("u_id does not refer to a valid user")
Exemple #9
0
def leaveChannel():
    data = getData()
    token = request.form.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    channel_id = int(request.args.get('channel_id'))

    removeUserFromChannel(data, int(channel_id), u_id)
    return sendSuccess({})
Exemple #10
0
def addOwner():
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    new_owner_u_id = request.form.get('u_id')
    channel_id = request.form.get('channel_id')

    addOwnerToChannel(data, channel_id, u_id, new_owner_u_id)
    return sendSuccess({})
Exemple #11
0
def removeOwner():
    token = request.form.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    target_owner_u_id, channel_id = (request.form[x]
                                     for x in ('u_id', 'channel_id'))

    removeOwnerFromChannel(data, int(channel_id), u_id, int(target_owner_u_id))
    return sendSuccess({})
Exemple #12
0
def removeOwner():
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    target_owner_u_id = request.form.get('u_id')
    channel_id = request.form.get('channel_id')

    removeOwnerFromChannel(data, channel_id, u_id, target_owner_u_id)
    return sendSuccess({})
Exemple #13
0
def standupEnd(data, channel_id, token, finish):
    u_id = getUserFromToken(token)
    for channel in data['channels']:
        if str(channel_id == channel['channel_id']):
            standupEndTime = channel['standup_end'] - datetime.datetime.now()
            if (channel['standup_active'] is True):
                standupTerminate(data, channel_id, token, standupEndTime)
                message = channel['standup_messages']
                message_send(data, message, channel_id, token)
Exemple #14
0
def channelJoin():
    data = getData()
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    channel_id = request.form.get('channel_id')

    joinChannel(data, channel_id, u_id)
    return sendSuccess({})
Exemple #15
0
def validate_message(data, message, channelid, token, u_id):
    if channelid in data['channels']:
        pass
    else:
        raise ValueError("invalid token")
    u_id = getUserFromToken(token)
    userIsInChannel(data, channelid, u_id)
    if len(message) > 1000:
        raise ValueError(
            "ValueError when:Message is more than 1000 characters")
Exemple #16
0
def channelDetails():
    data = getData()
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    channel_id = int(request.args.get('channel_id'))

    userIsInChannel(data, channel_id, u_id)

    return sendSuccess(getDetails(data, channel_id))
Exemple #17
0
def editMessage(data, messageId, newMessage, token):
    for channel in data['channels']:
        for message in channel['messages']:
            if message['message_id'] == messageId:
                channel_id = channel['channel_id']
    u_id = getUserFromToken(token)
    validate_message(data, newMessage, channel_id, token, u_id)
    validate_remove(data, token, messageId)
    for channel in data['channels']:
        for message in channel['messages']:
            if message['message_id'] == messageId:
                message['message'] = newMessage
Exemple #18
0
def channelInvite():
    data = getData()
    token = request.form.get('token')
    checkTokenValidity(token, data)
    channel_id, u_id = (request.form[x] for x in ('channel_id', 'u_id'))

    userIsInChannel(data, int(channel_id), getUserFromToken(token))
    if validUser(data, int(u_id)) is False:
        raise ValueError('The invitee is an invalid user.')

    addUserToChannel(data, int(channel_id), int(u_id))
    return sendSuccess({})
Exemple #19
0
def standup_send(data, token, channel_id, message):
    u_id = getUserFromToken(token)
    if channelExists(data, channel_id) is False:
        return ValueError("Channel ID is not a valid channel.")
    if userIsInChannel(data, channel_id, u_id) is False:
        return AccessError
    if len(message) > 1000:
        return ValueError ("Message exceeds 1000 char limit.")

    if standupActive(data, channel_id, u_id):
        #do seomthing
    else:
        raise ValueError ("An active standup is not currently running in this channel.")
Exemple #20
0
def user_profile_setemail(data, token, email):
    # Decode token to match user
    u_id = getUserFromToken(token)

    # Check email is vaild, use function in auth_register_helper
    checkEmail(email)

    # Reset
    for user in data['users']:
        if email in user['email']:
            raise ValueError("Email address is already being used")
        elif user['u_id'] == u_id:
            user['email'] = email
Exemple #21
0
def validate_messageLater(data, message, channelid, token, timeSend, Realtime):
    if channelid in data['channels']:
        pass
    else:
        raise ValueError("invalid token")
    u_id = getUserFromToken(token)
    userIsInChannel(data, channelid, u_id)

    #value error: Time sent is a time in the past
    #Value Error time sent is in past
    if len(message) > 1000:
        raise ValueError(
            "ValueError when:Message is more than 1000 characters")
Exemple #22
0
def validate_message(data, message, channelid, token, u_id):
    exists = False
    for channel in data['channels']:
        if str(channel['channel_id']) == str(channelid):
            exists = True
    if exists == False:
        raise ValueError("bad channel Id")
    u_id = getUserFromToken(token)
    #userIsInChannel(data, channelid, u_id)
    if isUserinChannelbool(data, channelid, u_id) == False:
        raise AccessError("User is not in that channel 184msg helper")
    if len(message) > 1000:
        raise ValueError(
            "ValueError when:Message is more than 1000 characters")
Exemple #23
0
def standup_send(data, token, channel_id, message):
    u_id = getUserFromToken(token)
    if channelExists(data, channel_id) is False:
        return ValueError("Channel ID is not a valid channel.")
    if userIsInChannel(data, channel_id, u_id) is False:
        return AccessError
    if len(message) > 1000:
        return ValueError("Message exceeds 1000 char limit.")
    if standupStillActive(data, channel_id, u_id):
        alteredMessage = u_id + ":" + message
        data['channels']['channel_id']['standup_messages'] += alteredMessage
    else:
        raise ValueError(
            "An active standup is not currently running in this channel.")
Exemple #24
0
def validate_messageLater(data, message, channelid, token, timeSend, Realtime):
    if channelid in data['channels']:
        pass
    else:
        raise ValueError("invalid token")
    u_id = getUserFromToken(token)
    #userIsInChannel(data, channelid, u_id)
    if isUserinChannelbool(data, channelid, u_id) == False:
        raise AccessError("User is not in that channel 184msg helper")

    #value error: Time sent is a time in the past
    #Value Error time sent is in past
    if len(message) > 1000:
        raise ValueError(
            "ValueError when:Message is more than 1000 characters")
Exemple #25
0
def listAll():
    # Returns a list of all the PUBLIC channels (as well as PRIVATE channels if the user is a member of any).
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)

    returnList = []
    for channel in data['channels']:
        if channel['is_public'] is True or u_id in channel['members']:
            positiveChannel = {
                'channel_id': channel['channel_id'],
                'name': channel['name'],
            }
            returnList.append(positiveChannel)
    return sendSuccess({'channels': returnList})
Exemple #26
0
def list():
    # Returns a list of all the PUBLIC and PRIVATE channels that the user is a member of.
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)

    returnList = []
    for channel in data['channels']:
        if u_id in channel['members']:
            positiveChannel = {
                'channel_id': channel['channel_id'],
                'name': channel['name'],
            }
            returnList.append(positiveChannel)
    return sendSuccess({'channels': returnList})
Exemple #27
0
def standupSendFunc(data, token, channel_id, message):
    u_id = getUserFromToken(token)
    if channelExists(data, channel_id) is False:
        raise ValueError("Channel ID is not a valid channel.")
    if userIsInChannel(data, channel_id, u_id) is False:
        return AccessError("User is not in the channel.")
    if len(message) > 1000:
        raise ValueError ("Message exceeds 1000 char limit.")
    if standupStillActive(data, channel_id, u_id):
        alteredMessage = str(u_id) + ":" + message
        for channel in data['channels']:
            if channel == channel_id:
                channel['standup_message'].append(alteredMessage)
    else:
        raise ValueError ("An active standup is not currently running in this channel.")
Exemple #28
0
def createChannel():
    data = getData()
    token = request.form.get('token')
    checkTokenValidity(token, data)
    name, is_public = (request.form[x] for x in ('name', 'is_public'))

    checkTokenValidity(token, data)
    channelNameCheck(name)
    u_id = getUserFromToken(token)

    channel_id = channelsCreate(data, u_id, name, is_public)

    print(data['channels'])
    return sendSuccess({
        'channel_id': channel_id,
    })
Exemple #29
0
def channelMessages():
    data = getData()
    token = request.args.get('token')
    checkTokenValidity(token, data)
    u_id = getUserFromToken(token)
    channel_id = request.form.get('channel_id')
    start = request.form.get('start')

    userIsInChannel(data, channel_id, u_id)

    # TODO
    return sendSuccess({
        #'messages': messages,
        'start': start,
        #'end': end,
    })
Exemple #30
0
def createChannel():
    data = getData()
    token = request.args.get('token')
    checkTokenValidity(token, data)
    name = request.form.get('name')
    is_public = request.form.get('is_public')  # Expects True or False

    checkTokenValidity(token, data)
    channelNameCheck(name)
    u_id = getUserFromToken(token)

    channel_id = channelsCreate(data, u_id, name, is_public)

    print(data['channels'])
    return sendSuccess({
        'channel_id': channel_id,
    })