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)
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)
def users_groups(): """Groups that user's are specifically members of""" if request.method == 'GET': query = { 'token': ciconnect_api_token, 'globus_id': session['primary_identity'] } # Get user info to derive unix name user = get_user_info(session) unix_name = user['metadata']['unix_name'] # Get user's group membership info based on session unix name users_group_memberships = get_user_group_memberships( session, unix_name) multiplexJson = {} group_membership_status = {} for group in users_group_memberships: if group['state'] not in ['nonmember']: group_name = group['name'] group_query = "/v1alpha1/groups/" + \ group_name + "?token=" + query['token'] multiplexJson[group_query] = {"method": "GET"} group_membership_status[group_query] = group['state'] # POST request for multiplex return multiplex = get_multiplex(multiplexJson) users_groups = [] for group in multiplex: if ((session['url_host']['unix_name'] in (json.loads( multiplex[group]['body'])['metadata']['name'])) and (len((json.loads(multiplex[group]['body'])['metadata']['name'] ).split('.')) > 1)): users_groups.append((json.loads(multiplex[group]['body']), group_membership_status[group])) # users_groups = [group for group in users_groups if len(group['name'].split('.')) == 3] # Query user's pending project requests pending_project_requests = get_user_pending_project_requests(unix_name) # Check user's member status of root connect group connect_group = session['url_host']['unix_name'] user_status = get_user_connect_status(unix_name, connect_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( 'users_groups.html', groups=users_groups, project_requests=pending_project_requests, user_status=user_status, group_unix_name_description=group_unix_name_description)
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)
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)
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)
def view_instances(): """Connect groups""" query = {'token': slate_api_token, 'dev': 'true'} if request.method == 'GET': app_name = 'jupyter-notebook' profile = get_user_profile(session['unix_name']) try: public_key = profile['metadata']['public_key'] except: public_key = None instances = list_users_instances_request(session) # Check user's member status of connect group specifically connect_group = session['url_host']['unix_name'] user_status = get_user_connect_status( session['unix_name'], connect_group) return render_template('instances.html', name=app_name, public_key=public_key, instances=instances, user_status=user_status)
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))
def groups(): """Connect groups""" if request.method == 'GET': connect_group = session['url_host']['unix_name'] # Get group's subgroups information groups = get_subgroups(connect_group, session) # Filter subgroups directly one level nested under group group_index = len(connect_group.split('.')) groups = [ group for group in groups if (len(group['name'].split('.')) == (group_index + 1) and not group['pending']) ] # Check user's member status of connect group specifically user_status = get_user_connect_status(session['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( 'groups.html', groups=groups, user_status=user_status, group_unix_name_description=group_unix_name_description)
def users_groups_pending(): """Groups that user's are specifically members of""" if request.method == 'GET': query = { 'token': ciconnect_api_token, 'globus_id': session['primary_identity'] } # Get user info user = get_user_info(session) unix_name = user['metadata']['unix_name'] # Query user's pending project requests project_requests = get_user_pending_project_requests(unix_name) project_requests = [ project_request for project_request in project_requests if session['url_host']['unix_name'] in project_request['name'] ] # Check user status of root connect group connect_group = session['url_host']['unix_name'] user_status = get_user_connect_status(unix_name, connect_group) return render_template('users_groups_pending.html', project_requests=project_requests, user_status=user_status)
def create_subgroup(group_name): access_token = get_user_access_token(session) query = {'token': access_token} if request.method == 'GET': sciences = requests.get( ciconnect_api_endpoint + '/v1alpha1/fields_of_science') sciences = sciences.json()['fields_of_science'] # Get group members group_members = get_group_members(group_name, session) # Return list of admins of group try: group_admins = [ member for member in group_members if member['state'] == 'admin'] except: group_admins = [] # Check if user status of root connect group specifically connect_group = session['url_host']['unix_name'] unix_name = session['unix_name'] user_status = get_user_connect_status(unix_name, connect_group) # Get group information group = get_group_info(group_name, session) return render_template('groups_create.html', sciences=sciences, group_name=group_name, group_admins=group_admins, user_status=user_status, group=group) elif request.method == 'POST': name = request.form['name'] display_name = request.form['display-name'] email = request.form['email'] phone = request.form['phone'] description = request.form['description'] try: # Purpose/Field of Science for CMS will always be High Energy Physics field_of_science = request.form['field_of_science'] except: field_of_science = "High Energy Physics" put_query = {"apiVersion": 'v1alpha1', 'metadata': {'name': name, 'display_name': display_name, 'purpose': field_of_science, 'email': email, 'phone': phone, 'description': description}} r = requests.put( ciconnect_api_endpoint + '/v1alpha1/groups/' + group_name + '/subgroup_requests/' + name, params=query, json=put_query) full_created_group_name = group_name + '.' + name # Check if user status of root connect group specifically connect_group = session['url_host']['unix_name'] unix_name = session['unix_name'] user_status = get_user_connect_status(unix_name, connect_group) if r.status_code == requests.codes.ok: if user_status == 'admin': flash_message = flash_message_parser('create_subgroup') flash(flash_message, 'success') return redirect(url_for('view_group', group_name=full_created_group_name)) else: flash( "The support team has been notified of your requested subgroup.", 'success') return redirect(url_for('users_groups_pending')) else: err_message = r.json()['message'] flash('Failed to request project creation: {}'.format( err_message), 'warning') return redirect(url_for('view_group_subgroups_requests', group_name=group_name))
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))