Skip to content

[ENG-7716] Allow for reinstatement of previous preprint versions (with date uploaded) via the admin app #11097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

antkryt
Copy link
Contributor

@antkryt antkryt commented Apr 15, 2025

Purpose

Add "Create new version 1" button on admin UI

Changes

  • Add button to admin UI
  • Extend existing preprint versioning functionality
  • Move permission validation logic from serializer to model level to keep everything in one place
    • add required_permission decorator (with ignore_permission functionality) that checks if user has enough permission to call method
Screencast.from.2025-04-22.14-43-05.webm

QA Notes

Expected behavior:

  1. Admin goes the preprint admin page
  2. Clicks "Create new version 1", a modal asking to choose date will be displayed
  3. If date is valid and file versions exists:
    • a new version 1 will be created
    • admin user will be redirected to v1
    • optionally, admin user can make new preprint published by clicking "Make published" button

(!) Preprint guid should point to the latest version, not the newly created one.
(!) Admin should be able to create new versions of a preprint even if they are not a contributor.

Documentation

Side Effects

Ticket

https://openscience.atlassian.net/browse/ENG-7716

@antkryt
Copy link
Contributor Author

antkryt commented Apr 15, 2025

Alternatives:

  1. Add admin user to contributors to create new version and remove after it
  2. Create incomplete new preprint version (do not call PreprintSeriazlier.update() method) and update only primary_file for new preprint. User should be able to fill all the other fields with "Edit" button on the osf website

Both requires additional actions from user, but will make this PR ~2x smaller

@brianjgeiger brianjgeiger changed the base branch from feature/pbs-25-07 to feature/pbs-25-08 April 21, 2025 18:14
@brianjgeiger
Copy link
Collaborator

@antkryt Looks like there's a failed test.

=========================== short test summary info ============================
FAILED admin_tests/preprints/test_views.py::TestPreprintReVersionView::test_admin_user_can_add_new_version_one - assert 1 == 2
 +  where 1 = len(<GuidMixinQuerySet [<Preprint: Preprint object (868)>]>)
 +    where <GuidMixinQuerySet [<Preprint: Preprint object (868)>]> = <bound method Preprint.get_preprint_versions of <Preprint: Preprint object (868)>>()
 +      where <bound method Preprint.get_preprint_versions of <Preprint: Preprint object (868)>> = <Preprint: Preprint object (868)>.get_preprint_versions
=== 1 failed, 2813 passed, 42 skipped, 20469 warnings in 1501.92s (0:25:01) ====

Copy link
Collaborator

@brianjgeiger brianjgeiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you going through the API for this instead of just using the Preprint model to make the changes? It seems as though it would save you a lot of trouble if you just made the changes directly via the model. The Admin app shouldn't interact with the API.

@antkryt
Copy link
Contributor Author

antkryt commented Apr 23, 2025

The Preprint.create_version documentation states:
"... The API, specifically the PreprintCreateVersionSerializer, must call .update() to fully finalize the creation of the new preprint version object."

If I don't use the serializer, I would need to manually call around 15 Preprint.set_ methods, each with ignore-permission=True. Also, if the data_to_update dictionary structure or PreprintCreateVersionSerializer.update logic ever changes in the future, it may easily break this feature.

So, nothing really changes if I use PreprintCreateVersionSerializer (API) or not because of the create_version() function

@brianjgeiger
Copy link
Collaborator

I see.

@brianjgeiger brianjgeiger merged commit 90d5b68 into CenterForOpenScience:feature/pbs-25-08 Apr 24, 2025
6 checks passed
Johnetordoff added a commit to Johnetordoff/osf.io that referenced this pull request May 1, 2025
…cience/osf.io into impact-notifications

* 'feature/pbs-25-08' of https://github.com/CenterForOpenScience/osf.io: (28 commits)
  [ENG-7716] Allow for reinstatement of previous preprint versions (with date uploaded) via the admin app (CenterForOpenScience#11118)
  [ENG-7263] Fix/eng 7263 part 3 (CenterForOpenScience#11119)
  [ENG-7263] Part 2 (CenterForOpenScience#11110)
  fix feature for non-contributor admin (CenterForOpenScience#11111)
  [ENG-7716] Allow for reinstatement of previous preprint versions (with date uploaded) via the admin app (CenterForOpenScience#11097)
  delete sharev2 push [ENG-7387] (CenterForOpenScience#11032)
  [ENG-7503] Fix/eng 7503 (CenterForOpenScience#11092)
  [ENG-7263] Fix/eng 7263 (CenterForOpenScience#11090)
  [ENG-7798] Parse versioned guid (CenterForOpenScience#11104)
  [ENG-7270] Enable Product Team to Force Archive Registrations in the Admin App (CenterForOpenScience#11105)
  gdpr deletion shouldn't take into account deleted nodes (CenterForOpenScience#11098)
  Bind task for proper retrying
  improved naming
  use newly built doi for previous versions
  mint missing doi when build metadata
  use minted doi for building metadata
  updated error text
  simplified query
  flat guids
  added version filtering
  ...

# Conflicts:
#	api/crossref/views.py
#	tests/test_events.py
#	tests/test_misc_views.py
Vlad0n20 pushed a commit to Vlad0n20/osf.io that referenced this pull request May 5, 2025
…h date uploaded) via the admin app (CenterForOpenScience#11097)

## Purpose
Add "Create new version 1" button on admin UI

## Changes
- Add button to admin UI
- Extend existing preprint versioning functionality
- Move permission validation logic from serializer to model level to keep everything in one place
    - add required_permission decorator (with ignore_permission functionality) that checks if user has enough permission to call method

## QA Notes
Expected behavior:
1. Admin goes the preprint admin page
2. Clicks "Create new version 1", a modal asking to choose date will be displayed
3. If date is valid and file versions exists:
    - a new version 1 will be created
    - admin user will be redirected to v1
    - optionally, admin user can make new preprint published by clicking "Make published" button

(!) Preprint guid should point to the latest version, not the newly created one.
(!) Admin should be able to create new versions of a preprint even if  they are not a contributor.

## Ticket
https://openscience.atlassian.net/browse/ENG-7716
ihorsokhanexoft pushed a commit to ihorsokhanexoft/osf.io that referenced this pull request Jun 4, 2025
…h date uploaded) via the admin app (CenterForOpenScience#11097)

## Purpose
Add "Create new version 1" button on admin UI

## Changes
- Add button to admin UI
- Extend existing preprint versioning functionality
- Move permission validation logic from serializer to model level to keep everything in one place
    - add required_permission decorator (with ignore_permission functionality) that checks if user has enough permission to call method

## QA Notes
Expected behavior:
1. Admin goes the preprint admin page
2. Clicks "Create new version 1", a modal asking to choose date will be displayed
3. If date is valid and file versions exists:
    - a new version 1 will be created
    - admin user will be redirected to v1
    - optionally, admin user can make new preprint published by clicking "Make published" button

(!) Preprint guid should point to the latest version, not the newly created one.
(!) Admin should be able to create new versions of a preprint even if  they are not a contributor.

## Ticket
https://openscience.atlassian.net/browse/ENG-7716
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants