def decorated_function(*args, **kwargs): instance_id = request.path.split('/')[-1] instance_details = get_instance_details(instance_id) if instance_details == 504: flash( 'The connection to {} has timed out. Please try again later.'. format(instance_id), 'warning') return redirect(url_for('list_instances')) if instance_details['kind'] == 'Error': message = instance_details['message'] flash('{}'.format(message), 'warning') return redirect(url_for('list_instances')) group_name = instance_details['metadata']['group'] group_members = get_group_members(group_name) group_members = group_members['items'] group_user_ids = [] for group_member in group_members: group_user_ids.append(group_member['metadata']['id']) if (not session.get('user_id') in group_user_ids): flash('You do not have permission to access this instance', 'warning') return redirect(url_for('list_instances')) return fn(*args, **kwargs)
def decorated_function(*args, **kwargs): if minislate_user: return fn(*args, **kwargs) group_name = request.path.split('/')[2] group_members = get_group_members(group_name) try: if group_members['kind'] == 'Error': message = group_members['message'] flash('{}'.format(message), 'warning') return redirect(url_for('list_groups')) except: print("Finished querying group members") try: group_members = group_members['items'] except: if group_members['message'] == 'Not authorized': flash('You do not have permission to access this group', 'warning') return redirect(url_for('list_groups')) group_user_ids = [] for group_member in group_members: group_user_ids.append(group_member['metadata']['id']) if (not session.get('user_id') in group_user_ids): flash('You do not have permission to access this group', 'warning') return redirect(url_for('list_groups')) return fn(*args, **kwargs)
def view_group_members_ajax_request(group_name): """Detailed view of group's members""" query = {'token': ciconnect_api_token} if request.method == 'GET': group_members = get_group_members(group_name, session) multiplexJson = {} users_statuses = {} # Get detailed user information from list of users for user in group_members: unix_name = user['user_name'] user_state = user['state'] if (user_state != 'nonmember' and unix_name != 'root'): 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) user_dict = {} group_user_dict = {} for user in multiplex: user_name = user.split('/')[3].split('?')[0] user_dict[user_name] = json.loads(multiplex[user]['body']) for user, info in user_dict.items(): for group_membership in info['metadata']['group_memberships']: if group_membership['name'] == group_name: group_user_dict[user] = info return user_dict, users_statuses
def view_group_add_members_request(group_name): """Detailed view of group's non-members""" query = {'token': ciconnect_api_token} if request.method == 'GET': # Get root base group users # If enclosing group is root # just display group_name connect group users # rather than all users in root i.e. from other connects group_name_list = group_name.split('.') if len(group_name_list) > 1: enclosing_group_name = '.'.join(group_name_list[:-1]) else: enclosing_group_name = group_name # Get all active members of enclosing group if enclosing_group_name: enclosing_group = get_group_members(enclosing_group_name, session) enclosing_group_members_names = [ member['user_name'] for member in enclosing_group if member['state'] != 'pending' ] else: enclosing_group_members_names = [] # Get all members of current group group_members = get_group_members(group_name, session) memberships_names = [member['user_name'] for member in group_members] # Set the difference to filter all non-members of current group non_members = list( set(enclosing_group_members_names) - set(memberships_names)) # Set up multiplex to query detailed info about all non-members multiplexJson = {} for user in non_members: unix_name = user user_query = "/v1alpha1/users/" + \ unix_name + "?token=" + query['token'] multiplexJson[user_query] = {"method": "GET"} # POST request for multiplex return and set up user_dict with user info multiplex = get_multiplex(multiplexJson) user_dict = {} for user in multiplex: user_name = user.split('/')[3].split('?')[0] user_dict[user_name] = json.loads(multiplex[user]['body']) return user_dict
def group_pending_members_count_request(group_name): """Get a group's pending members count""" if request.method == 'GET': group_members = get_group_members(group_name, session) pending_user_count = 0 for user in group_members: if user['state'] == 'pending': pending_user_count += 1 return pending_user_count
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 groups_profile_members_xhr(group_name): if request.method == 'GET': group_members = get_group_members(group_name) return jsonify(group_members)
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))