From eb915e065edc7814be2db4f8ebceb6d79a012549 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 5 Oct 2016 12:11:43 +0200 Subject: [PATCH] Dont create new requests for a credential, when target user has pending requests for that credential --- controller/sharecontroller.php | 10 ++++++++-- lib/Db/ShareRequestMapper.php | 10 ++++++++++ lib/Service/ShareService.php | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 419649bc..57d3b630 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -110,6 +110,13 @@ class ShareController extends ApiController { //@TODO add expire_views $credential = $this->credentialService->getCredentialById($item_id, $this->userId->getUID()); $credential_owner = $credential->getUserId(); + + $first_vault = $vaults[0]; + $shareRequests = $this->shareService->getPendingShareRequests($item_guid, $first_vault['user_id']); + if(count($shareRequests) > 0){ + return new JSONResponse(array('error'=> 'User got already pending requests')); + } + $result = $this->shareService->createBulkRequests($item_id, $item_guid, $vaults, $permissions, $credential_owner); if ($credential) { $processed_users = array(); @@ -130,8 +137,6 @@ class ShareController extends ApiController { array_push($processed_users, $target_user); } } - - } return new JSONResponse($result); } @@ -377,6 +382,7 @@ class ShareController extends ApiController { $acl = $this->shareService->getACL($user_id, $item_guid); $acl->setPermissions($permission); $this->shareService->updateCredentialACL($acl); + } } } \ No newline at end of file diff --git a/lib/Db/ShareRequestMapper.php b/lib/Db/ShareRequestMapper.php index 3e7f5b93..242dc547 100644 --- a/lib/Db/ShareRequestMapper.php +++ b/lib/Db/ShareRequestMapper.php @@ -77,4 +77,14 @@ class ShareRequestMapper extends Mapper { $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ?"; return $this->findEntities($q, [$item_guid]); } + + public function updateShareRequest(ShareRequest $shareRequest){ + return $this->update($shareRequest); + } + + public function getPendingShareRequests($item_guid, $user_id){ + $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? and target_user_id= ?"; + return $this->findEntities($q, [$item_guid, $user_id]); + } + } \ No newline at end of file diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 6f56f856..4fb9346c 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -252,4 +252,12 @@ class ShareService { public function updateCredentialACL(SharingACL $sharingACL){ return $this->sharingACL->updateCredentialACL($sharingACL); } + + public function updateCredentialShareRequest(ShareRequest $shareRequest){ + return $this->shareRequest->updateShareRequest($shareRequest); + } + + public function getPendingShareRequests($item_guid, $user_id){ + return $this->shareRequest->getPendingShareRequests($item_guid, $user_id); + } } \ No newline at end of file