From 2baae50691629dd47da4c00cc965d8bd1b74970b Mon Sep 17 00:00:00 2001 From: brantje Date: Sun, 2 Oct 2016 19:29:06 +0200 Subject: [PATCH] Get shared items working --- controller/sharecontroller.php | 2 +- lib/Db/CredentialMapper.php | 8 ++++++-- lib/Db/SharingACL.php | 5 ++--- lib/Db/SharingACLMapper.php | 2 +- lib/Service/ShareService.php | 1 + 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/controller/sharecontroller.php b/controller/sharecontroller.php index 129dc2d5..cc43c994 100644 --- a/controller/sharecontroller.php +++ b/controller/sharecontroller.php @@ -211,7 +211,7 @@ class ShareController extends ApiController { * @NoAdminRequired */ public function getVaultItems($vault_guid){ - $this->shareService->getSharedItems($this->userId->getUID(), $vault_guid); + return new JSONResponse($this->shareService->getSharedItems($this->userId->getUID(), $vault_guid)); } public function deleteShareRequest($share_request_id){ diff --git a/lib/Db/CredentialMapper.php b/lib/Db/CredentialMapper.php index 18cad95d..a38a984d 100644 --- a/lib/Db/CredentialMapper.php +++ b/lib/Db/CredentialMapper.php @@ -48,8 +48,12 @@ class CredentialMapper extends Mapper { $sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' . 'WHERE `id` = ?'; // If we want to check the owner, add it to the query - if ($user_id !== null) $sql .= ' and `user_id` = ? '; - return $this->findEntity($sql,[$credential_id, $user_id]); + $params = [$credential_id]; + if ($user_id !== null){ + $sql .= ' and `user_id` = ? '; + array_push($params, $user_id); + } + return $this->findEntity($sql,$params); } public function getCredentialLabelById($credential_id){ diff --git a/lib/Db/SharingACL.php b/lib/Db/SharingACL.php index d6f37db4..af4d89dd 100644 --- a/lib/Db/SharingACL.php +++ b/lib/Db/SharingACL.php @@ -18,7 +18,7 @@ use OCP\AppFramework\Db\Entity; * @method void setItemGuid(string $value) * @method string getItemGuid() * @method void setUserId(string $value) - * @method string getUserid() + * @method string getUserId() * @method void setCreated(integer $value) * @method integer getCreated() * @method void setExpire(integer $value) @@ -69,8 +69,7 @@ class SharingACL extends PermissionEntity implements \JsonSerializable 'acl_id' => $this->getId(), 'item_id' => $this->getItemId(), 'item_guid' => $this->getItemGuid(), - 'user_id' => $this->getUserid(), - 'group_id' => $this->getGroupId(), + 'user_id' => $this->getUserId(), 'created' => $this->getCreated(), 'expire' => $this->getExpire(), 'permissions' => $this->getPermissions(), diff --git a/lib/Db/SharingACLMapper.php b/lib/Db/SharingACLMapper.php index def4ad5b..47ea59e6 100644 --- a/lib/Db/SharingACLMapper.php +++ b/lib/Db/SharingACLMapper.php @@ -42,7 +42,7 @@ class SharingACLMapper extends Mapper { * Gets the currently accepted share requests from the given user for the given vault guid * @param $user_id * @param $vault_id - * @return SharingACL[] + * */ public function getVaultEntries($user_id, $vault_id) { $q = "SELECT * FROM ". self::TABLE_NAME ." WHERE user_id = ? AND vault_guid = ?"; diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 441bfc09..8c720ee8 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -95,6 +95,7 @@ class ShareService { public function getSharedItems($user_id, $vault_guid){ $entries = $this->sharingACL->getVaultEntries($user_id, $vault_guid); + $return = []; foreach ($entries as $entry){ $tmp = $entry->jsonSerialize();