def check_if_channel_exists(channel_id):
    channel_store = get_channel_store()
    result = False
    for id in channel_store['Channels']:
        if id['channel_id'] == int(channel_id):
            result = True
    return result
def channel_list(token):
    '''Lists channels a user is apart of.

        Parameters: 
            token (str): authorization hash 
            name (string): what channel will be named
            is_public (bool): true/false for public channel
        
        Returns: 
            (int): channel id 
    '''

    if token_check(token) == False:

        raise InputError
    channel_store = get_channel_store()
    user = token_check(token)
    empty_list = []
    for channels in channel_store["Channels"]:
        for member in channels['all_members']:
            if member["u_id"] == user["u_id"]:
                empty_list.append({
                    "channel_id": channels["channel_id"],
                    "name": channels["name"]
                })
    return {'channels': empty_list}
def check_if_user_in_channel_member_uid(u_id, channel_id):
    channel_store = get_channel_store()
    result = False
    for mem_check in channel_store["Channels"]:
        if mem_check['channel_id'] == channel_id:
            for mem in mem_check['all_members']:
                if mem["u_id"] == u_id:
                    result = True
    return result
def check_if_user_in_channel_owner(token, channel_id):
    user = token_check(token)
    channel_store = get_channel_store()
    result = False
    for mem_check in channel_store["Channels"]:
        if mem_check['channel_id'] == channel_id:
            for mem in mem_check['owner_members']:
                if mem["u_id"] == user["u_id"]:
                    result = True
    return result
def check_if_channel_is_public(channel_id):
    channel_store = get_channel_store()
    result = False
    for pub in channel_store['Channels']:

        if pub['channel_id'] == int(channel_id):

            if pub['is_public'] == True:
                result = True
    return result
def test_channels_create_valid():
    channel_id = channels_create(hamish_token['token'], 'New_channel', True)
    # Now to call our storage and assert that the channel_id is present in our store
    channel_store = get_channel_store()
    result = False
    for probe in channel_store['Channels']:
        if probe['channel_id'] == channel_id['channel_id']:
            result = True
    # Now we assert the value of result
    assert (result == True)
Example #7
0
def update_standup():
    channel_store = get_channel_store()
    for channel in channel_store['Channels']:
        if (not channel['standup']['is_message_sent']) and (channel['standup']['time_standup_finished'] is not None):
            if (int(datetime.utcnow().replace(tzinfo=timezone.utc).timestamp()) > int(channel['standup']['time_standup_finished'])):
                channel['standup']['is_standup_active'] = False
                channel['standup']['time_standup_finished'] = None
                channel['standup']['u_id_standup_started'] = 0
                channel['standup']['is_message_sent'] = True
                channel['standup']["standup_message"] = ""
    return
Example #8
0
def c_create():
    
    data = request.get_json()

    token = data['token']
    name = data['name']
    is_public = bool(data['is_public'])

    channel_id = channels_create(token, name, is_public)
    print(get_channel_store())
    #message_id = {'message_id':1}
    return dumps(channel_id)
Example #9
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 check_if_user_in_channel_member(token, channel_id):
    user = token_check(token)
    channel_store = get_channel_store()
    result = False

    for mem_check in channel_store["Channels"]:

        if int(mem_check['channel_id']) == int(channel_id):

            for mem in mem_check['all_members']:

                if int(mem["u_id"]) == int(user["u_id"]):

                    result = True
    return result
def workspace_reset():
    store = get_user_store()
    pemrission_store = get_permission_store()
    channel_store = get_channel_store()
    message_store = get_messages_store()
    store = {
        'users': []
    }
    channel_store = {
        'Channels':[]
    }
    message_store = {
        'Messages': []
    }
    pemrission_store = {}
    return None
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 {}
def channels_list_all(token):
    '''Returns all channels.
    
        Parameters: 
            token (str): authorization hash 
        
        Returns: 
            (list):  list of channels
    '''

    if token_check(token) == False:
        raise InputError

    channel_store = get_channel_store()
    empty_list = []

    for channels in channel_store['Channels']:
        empty_list.append({
            "channel_id": channels["channel_id"],
            "name": channels["name"]
        })
    return {'channels': empty_list}
def channel_join(token, channel_id):
    '''Adds a member to a channel.
    
        Parameters: 
            token (str): authorization hash 
            channel_id (int): channel identification
        
    '''
    if channel_check(channel_id) == False:

        raise InputError

    if (check_if_channel_is_public(channel_id) == False
            or check_if_user_in_channel_member(token, channel_id) == True):

        raise AccessError

    channel_store = get_channel_store()
    channel = channel_check(channel_id)
    user = token_check(token)

    for channel in channel_store["Channels"]:
        #print("gets in for loop")
        if channel["channel_id"] == int(channel_id):
            #print("gets in if statement")
            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 {}
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 {}
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 {}
def channels_create(token, name, is_public):
    '''Creates a new channel.
   
        Parameters: 
            token (str): authorization hash 
            name (string): what channel will be named
            is_public (bool): true/false for public channel
        
        Returns: 
            (int): channel id 
        
    '''
    if len(name) > 20:
        raise InputError

    channel_dict = {
        'channel_id': int(len(name) + len(token) + randrange(25000)),
        'owner_members': [],
        'all_members': [],
        'is_public': bool(is_public),
        'name': name,
        'standup': {
            'is_standup_active': False,
            'time_standup_finished': None,
            "standup_message": "",
            'u_id_standup_started': 0,
            'is_message_sent': True
        },
        'Hangman': {
            'is_hangman_active': False,
            'Guess': ""
        }
    }

    store = get_channel_store()

    store1 = get_user_store
    user_store = token_check(token)

    if user_store == False:
        raise InputError(description="channel create user not found")

    channel_dict['owner_members'].append({
        'u_id':
        user_store['u_id'],
        'name_first':
        user_store['name_first'],
        'name_last':
        user_store['name_last'],
        'profile_img_url':
        user_store['profile_img_url']
    })

    channel_dict['all_members'].append({
        'u_id':
        user_store['u_id'],
        'name_first':
        user_store['name_first'],
        'name_last':
        user_store['name_last'],
        'profile_img_url':
        user_store['profile_img_url']
    })

    store['Channels'].append(channel_dict)
    user_store['channel_id_owned'].append(channel_dict["channel_id"])
    user_store['channel_id_part'].append(channel_dict["channel_id"])

    return {'channel_id': channel_dict["channel_id"]}