Skip to content

fix: preserve link shares on ownership transfer - #64209

Merged
susnux merged 3 commits into
masterfrom
fix/transfer-link-shares
Sep 14, 2026
Merged

susnux merged 3 commits into
masterfrom
fix/transfer-link-shares

Conversation

@salmart-dev

@salmart-dev salmart-dev commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue on file ownership transfer, which causes link and email shares to be incorrectly dropped.

Link and email shares get their parent database column set when they come from a reshare, this is used to delete them once the parent share is deleted. During transfer, all shares related to the transferred content are collected and are, in some cases, deleted. The delete triggers the cascade-delete of link and email shares, so they are effectively lost. This PR sets the parent column of the affected shares to null before the main share is deleted, so that the subsequent handling of those shares updates the owner to the user receiving the transfer.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@salmart-dev salmart-dev self-assigned this Sep 11, 2026
@salmart-dev
salmart-dev force-pushed the fix/transfer-link-shares branch from 8a825d4 to a7c6dfb Compare September 11, 2026 11:00
@salmart-dev salmart-dev added this to the Nextcloud 35.0.1 milestone Sep 11, 2026
@salmart-dev salmart-dev added 3. to review Waiting for reviews bug labels Sep 11, 2026
@salmart-dev

Copy link
Copy Markdown
Contributor Author

/backport to stable35

@salmart-dev

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@salmart-dev

Copy link
Copy Markdown
Contributor Author

/backport to stable33

@salmart-dev

Copy link
Copy Markdown
Contributor Author

/backport to stable32

@salmart-dev
salmart-dev marked this pull request as ready for review September 11, 2026 13:40
@salmart-dev
salmart-dev requested a review from a team as a code owner September 11, 2026 13:40
@salmart-dev
salmart-dev requested review from Altahrim, CarlSchwan, leftybournes and provokateurin and removed request for a team September 11, 2026 13:40
@salmart-dev

Copy link
Copy Markdown
Contributor Author

Test failures are unrelated, both should be caused by #53048, the psalm one has already been addressed, but the issue with the non-cleared cache is not yet.

@susnux
susnux force-pushed the fix/transfer-link-shares branch from a7c6dfb to e2f617a Compare September 13, 2026 13:08

@provokateurin provokateurin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure if this is correct. As far as I understand the parent share is not actually deleted, but transferred, so you're changing the share without it being necessary.

Doesn't this mean, we have to change the order in which shares are transferred? The ones that are the most deeply nested first and the root last, so that deleting the "old" shares doesn't unintentionally delete any shares.

@salmart-dev
salmart-dev force-pushed the fix/transfer-link-shares branch from e2f617a to 9a381a3 Compare September 14, 2026 12:30
@salmart-dev

salmart-dev commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure if this is correct. As far as I understand the parent share is not actually deleted, but transferred, so you're changing the share without it being necessary.

Shares are not all transferred. The code is dropping the following redundant share rows:

  1. user shares created by the user receiving the transfer targeting the source user as share-receiver. In this case links that the source user had created are incorrectly dropped.
  2. shares for nodes the receiving user had already access to through other shares. In this case, which share row is removed depends on permissions, and in any case the share entry of the receiver or of the source is deleted. Also here links may be dropped dropped if the deleted share was a parent for those links.
  3. shares for nodes the destination user owns. Since the receiving user owns the nodes, it makes no sense to transfer the share, so it is deleted. Link shares that the source had created get deleted as a consequence.

So in all those cases a share entry is being dropped and, due to the fact that link and email oc_share entries can carry a parent ID, results in their removal once the parent share gets deleted. The update query targets only link/email shares and uses the ID of the parent row which is about to be deleted, so nothing that would not be immediately deleted is being modified.

I did miss the fact that we should re-parent links in the case where the user receiving the transfer already has received shares for the same node, is this what you meant? I added a commit to address that.

@provokateurin

Copy link
Copy Markdown
Member

I did miss the fact that we should re-parent links in the case where the user receiving the transfer already has received shares for the same node, is this what you meant?

Yes, that was mostly my concern.

CommandLine defines both logic to run occ commands in integration tests
as wel as behat steps. This is problematic as if two contexts are loaded
and both need the ability to run occ commands, they will cause a
conflict due to the steps being defined more than once.

Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
@susnux
susnux force-pushed the fix/transfer-link-shares branch from 9a381a3 to 217eb44 Compare September 14, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Public shares get deleted after ownership transfer

3 participants