Exemplo n.º 1
0
def view_group_subgroups_requests(group_name):
    """List view of group's subgroups requests"""
    query = {'token': ciconnect_api_token}
    if request.method == 'GET':
        # Get group information
        group = get_group_info(group_name, session)

        # Get User's Group Status
        unix_name = session['unix_name']
        user_status = get_user_group_status(unix_name, group_name, session)

        subgroup_requests = requests.get(ciconnect_api_endpoint +
                                         '/v1alpha1/groups/' + group_name +
                                         '/subgroup_requests',
                                         params=query)
        subgroup_requests = subgroup_requests.json()['groups']

        # Query to return user's enclosing membership status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)

        # Query to check if user's status in root connect group
        connect_group = session['url_host']['unix_name']
        connect_status = get_user_connect_status(unix_name, connect_group)

        return render_template('group_profile_subgroups_requests.html',
                               subgroup_requests=subgroup_requests,
                               group_name=group_name,
                               user_status=user_status,
                               group=group,
                               connect_status=connect_status,
                               enclosing_status=enclosing_status)
Exemplo n.º 2
0
def view_group_add_members(group_name):
    """Detailed view of group's non-members"""
    query = {'token': ciconnect_api_token}
    if request.method == 'GET':
        # Get group information
        group = get_group_info(group_name, session)

        # Get User's Group Status
        unix_name = session['unix_name']
        user_status = get_user_group_status(unix_name, group_name, session)

        # Query user's enclosing group status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)

        # Query user's status in root connect group
        connect_group = session['url_host']['unix_name']
        connect_status = get_user_connect_status(unix_name, connect_group)

        user_super = requests.get(ciconnect_api_endpoint + '/v1alpha1/users/' +
                                  session['unix_name'],
                                  params=query)
        try:
            user_super = user_super.json()['metadata']['superuser']
        except:
            user_super = False

        return render_template('group_profile_add_members.html',
                               group_name=group_name,
                               user_status=user_status,
                               enclosing_status=enclosing_status,
                               user_super=user_super,
                               group=group,
                               connect_status=connect_status)
Exemplo n.º 3
0
def view_group_ajax_request(group_name):
    # Get user info
    user = get_user_info(session)
    unix_name = user['metadata']['unix_name']
    # Get group info
    group = get_group_info(group_name, session)
    # Get User's Group Status
    user_status = get_user_group_status(unix_name, group_name, session)
    return group, user_status
Exemplo n.º 4
0
def view_group_members_requests(group_name):
    """Detailed view of group's pending members"""
    query = {'token': ciconnect_api_token}
    if request.method == 'GET':
        # Get group information and group members
        group = get_group_info(group_name, session)
        group_members = get_group_members(group_name, session)

        # Set up multiplex while also tracking user status
        multiplexJson = {}
        users_statuses = {}
        for user in group_members:
            unix_name = user['user_name']
            if user['state'] == 'pending':
                user_state = user['state']
                user_query = "/v1alpha1/users/" + \
                    unix_name + "?token=" + query['token']
                multiplexJson[user_query] = {"method": "GET"}
                users_statuses[unix_name] = user_state

        # POST request for multiplex return
        multiplex = get_multiplex(multiplexJson)

        # Clean up multiplex return queries in user_dict
        user_dict = {}
        for user in multiplex:
            user_name = user.split('/')[3].split('?')[0]
            user_dict[user_name] = json.loads(multiplex[user]['body'])

        # Get User's Group Status
        unix_name = session['unix_name']
        user_status = get_user_group_status(unix_name, group_name, session)

        # Query user's enclosing group status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)

        # Query user's status in root connect group
        connect_group = session['url_host']['unix_name']
        connect_status = get_user_connect_status(unix_name, connect_group)

        return render_template('group_profile_members_requests.html',
                               group_members=user_dict,
                               group_name=group_name,
                               user_status=user_status,
                               users_statuses=users_statuses,
                               connect_status=connect_status,
                               enclosing_status=enclosing_status,
                               group=group)
Exemplo n.º 5
0
def view_group_members(group_name):
    """Detailed view of group's members"""
    if request.method == 'GET':
        # Get group information
        group = get_group_info(group_name, session)
        # Get User's Group Status
        unix_name = session['unix_name']
        user_status = get_user_group_status(unix_name, group_name, session)
        # Query to return user's enclosing group's membership status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)
        # Query to check user's connect status
        connect_group = session['url_host']['unix_name']
        connect_status = get_user_connect_status(unix_name, connect_group)

        return render_template('group_profile_members.html',
                               group_name=group_name,
                               user_status=user_status,
                               group=group,
                               connect_status=connect_status,
                               enclosing_status=enclosing_status)
Exemplo n.º 6
0
def view_group_subgroups(group_name):
    """Detailed view of group's subgroups"""
    if request.method == 'GET':
        # Get group information
        group = get_group_info(group_name, session)
        # Get User's Group Status
        unix_name = session['unix_name']
        user_status = get_user_group_status(unix_name, group_name, session)

        # Query to return user's enclosing group membership status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)

        # Query to check if user's status in root brand group, i.e. CMS, SPT, OSG
        connect_group = session['url_host']['unix_name']
        connect_status = get_user_connect_status(unix_name, connect_group)

        domain_name = request.headers['Host']

        if 'usatlas' in domain_name:
            domain_name = 'atlas.ci-connect.net'
        elif 'uscms' in domain_name:
            domain_name = 'cms.ci-connect.net'
        elif 'uchicago' in domain_name:
            domain_name = 'psdconnect.uchicago.edu'
        elif 'snowmass21' in domain_name:
            domain_name = 'snowmass21.ci-connect.net'

        with open(
                brand_dir + '/' + domain_name +
                "/form_descriptions/group_unix_name_description.md",
                "r") as file:
            group_unix_name_description = file.read()

        return render_template(
            'group_profile_subgroups.html',
            group_name=group_name,
            user_status=user_status,
            group=group,
            connect_status=connect_status,
            enclosing_status=enclosing_status,
            group_unix_name_description=group_unix_name_description)
