Exemplo n.º 1
0
def update_message():
    channel_store = get_channel_store()
    # The following piece of code does the following:
    # 1. Loop through each of the channels
    # 2. Check if message at the end of statdup is sent
    # 3. If not send the message
    for channel in channel_store['Channels']:
        if (not channel['standup']['is_message_sent']) and (channel['standup']['time_standup_finished'] is not None):
            user = u_id_check(channel['standup']['u_id_standup_started'])
            if (int(datetime.utcnow().replace(tzinfo=timezone.utc).timestamp()) > int(channel['standup']['time_standup_finished'])):
                message_send(user['token'], channel['channel_id'], channel['standup']['standup_message'])
    return
def get_all():
    # Get current data inside store
    data = request.get_json()
    token = data['token']
    u_id = data['token']
    # Authenticate if token is a valid token
    if not u_id_check(u_id):
        raise InputError
    profile = user_profile(token, u_id)

    return dumps({
        'user': profile
    })
Exemplo n.º 3
0
def user_profile(token, u_id):
    if token_check(token) == False:
        raise InputError

    # First we need to assert if the u_id is registered
    if u_id_check(u_id) == False:
        raise InputError

    # get required user dict

    user = u_id_check(u_id)
    # create a dict of what we need

    user_prof_dict = {
        'u_id': user['u_id'],
        'email': user['email'],
        'name_first': user['name_first'],
        'name_last': user['name_last'],
        'handle_str': user['handle_str'],
        'profile_img_url': user['profile_img_url'],
    }
    return user_prof_dict
def channel_invite(token, channel_id, u_id):
    ''' Invites a user to join a channel that they are not already in
    
        Parameters: 
            token (str): authorization hash 
            channel_id (int): channel identification
            u_id (int): unique user identification
       
    '''

    if not channel_check(channel_id):
        raise InputError

    if not u_id_check(u_id):
        return InputError

    if check_if_user_in_channel_member_uid(u_id, channel_id):
        raise AccessError

    channel_store = get_channel_store()
    user = u_id_check(u_id)
    for channel in channel_store["Channels"]:
        if channel["channel_id"] == channel_id:
            channel["all_members"].append({
                "u_id":
                user["u_id"],
                "name_first":
                user['name_first'],
                "name_last":
                user["name_last"],
                'profile_img_url':
                user['profile_img_url']
            })

    user['channel_id_part'].append(channel_id)

    return {}
Exemplo n.º 5
0
def user_remove(token, u_id):
    user_remove = u_id_check(u_id)
    permission = get_permission_store()

    if user_remove == False:
        raise InputError
    user_action = token_check(token)
    print(user_action['u_id'])
    print(permission['USER_NUM'])
    if user_action['u_id'] != permission['USER_NUM'][0]:
        print('raise access error')
        raise AccessError

    remove_from_channel(u_id)
    remove_from_user(u_id)
def channel_addowner(token, channel_id, u_id):
    '''Adds someone as owner to a channel.
   
        Parameters: 
            token (str): authorization hash 
            channel_id (int): channel identification
            u_id (int): user identification 
        
    '''
    if channel_check(channel_id) == False:
        raise InputError

    if check_if_user_in_channel_owner_uid(u_id, channel_id) == True:
        raise InputError

    permission_error = token_check(token)

    if check_if_user_in_channel_owner(token, channel_id) == False:
        if permission_error['permission_id'] != 1:
            raise AccessError
        else:
            pass

    channel_store = get_channel_store()
    user = u_id_check(u_id)

    for channel in channel_store["Channels"]:
        if channel["channel_id"] == channel_id:
            if member_channel_check(user['token'], channel_id) == False:
                channel["all_members"].append({
                    "u_id": user["u_id"],
                    "name_first": user['name_first'],
                    "name_last": user["name_last"]
                })
            channel["owner_members"].append({
                "u_id": user["u_id"],
                "name_first": user['name_first'],
                "name_last": user["name_last"]
            })

    user['channel_id_owned'].append(channel_id)
    user['channel_id_part'].append(channel_id)
    return {}
Exemplo n.º 7
0
def get_all():
    """ This is a flask wrapper for the user_profile function

    Parameters:
        No parameters

    Returns:
        (dictionary): A dictionary which contains information
        about user_id, email, first name, last name and handle
    """
    # Get current data inside store
    token = request.args.get("token")
    u_id = request.args.get("u_id")

    # Check for valid u_id
    if not u_id_check(u_id):
        raise InputError(description="u_id is not valid")

    profile = user_profile(token, u_id)
    return dumps({
        'user':profile
    })
def channel_removeowner(token, channel_id, u_id):
    '''Removes someone from owner to a channel.
   
        Parameters: 
            token (str): authorization hash 
            channel_id (int): channel identification
            u_id (int): user identification 
        
    '''
    if channel_check(channel_id) == False:
        raise InputError

    if check_if_user_in_channel_owner_uid(u_id, channel_id) == False:
        raise InputError

    permission_error = token_check(token)

    if check_if_user_in_channel_owner(token, channel_id) == False:
        if permission_error['permission_id'] != 1:
            raise AccessError
        else:
            pass

    user = u_id_check(u_id)
    channel_store = get_channel_store()
    for channel in channel_store["Channels"]:
        if channel["channel_id"] == channel_id:
            for member in channel["owner_members"]:
                if member["u_id"] == u_id:
                    channel["owner_members"].remove(member)

    for leave in user['channel_id_owned']:
        if leave == channel_id:
            user['channel_id_owned'].remove(leave)

    return {}