Exemple #1
0
def test_prepare_submissions_empty(app):
    with app.app_context():
        user = User(email='*****@*****.**',
                    password='******',
                    active=True,
                    id=101)
        submissions = prepare_submissions(user)
        assert (submissions == {})
Exemple #2
0
def dashboard():
    """
        Depending on the user that is logged in, they will get a
        dashboard that reflects the
        current status of all submissions of which they are part.
    """

    submissions = prepare_submissions(current_user)

    submission_meta = []
    submission_stats = []

    for record_id in submissions:
        stats = []

        for key in submissions[record_id]["stats"].keys():
            stats.append({
                "name": key,
                "count": submissions[record_id]["stats"][key]
            })

        submission_stats.append({"recid": record_id, "stats": stats})

        review_flag = "todo"
        if submissions[record_id]["stats"]["attention"] == 0 and \
                submissions[record_id]["stats"]["todo"] == 0 and \
                submissions[record_id]["stats"]["passed"] == 0:
            review_flag = "todo"
        elif submissions[record_id]["stats"]["attention"] > 0 or \
                submissions[record_id]["stats"]["todo"] > 0:
            review_flag = "attention"
        elif submissions[record_id]["stats"]["attention"] == 0 and \
                submissions[record_id]["stats"]["todo"] == 0:
            review_flag = "passed"

        if submissions[record_id]["status"] == 'finished':
            review_flag = "finished"

        submissions[record_id]["metadata"]["submission_status"] = \
            submissions[record_id]["status"]
        submissions[record_id]["metadata"]["review_flag"] = review_flag

        submission_meta.append(submissions[record_id]["metadata"])

    user_profile = current_userprofile.query.filter_by(
        user_id=current_user.get_id()).first()

    ctx = {
        'user_is_admin': has_role(current_user, 'admin'),
        'submissions': submission_meta,
        'user_profile': user_profile,
        'user_has_coordinator_request': get_pending_request(),
        'pending_coordinator_requests': get_pending_coordinator_requests(),
        'submission_stats': json.dumps(submission_stats),
        'pending_invites': get_pending_invitations_for_user(current_user)
    }

    return render_template('hepdata_dashboard/dashboard.html', ctx=ctx)
def test_submissions_empty(app):
    with app.app_context():
        user = User(email='*****@*****.**',
                    password='******',
                    active=True,
                    id=101)
        assert (get_submission_count(user) == 0)
        assert (list_submission_titles(user) == [])
        assert (prepare_submissions(user) == {})
Exemple #4
0
def dashboard():
    """
        Depending on the user that is logged in, they will get a
        dashboard that reflects the
        current status of all submissions of which they are part.
    """

    submissions = prepare_submissions(current_user)

    submission_meta = []
    submission_stats = []

    for record_id in submissions:
        stats = []

        for key in submissions[record_id]["stats"].keys():
            stats.append(
                {"name": key, "count": submissions[record_id]["stats"][key]})

        submission_stats.append({"recid": record_id, "stats": stats})

        review_flag = "todo"
        if submissions[record_id]["stats"]["attention"] == 0 and \
                submissions[record_id]["stats"]["todo"] == 0 and \
                submissions[record_id]["stats"]["passed"] == 0:
            review_flag = "todo"
        elif submissions[record_id]["stats"]["attention"] > 0 or \
                submissions[record_id]["stats"]["todo"] > 0:
            review_flag = "attention"
        elif submissions[record_id]["stats"]["attention"] == 0 and \
                submissions[record_id]["stats"]["todo"] == 0:
            review_flag = "passed"

        if submissions[record_id]["status"] == 'finished':
            review_flag = "finished"

        submissions[record_id]["metadata"]["submission_status"] = \
            submissions[record_id]["status"]
        submissions[record_id]["metadata"]["review_flag"] = review_flag

        submission_meta.append(submissions[record_id]["metadata"])

    user_profile = current_userprofile.query.filter_by(user_id=current_user.get_id()).first()

    ctx = {'user_is_admin': has_role(current_user, 'admin'),
           'submissions': submission_meta,
           'user_profile': user_profile,
           'user_has_coordinator_request': get_pending_request(),
           'pending_coordinator_requests': get_pending_coordinator_requests(),
           'submission_stats': json.dumps(submission_stats),
           'pending_invites': get_pending_invitations_for_user(current_user)}

    return render_template('hepdata_dashboard/dashboard.html', ctx=ctx)
