Beispiel #1
0
def helper_check_group_exists(group):
    """List members of a group."""
    access_token, url = oauth_helper()
    url = PARSE(url, group)
    headers = {'Authorization': 'Bearer ' + access_token}
    response = requests.get(url, headers=headers)
    status_code = response.status_code
    return status_code
Beispiel #2
0
def helper_search_members(group):
    """List members of a group."""
    access_token, url = oauth_helper()
    url = PARSE(url, group)
    headers = {'Authorization': 'Bearer ' + access_token}
    response = requests.get(url, headers=headers)
    check_response_code(response)
    result = (response.json())
    members = result["members"]
    print(json.dumps(members, indent=4, sort_keys=True))
    return members
Beispiel #3
0
def helper_user(user, group, delete):
    """Add and remove users from groups."""
    access_token, url = oauth_helper()
    url = PARSE(url, group)
    headers = {'Authorization': 'Bearer ' + access_token}
    data = {"username": user}
    if delete:
        response = requests.delete(url, json=data, headers=headers)
    else:
        response = requests.put(url, json=data, headers=headers)
    check_response_code(response)
    result = (response.json())
    print(json.dumps(result, indent=4, sort_keys=True))
Beispiel #4
0
def helper_create_group(group):
    """Create group."""
    check_response_code = helper_check_group_exists(group)
    if check_response_code == 200:
        print("Group {} already exists exiting...".format(group))
    else:
        access_token, url = oauth_helper()
        url = '{}/'.format(url)
        headers = {'Authorization': 'Bearer ' + access_token}
        data = {"title": group, "type": "group"}
        print(data)
        response = requests.post(url, json=data, headers=headers)
        check_response_code(response)
        result = (response.json())
        print(json.dumps(result, indent=4, sort_keys=True))
Beispiel #5
0
def helper_invite(email, group):
    """Email invitation to join group."""
    access_token, url = oauth_helper()
    prejoin = group + '/invite'
    url = PARSE(url, prejoin)
    headers = {'Authorization': 'Bearer ' + access_token}
    data = {"mail": email}
    print('Validating email', email)
    if validate_email(email):
        response = requests.post(url, json=data, headers=headers)
        check_response_code(response)
        result = (response.json())
        print(json.dumps(result, indent=4, sort_keys=True))
    else:
        print("Email is not valid")