示例#1
0
def edit_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']
        group = get_group_info(group_name, session)
        return render_template('groups_edit.html', sciences=sciences,
                                group_name=group_name, group=group)

    elif request.method == 'POST':
        display_name = request.form['display-name']
        email = request.form['email']
        phone = request.form['phone']
        description = request.form['description']

        put_query = {"apiVersion": 'v1alpha1',
                     'metadata': {'display_name': display_name,
                                  'email': email, 'phone': phone,
                                  'description': description}}

        r = requests.put(
            ciconnect_api_endpoint + '/v1alpha1/groups/' + group_name, params=query, json=put_query)

        if r.status_code == requests.codes.ok:
            flash_message = flash_message_parser('edit_subgroup')
            flash(flash_message, 'success')
            return redirect(url_for('view_group', group_name=group_name))
        else:
            err_message = r.json()['message']
            flash('Failed to update subgroup information: {}'.format(
                err_message), 'warning')
            return redirect(url_for('edit_subgroup', group_name=group_name))
示例#2
0
def delete_group(group_name):
    if request.method == 'POST':
        r = delete_group_entry(group_name, session)

        if r.status_code == requests.codes.ok:
            flash_message = flash_message_parser('delete_group')
            flash(flash_message, 'success')
            return redirect(url_for('groups'))
        else:
            err_message = r.json()['message']
            flash('Failed to delete group: {}'.format(err_message), 'warning')
            return redirect(url_for('view_group', group_name=group_name))
