Exemplo n.º 1
0
def index():
    """
    Main landing page
    """
    studies = current_user.get_studies()

    timepoint_count = Timepoint.query.count()
    study_count = Study.query.count()
    site_count = Site.query.count()
    return render_template('index.html',
                           studies=studies,
                           timepoint_count=timepoint_count,
                           study_count=study_count,
                           site_count=site_count)
Exemplo n.º 2
0
def index():
    """
    Main landin page
    """
    # studies = db_session.query(Study).order_by(Study.nickname).all()
    studies = current_user.get_studies()

    session_count = Session.query.count()
    study_count = Study.query.count()
    site_count = Site.query.count()
    return render_template('index.html',
                           studies=studies,
                           session_count=session_count,
                           study_count=study_count,
                           site_count=site_count)
Exemplo n.º 3
0
def scan(scan_id=None):
    """
    Default view for a single scan
    """
    if scan_id is None:
        flash('Invalid scan')
        return redirect(url_for('index'))

    # Check the user has permission to see this study
    studies = current_user.get_studies()
    scan = Scan.query.get(scan_id)
    if not current_user.has_study_access(scan.session.study):
        flash('Not authorised')
        return redirect(url_for('index'))

    # form for updating the study blacklist.csv on the filesystem
    bl_form = ScanBlacklistForm()
    # form used for updating the analysis comments
    scancomment_form = ScanCommentForm()

    if not bl_form.is_submitted():
        # this isn't an update so just populate the blacklist form with current values from the database
        # these should be the same as in the filesystem
        bl_form.scan_id = scan_id
        bl_form.bl_comment.data = scan.bl_comment

    if bl_form.validate_on_submit():
        # going to make an update to the blacklist
        # update the scan object in the database with info from the form
        # updating the databse object automatically syncronises blacklist.csv on the filesystem
        #   see models.py
        scan.bl_comment = bl_form.bl_comment.data
        try:
            db.session.add(scan)
            db.session.commit()
            flash("Blacklist updated")
            return redirect(url_for('session', session_id=scan.session_id))
        except SQLAlchemyError as err:
            logger.error('Scan blacklist update failed:{}'.format(str(err)))
            flash('Update failed, admins have been notified, please try again')

    return render_template('scan.html',
                           studies=studies,
                           scan=scan,
                           blacklist_form=bl_form,
                           scancomment_form=scancomment_form)
Exemplo n.º 4
0
def users():
    """
    View that lists all users
    """
    if not current_user.is_admin:
        flash('You are not authorised')
        return redirect(url_for('user'))
    users = User.query.all()
    user_forms = []
    for user in users:
        form = UserForm()
        form.user_id.data = user.id
        form.realname.data = user.realname
        form.is_admin.data = user.is_admin
        form.has_phi.data = user.has_phi
        study_ids = [str(study.id) for study in user.studies]
        form.studies.data = study_ids
        user_forms.append(form)
    return render_template('users.html',
                           studies=current_user.get_studies(),
                           user_forms=user_forms)
Exemplo n.º 5
0
def session(session_id=None, delete=False, flag_finding=False):
    """
    Default view for a single session_id
    If called as http://srv-dashboard/session/<session_id>/delete/True it will
    delete the session from the database

    """
    if session_id is None:
        return redirect('index')

    session = Session.query.get(session_id)

    if not current_user.has_study_access(session.study):
        flash('Not authorised')
        return redirect(url_for('index'))

    try:
        # Update open issue ID if necessary
        # this is necessary because GitHub may timeout a user without telling us
        token = flask_session['active_token']
    except:
        flash('It appears you\'ve been idle too long; please sign in again.')
        return redirect(url_for('login'))

    try:
        # check to see if any issues have been posted on github for this session
        gh = Github(token)
        # Due to the way GitHub search API works, splitting session name into separate search terms will find a session
        # regardless of repeat number, and will not match other sessions with the same study/site
        open_issues = gh.search_issues(
            "{} in:title repo:TIGRLab/admin state:open".format(
                str(session.name).replace("_", " ")))
        if open_issues.totalCount:
            session.gh_issue = open_issues[0].number
        else:
            session.gh_issue = None
        db.session.commit()
    except:
        flash("Error searching for session's GitHub issue.")

    if delete:
        try:
            if not current_user.is_admin:
                flash('You dont have permission to do that')
                raise Exception
            db.session.delete(session)
            db.session.commit()
            flash('Deleted session:{}'.format(session.name))
            return redirect(
                url_for('study', study_id=session.study_id, active_tab='qc'))
        except Exception:
            flash('Failed to delete session:{}'.format(session.name))

    if flag_finding:
        try:
            incident = IncidentalFinding()
            incident.session_id = session.id
            incident.user_id = current_user.id

            db.session.add(incident)
            db.session.commit()
            flash('Finding flagged.')
            return redirect(url_for('session', session_id=session.id))
        except:
            logger.error('Failed flagging finding for session:{}'.format(
                session.id))
            flash('Failed flagging finding. Admins have been notified')

    studies = current_user.get_studies()
    form = SessionForm(obj=session)

    # This form deals with the checklist comments.
    # Updating the checklist in the database causes checklist.csv to be updated
    # see models.py
    scancomment_form = ScanCommentForm()

    if form.validate_on_submit():
        # form has been submitted
        session.cl_comment = form.cl_comment.data
        try:
            db.session.add(session)
            db.session.commit()
            flash('Session updated')
            return redirect(
                url_for('study', study_id=session.study_id, active_tab='qc'))

        except SQLAlchemyError as err:
            logger.error('Session update failed:{}'.format(str(err)))
            flash('Update failed, admins have been notified, please try again')
        form.populate_obj(session)

    return render_template('session.html',
                           studies=studies,
                           study=session.study,
                           session=session,
                           form=form,
                           scancomment_form=scancomment_form)