def test_submissions_admin(app, load_submission):
    with app.app_context():
        record_information = create_record({
            'journal_info': 'Phys. Letts',
            'title': 'My Journal Paper',
            'inspire_id': '1487726'
        })
        hepsubmission = get_or_create_hepsubmission(
            record_information['recid'])

        role = Role(name='admin')
        user = User(email='*****@*****.**',
                    password='******',
                    active=True,
                    id=101,
                    roles=[role])

        assert (get_submission_count(user) == 1)
        assert (list_submission_titles(user) == [{
            'id':
            record_information['recid'],
            'title':
            'My Journal Paper'
        }])

        submissions = prepare_submissions(user)
        assert (len(submissions) == 1)
        assert (submissions[str(record_information['recid'])] == {
            'metadata': {
                'coordinator': {
                    'email': u'*****@*****.**',
                    'name': u'*****@*****.**',
                    'id': 1
                },
                'recid': str(record_information['recid']),
                'role': [],
                'show_coord_view': False,
                'start_date': hepsubmission.created,
                'last_updated': hepsubmission.last_updated,
                'title': u'My Journal Paper',
                'versions': 1
            },
            'stats': {
                'attention': 0,
                'passed': 0,
                'todo': 0
            },
            'status': u'todo'
        })
def test_submissions_participant(app, load_submission):
    with app.app_context():
        record_information = create_record({
            'journal_info': 'Phys. Letts',
            'title': 'My Journal Paper',
            'inspire_id': '1487726'
        })
        hepsubmission = get_or_create_hepsubmission(
            record_information['recid'])
        db.session.add(hepsubmission)

        user = User(email='*****@*****.**', password='******', active=True)
        db.session.add(user)
        db.session.commit()

        # Check the user doesn't see the record before they are a participant
        assert (get_submission_count(user) == 0)
        assert (list_submission_titles(user) == [])

        # Add the user as a participant
        participant = SubmissionParticipant(
            publication_recid=record_information['recid'],
            role="uploader",
            email='*****@*****.**',
            status='primary',
            user_account=user.id)
        db.session.add(participant)
        hepsubmission.participants.append(participant)
        db.session.add(hepsubmission)
        db.session.commit()

        assert (get_submission_count(user) == 1)
        assert (list_submission_titles(user) == [{
            'id':
            record_information['recid'],
            'title':
            'My Journal Paper'
        }])

        participant_submissions = prepare_submissions(user)
        assert (len(participant_submissions) == 1)
        assert (participant_submissions[str(record_information['recid'])] == {
            'metadata': {
                'coordinator': {
                    'email': u'*****@*****.**',
                    'name': u'*****@*****.**',
                    'id': 1
                },
                'recid': str(record_information['recid']),
                'role': ['uploader'],
                'show_coord_view': False,
                'start_date': hepsubmission.created,
                'last_updated': hepsubmission.last_updated,
                'title': u'My Journal Paper',
                'versions': 1
            },
            'stats': {
                'attention': 0,
                'passed': 0,
                'todo': 0
            },
            'status': u'todo'
        })

        # Add a new submission as coordinator
        record_information2 = create_record({
            'journal_info': 'Another Journal',
            'title': 'My New Journal Paper',
            'inspire_id': '123456'
        })
        hepsubmission = get_or_create_hepsubmission(
            record_information2['recid'], coordinator=user.id)

        assert (get_submission_count(user) == 2)
        assert (list_submission_titles(user) == [{
            'id':
            record_information2['recid'],
            'title':
            'My New Journal Paper'
        }, {
            'id':
            record_information['recid'],
            'title':
            'My Journal Paper'
        }])

        all_submissions = prepare_submissions(user)
        assert (len(all_submissions) == 2)
        assert (all_submissions[str(record_information2['recid'])] == {
            'metadata': {
                'coordinator': {
                    'email': u'*****@*****.**',
                    'name': u'*****@*****.**',
                    'id': user.id
                },
                'recid': str(record_information2['recid']),
                'role': ['coordinator'],
                'show_coord_view': True,
                'start_date': hepsubmission.created,
                'last_updated': hepsubmission.last_updated,
                'title': u'My New Journal Paper',
                'versions': 1
            },
            'stats': {
                'attention': 0,
                'passed': 0,
                'todo': 0
            },
            'status': u'todo'
        })

        # Check pagination
        page1_submissions = prepare_submissions(user, 1)
        assert (len(page1_submissions) == 1)
        assert (page1_submissions[str(
            record_information2['recid'])] == all_submissions[str(
                record_information2['recid'])])

        page2_submissions = prepare_submissions(user, 1, 2)
        assert (len(page2_submissions) == 1)
        assert (page2_submissions[str(
            record_information['recid'])] == all_submissions[str(
                record_information['recid'])])

        # Check filtering by record id
        record_submissions = prepare_submissions(
            user, record_id=record_information2['recid'])
        assert (len(record_submissions) == 1)
        assert (record_submissions[str(
            record_information2['recid'])] == all_submissions[str(
                record_information2['recid'])])

        # change status to 'finished' and check new submission no longer appears
        hepsubmission.overall_status = 'finished'
        db.session.add(hepsubmission)
        db.session.commit()

        assert (get_submission_count(user) == 1)
        all_submissions = prepare_submissions(user)
        assert (len(all_submissions) == 1)
        assert (list(
            all_submissions.keys()) == [str(record_information['recid'])])
