Esempio n. 1
0
def add_participant(recid):
    """
    Adds a participant to a record.

    :param recid:
    :return:
    """
    try:
        submission_record = get_latest_hepsubmission(publication_recid=recid)
        full_name = request.form['name']
        email = request.form['email']
        participant_type = request.form['type']

        new_record = SubmissionParticipant(publication_recid=recid,
                                           full_name=full_name,
                                           email=email,
                                           role=participant_type)
        submission_record.participants.append(new_record)
        db.session.commit()
        return json.dumps({
            "success":
            True,
            "recid":
            recid,
            "message":
            "{0} {1} added.".format(full_name, participant_type)
        })

    except Exception as e:
        return json.dumps({
            "success": False,
            "recid": recid,
            "message": 'Unable to add participant.'
        })
Esempio n. 2
0
def create_participant_record(name, email, role, status, recid):
    participant_record = SubmissionParticipant(full_name=name,
                                               email=email,
                                               status=status,
                                               role=role,
                                               publication_recid=recid)

    return participant_record
Esempio n. 3
0
def test_has_upload_permissions(app):
    # Test uploader permissions
    with app.app_context():
        # Create a record
        recid = '12345'
        get_or_create_hepsubmission(recid, 1)

        # Check admin user has upload permissions to new record
        admin_user = user = User.query.first()
        assert has_upload_permissions(recid, admin_user)

        # Create a user who is not admin and not associated with a record
        user = User(email='*****@*****.**',
                    password='******',
                    active=True)
        db.session.add(user)
        db.session.commit()
        login_user(user)

        assert not has_upload_permissions(recid, user)

        # Add the user as an uploader but not primary - should not be allowed
        submission_participant = SubmissionParticipant(user_account=user.id,
                                                       publication_recid=recid,
                                                       email=user.email,
                                                       role='uploader')
        db.session.add(submission_participant)
        db.session.commit()

        assert not has_upload_permissions(recid, user)

        # Make the participant primary uploader - should now work
        submission_participant.status = 'primary'
        db.session.add(submission_participant)
        db.session.commit()

        assert has_upload_permissions(recid, user)
Esempio n. 4
0
def parse_modifications(hepsubmission, recid, submission_info_document):
    for modification in submission_info_document['modifications']:
        try:
            date = parse(modification['date'])
        except ValueError as ve:
            date = datetime.utcnow()

        # don't add another if it's not necessary to do so
        existing_participant = SubmissionParticipant.query.filter_by(
            publication_recid=recid,
            full_name=modification["who"],
            role=modification["action"],
            action_date=date)

        if existing_participant.count() == 0:
            participant = SubmissionParticipant(
                publication_recid=recid, full_name=modification["who"],
                role=modification["action"], action_date=date)
            db.session.add(participant)
Esempio n. 5
0
def test_create_new_version(app, load_default_data, identifiers, mocker):
    hepsubmission = get_latest_hepsubmission(publication_recid=1)
    assert hepsubmission.version == 1

    # Add an uploader
    uploader = SubmissionParticipant(publication_recid=1,
                                     email='*****@*****.**',
                                     role='uploader',
                                     status='primary')
    db.session.add(uploader)
    db.session.commit()

    user = User.query.first()

    # Mock `send_cookie_email` method
    send_cookie_mock = mocker.patch(
        'hepdata.modules.records.api.send_cookie_email')

    # Create new version of valid finished record
    result = create_new_version(1, user, uploader_message="Hello!")
    assert result.status_code == 200
    assert result.json == {'success': True, 'version': 2}

    # get_latest_hepsubmission should now return version 2
    hepsubmission = get_latest_hepsubmission(publication_recid=1)
    assert hepsubmission.version == 2
    assert hepsubmission.overall_status == 'todo'

    # Should have attempted to send uploader email
    send_cookie_mock.assert_called_with(uploader,
                                        get_record_by_id(1),
                                        message="Hello!",
                                        version=2)

    # Try creating a new version - should not work as status of most recent is 'todo'
    result, status_code = create_new_version(1, user)
    assert status_code == 400
    assert result.json == {
        'message': 'Rec id 1 is not finished so cannot create a new version'
    }
Esempio n. 6
0
def test_has_coordinator_permissions(app):
    # Test coordinator permissions
    with app.app_context():
        recid = '12345'
        hepsubmission = get_or_create_hepsubmission(recid, 1)

        # Check admin user has coordinator permissions to new record
        admin_user = user = User.query.first()
        assert has_coordinator_permissions(recid, admin_user)

        # Create a user who is not admin and not associated with a record
        user = User(email='*****@*****.**',
                    password='******',
                    active=True)
        db.session.add(user)
        db.session.commit()
        login_user(user)

        assert not has_coordinator_permissions(recid, user)

        # Add the user as an uploader - should not have permission
        submission_participant = SubmissionParticipant(user_account=user.id,
                                                       publication_recid=recid,
                                                       email=user.email,
                                                       role='uploader')
        db.session.add(submission_participant)
        db.session.commit()

        assert not has_coordinator_permissions(recid, user)

        # Modify record to add this user as coordinator - should now work
        hepsubmission.coordinator = user.get_id()
        db.session.add(hepsubmission)
        db.session.commit()

        assert has_coordinator_permissions(recid, user)