示例#3
0
def edit_subgroup_requests(group_name):
    access_token = get_user_access_token(session)
    query = {'token': access_token}
    enclosing_group_name = '.'.join(group_name.split('.')[:-1])
    if request.method == 'GET':
        sciences = requests.get(
            ciconnect_api_endpoint + '/v1alpha1/fields_of_science')
        sciences = sciences.json()['fields_of_science']

        group = get_group_info(group_name, session)

        return render_template('groups_requests_edit.html', sciences=sciences,
                                group_name=group_name, 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']

        new_unix_name = enclosing_group_name + '.' + name

        if new_unix_name == group_name:
            put_query = {"apiVersion": 'v1alpha1',
                         'metadata': {'display_name': display_name,
                                      'email': email, 'phone': phone,
                                      'description': description}}
        else:
            put_query = {"apiVersion": 'v1alpha1',
                         'metadata': {'name': name,
                                      'display_name': display_name,
                                      'email': email, 'phone': phone,
                                      'description': description}}

        r = requests.put(
            ciconnect_api_endpoint + '/v1alpha1/groups/' + group_name, params=query, json=put_query)

        enclosing_group_name = '.'.join(group_name.split('.')[:-1])
        if r.status_code == requests.codes.ok:
            flash_message = flash_message_parser('edit_subgroup_requests')
            flash(flash_message, 'success')
            return redirect(url_for('users_groups_pending'))
        else:
            err_message = r.json()['message']
            flash('Failed to edit subgroup request: {}'.format(
                err_message), 'warning')
            return redirect(url_for('edit_subgroup_requests', group_name=group_name,
                                    name=name, display_name=display_name,
                                    email=email, phone=phone,
                                    description=description))
示例#4
0
def admin_group_member(group_name, unix_name):
    if request.method == 'POST':
        status = 'admin'
        user_status = update_user_group_status(group_name, unix_name, status, session)

        if user_status.status_code == requests.codes.ok:
            flash_message = flash_message_parser('admin_group_member')
            flash(flash_message, 'success')
            return redirect(url_for('view_group_members', group_name=group_name))
        else:
            err_message = user_status.json()['message']
            flash('Failed make member an admin: {}'.format(
                err_message), 'warning')
            return redirect(url_for('view_group_members', group_name=group_name))
示例#5
0
def add_group_member(group_name, unix_name):
    if request.method == 'POST':
        # Add user to group by setting user status to active
        status = 'active'
        user_status = update_user_group_status(group_name, unix_name, status, session)

        if user_status.status_code == requests.codes.ok:
            flash_message = flash_message_parser('add_group_member')
            flash(flash_message, 'success')
            return redirect(url_for('view_group_members', group_name=group_name))
        else:
            err_message = user_status.json()['message']
            flash('Failed to add member to group: {}'.format(
                err_message), 'warning')
            return redirect(url_for('view_group_members', group_name=group_name))
示例#6
0
def approve_subgroup(group_name, subgroup_name):
    access_token = get_user_access_token(session)
    query = {'token': access_token}
    if request.method == 'GET':

        r = requests.put(
            ciconnect_api_endpoint + '/v1alpha1/groups/' + group_name +
            '/subgroup_requests/' + subgroup_name + '/approve', params=query)

        if r.status_code == requests.codes.ok:
            flash_message = flash_message_parser('approve_subgroup')
            flash(flash_message, 'success')
            return redirect(url_for('view_group_subgroups_requests', group_name=group_name))
        else:
            err_message = r.json()['message']
            flash('Failed to approve subgroup creation: {}'.format(
                err_message), 'warning')
            return redirect(url_for('view_group_subgroups_requests', group_name=group_name))
示例#7
0
def deny_subgroup(group_name, subgroup_name):
    access_token = get_user_access_token(session)
    query = {'token': access_token}
    if request.method == 'POST':
        message = request.form['denial-message']
        denial_message = {'message': message}

        r = requests.delete(
            ciconnect_api_endpoint + '/v1alpha1/groups/' + group_name +
            '/subgroup_requests/' + subgroup_name, params=query, json=denial_message)

        if r.status_code == requests.codes.ok:
            flash_message = flash_message_parser('deny_subgroup')
            flash(flash_message, 'success')
            return redirect(url_for('view_group_subgroups_requests', group_name=group_name))
        else:
            err_message = r.json()['message']
            flash('Failed to deny subgroup request: {}'.format(
                err_message), 'warning')
            return redirect(url_for('view_group_subgroups_requests', group_name=group_name))
示例#8
0
def remove_group_member(group_name, unix_name):
    if request.method == 'POST':
        access_token = get_user_access_token(session)
        query = {'token': access_token}
        try:
            message = request.form['denial-message']
            denial_message = {'message': message}
            remove_user = requests.delete(
                ciconnect_api_endpoint + '/v1alpha1/groups/' +
                group_name + '/members/' + unix_name, params=query, json=denial_message)
        except:
            remove_user = requests.delete(
                ciconnect_api_endpoint + '/v1alpha1/groups/' +
                group_name + '/members/' + unix_name, params=query)

        if remove_user.status_code == requests.codes.ok:
            flash_message = flash_message_parser('remove_group_member')
            flash(flash_message, 'success')
            return redirect(url_for('view_group_members', group_name=group_name))
        else:
            err_message = remove_user.json()['message']
            flash('Failed to remove member from group: {}'.format(
                err_message), 'warning')
            return redirect(url_for('view_group_members', group_name=group_name))
示例#9
0
def create_group():
    """Create groups"""
    access_token = get_user_access_token(session)
    query = {'token': access_token}
    print(query)
    if request.method == 'GET':
        sciences = requests.get(
            ciconnect_api_endpoint + '/v1alpha1/fields_of_science')
        sciences = sciences.json()['fields_of_science']
        return render_template('groups_create.html', sciences=sciences)
    elif request.method == 'POST':
        name = request.form['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_group = {"apiVersion": 'v1alpha1', "kind": "Group",
                     'metadata': {'name': name,
                                  'field_of_science': field_of_science,
                                  'email': email, 'phone': phone,
                                  'description': description}}
        create_group = requests.put(
            ciconnect_api_endpoint + '/v1alpha1/groups/root/subgroups/' + name, params=query, json=put_group)
        if create_group.status_code == requests.codes.ok:
            flash_message = flash_message_parser('create_group')
            flash(flash_message, 'success')
            return redirect(url_for('groups'))
        else:
            err_message = create_group.json()['message']
            flash('Failed to create group: {}'.format(err_message), 'warning')
            return redirect(url_for('groups'))
示例#10
0
def edit_profile(unix_name):
    identity_id = session.get('primary_identity')
    query = {'token': ciconnect_api_token,
             'globus_id': identity_id}
    user = get_user_info(session)
    expected_unix_name = user['metadata']['unix_name']

    try:
        unix_name == expected_unix_name
    except Exception:
        return redirect(url_for('handle_exception', e=Exception))

    if request.method == 'GET':
        # Get user info, pass through as args, convert to json and load input fields
        profile = get_user_profile(unix_name)
        profile = profile['metadata']

        return render_template('profile_edit.html', profile=profile, unix_name=unix_name)

    elif request.method == 'POST':
        name = request.form['name']
        email = request.form['email']
        phone = request.form['phone-number']
        institution = request.form['institution']
        public_key = request.form['sshpubstring']
        globus_id = session['primary_identity']
        x509dn = request.form['x509dn']
        access_token = get_user_access_token(session)
        query = {'token': access_token,
                 'globus_id': identity_id}
        # Schema and query for adding users to CI Connect DB
        if public_key != ' ':
            post_user = {"apiVersion": 'v1alpha1',
                         'metadata': {'name': name, 'email': email,
                                      'phone': phone, 'institution': institution,
                                      'public_key': public_key,
                                      'X.509_DN': x509dn}}
        else:
            post_user = {"apiVersion": 'v1alpha1',
                         'metadata': {'name': name, 'email': email,
                                      'phone': phone, 'institution': institution,
                                      'X.509_DN': x509dn}}
        # PUT request to update user information
        r = requests.put(ciconnect_api_endpoint + '/v1alpha1/users/' +
                         unix_name, params=query, json=post_user)

        session['name'] = name
        session['email'] = email
        session['phone'] = phone
        session['institution'] = institution

        flash_message = flash_message_parser('edit_profile')
        flash(flash_message, 'success')

        if 'next' in session:
            redirect_to = session['next']
            session.pop('next')
        else:
            redirect_to = url_for('profile')

        return redirect(url_for('profile'))
示例#11
0
def create_profile():
    identity_id = session.get('primary_identity')
    institution = session.get('institution')
    globus_id = identity_id
    query = {'token': ciconnect_api_token}

    if request.method == 'GET':
        unix_name = ''
        phone = ''
        public_key = ''
        return render_template('profile_create.html', unix_name=unix_name, phone=phone, public_key=public_key)

    elif request.method == 'POST':
        name = request.form['name']
        unix_name = request.form['unix_name']
        email = request.form['email']
        phone = request.form['phone-number']
        institution = request.form['institution']
        public_key = request.form['sshpubstring']
        globus_id = session['primary_identity']
        superuser = False
        service_account = False

        # Schema and query for adding users to CI Connect DB
        if public_key:
            post_user = {"apiVersion": 'v1alpha1',
                         'metadata': {'globusID': globus_id, 'name': name, 'email': email,
                                      'phone': phone, 'institution': institution,
                                      'public_key': public_key,
                                      'unix_name': unix_name, 'superuser': superuser,
                                      'service_account': service_account}}
        else:
            post_user = {"apiVersion": 'v1alpha1',
                         'metadata': {'globusID': globus_id, 'name': name, 'email': email,
                                      'phone': phone, 'institution': institution,
                                      'unix_name': unix_name, 'superuser': superuser,
                                      'service_account': service_account}}
        r = requests.post(ciconnect_api_endpoint +
                          '/v1alpha1/users', params=query, json=post_user)
        # print("REQUEST RESPONSE: {}".format(r))
        # print("REQUEST URL: {}".format(r.url))
        if r.status_code == requests.codes.ok:
            r = r.json()['metadata']
            session['name'] = r['name']
            session['email'] = r['email']
            session['phone'] = r['phone']
            session['institution'] = r['institution']
            session['unix_name'] = r['unix_name']

            # Auto generate group membership into connect group
            # put_query = {"apiVersion": 'v1alpha1',
            #              'group_membership': {'state': 'pending'}}
            # user_status = requests.put(
            #     ciconnect_api_endpoint +
            #     '/v1alpha1/groups/' +
            #     session['url_host']['unix_name'] + '/members/' + unix_name,
            #     params=query, json=put_query)
            group_name = session['url_host']['unix_name']
            status = 'pending'
            update_user_group_status(group_name, unix_name, status, session)

            flash_message = flash_message_parser('create_profile')
            flash(flash_message, 'success')

            if 'next' in session:
                redirect_to = session['next']
                session.pop('next')
            else:
                redirect_to = url_for('profile')
            return redirect(url_for('profile'))
        else:
            error_msg = r.json()['message']
            flash(
                'Failed to create your account: {}'.format(error_msg), 'warning')
            return render_template('profile_create.html', name=name, unix_name=unix_name,
                                   email=email, phone=phone, institution=institution,
                                   public_key=public_key)
示例#12
0
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))