Beispiel #1
0
def get_project_moments(proj_id):
    if not auth_consultant():
        abort(401)

    if 'since_moment_id' in request.values:
        since_moment_id = request.values['since_moment_id']
    else:
        since_moment_id = 0

    if 'order' in request.values:
        order = request.values['order']
    else:
        order = "asc"

    # Get moments for a project, since the specified moment id
    moments = db_models.Moment.get_moments_for_project(proj_id,
                                                       since_moment_id)

    moment_dicts = []

    for m in moments['moments']:
        m_dict = m.to_dict()
        m_dict['participant_display_name'] = db_models.Participant(
            m.parent_participant_id).display_name
        moment_dicts.append(m_dict)

    return json.dumps(moment_dicts, indent=4)
Beispiel #2
0
def api_projects_participant(project_id, participant_id):
    if not auth_consultant():
        abort(401)

    c = get_active_consultant()

    try:

        if request.method == "PUT":

            if not db_models.Project(project_id).consultant_is_assigned(c):
                return 'Only consultants assigned to this project can update its participants.', 401

            p = db_models.Participant(participant_id)
            if p.project_id != int(project_id):
                abort(401)
            p.display_name = request.values['display_name']
            p.description = request.values['description']
            p.update_in_db()
            return p.to_json()

        elif request.method == "GET":

            return db_models.Participant(participant_id).to_json()

        elif request.method == "DELETE":

            p = db_models.Participant(participant_id)
            p.delete_from_db(c)
            return p.to_json()

    except db_models.DeleteActiveParticipantError:
        return 'You cannot delete an active participant. Please deactivate this participant before deleting.', 400

    except db_models.ConsultantNotAssignedToProjectError:
        return 'Only those consultants that are assigned to a project can delete its participants.', 401

    except db_models.ParticipantNotFoundError:
        abort(404)

    except Exception as e:
        return str(e), 400
Beispiel #3
0
def get_participant(id):
    # Only authorise is a consultant is logged in or a participant has logged in and the currently logged-in
    # participant is the same as the participant's info being requested.

    if request.method == "GET":
        if auth_consultant() or auth_participant(id):

            try:
                return db_models.Participant(id).to_json()
            except db_models.ParticipantNotFoundError:
                return json.dumps({
                    "error_code":
                    "101",
                    "error_text":
                    "No participant found with ID {}".format(id)
                })

        else:
            abort(401)

    elif request.method == "PUT":
        # Update participant based on values sent with request
        if auth_consultant():
            try:
                p = db_models.Participant(id)

                if 'active' in request.values:
                    p.active = True if request.values[
                        'active'] == 'true' else False

                p.update_in_db()

                return p.to_json()

            except db_models.ParticipantNotFoundError:
                abort(404)
        else:
            abort(401)
Beispiel #4
0
def project_participant_edit(proj_id, participant_id):
    c = get_active_consultant()
    if not c:
        abort(401)

    if not (c.admin or int(proj_id) in c.project_ids):
        abort(401)

    try:
        p = db_models.Participant(participant_id)
        print(p.to_dict())

        return render_template('dashboard/modals/view_edit_participant_form.html', participant=p.to_dict())

    except db_models.ParticipantNotFoundError:
        abort(404)
Beispiel #5
0
def projects_participants_download(proj_id, participant_id):

    c = get_active_consultant()
    if not c:
        abort(401)

    if not (c.admin or int(proj_id) in c.project_ids):
        abort(401)

    try:
        p = db_models.Participant(participant_id)

        download_file = p.generate_download_bundle(ignore_moment_flag=True, participant_zip=True)

        return send_file(download_file, as_attachment=True, mimetype='application/zip')

    except db_models.ParticipantNotFoundError:
        abort(404)
Beispiel #6
0
def project_participant_pin(proj_id, participant_id, i):

    c = get_active_consultant()
    if not c:
        abort(401)

    if not (c.admin or int(proj_id) in c.project_ids):
        abort(401)

    try:
        p = db_models.Participant(participant_id)
        if i.lower()=='pin':
            p.generate_new_pin()
        elif i.lower() == 'url':
            p.generate_login_url(c)
        else:
            abort(400)

        p.update_in_db()

        return p.to_json()

    except db_models.ParticipantNotFoundError:
        abort(404)
Beispiel #7
0
def get_active_participant():
    if 'active_participant_id' in session:
        return db_models.Participant(session['active_participant_id'])
    else:
        return None
Beispiel #8
0
def test_participant_add_moment(p_id):
    tests.add_moment_to_participant(p_id)
    m = db_models.Participant(p_id).moments[0]
    return json.dumps(m.to_dict(), indent=4)