Esempio n. 7
0
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'])])
Esempio n. 8
0
def test_dashboard(live_server, logged_in_browser):
    """
    Test dashboard functions
    """
    browser = logged_in_browser

    # Create some submissions so that there'll be something on the dashboard
    # and on 2 pages. Current user will be coordinator and uploader.
    for i in range(26):
        content = {'title': f'Dashboard Test {i}'}
        record_information = create_record(content)
        hepsubmission = get_or_create_hepsubmission(record_information["recid"], 1)
        participant_record = SubmissionParticipant(email='*****@*****.**',
                                                   status='primary',
                                                   role='uploader',
                                                   user_account=1,
                                                   publication_recid=record_information["recid"])
        db.session.add(hepsubmission)
        db.session.add(participant_record)

    db.session.commit()

    # Confirm there are 26 'todo' submissions
    submissions = HEPSubmission.query \
        .filter_by(overall_status='todo').all()
    assert len(submissions) == 26

    # Click on dashboard link
    browser.find_element_by_link_text('Dashboard').click()
    e2e_assert_url(browser, 'hep_dashboard.dashboard')

    # Check links in top section work
    # Submissions Overview link
    browser.find_element_by_link_text('Submissions Overview').click()
    e2e_assert_url(browser, 'hep_dashboard.submissions')

    # Wait for graph to load
    WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "#submission_vis svg"))
    )

    # Go back
    browser.back()
    e2e_assert_url(browser, 'hep_dashboard.dashboard')

    # Edit Profile link
    browser.find_element_by_link_text('Edit Profile').click()
    e2e_assert_url(browser, 'invenio_userprofiles.profile')

    # Go back
    browser.back()
    e2e_assert_url(browser, 'hep_dashboard.dashboard')

    # Wait for submissions to load
    submissions_list = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, "hep-submissions"))
    )
    submission_items = submissions_list.find_elements_by_class_name('submission-item')
    assert len(submission_items) == 25

    # Check pagination works
    browser.find_element_by_css_selector(".pagination-bar a[href='/dashboard/?page=2']").click()
    # Wait for loader, then new items appear
    WebDriverWait(browser, 10).until(
        EC.text_to_be_present_in_element(
            (By.CSS_SELECTOR, '.submission-item h4 a'),
            'Dashboard Test 0'
        )
    )
    # Should just be 1 submission on page 2
    submission_items = browser.find_elements_by_class_name('submission-item')
    assert len(submission_items) == 1

    # Check settings modal appears
    submission_items[0].find_element_by_class_name('manage-submission-trigger').click()
    manage_widget = WebDriverWait(browser, 10).until(
        EC.visibility_of_element_located((By.ID, 'manageWidget'))
    )
    assert manage_widget.find_element_by_class_name('modal-title').text == 'Manage Submission'
    # Close modal
    manage_widget.find_element_by_css_selector('.modal-footer .btn-default').click()
    WebDriverWait(browser, 10).until(
        EC.invisibility_of_element(manage_widget)
    )

    # Click delete button
    # Check settings modal appears
    submission_items[0].find_element_by_class_name('delete-submission-trigger').click()
    delete_widget = WebDriverWait(browser, 10).until(
        EC.visibility_of_element_located((By.ID, 'deleteWidget'))
    )
    assert delete_widget.find_element_by_class_name('modal-title').text == 'Delete Submission'
    # Confirm deletion
    delete_widget.find_element_by_class_name('confirm-delete').click()
    # Wait for confirmation of deletion
    WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, 'delete-success'))
    )
    assert 'Submission deleted' in \
        delete_widget.find_element_by_css_selector('#delete-success p').text

    # Should now be 25 submissions not 26
    submissions = HEPSubmission.query \
        .filter_by(overall_status='todo').all()
    assert len(submissions) == 25

    # Reload the dashboard (rather than waiting)
    browser.refresh()

    # Check permissions widget
    # Coordinator tab should have 5 items (restricted as we are user id 1)
    coordinator_pane = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, 'coordinator'))
    )
    coordinator_rows = coordinator_pane.find_elements_by_class_name('row')
    assert len(coordinator_rows) == 5

    # Click on uploader pane - should be all 25 items
    browser.find_element_by_link_text('uploader').click()
    uploader_pane = browser.find_element_by_id('uploader')
    uploader_rows = uploader_pane.find_elements_by_class_name('row')
    assert len(uploader_rows) == 25

    # Only first 5 should be visible
    assert all(row.is_displayed() for row in uploader_rows[:5])
    assert all(not row.is_displayed() for row in uploader_rows[5:])
    # Scroll down to find paginator
    ActionChains(browser).move_to_element(uploader_rows[4]).perform()
    # Click on last page
    uploader_pane.find_element_by_css_selector(".pagination-bar li a[title=last]").click()
    # Now last 5 items should be visible
    assert all(not row.is_displayed() for row in uploader_rows[:20])
    assert all(row.is_displayed() for row in uploader_rows[20:])