Skip to content

Commit

Permalink
filter out deleted preprint drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Aug 30, 2024
1 parent 6f4c7b8 commit fb8aeb6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def get_default_queryset(self):
user = self.get_user()
return user.preprints.filter(
machine_state='initial',
deleted__isnull=True,
)

def get_queryset(self):
Expand Down
29 changes: 28 additions & 1 deletion api_tests/users/views/test_user_draft_preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PreprintProviderFactory,
)
from api.base.settings.defaults import API_BASE

from django.utils import timezone

@pytest.mark.django_db
class TestPreprintDraftList:
Expand Down Expand Up @@ -97,6 +97,20 @@ def abandoned_public_preprint(self, admin, provider, subject, public_project):
machine_state='initial'
)

@pytest.fixture()
def deleted_preprint(self, admin, provider, subject, public_project):
preprint = PreprintFactory(
creator=admin,
provider=provider,
project=public_project,
is_published=False,
is_public=False,
machine_state='initial',
)
preprint.deleted = timezone.now()
preprint.save()
return preprint

def test_gets_preprint_drafts(self, app, admin, abandoned_public_preprint, abandoned_private_preprint, published_preprint):
res = app.get(
f'/{API_BASE}users/{admin._id}/draft_preprints/',
Expand Down Expand Up @@ -131,3 +145,16 @@ def test_get_projects_logged_in_as_write_user(self, app, admin, write_contrib, a
expect_errors=True
)
assert res.status_code == 403

def test_deleted_drafts_ecluded(self, app, admin, abandoned_public_preprint, abandoned_private_preprint, published_preprint, deleted_preprint):
res = app.get(
f'/{API_BASE}users/{admin._id}/draft_preprints/',
auth=admin.auth
)
assert res.status_code == 200

ids = [each['id'] for each in res.json['data']]
assert abandoned_public_preprint._id in ids
assert abandoned_private_preprint._id in ids
assert published_preprint._id not in ids
assert deleted_preprint._id not in ids # Make sure deleted preprints are not listed

0 comments on commit fb8aeb6

Please sign in to comment.