def is_slackr_owner(token): """ Determine whether the user owns the slackr """ owners = get_slackr_owners() u_id = check_token(token) return u_id in owners
def permission_change(token, u_id, permission_id): '''change a user's permissions on the server :param token: jwt token :type token: str :param u_id: User id corresponding to the target user :type u_id: int :param permission_id: ID of user new permissions :type permission_id: int :raises InputError: u_id does not correspond to a user :raises InputError: Invalid Permission ID :raises AccessError: User is not a slackr owner :return: empty dictionary :rtype: dict ''' user_id = check_token(token) if not user_id in get_slackr_owners(): raise AccessError( description='You are not permitted to perform this action') if not is_valid_user(u_id): raise InputError(description='User does not exist') if permission_id not in (1, 2): raise InputError(description='Invalid permission ID') # all possible errors raised. if permission_id == 1: get_users()[u_id]['is_owner'] = True elif permission_id == 2: get_users()[u_id]['is_owner'] = False return {}
def channel_join(token, channel_id): ''' Adds a user to a channel if they are authorised to join it ''' user_id = check_token(token) if not is_valid_channel(channel_id): raise InputError(description="No channel found with that ID") if not is_channel_public( channel_id) and not user_id in get_slackr_owners(): raise AccessError(description="This channel is private") get_channel_members(channel_id).append(user_id) return {}
def test_application_clean(): ''' Tests that all global variables have been emptied by the reset ''' for new_user in range(100): user = auth_register("z55555" + str(new_user) + "@unsw.edu.au", "f for hayden rip", "hydaen", "smith") channels_create(user['token'], "test channel" + str(new_user), True) workspace_reset() assert len(get_channels().keys()) == 0 assert len(get_users().keys()) == 0 assert len(get_users()) == 0 assert len(get_slackr_owners()) == 0 assert len(get_valid_tokens()) == 0 original_image_folder = os.path.join(os.getcwd(), 'images/original') assert len(os.listdir(original_image_folder)) == 1 cropped_image_folder = os.path.join(os.getcwd(), 'images/cropped') assert len(os.listdir(cropped_image_folder)) == 1
def user_remove(token, u_id): ''' Removes a user from a channel, only a slackr Owner can use this function ''' host_user_id = check_token(token) if not is_valid_user(u_id): raise InputError if not host_user_id in get_slackr_owners(): raise AccessError for channel_id in get_channels(): if is_user_a_owner(channel_id, u_id): get_channel_owners(channel_id).remove(u_id) elif is_user_a_member(channel_id, u_id): get_channel_members(channel_id).remove(u_id) glob_users = get_users() glob_users[u_id]['disabled'] = True return {}
def channel_removeowner(token, channel_id, user_id): ''' Makes a channel owner a regular channel member the token must be one of the channel owners or the slackr owner ''' owner_id = check_token(token) if not is_valid_channel(channel_id): raise InputError if not is_user_a_owner(channel_id, owner_id) and not owner_id in get_slackr_owners(): raise AccessError if not is_user_a_owner(channel_id, user_id): raise InputError if is_user_a_owner(channel_id, user_id): get_channel_owners(channel_id).remove(user_id) get_channel_members(channel_id).append(user_id) return {}
def is_user_a_slackr_owner(user_id): ''' returns true is user is a slackr owner ''' return user_id in get_slackr_owners()