Exemple #7
0
def dashboard_submissions():
    filter_record_id = request.args.get('record_id')
    current_page = request.args.get('page', default=1, type=int)
    size = request.args.get('size', 25)
    submissions = prepare_submissions(current_user,
                                      items_per_page=size,
                                      current_page=current_page,
                                      record_id=filter_record_id)

    submission_meta = []
    submission_stats = []

    for record_id in submissions:
        stats = []

        for key in submissions[record_id]["stats"].keys():
            stats.append({
                "name": key,
                "count": submissions[record_id]["stats"][key]
            })

        submission_stats.append({"recid": record_id, "stats": stats})

        review_flag = "todo"
        if submissions[record_id]["stats"]["attention"] == 0 and \
                submissions[record_id]["stats"]["todo"] == 0 and \
                submissions[record_id]["stats"]["passed"] == 0:
            review_flag = "todo"
        elif submissions[record_id]["stats"]["attention"] > 0 or \
                submissions[record_id]["stats"]["todo"] > 0:
            review_flag = "attention"
        elif submissions[record_id]["stats"]["attention"] == 0 and \
                submissions[record_id]["stats"]["todo"] == 0:
            review_flag = "passed"

        if submissions[record_id]["status"] == 'finished':
            review_flag = "finished"

        submissions[record_id]["metadata"]["submission_status"] = \
            submissions[record_id]["status"]
        submissions[record_id]["metadata"]["review_flag"] = review_flag

        submission_meta.append(submissions[record_id]["metadata"])

    total_records = get_submission_count(current_user)
    total_pages = int(math.ceil(total_records / size))

    ctx = {
        'user_is_admin': has_role(current_user, 'admin'),
        'modify_query': modify_query,
        'submissions': submission_meta,
        'submission_stats': submission_stats
    }

    if filter_record_id is None:
        ctx['pages'] = {
            'total': total_pages,
            'current': current_page,
            'endpoint': '.dashboard'
        }

    return render_template('hepdata_dashboard/dashboard-submissions.html',
                           ctx=ctx)