Dont create new requests for a credential, when target user has pending requests for that credential

This commit is contained in:
brantje 2016-10-05 12:11:43 +02:00
parent 00149bb912
commit eb915e065e
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
3 changed files with 26 additions and 2 deletions

View file

@ -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);
}
}
}

View file

@ -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]);
}
}

View file

@ -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);
}
}