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

[stable10] Move "no-change" result below all the checks #32156

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions apps/files_sharing/lib/API/Share20OCS.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,6 @@ private function updateShareState($id, $state) {
return new \OC\OCS\Result(null, 404, $this->l->t('Wrong share ID, share doesn\'t exist'));
}

if ($share->getState() === $state) {
if ($eventName !== '') {
$this->eventDispatcher->dispatch('share.after' . $eventName, new GenericEvent(null, ['share' => $share]));
}
// if there are no changes in the state, just return the share as if the change was successful
return new \OC\OCS\Result([$this->formatShare($share, true)]);
}

$node = $share->getNode();
$node->lock(\OCP\Lock\ILockingProvider::LOCK_SHARED);

Expand All @@ -912,6 +904,15 @@ private function updateShareState($id, $state) {
return new \OC\OCS\Result(null, 403, $this->l->t('Only recipient can change accepted state'));
}

if ($share->getState() === $state) {
if ($eventName !== '') {
$this->eventDispatcher->dispatch('share.after' . $eventName, new GenericEvent(null, ['share' => $share]));
}
// if there are no changes in the state, just return the share as if the change was successful
$node->unlock(\OCP\Lock\ILockingProvider::LOCK_SHARED);
return new \OC\OCS\Result([$this->formatShare($share, true)]);
}

// we actually want to update all shares related to the node in case there are multiple
// incoming shares for the same node (ex: receiving simultaneously through group share and user share)
$allShares = $this->shareManager->getSharedWith($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
Expand Down
6 changes: 1 addition & 5 deletions apps/files_sharing/tests/API/Share20OCSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3215,11 +3215,7 @@ public function providesAcceptRejectShareSameState() {
* @dataProvider providesAcceptRejectShareSameState
*/
public function testAcceptRejectShareSameState($method, $target) {
$node = $this->createMock(Node::class);

$userShare = $this->newShare();
$userShare->setId(123);
$userShare->setNode($node);
$userShare = $this->makeReceivedUserShareForOperation($target);

$this->shareManager->expects($this->exactly(1))
->method('getShareById')
Expand Down