コード例 #1
0
ファイル: server.py プロジェクト: TansonWang/Old-Uni-Projects
def removeowner_channel():
    response = request.get_json()
    token = response['token']
    channel_id = response['channel_id']
    u_id = response['u_id']
    channel_removeowner(token, channel_id, u_id, da.USERS, da.CHANNEL)
    return dumps({})
コード例 #2
0
def test_removeowner_non_owner():
    '''Function cannot remove u_id from owners list if u_id is not channel owner'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi')
    other_user_id = data_two['u_id']
    with pytest.raises(InputError):
        channel_removeowner(token, channel_id['channel_id'], other_user_id)
コード例 #3
0
def test_removeowner_invalid_channel_id():
    '''Function won't run with invalid channel_id'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    assert channel_id['channel_id'] == 1
    data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi')
    other_user_id = data_two['u_id']
    with pytest.raises(InputError):
        channel_removeowner(token, 2, other_user_id)
コード例 #4
0
def test_removeowner_authorised_non_owner():
    '''Function won't run if authorised user is not owner of channel'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi')
    user_two_id = data_two['u_id']
    channel_addowner(token, channel_id['channel_id'], user_two_id)
    data_three = auth_register('*****@*****.**', 'cs1531', 'Yuri', 'Jo')
    token_three = data_three['token']
    with pytest.raises(AccessError):
        channel_removeowner(token_three, channel_id['channel_id'], user_two_id)
コード例 #5
0
def test_channel_removeowner():
    '''Function should remove owner based on their u_id in specified channel'''
    reset_data()
    data = auth_register('*****@*****.**', 'cs1531', 'Kevin', 'Trang')
    token = data['token']
    channel_id = channels_create(token, 'Channel One', True)
    data_two = auth_register('*****@*****.**', 'cs1531', 'Yena', 'Choi')
    other_user_id = data_two['u_id']
    channel_addowner(token, channel_id['channel_id'], other_user_id)
    assert channel_removeowner(token, channel_id['channel_id'],
                               other_user_id) == {}
コード例 #6
0
def user_remove(token, u_id):
    email = check_token(token)
    database = get_data()
    for user in database["users"]:
        if user["email"] == email:
            if user["permissions"]["global"] != 1:
                raise AccessError(description='Given token is not from owner')
    for user in database["users"]:
        if user["u_id"] == u_id:
            for channel in database["channels"]:
                if u_id in channel["members"]:
                    for message in channel['messages']:
                        if message['u_id'] == u_id:
                            message_remove(token, message['message_id'])
                if u_id in channel['owners']:
                    channel_removeowner(token, channel['channel_id'], u_id)
                elif u_id in channel["members"]:
                    channel["members"].remove(u_id)
            database["users"].remove(user)
            with open('data_store.json', 'w') as FILE:
                json.dump(database, FILE)
            return {}
    raise InputError(description='Invalid u_id')
コード例 #7
0
ファイル: channel.py プロジェクト: joeyvu/MessagingPlatform
def removeowner():
    '''Removes user with u_id as the owner of the channel'''
    details = request.get_json()
    return dumps(
        channel_removeowner(details['token'], details['channel_id'],
                            details['u_id']))