Exemplo n.º 1
0
def search_users(nels_id=None,
                 idp_number=None,
                 federated_id=None,
                 name=None,
                 email=None,
                 user_type_id=None,
                 is_active=None,
                 affiliation=None):
    try:
        json_body = {}
        if nels_id:
            json_body['id'] = nels_id
        if idp_number:
            json_body['idpnumber'] = idp_number
        if federated_id:
            json_body['idpusername'] = federated_id
        if name:
            json_body['name'] = name
        if email:
            json_body['email'] = email
        if user_type_id:
            json_body['usertype'] = user_type_id
        if is_active:
            json_body['isactivie'] = is_active
        if affiliation:
            json_body['affiliation'] = affiliation

        response = requests.post(config.api_url("users/query"),
                                 json=json_body,
                                 auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.ok:
            return response.json()
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 2
0
def delete_project(project_id):
    try:
        response = requests.delete(config.api_url("projects/%s" % project_id),
                                   auth=(config.API_KEY, config.API_SECRET))
        return response.status_code == requests.codes.no_content
    except:
        feed_utils.error(sys.exc_info()[0])
    return False
Exemplo n.º 3
0
def get_project(project_id):
    try:
        response = requests.get(config.api_url("projects/%s" % project_id),
                                auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.ok:
            return response.json()
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 4
0
def add_project(name, description):
    try:
        json_body = {"name": name, "description": description}
        response = requests.post(config.api_url("projects"),
                                 json=json_body,
                                 auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.created:
            return response.json()["id"]
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 5
0
def get_user_in_project(project_id, user_id):
    try:
        response = requests.get(config.api_url("projects/%s/users/%s" %
                                               (project_id, user_id)),
                                auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.ok:
            json_response = response.json()
            return int(json_response["membership_type"])
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 6
0
def add_user_to_project(project_id, user_id, membership_type):
    try:
        json_body = {"membership_type": membership_type}
        response = requests.post(config.api_url("projects/%s/users/%s" %
                                                (project_id, user_id)),
                                 json=json_body,
                                 auth=(config.API_KEY, config.API_SECRET))
        return response.status_code == requests.codes.ok
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 7
0
def get_project_ids():
    try:
        ids = []
        response = requests.get(config.api_url("projects/ids"),
                                auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.ok:
            json_response = response.json()
            for uid in json_response:
                ids.append(uid[u'id'])
            return ids
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 8
0
def search_projects(project_id=None, name=None):
    try:
        json_body = {}
        if project_id:
            json_body['id'] = project_id
        if name:
            json_body['name'] = name

        response = requests.post(config.api_url("projects/query"),
                                 json=json_body,
                                 auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.ok:
            return response.json()
    except:
        feed_utils.error(sys.exc_info()[0])
    return None
Exemplo n.º 9
0
def register_user(idp_number, federated_id, name, email, user_type_id,
                  is_active, affiliation):
    try:
        json_body = {
            "idpnumber": idp_number,
            "idpusername": federated_id,
            "usertype": user_type_id,
            "isactivie": is_active,
            "name": name,
            "email": email,
            "affiliation": affiliation
        }
        response = requests.post(config.api_url("users"),
                                 json=json_body,
                                 auth=(config.API_KEY, config.API_SECRET))
        if response.status_code == requests.codes.created:
            return response.json()["id"]
    except:
        feed_utils.error(sys.exc_info()[0])
    return None