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

Fix content composition blocking undo operation #7056

Closed
wants to merge 2 commits into from

Conversation

aschempp
Copy link
Member

If you delete the whole page tree in the Contao demo, and try to restore it, the current system fails, because some pages contain articles that should not be allowed. This is because a page can be regular, have an article, and then change its type to something that does not allow content composition.

I think the best option would be to allow such a restore, because we don't want to loose data without telling the user. If a CreateAction has an ID, it most likely is a restore (at least internally, maybe not from an API). Since this will only allow "invalid" content composition, but still correctly check access permissions in other voters, I think that should be fine.

@aschempp aschempp added the bug label Mar 25, 2024
@aschempp aschempp added this to the 5.3 milestone Mar 25, 2024
@aschempp aschempp requested a review from a team March 25, 2024 07:12
@aschempp aschempp self-assigned this Mar 25, 2024
@leofeyer
Copy link
Member

I don‘t think this is the right solution. We should wrap the following line in a try/catch block instead:

$this->denyAccessUnlessGranted(ContaoCorePermissions::DC_PREFIX . $table, new CreateAction($table, $row));

This way, the undo operation would continue to restore all records except the faulty one.

@aschempp
Copy link
Member Author

I disagree. This would silentry drop data from the database on restore. We don't warn the user, we don't give any option, and it would also delete the undo record meaning everything is just gone. My behaviour would undo the existing records as it was, which is what I would expect from an undo operation.

@aschempp aschempp force-pushed the fix/content-composition-undo branch from b88bbda to 7cbe56c Compare March 25, 2024 08:23
@leofeyer
Copy link
Member

I agree that we should not delete the undo record if the restore operation was not successful. And we should probably give feedback to the user in this case.

Still your suggestion only handles one of many possible cases. We should have a more general solution IMHO.

@m-vo
Copy link
Member

m-vo commented Mar 25, 2024

But in general, undoing something that now (with changed permissions in the meantime) is not allowed anymore, must be prohibited? Or should undoing bypass permissions completely?

@aschempp
Copy link
Member Author

If the permissions are changed, I think it is correct that you cannot undo something. Using stored procedures would be a separate topic though (not sure if that already works, it didn't for me locally on MySQL 5.1).

This specific use case is because we allow to create content that is later prohibited, I think that is valid to be restored.

@leofeyer leofeyer added up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. and removed up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. labels Apr 4, 2024
@@ -55,6 +55,12 @@ public function vote(TokenInterface $token, $subject, array $attributes): int
return self::ACCESS_ABSTAIN;
}

// If the record has an ID, it is most likely an undo operation, which should
// allowed if there were articles on a page without content composition.
if ($subject instanceof CreateAction && $subject->getNewId()) {
Copy link
Member

Choose a reason for hiding this comment

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

As discussed in the Contao call, the restore operation should be an update action instead of a create action.

leofeyer pushed a commit that referenced this pull request May 7, 2024
Description
-----------

This restores the permission handling we had in all previous Contao versions. After discussing with @Toflar, this is the only viable solution to fix our permission issues. Here are two examples that are imho impossible to fix otherwise. They are not a technical issue, but a logical one.

1. If you duplicate a page, its articles will be duplicated as well as its content elements. If you do not have access to some elements, the whole page and articles are duplicated, **but "random" content elements will be missing**.

2. even worse, when deleting a page, DC_Table tries to delete all child records and create an undo record for them. The ones that the user does not have access will not be deleted, **and will not be added to the undo record**. They are however still removed by our reviseTable, and will therefore be lost without the option to undo.

In the same sense we could discuss to adjust the `undo` method instead of what we discussed in #7056

FYI @Toflar and me discussed that the same handling will not be possible in a regular REST/CRUD API. It would require special APIs for that, which can always be added if necessary.


- Fixes #7101
- Probably also makes #7102 obsolete but correctly checking the IDs/updating the cache might still be correct.

Commits
-------

eb388c6 Skip permissions checks for child records
961033f Also remove permission check in undo operation
70d7577 Fixed duplicate variable name
leofeyer pushed a commit to contao/core-bundle that referenced this pull request May 7, 2024
Description
-----------

This restores the permission handling we had in all previous Contao versions. After discussing with @Toflar, this is the only viable solution to fix our permission issues. Here are two examples that are imho impossible to fix otherwise. They are not a technical issue, but a logical one.

1. If you duplicate a page, its articles will be duplicated as well as its content elements. If you do not have access to some elements, the whole page and articles are duplicated, **but "random" content elements will be missing**.

2. even worse, when deleting a page, DC_Table tries to delete all child records and create an undo record for them. The ones that the user does not have access will not be deleted, **and will not be added to the undo record**. They are however still removed by our reviseTable, and will therefore be lost without the option to undo.

In the same sense we could discuss to adjust the `undo` method instead of what we discussed in contao/contao#7056

FYI @Toflar and me discussed that the same handling will not be possible in a regular REST/CRUD API. It would require special APIs for that, which can always be added if necessary.


- Fixes contao/contao#7101
- Probably also makes contao/contao#7102 obsolete but correctly checking the IDs/updating the cache might still be correct.

Commits
-------

eb388c66 Skip permissions checks for child records
961033f3 Also remove permission check in undo operation
70d75771 Fixed duplicate variable name
@leofeyer
Copy link
Member

@aschempp Can this pull request be closed now that #7133 has been merged?

@aschempp aschempp closed this May 15, 2024
@aschempp aschempp deleted the fix/content-composition-undo branch May 15, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants