Skip to content

Commit

Permalink
Move "no-change" result below all the checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jvillafanez committed Jul 25, 2018
1 parent a4d129b commit a62b9fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
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 @@ -880,14 +880,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 @@ -904,6 +896,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 @@ -3138,11 +3138,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

0 comments on commit a62b9fe

Please sign in to comment.