"user2" received a single folder "test" with edit permissions
At step 6 (direct user share), OC doesn't allow sharing because it's already shared.
At step 7 it works however.
Observed in v9.0.3.
Regression from v8.2.
A bisect shows that this problem starts to appear after we made the share dialog use the public OCS Share API instead of the old internal ajax endpoints: #21860
It is likely that the OCS Share API never allowed this configuration before, so need to find a way to make it align to the way the old API behaved.
Weiiiird, this seems to work on master. I found this check in the code: https://github.com/owncloud/core/blob/stable9/lib/private/share20/manager.php#L362
It would only show the error if someone else tried to share with that user. If the share owner is the same, it goes through.
Now to find out why it works on master and not stable9.
Aha! It turns out that the share owner of the new share isn't set properly (null), so the comparison would always be true: https://github.com/owncloud/core/blob/stable9/lib/private/share20/manager.php#L362
Now to find out what commit fixed it in master
Found it, this is the commit that fixes it on master: afa37d3
Looks like it's not as easy as just backporting it. Even applying this wouldn't solve the problem.
It seems it might have been broken again later on and then fixed again.
From what I see on master the order between "setShareOwner" and "userCreateChecks" has been changed at some point. It makes sense to first set the owner before doing the checks.
I'll try and fix this manually then instead of backporting.
Fix is here: #25360