def remove_user_from_organization(organization, username):
    logging.debug('remove_user_from_organization %s - %s', organization, username)
    try:
        result = get_itsyouonline_client().organizations.RemoveOrganizationMember(username, organization)
        logging.debug('remove_user_from_organization %s %s', result.status_code, result.text)
    except HTTPError as e:
        raise_for_other_statuses(e, [])
Example #2
0
def update_grant(username, oldgrant, newgrant):
    client = get_itsyouonline_client()
    data = UpdateGrantBody(username=convert_to_str(username),
                           oldgrant=oldgrant,
                           newgrant=newgrant)
    return client.organizations.UpdateUserGrant(data,
                                                get_iyo_organization_id())
def add_user_to_organization(organization, username):
    logging.debug('add_user_to_organization %s - %s', organization, username)
    try:
        data = AddOrganizationMemberReqBody(searchstring=username)
        result = get_itsyouonline_client().organizations.AddOrganizationMember(data, organization)
        logging.debug('add_user_to_organization %s %s', result.status_code, result.text)
    except HTTPError as e:
        raise_for_other_statuses(e, [httplib.CONFLICT])
Example #4
0
def add_user_to_public_role(user_detail):
    client = get_itsyouonline_client()
    username = get_iyo_username(user_detail)
    organization_id = Organization.get_by_role_name(Roles.MEMBERS)
    if has_access_to_organization(client, organization_id, username):
        logging.info('User is already in members role, not adding to public role')
    else:
        add_user_to_role(user_detail, RogerthatRoles.PUBLIC)
Example #5
0
def add_user_to_public_role(user_detail):
    client = get_itsyouonline_client()
    username = get_iyo_username(user_detail)
    grant = Grants.get_by_role_name(Roles.MEMBERS)
    if has_grant(client, username, grant):
        logging.info(
            'User is already in members role, not adding to public role')
    else:
        add_user_to_role(user_detail, RogerthatRoles.PUBLIC)
def get_organization_users(organization, permission_type):
    logging.debug('get_organization_users %s', organization)
    try:
        rpc = get_itsyouonline_client().organizations.GetOrganizationUsers
        args = {'globalid': organization}
        result = _create_org_if_not_exists(rpc, organization, permission_type, args)
        logging.debug('get_organization_users %s %s', result.status_code, result.text)
        return [organization_member['username'] for organization_member in result.json()['users']]
    except HTTPError as e:
        raise_for_other_statuses(e, [])
Example #7
0
def is_user_in_roles(user_detail, roles):
    client = get_itsyouonline_client()
    username = get_iyo_username(user_detail)
    result = []
    for role in roles:
        organization_id = Organization.get_by_role_name(role.name)
        if not organization_id:
            continue
        if has_access_to_organization(client, organization_id, username):
            result.append(role.id)
    return result
Example #8
0
def invite_user_to_organization(username, organization_id):
    logging.info('Inviting user %s to IYO organization %s', username,
                 organization_id)
    client = get_itsyouonline_client()
    try:
        data = AddOrganizationMemberReqBody(
            searchstring=convert_to_str(username))
        client.api.organizations.AddOrganizationMember(
            data=data, globalid=organization_id)
    except HTTPError as e:
        if e.response.status_code != httplib.CONFLICT:
            raise e
Example #9
0
def is_user_in_roles(user_detail, roles):
    result = []
    client = get_itsyouonline_client()
    username = get_iyo_username(user_detail)
    if not username:
        return result
    for role in roles:
        grant = Grants.get_by_role_name(role.name)
        if not grant:
            continue
        if has_grant(client, username, grant):
            result.append(role.id)
    return result
def create_organization(organization):
    """
    Creates an organization if it doesn't exist already
    Args:
        organization (unicode)
    """
    logging.debug('create_organization %s', organization)
    parent_organization = organization.rsplit('.', 1)[0]
    data = {
        'globalid': organization
    }
    try:
        result = get_itsyouonline_client().organizations.CreateNewSubOrganization(data, parent_organization)
        logging.debug('create_organization %s %s', result.status_code, result.text)
    except HTTPError as e:
        raise_for_other_statuses(e, [httplib.CONFLICT])
Example #11
0
def remove_user_from_organization(username, organization_id):
    logging.info('Removing user %s from IYO organization %s', username,
                 organization_id)
    client = get_itsyouonline_client()
    client.api.organizations.RemoveOrganizationMember(convert_to_str(username),
                                                      organization_id)
def get_organization_invited_users(organization):
    result = get_itsyouonline_client().organizations.GetInvitations(organization)
    return [InvitationTO(**invite) for invite in result.json()]
Example #13
0
def remove_all_grants(username):
    client = get_itsyouonline_client()
    return client.organizations.DeleteAllUserGrants(convert_to_str(username),
                                                    get_iyo_organization_id())
Example #14
0
def remove_grant(username, grant):
    client = get_itsyouonline_client()
    return client.organizations.DeleteUserGrant(grant,
                                                convert_to_str(username),
                                                get_iyo_organization_id())
Example #15
0
def add_grant(username, grant):
    client = get_itsyouonline_client()
    data = CreateGrantBody(username=convert_to_str(username), grant=grant)
    return client.organizations.CreateUserGrant(data,
                                                get_iyo_organization_id())
Example #16
0
def list_all_users_with_grant(grant):
    client = get_itsyouonline_client()
    return client.organizations.ListUsersWithGrant(grant,
                                                   get_iyo_organization_id())
Example #17
0
def list_grants(username):
    client = get_itsyouonline_client()
    return client.organizations.GetUserGrants(convert_to_str(username),
                                              get_iyo_organization_id())