Skip to content
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

[ENG-6447] Update preprint model for versioning #2419

Conversation

futa-ikeda
Copy link
Contributor

@futa-ikeda futa-ikeda commented Dec 3, 2024

Purpose

  • Update the Preprint model to add new version-specific fields

Summary of Changes

  • Add new preprintVersion and isLatestVersion attrs to Preprint
  • Add new versions relationship to Preprint
    • This won't be returned from the API, but the preprint response should have a preprint_version URL that can be used to get versions, hence the chicanery with the preprint-serializer
  • Add new mirage view to handle fetching versions
  • Add new trait to preprint factory to quickly create versions for a given preprint

Screenshot(s)

  • This is the mirage request/response made when accessing the detail page of a preprint with versions
    image

Side Effects

QA Notes

Copy link
Collaborator

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

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

Looks good as we discussed 🎆

Copy link
Contributor

@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.

Just a question and a couple of small things.

Comment on lines +9 to +14
// Insert a `versions` relationship to the model
result.data.relationships!.versions = {
links: {
related: resourceHash.links!.preprint_versions!,
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary?

Copy link
Contributor Author

@futa-ikeda futa-ikeda Dec 3, 2024

Choose a reason for hiding this comment

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

According to the API Contract, the API won't be serializing the Preprint.versions relationship, since it is recursive.

Comment on lines +81 to +82
preprintVersion: 1,
isLatestVersion: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is the latest version, shouldn't it be version 3 based on the withVersions afterCreate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

withVersions is a factory trait, so only preprints created with that trait (server.create('preprint', 'withVersions')) will have 3 versions. Every other preprint will just have only 1 version.

@@ -35,6 +36,8 @@ export function createPreprint(this: HandlerContext, schema: Schema) {
subjects: [],
tags: [] as string[] ,
currentUserPermission: [Permission.Admin, Permission.Read, Permission.Write],
versionNumber: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

And I would presume this needs to be 3 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in the createPreprint view, so the versionNumber property for a freshly created preprint should just be 1 in this case. I will have a separate view for createPreprintVersion that will increment the versionNumber property

@futa-ikeda futa-ikeda merged commit 500e4bd into CenterForOpenScience:feature/preprints-doi-versioning Dec 3, 2024
9 checks passed
@futa-ikeda futa-ikeda deleted the update-preprint-model branch December 3, 2024 22:15
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.

3 participants