Exemplo n.º 7
0
def profile():
    """User profile information. Assocated with a Globus Auth identity."""
    if request.method == 'GET':
        identity_id = session.get('primary_identity')
        try:
            user = get_user_info(session)
            unix_name = user['metadata']['unix_name']
            profile = get_user_profile(unix_name)
        except:
            profile = None

        if profile:
            print("Found profile: {}".format(profile))
            profile = profile['metadata']
            unix_name = profile['unix_name']
            group_name = session['url_host']['unix_name']
            user_status = get_user_group_status(unix_name, group_name, session)
        else:
            flash(
                'Please complete any missing profile fields and press Save.', 'warning')
            return redirect(url_for('create_profile'))

        if request.args.get('next'):
            session['next'] = get_safe_redirect()

        group_memberships = []
        for group in profile['group_memberships']:
            if ((session['url_host']['unix_name'] in group['name']) and (len(group['name'].split('.')) > 1)):
                group_memberships.append(group)

        domain_name = domain_name_edgecase()

        with open(brand_dir + '/' + domain_name + "/form_descriptions/group_unix_name_description.md", "r") as file:
            group_unix_name_description = file.read()

        return render_template('profile.html', profile=profile,
                               user_status=user_status,
                               group_memberships=group_memberships,
                               group_unix_name_description=group_unix_name_description)
Exemplo n.º 8
0
def view_group(group_name):
    """Detailed view of specific groups"""
    query = {
        'token': ciconnect_api_token,
        'globus_id': session['primary_identity']
    }

    user = get_user_info(session)
    unix_name = user['metadata']['unix_name']

    if request.method == 'GET':
        # Get group information
        group = get_group_info(group_name, session)
        # print(group)
        group_creation_date = group['creation_date'].split(' ')[0]
        # Get User's Group Status
        user_status = get_user_group_status(unix_name, group_name, session)
        # Query to return user's enclosing group membership status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)
        # Query to check user's connect group membership status
        connect_group = session['url_host']['unix_name']
        # print(connect_group)
        connect_status = get_user_connect_status(unix_name, connect_group)

        return render_template('group_profile_overview.html',
                               group=group,
                               group_name=group_name,
                               user_status=user_status,
                               enclosing_status=enclosing_status,
                               connect_status=connect_status,
                               group_creation_date=group_creation_date)
    elif request.method == 'POST':
        '''
        Request group membership by setting user status to pending
        '''
        status = 'pending'
        update_user_group_status(group_name, unix_name, status, session)
        # print("UPDATED MEMBERSHIP: {}".format(user_status))
        return redirect(url_for('view_group', group_name=group_name))
Exemplo n.º 9
0
def view_group_email(group_name):
    """View for email form to members"""
    if request.method == 'GET':
        # Get group information
        group = get_group_info(group_name, session)
        # Get User's Group Status
        unix_name = session['unix_name']
        user_status = get_user_group_status(unix_name, group_name, session)
        # Query to return user's enclosing group's membership status
        enclosing_status = get_enclosing_group_status(group_name, unix_name)
        # Query to check user's connect status
        connect_group = session['url_host']['unix_name']
        connect_status = get_user_connect_status(unix_name, connect_group)

        return render_template('group_profile_email.html',
                               group_name=group_name,
                               user_status=user_status,
                               group=group,
                               connect_status=connect_status,
                               enclosing_status=enclosing_status)
    elif request.method == 'POST':
        subject = request.form['subject']
        body = request.form['description']
        try:
            html = request.form['html-enabled']
            body_or_html = "html"
        except:
            body_or_html = "text"

        # mailgun setup here
        domain_name = domain_name_edgecase()
        support_emails = {
            "cms.ci-connect.net": "*****@*****.**",
            "duke.ci-connect.net": "*****@*****.**",
            "spt.ci-connect.net": "*****@*****.**",
            "atlas.ci-connect.net": "*****@*****.**",
            "psdconnect.uchicago.edu": "*****@*****.**",
            "www.ci-connect.net": "*****@*****.**",
            "localhost:5000": "*****@*****.**"
        }

        try:
            support_email = support_emails[domain_name]
        except:
            support_email = "*****@*****.**"

        user_dict, users_statuses = get_group_members_emails(group_name)
        user_emails = [
            user_dict[user]['metadata']['email'] for user in user_dict
        ]
        # print(user_emails)
        r = requests.post(
            "https://api.mailgun.net/v3/api.ci-connect.net/messages",
            auth=('api', mailgun_api_token),
            data={
                "from": "<" + support_email + ">",
                "to": [support_email],
                "bcc": user_emails,
                "subject": subject,
                body_or_html: body,
            })
        if r.status_code == requests.codes.ok:
            flash("Your message has been sent to the members of this group",
                  'success')
            return redirect(url_for('view_group_email', group_name=group_name))
        else:
            flash("Unable to send message: {}".format(r.json()), 'warning')
            return redirect(url_for('view_group_email', group_name=group_name))