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

[WJ-1032] Add file_rollback #2133

Merged
merged 14 commits into from
Oct 10, 2024
Merged

[WJ-1032] Add file_rollback #2133

merged 14 commits into from
Oct 10, 2024

Conversation

emmiegit
Copy link
Member

This adds rollback capability to files, which like for page rollbacks, changes a file to have the same state it had earlier. (This cannot be used to move a file to a different page). While working on this, I discovered a bug in file moves where it wasn't properly updating the name.

Example output after local tests:

 revision_id | revision_type |          created_at           | revision_number | file_id | page_id | site_id | user_i>
-------------+---------------+-------------------------------+-----------------+---------+---------+---------+------->
           1 | create        | 2024-10-10 08:52:01.028316+00 |               0 |       1 |       1 |       1 |       >
           2 | regular       | 2024-10-10 08:52:13.901203+00 |               1 |       1 |       1 |       1 |       >
           3 | rollback      | 2024-10-10 08:52:21.541878+00 |               2 |       1 |       1 |       1 |       >
(3 rows)

@emmiegit emmiegit requested a review from Zokhoi October 10, 2024 08:58
@emmiegit emmiegit self-assigned this Oct 10, 2024
#[sea_orm(string_value = "undelete")]
Undelete,
#[sea_orm(string_value = "undo")]
Undo,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does PageRevisionType::Undo mean? Is it like the opposite of a rollback?

Copy link
Member Author

Choose a reason for hiding this comment

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

Undos are a planned operation. I am avoiding the term "revert" because it means two different things in git vs wikidot, and instead have two unambiguous terms:

  • Rollback (what wikidot calls "revert", what git calls "reset") is where you set the current state of a page or file to some revision in the past.
  • Undo (what git calls "revert") is where it applies the opposite of the given revision. Since this involves applying a diff, it can fail.

An example of the difference between the two. Imagine we have a page with this history:

Revision 10
**Item #:** SCP-XX

**Object Class:** Euclid

**Special Containment Procedures:** SCP-XX is to be kept in a cardboard box.
Revision 11
**Item #:** SCP-XX

**Object Class:** HAHA EPIC TROLL

**Special Containment Procedures:** SCP-XX is to be kept in a cardboard box.
Revision 12
**Item #:** SCP-XX

**Object Class:** HAHA EPIC TROLL

**Special Containment Procedures:** SCP-XX is to be kept in a cardboard or paper box.

So here, revision 11 is vandalism and we'd like to remove it. But the page has been edited since, so that means we'd lose any subsequent (legitimate) changes with a simple rollback. But using undo, similar to git revert, we can remove just the specific change from 10 -> 11 and leave the 12 revision in-place.

So basically it would produce the 11..10 diff (not that this is the inverse of the 10..11 diff that was applied in revision 11):

3c3
< **Object Class:** HAHA EPIC TROLL
---
> **Object Class:** Euclid

And then we could attempt to apply it.

(If there are conflicts, then like git revert, we should error out rather than attempting to ram our way through. Also, we should have some way of allowing a user to verify that the undo change is what they want before doing it.)

@emmiegit
Copy link
Member Author

thanks @Zokhoi

@emmiegit emmiegit merged commit e65d333 into develop Oct 10, 2024
8 checks passed
@emmiegit emmiegit deleted the WJ-1032-file-ops branch October 10, 2024 17:44
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