sul-dlss / happy-heron

Self-Deposit for the Stanford Digital Repository (SDR): H2 is a Rails web application enabling users to deposit scholarly content into SDR
Apache License 2.0
10 stars 2 forks source link

Update WorkVersion.user_version when submitting work form #3506

Closed justinlittman closed 1 month ago

justinlittman commented 2 months ago

This ticket involves changing the approach for persisting user versions. Currently, user_version of an attribute of a WorkVersion with a unique index on id, user_version. So, for example:

Work Version user_version
1
2 1
3
4 2

In this case, user version 1 is work version 2 and user version 2 is work version 4.

In the new approach, every WorkVersion will have a user_version (except maybe the current draft). Work Version user_version
1 1
2 1
3 2
4 2

To find the Work Version for a user version, you find the highest WorkVersion with the user_version value. In this case, user version 1 is work version 2 and user version 2 is work version 4. (Though there aren't currently any features that require this.)

This means that discarding a draft doesn't require making any changes to user_version values. If WorkVersion 4 would be discarded then work version 3 would become user version 2:

Work Version user_version
1 1
2 1
3 2

This also allows it to be determined which radio button to select when displaying the new version section: image

When a draft WorkVersion is created, no radio button should be selected. While the user will have to make a choice before depositing, they can still save a draft without making a choice. No choice is represented by a null. Thus, if there is no user_version, select no radio buttons: Work Version user_version
1 1
2 1
3 2
4
If the user_version is the same as the last WorkVersion, then select the "No" radio: Work Version user_version
1 1
2 1
3 2
4 2
If the user_version is different than the last WorkVersion, then select the "Yes" radio: Work Version user_version
1 1
2 1
3 2
4 3

Thus, the work for this ticket includes (but may not be limited to):

  1. Remove the unique index.
  2. Populate user_version for existing WorkVersions. (The value is probably just 1.)
  3. When creating a new WorkVersion, set user_version to nil, except the first WorkVersion which should be 1.
  4. If feature flag is set, populate the version section radio button and version description field as described above.
  5. If feature flag is set, when saving a WorkVersion, update the user_version based on the radio button. (If "yes", increment the user_version of the previous WorkVersion. If "no", use the user_version of the previous WorkVersion. If neither, set to nil.)
  6. If the feature flag is not set, when saving a WorkVersion, set the user_version to the user_version of the previous WorkVersion.
  7. Make sure that there are enough code comments and/or README docs to document this approach for our future selves.