Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/arxiv/submission/services/classic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ def get_events(submission_id: int) -> List[Event]:
@handle_operational_errors
def get_user_submissions_fast(user_id: int) -> List[Submission]:
"""
Get all active submissions for a user.
Get active NG submissions for a user.

This should not return submissions for which there are no events.

Uses the same approach as :func:`get_submission_fast`.

Expand All @@ -151,6 +153,7 @@ def get_user_submissions_fast(user_id: int) -> List[Submission]:
db_submissions = list(
session.query(models.Submission)
.filter(models.Submission.submitter_id == user_id)
.join(DBEvent) # Only get submissions that are also in the event table
.order_by(models.Submission.doc_paper_id.desc())
)
grouped = groupby(db_submissions, key=lambda dbs: dbs.doc_paper_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
SetComments, SetAuthors, Announce, ConfirmAuthorship, ConfirmPolicy, \
SetUploadPackage
from .. import init_app, create_all, drop_all, models, DBEvent, \
get_submission, current_session, get_licenses, exceptions, store_event, \
transaction
get_submission, get_user_submissions_fast, current_session, get_licenses, \
exceptions, store_event, transaction

from .util import in_memory_db

Expand Down Expand Up @@ -157,3 +157,91 @@ def test_get_submission_with_hold_and_reclass(self):
self.assertTrue(submission_loaded.is_on_hold,
"Hold status should reflect hold action performed"
" outside the purview of the event model.")

def test_get_submission_list(self):
"""Test that the set of submissions for a user can be retrieved."""
user = User(42, '[email protected]',
endorsements=['astro-ph.GA', 'astro-ph.EP'])
events1 = [
# first submission
CreateSubmission(creator=user),
SetTitle(creator=user, title='Foo title'),
SetAbstract(creator=user, abstract='Indeed' * 20),
SetAuthors(creator=user, authors=[
Author(order=0, forename='Arthur', surname='Dent',
email='[email protected]'),
Author(order=1, forename='Ford', surname='Prefect',
email='[email protected]'),
]),
SetLicense(creator=user, license_uri='http://creativecommons.org/publicdomain/zero/1.0/',
license_name='Foo zero 1.0'),
SetPrimaryClassification(creator=user, category='astro-ph.GA'),
ConfirmPolicy(creator=user),
SetUploadPackage(creator=user, identifier='1'),
ConfirmContactInformation(creator=user),
FinalizeSubmission(creator=user)
]
events2 = [
# second submission
CreateSubmission(creator=user),
SetTitle(creator=user, title='Bar title'),
SetAbstract(creator=user, abstract='Indubitably' * 20),
SetAuthors(creator=user, authors=[
Author(order=0, forename='Jane', surname='Doe',
email='[email protected]'),
Author(order=1, forename='John', surname='Doe',
email='[email protected]'),
]),
SetLicense(creator=user, license_uri='http://creativecommons.org/publicdomain/zero/1.0/',
license_name='Foo zero 1.0'),
SetPrimaryClassification(creator=user, category='astro-ph.GA'),
ConfirmPolicy(creator=user),
SetUploadPackage(creator=user, identifier='1'),
ConfirmContactInformation(creator=user),
FinalizeSubmission(creator=user)
]

with in_memory_db():
# User creates and finalizes submission.
with transaction():
before = None
for i, event in enumerate(list(events1)):
event.created = datetime.now(UTC)
after = event.apply(before)
event, after = store_event(event, before, after)
events1[i] = event
before = after
submission1 = after
ident1 = submission1.submission_id

before = None
for i, event in enumerate(list(events2)):
event.created = datetime.now(UTC)
after = event.apply(before)
event, after = store_event(event, before, after)
events2[i] = event
before = after
submission2 = after
ident2 = submission2.submission_id

classic_sub = models.Submission(
type='new',
submitter_id=42)
session = current_session()
session.add(classic_sub)
# Now get the submissions for this user.
submissions = get_user_submissions_fast(42)
submission_loaded1, _ = get_submission(ident1)
submission_loaded2, _ = get_submission(ident2)

self.assertEqual(submission1.metadata.title,
submission_loaded1.metadata.title,
"Event-derived metadata for submission 1 should be preserved.")
self.assertEqual(submission2.metadata.title,
submission_loaded2.metadata.title,
"Event-derived metadata for submission 2 should be preserved.")

self.assertEqual(len(submissions),
2,
"There should be exactly two NG submissions.")