@@ -14,11 +14,11 @@ |
||
| 14 | 14 | |
| 15 | 15 | class NotFoundJSONResponse extends JSONResponse { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Creates a new json response with a not found status code. |
|
| 19 | - * @param array $response_data |
|
| 20 | - */ |
|
| 21 | - public function __construct($response_data = []) { |
|
| 22 | - parent::__construct($response_data, Http::STATUS_NOT_FOUND); |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * Creates a new json response with a not found status code. |
|
| 19 | + * @param array $response_data |
|
| 20 | + */ |
|
| 21 | + public function __construct($response_data = []) { |
|
| 22 | + parent::__construct($response_data, Http::STATUS_NOT_FOUND); |
|
| 23 | + } |
|
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |
@@ -13,11 +13,11 @@ |
||
| 13 | 13 | use OCP\AppFramework\Db\Entity; |
| 14 | 14 | |
| 15 | 15 | class PermissionEntity extends Entity { |
| 16 | - CONST READ = 0b00000001; |
|
| 17 | - CONST WRITE = 0b00000010; |
|
| 18 | - CONST FILES = 0b00000100; |
|
| 16 | + CONST READ = 0b00000001; |
|
| 17 | + CONST WRITE = 0b00000010; |
|
| 18 | + CONST FILES = 0b00000100; |
|
| 19 | 19 | CONST HISTORY = 0b00001000; |
| 20 | - CONST OWNER = 0b10000000; |
|
| 20 | + CONST OWNER = 0b10000000; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Checks wether a user matches one or more permissions at once |
@@ -13,40 +13,40 @@ |
||
| 13 | 13 | use OCP\AppFramework\Db\Entity; |
| 14 | 14 | |
| 15 | 15 | class PermissionEntity extends Entity { |
| 16 | - CONST READ = 0b00000001; |
|
| 17 | - CONST WRITE = 0b00000010; |
|
| 18 | - CONST FILES = 0b00000100; |
|
| 19 | - CONST HISTORY = 0b00001000; |
|
| 20 | - CONST OWNER = 0b10000000; |
|
| 16 | + CONST READ = 0b00000001; |
|
| 17 | + CONST WRITE = 0b00000010; |
|
| 18 | + CONST FILES = 0b00000100; |
|
| 19 | + CONST HISTORY = 0b00001000; |
|
| 20 | + CONST OWNER = 0b10000000; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Checks wether a user matches one or more permissions at once |
|
| 24 | - * @param $permission |
|
| 25 | - * @return bool |
|
| 26 | - */ |
|
| 27 | - public function hasPermission($permission) { |
|
| 28 | - $tmp = $this->getPermissions(); |
|
| 29 | - $tmp = $tmp & $permission; |
|
| 30 | - return $tmp === $permission; |
|
| 31 | - } |
|
| 22 | + /** |
|
| 23 | + * Checks wether a user matches one or more permissions at once |
|
| 24 | + * @param $permission |
|
| 25 | + * @return bool |
|
| 26 | + */ |
|
| 27 | + public function hasPermission($permission) { |
|
| 28 | + $tmp = $this->getPermissions(); |
|
| 29 | + $tmp = $tmp & $permission; |
|
| 30 | + return $tmp === $permission; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Adds the given permission or permissions set to the user current permissions |
|
| 35 | - * @param $permission |
|
| 36 | - */ |
|
| 37 | - public function addPermission($permission) { |
|
| 38 | - $tmp = $this->getPermissions(); |
|
| 39 | - $tmp = $tmp | $permission; |
|
| 40 | - $this->setPermissions($tmp); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Adds the given permission or permissions set to the user current permissions |
|
| 35 | + * @param $permission |
|
| 36 | + */ |
|
| 37 | + public function addPermission($permission) { |
|
| 38 | + $tmp = $this->getPermissions(); |
|
| 39 | + $tmp = $tmp | $permission; |
|
| 40 | + $this->setPermissions($tmp); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Takes the given permission or permissions out from the user |
|
| 45 | - * @param $permission |
|
| 46 | - */ |
|
| 47 | - public function removePermission($permission) { |
|
| 48 | - $tmp = $this->getPermissions(); |
|
| 49 | - $tmp = $tmp & ~$permission; |
|
| 50 | - $this->setPermissions($tmp); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Takes the given permission or permissions out from the user |
|
| 45 | + * @param $permission |
|
| 46 | + */ |
|
| 47 | + public function removePermission($permission) { |
|
| 48 | + $tmp = $this->getPermissions(); |
|
| 49 | + $tmp = $tmp & ~$permission; |
|
| 50 | + $this->setPermissions($tmp); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -27,11 +27,11 @@ |
||
| 27 | 27 | use OCP\AppFramework\Db\Entity; |
| 28 | 28 | |
| 29 | 29 | class PermissionEntity extends Entity { |
| 30 | - CONST READ = 0b00000001; |
|
| 31 | - CONST WRITE = 0b00000010; |
|
| 32 | - CONST FILES = 0b00000100; |
|
| 33 | - CONST HISTORY = 0b00001000; |
|
| 34 | - CONST OWNER = 0b10000000; |
|
| 30 | + const READ = 0b00000001; |
|
| 31 | + const WRITE = 0b00000010; |
|
| 32 | + const FILES = 0b00000100; |
|
| 33 | + const HISTORY = 0b00001000; |
|
| 34 | + const OWNER = 0b10000000; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Checks wether a user matches one or more permissions at once |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | private $userId; |
| 23 | 23 | |
| 24 | - public function __construct($AppName, IRequest $request, $UserId){ |
|
| 24 | + public function __construct($AppName, IRequest $request, $UserId) { |
|
| 25 | 25 | parent::__construct($AppName, $request); |
| 26 | 26 | $this->userId = $UserId; |
| 27 | 27 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | private $userId; |
| 23 | 23 | |
| 24 | - public function __construct($AppName, IRequest $request, $UserId){ |
|
| 24 | + public function __construct($AppName, IRequest $request, $UserId) { |
|
| 25 | 25 | parent::__construct($AppName, $request); |
| 26 | 26 | $this->userId = $UserId; |
| 27 | 27 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function index() { |
| 40 | 40 | $params = ['user' => $this->userId]; |
| 41 | - return new TemplateResponse('passman', 'main', $params); // templates/main.php |
|
| 41 | + return new TemplateResponse('passman', 'main', $params); // templates/main.php |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @NoAdminRequired |
| 47 | 47 | * @NoCSRFRequired |
| 48 | 48 | */ |
| 49 | - public function bookmarklet($url='',$title='') { |
|
| 49 | + public function bookmarklet($url = '', $title = '') { |
|
| 50 | 50 | $params = array('url' => $url, 'title' => $title); |
| 51 | 51 | return new TemplateResponse('passman', 'bookmarklet', $params); |
| 52 | 52 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | public function expireCredentials() { |
| 38 | 38 | $this->logger->info('Passman cron test', array('app' => 'passman')); |
| 39 | 39 | $expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime()); |
| 40 | - foreach($expired_credentials as $credential){ |
|
| 40 | + foreach($expired_credentials as $credential) { |
|
| 41 | 41 | $link = ''; // @TODO create direct link to credential |
| 42 | 42 | |
| 43 | 43 | $sql = 'SELECT count(*) as rows from `*PREFIX*notifications` WHERE `subject`= \'credential_expired\' AND object_id=?'; |
@@ -50,16 +50,16 @@ |
||
| 50 | 50 | public function expireCredentials() { |
| 51 | 51 | $this->logger->info('Passman cron test', array('app' => 'passman')); |
| 52 | 52 | $expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime()); |
| 53 | - foreach($expired_credentials as $credential){ |
|
| 53 | + foreach ($expired_credentials as $credential) { |
|
| 54 | 54 | $link = ''; // @TODO create direct link to credential |
| 55 | 55 | |
| 56 | 56 | $sql = 'SELECT count(*) as rows from `*PREFIX*notifications` WHERE `subject`= \'credential_expired\' AND object_id=?'; |
| 57 | 57 | $id = $credential->getId(); |
| 58 | 58 | $result = $this->db->executeQuery($sql, array($id)); |
| 59 | - $this->logger->debug($credential->getLabel() .' is expired, checking notifications!', array('app' => 'passman')); |
|
| 59 | + $this->logger->debug($credential->getLabel() . ' is expired, checking notifications!', array('app' => 'passman')); |
|
| 60 | 60 | $notifications = intval($result->fetch()['rows']); |
| 61 | - if($notifications === 0) { |
|
| 62 | - $this->logger->debug($credential->getLabel() .' is expired, adding notification!', array('app' => 'passman')); |
|
| 61 | + if ($notifications === 0) { |
|
| 62 | + $this->logger->debug($credential->getLabel() . ' is expired, adding notification!', array('app' => 'passman')); |
|
| 63 | 63 | $this->activityService->add( |
| 64 | 64 | Activity::SUBJECT_ITEM_EXPIRED, array($credential->getLabel(), $credential->getUserId()), |
| 65 | 65 | '', array(), |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | parent::__construct($db, self::TABLE_NAME); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function createRequest(ShareRequest $request){ |
|
| 25 | + public function createRequest(ShareRequest $request) { |
|
| 26 | 26 | return $this->insert($request); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param $target_vault_guid |
| 33 | 33 | * @return ShareRequest |
| 34 | 34 | */ |
| 35 | - public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid){ |
|
| 35 | + public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid) { |
|
| 36 | 36 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? AND target_vault_guid = ?"; |
| 37 | 37 | return $this->findEntity($q, [$item_guid, $target_vault_guid]); |
| 38 | 38 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @param $item_guid |
| 43 | 43 | * @return ShareRequest[] |
| 44 | 44 | */ |
| 45 | - public function getRequestsByItemGuidGroupedByUser($item_guid){ |
|
| 46 | - if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql'){ |
|
| 45 | + public function getRequestsByItemGuidGroupedByUser($item_guid) { |
|
| 46 | + if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql') { |
|
| 47 | 47 | $this->db->executeQuery("SET sql_mode = '';"); |
| 48 | 48 | } |
| 49 | 49 | $q = "SELECT *, target_user_id FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? GROUP BY target_user_id;"; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param $target_user_id The target user |
| 57 | 57 | * @return \PDOStatement The result of running the db query |
| 58 | 58 | */ |
| 59 | - public function cleanItemRequestsForUser($item_id, $target_user_id){ |
|
| 59 | + public function cleanItemRequestsForUser($item_id, $target_user_id) { |
|
| 60 | 60 | $q = "DELETE FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_id = ? AND target_user_id = ?"; |
| 61 | 61 | $this->execute($q, [$item_id, $target_user_id]); |
| 62 | 62 | return $this->execute($q, [$item_id, $target_user_id]); |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | * @param $user_id |
| 68 | 68 | * @return ShareRequest[] |
| 69 | 69 | */ |
| 70 | - public function getUserPendingRequests($user_id){ |
|
| 71 | - $q = "SELECT * FROM *PREFIX*". self::TABLE_NAME ." WHERE target_user_id = ?"; |
|
| 70 | + public function getUserPendingRequests($user_id) { |
|
| 71 | + $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE target_user_id = ?"; |
|
| 72 | 72 | return $this->findEntities($q, [$user_id]); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @param ShareRequest $shareRequest Request to delete |
| 78 | 78 | * @return ShareRequest The deleted request |
| 79 | 79 | */ |
| 80 | - public function deleteShareRequest(ShareRequest $shareRequest){ |
|
| 80 | + public function deleteShareRequest(ShareRequest $shareRequest) { |
|
| 81 | 81 | return $this->delete($shareRequest); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @return ShareRequest |
| 88 | 88 | * @throws DoesNotExistException |
| 89 | 89 | */ |
| 90 | - public function getShareRequestById($id){ |
|
| 90 | + public function getShareRequestById($id) { |
|
| 91 | 91 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE id = ?"; |
| 92 | 92 | return $this->findEntity($q, [$id]); |
| 93 | 93 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param $item_guid |
| 98 | 98 | * @return ShareRequest[] |
| 99 | 99 | */ |
| 100 | - public function getShareRequestsByItemGuid($item_guid){ |
|
| 100 | + public function getShareRequestsByItemGuid($item_guid) { |
|
| 101 | 101 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ?"; |
| 102 | 102 | return $this->findEntities($q, [$item_guid]); |
| 103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param ShareRequest $shareRequest |
| 108 | 108 | * @return ShareRequest |
| 109 | 109 | */ |
| 110 | - public function updateShareRequest(ShareRequest $shareRequest){ |
|
| 110 | + public function updateShareRequest(ShareRequest $shareRequest) { |
|
| 111 | 111 | return $this->update($shareRequest); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param $user_id |
| 118 | 118 | * @return ShareRequest[] |
| 119 | 119 | */ |
| 120 | - public function getPendingShareRequests($item_guid, $user_id){ |
|
| 120 | + public function getPendingShareRequests($item_guid, $user_id) { |
|
| 121 | 121 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? and target_user_id= ?"; |
| 122 | 122 | return $this->findEntities($q, [$item_guid, $user_id]); |
| 123 | 123 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param $permissions The new permissions to apply |
| 130 | 130 | * @return \PDOStatement The result of the operation |
| 131 | 131 | */ |
| 132 | - public function updatePendingRequestPermissions($item_guid, $user_id, $permissions){ |
|
| 132 | + public function updatePendingRequestPermissions($item_guid, $user_id, $permissions) { |
|
| 133 | 133 | $q = "UPDATE *PREFIX*" . self::TABLE_NAME . " SET permissions = ? WHERE item_guid = ? AND target_user_id = ?"; |
| 134 | 134 | return $this->execute($q, [$permissions, $item_guid, $user_id]); |
| 135 | 135 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | parent::__construct($db, self::TABLE_NAME); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function createRequest(ShareRequest $request){ |
|
| 25 | + public function createRequest(ShareRequest $request) { |
|
| 26 | 26 | return $this->insert($request); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @param $target_vault_guid |
| 33 | 33 | * @return ShareRequest |
| 34 | 34 | */ |
| 35 | - public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid){ |
|
| 35 | + public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid) { |
|
| 36 | 36 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? AND target_vault_guid = ?"; |
| 37 | 37 | return $this->findEntity($q, [$item_guid, $target_vault_guid]); |
| 38 | 38 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @param $item_guid |
| 43 | 43 | * @return ShareRequest[] |
| 44 | 44 | */ |
| 45 | - public function getRequestsByItemGuidGroupedByUser($item_guid){ |
|
| 46 | - if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql'){ |
|
| 45 | + public function getRequestsByItemGuidGroupedByUser($item_guid) { |
|
| 46 | + if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql') { |
|
| 47 | 47 | $this->db->executeQuery("SET sql_mode = '';"); |
| 48 | 48 | } |
| 49 | 49 | $q = "SELECT *, target_user_id FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? GROUP BY target_user_id;"; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param $target_user_id The target user |
| 57 | 57 | * @return \PDOStatement The result of running the db query |
| 58 | 58 | */ |
| 59 | - public function cleanItemRequestsForUser($item_id, $target_user_id){ |
|
| 59 | + public function cleanItemRequestsForUser($item_id, $target_user_id) { |
|
| 60 | 60 | $q = "DELETE FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_id = ? AND target_user_id = ?"; |
| 61 | 61 | $this->execute($q, [$item_id, $target_user_id]); |
| 62 | 62 | return $this->execute($q, [$item_id, $target_user_id]); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param $user_id |
| 68 | 68 | * @return ShareRequest[] |
| 69 | 69 | */ |
| 70 | - public function getUserPendingRequests($user_id){ |
|
| 70 | + public function getUserPendingRequests($user_id) { |
|
| 71 | 71 | $q = "SELECT * FROM *PREFIX*". self::TABLE_NAME ." WHERE target_user_id = ?"; |
| 72 | 72 | return $this->findEntities($q, [$user_id]); |
| 73 | 73 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @param ShareRequest $shareRequest Request to delete |
| 78 | 78 | * @return ShareRequest The deleted request |
| 79 | 79 | */ |
| 80 | - public function deleteShareRequest(ShareRequest $shareRequest){ |
|
| 80 | + public function deleteShareRequest(ShareRequest $shareRequest) { |
|
| 81 | 81 | return $this->delete($shareRequest); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @return ShareRequest |
| 88 | 88 | * @throws DoesNotExistException |
| 89 | 89 | */ |
| 90 | - public function getShareRequestById($id){ |
|
| 90 | + public function getShareRequestById($id) { |
|
| 91 | 91 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE id = ?"; |
| 92 | 92 | return $this->findEntity($q, [$id]); |
| 93 | 93 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param $item_guid |
| 98 | 98 | * @return ShareRequest[] |
| 99 | 99 | */ |
| 100 | - public function getShareRequestsByItemGuid($item_guid){ |
|
| 100 | + public function getShareRequestsByItemGuid($item_guid) { |
|
| 101 | 101 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ?"; |
| 102 | 102 | return $this->findEntities($q, [$item_guid]); |
| 103 | 103 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param ShareRequest $shareRequest |
| 108 | 108 | * @return ShareRequest |
| 109 | 109 | */ |
| 110 | - public function updateShareRequest(ShareRequest $shareRequest){ |
|
| 110 | + public function updateShareRequest(ShareRequest $shareRequest) { |
|
| 111 | 111 | return $this->update($shareRequest); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param $user_id |
| 118 | 118 | * @return ShareRequest[] |
| 119 | 119 | */ |
| 120 | - public function getPendingShareRequests($item_guid, $user_id){ |
|
| 120 | + public function getPendingShareRequests($item_guid, $user_id) { |
|
| 121 | 121 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? and target_user_id= ?"; |
| 122 | 122 | return $this->findEntities($q, [$item_guid, $user_id]); |
| 123 | 123 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param $permissions The new permissions to apply |
| 130 | 130 | * @return \PDOStatement The result of the operation |
| 131 | 131 | */ |
| 132 | - public function updatePendingRequestPermissions($item_guid, $user_id, $permissions){ |
|
| 132 | + public function updatePendingRequestPermissions($item_guid, $user_id, $permissions) { |
|
| 133 | 133 | $q = "UPDATE *PREFIX*" . self::TABLE_NAME . " SET permissions = ? WHERE item_guid = ? AND target_user_id = ?"; |
| 134 | 134 | return $this->execute($q, [$permissions, $item_guid, $user_id]); |
| 135 | 135 | } |
@@ -31,122 +31,122 @@ |
||
| 31 | 31 | use OCP\IDBConnection; |
| 32 | 32 | |
| 33 | 33 | class ShareRequestMapper extends Mapper { |
| 34 | - const TABLE_NAME = 'passman_share_request'; |
|
| 35 | - |
|
| 36 | - public function __construct(IDBConnection $db) { |
|
| 37 | - parent::__construct($db, self::TABLE_NAME); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function createRequest(ShareRequest $request){ |
|
| 41 | - return $this->insert($request); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Obtains a request by the given item and vault GUID pair |
|
| 46 | - * @param $item_guid |
|
| 47 | - * @param $target_vault_guid |
|
| 48 | - * @return ShareRequest |
|
| 49 | - */ |
|
| 50 | - public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid){ |
|
| 51 | - $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? AND target_vault_guid = ?"; |
|
| 52 | - return $this->findEntity($q, [$item_guid, $target_vault_guid]); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Get shared items for the given item_guid |
|
| 57 | - * @param $item_guid |
|
| 58 | - * @return ShareRequest[] |
|
| 59 | - */ |
|
| 60 | - public function getRequestsByItemGuidGroupedByUser($item_guid){ |
|
| 61 | - if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql'){ |
|
| 62 | - $this->db->executeQuery("SET sql_mode = '';"); |
|
| 34 | + const TABLE_NAME = 'passman_share_request'; |
|
| 35 | + |
|
| 36 | + public function __construct(IDBConnection $db) { |
|
| 37 | + parent::__construct($db, self::TABLE_NAME); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function createRequest(ShareRequest $request){ |
|
| 41 | + return $this->insert($request); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Obtains a request by the given item and vault GUID pair |
|
| 46 | + * @param $item_guid |
|
| 47 | + * @param $target_vault_guid |
|
| 48 | + * @return ShareRequest |
|
| 49 | + */ |
|
| 50 | + public function getRequestByItemAndVaultGuid($item_guid, $target_vault_guid){ |
|
| 51 | + $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? AND target_vault_guid = ?"; |
|
| 52 | + return $this->findEntity($q, [$item_guid, $target_vault_guid]); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Get shared items for the given item_guid |
|
| 57 | + * @param $item_guid |
|
| 58 | + * @return ShareRequest[] |
|
| 59 | + */ |
|
| 60 | + public function getRequestsByItemGuidGroupedByUser($item_guid){ |
|
| 61 | + if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql'){ |
|
| 62 | + $this->db->executeQuery("SET sql_mode = '';"); |
|
| 63 | 63 | } |
| 64 | - $q = "SELECT *, target_user_id FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? GROUP BY target_user_id;"; |
|
| 65 | - return $this->findEntities($q, [$item_guid]); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Deletes all pending requests for the given user to the given item |
|
| 70 | - * @param $item_id The item ID |
|
| 71 | - * @param $target_user_id The target user |
|
| 72 | - * @return \PDOStatement The result of running the db query |
|
| 73 | - */ |
|
| 74 | - public function cleanItemRequestsForUser($item_id, $target_user_id){ |
|
| 64 | + $q = "SELECT *, target_user_id FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? GROUP BY target_user_id;"; |
|
| 65 | + return $this->findEntities($q, [$item_guid]); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Deletes all pending requests for the given user to the given item |
|
| 70 | + * @param $item_id The item ID |
|
| 71 | + * @param $target_user_id The target user |
|
| 72 | + * @return \PDOStatement The result of running the db query |
|
| 73 | + */ |
|
| 74 | + public function cleanItemRequestsForUser($item_id, $target_user_id){ |
|
| 75 | 75 | $q = "DELETE FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_id = ? AND target_user_id = ?"; |
| 76 | 76 | $this->execute($q, [$item_id, $target_user_id]); |
| 77 | - return $this->execute($q, [$item_id, $target_user_id]); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Obtains all pending share requests for the given user ID |
|
| 82 | - * @param $user_id |
|
| 83 | - * @return ShareRequest[] |
|
| 84 | - */ |
|
| 85 | - public function getUserPendingRequests($user_id){ |
|
| 86 | - $q = "SELECT * FROM *PREFIX*". self::TABLE_NAME ." WHERE target_user_id = ?"; |
|
| 87 | - return $this->findEntities($q, [$user_id]); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Deletes the given share request |
|
| 92 | - * @param ShareRequest $shareRequest Request to delete |
|
| 93 | - * @return ShareRequest The deleted request |
|
| 94 | - */ |
|
| 95 | - public function deleteShareRequest(ShareRequest $shareRequest){ |
|
| 96 | - return $this->delete($shareRequest); |
|
| 77 | + return $this->execute($q, [$item_id, $target_user_id]); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Obtains all pending share requests for the given user ID |
|
| 82 | + * @param $user_id |
|
| 83 | + * @return ShareRequest[] |
|
| 84 | + */ |
|
| 85 | + public function getUserPendingRequests($user_id){ |
|
| 86 | + $q = "SELECT * FROM *PREFIX*". self::TABLE_NAME ." WHERE target_user_id = ?"; |
|
| 87 | + return $this->findEntities($q, [$user_id]); |
|
| 97 | 88 | } |
| 98 | 89 | |
| 99 | - /** |
|
| 100 | - * Gets a share request by it's unique incremental id |
|
| 101 | - * @param $id |
|
| 102 | - * @return ShareRequest |
|
| 90 | + /** |
|
| 91 | + * Deletes the given share request |
|
| 92 | + * @param ShareRequest $shareRequest Request to delete |
|
| 93 | + * @return ShareRequest The deleted request |
|
| 94 | + */ |
|
| 95 | + public function deleteShareRequest(ShareRequest $shareRequest){ |
|
| 96 | + return $this->delete($shareRequest); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Gets a share request by it's unique incremental id |
|
| 101 | + * @param $id |
|
| 102 | + * @return ShareRequest |
|
| 103 | 103 | * @throws DoesNotExistException |
| 104 | - */ |
|
| 104 | + */ |
|
| 105 | 105 | public function getShareRequestById($id){ |
| 106 | 106 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE id = ?"; |
| 107 | 107 | return $this->findEntity($q, [$id]); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Gets all share requests by a given item GUID |
|
| 112 | - * @param $item_guid |
|
| 113 | - * @return ShareRequest[] |
|
| 114 | - */ |
|
| 110 | + /** |
|
| 111 | + * Gets all share requests by a given item GUID |
|
| 112 | + * @param $item_guid |
|
| 113 | + * @return ShareRequest[] |
|
| 114 | + */ |
|
| 115 | 115 | public function getShareRequestsByItemGuid($item_guid){ |
| 116 | 116 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ?"; |
| 117 | 117 | return $this->findEntities($q, [$item_guid]); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Updates the given share request, |
|
| 122 | - * @param ShareRequest $shareRequest |
|
| 123 | - * @return ShareRequest |
|
| 124 | - */ |
|
| 120 | + /** |
|
| 121 | + * Updates the given share request, |
|
| 122 | + * @param ShareRequest $shareRequest |
|
| 123 | + * @return ShareRequest |
|
| 124 | + */ |
|
| 125 | 125 | public function updateShareRequest(ShareRequest $shareRequest){ |
| 126 | 126 | return $this->update($shareRequest); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Finds pending requests sent to the given user to the given item. |
|
| 131 | - * @param $item_guid |
|
| 132 | - * @param $user_id |
|
| 133 | - * @return ShareRequest[] |
|
| 134 | - */ |
|
| 129 | + /** |
|
| 130 | + * Finds pending requests sent to the given user to the given item. |
|
| 131 | + * @param $item_guid |
|
| 132 | + * @param $user_id |
|
| 133 | + * @return ShareRequest[] |
|
| 134 | + */ |
|
| 135 | 135 | public function getPendingShareRequests($item_guid, $user_id){ |
| 136 | 136 | $q = "SELECT * FROM *PREFIX*" . self::TABLE_NAME . " WHERE item_guid = ? and target_user_id= ?"; |
| 137 | 137 | return $this->findEntities($q, [$item_guid, $user_id]); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Updates all pending requests with the given permissions |
|
| 142 | - * @param $item_guid The item for which to update the requests |
|
| 143 | - * @param $user_id The user for which to update the requests |
|
| 144 | - * @param $permissions The new permissions to apply |
|
| 145 | - * @return \PDOStatement The result of the operation |
|
| 146 | - */ |
|
| 140 | + /** |
|
| 141 | + * Updates all pending requests with the given permissions |
|
| 142 | + * @param $item_guid The item for which to update the requests |
|
| 143 | + * @param $user_id The user for which to update the requests |
|
| 144 | + * @param $permissions The new permissions to apply |
|
| 145 | + * @return \PDOStatement The result of the operation |
|
| 146 | + */ |
|
| 147 | 147 | public function updatePendingRequestPermissions($item_guid, $user_id, $permissions){ |
| 148 | - $q = "UPDATE *PREFIX*" . self::TABLE_NAME . " SET permissions = ? WHERE item_guid = ? AND target_user_id = ?"; |
|
| 149 | - return $this->execute($q, [$permissions, $item_guid, $user_id]); |
|
| 150 | - } |
|
| 148 | + $q = "UPDATE *PREFIX*" . self::TABLE_NAME . " SET permissions = ? WHERE item_guid = ? AND target_user_id = ?"; |
|
| 149 | + return $this->execute($q, [$permissions, $item_guid, $user_id]); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | } |
| 153 | 153 | \ No newline at end of file |
@@ -48,10 +48,10 @@ |
||
| 48 | 48 | * @param $type string |
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | - public function add($subject,$subjectParams=array(), |
|
| 52 | - $message='',$messageParams=array(), |
|
| 53 | - $link='',$user=null,$type='') { |
|
| 54 | - if($user) { |
|
| 51 | + public function add($subject, $subjectParams = array(), |
|
| 52 | + $message = '', $messageParams = array(), |
|
| 53 | + $link = '', $user = null, $type = '') { |
|
| 54 | + if ($user) { |
|
| 55 | 55 | $activity = $this->manager->generateEvent(); |
| 56 | 56 | $activity->setType($type); |
| 57 | 57 | $activity->setApp('passman'); |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | parent::__construct('passman'); |
| 52 | 52 | $container = $this->getContainer(); |
| 53 | 53 | // Allow automatic DI for the View, until we migrated to Nodes API |
| 54 | - $container->registerService(View::class, function () { |
|
| 54 | + $container->registerService(View::class, function() { |
|
| 55 | 55 | return new View(''); |
| 56 | 56 | }, false); |
| 57 | - $container->registerService('isCLI', function () { |
|
| 57 | + $container->registerService('isCLI', function() { |
|
| 58 | 58 | return \OC::$CLI; |
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Middleware |
| 63 | 63 | */ |
| 64 | - $container->registerService('ShareMiddleware', function ($c) { |
|
| 64 | + $container->registerService('ShareMiddleware', function($c) { |
|
| 65 | 65 | return new ShareMiddleware($c->query('SettingsService')); |
| 66 | 66 | }); |
| 67 | 67 | $container->registerMiddleware('ShareMiddleware'); |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * Controllers |
| 71 | 71 | */ |
| 72 | - $container->registerService('ShareController', function ($c) { |
|
| 72 | + $container->registerService('ShareController', function($c) { |
|
| 73 | 73 | $container = $this->getContainer(); |
| 74 | 74 | $server = $container->getServer(); |
| 75 | 75 | return new ShareController( |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | /** Cron **/ |
| 93 | - $container->registerService('CronService', function ($c) { |
|
| 93 | + $container->registerService('CronService', function($c) { |
|
| 94 | 94 | return new CronService( |
| 95 | 95 | $c->query('CredentialService'), |
| 96 | 96 | $c->query('Logger'), |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | ); |
| 102 | 102 | }); |
| 103 | 103 | |
| 104 | - $container->registerService('Db', function () { |
|
| 104 | + $container->registerService('Db', function() { |
|
| 105 | 105 | return new Db(); |
| 106 | 106 | }); |
| 107 | 107 | |
| 108 | - $container->registerService('Logger', function ($c) { |
|
| 108 | + $container->registerService('Logger', function($c) { |
|
| 109 | 109 | return $c->query('ServerContainer')->getLogger(); |
| 110 | 110 | }); |
| 111 | 111 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $c = $this->getContainer(); |
| 134 | 134 | /** @var \OCP\IServerContainer $server */ |
| 135 | 135 | $server = $c->getServer(); |
| 136 | - $navigationEntry = function () use ($c, $server) { |
|
| 136 | + $navigationEntry = function() use ($c, $server) { |
|
| 137 | 137 | return [ |
| 138 | 138 | 'id' => $c->getAppName(), |
| 139 | 139 | 'order' => 10, |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | use OCA\Passman\Service\VaultService; |
| 39 | 39 | use OCA\Passman\Utility\Utils; |
| 40 | 40 | use OCA\Passman\Service\NotificationService; |
| 41 | -Use OCA\Passman\Service\SettingsService; |
|
| 41 | +use OCA\Passman\Service\SettingsService; |
|
| 42 | 42 | use OCP\IConfig; |
| 43 | 43 | use OCP\IDBConnection; |
| 44 | 44 | |
@@ -272,7 +272,9 @@ |
||
| 272 | 272 | protected function unpad($data) { |
| 273 | 273 | $length = $this->getKeySize(); |
| 274 | 274 | $last = ord($data[strlen($data) - 1]); |
| 275 | - if ($last > $length) return false; |
|
| 275 | + if ($last > $length) { |
|
| 276 | + return false; |
|
| 277 | + } |
|
| 276 | 278 | if (substr($data, -1 * $last) !== str_repeat(chr($last), $last)) { |
| 277 | 279 | return false; |
| 278 | 280 | } |
@@ -205,6 +205,10 @@ discard block |
||
| 205 | 205 | return array($cipherKey, $macKey, $iv); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | + /** |
|
| 209 | + * @param string $a |
|
| 210 | + * @param string $b |
|
| 211 | + */ |
|
| 208 | 212 | protected function hash_equals($a, $b) { |
| 209 | 213 | if (function_exists('random_bytes')) { |
| 210 | 214 | $key = random_bytes(128); |
@@ -246,7 +250,7 @@ discard block |
||
| 246 | 250 | /** |
| 247 | 251 | * Pad the data with a random char chosen by the pad amount. |
| 248 | 252 | * |
| 249 | - * @param $data |
|
| 253 | + * @param string $data |
|
| 250 | 254 | * @return string |
| 251 | 255 | */ |
| 252 | 256 | protected function pad($data) { |
@@ -262,8 +266,8 @@ discard block |
||
| 262 | 266 | /** |
| 263 | 267 | * Unpad the the data |
| 264 | 268 | * |
| 265 | - * @param $data |
|
| 266 | - * @return bool|string |
|
| 269 | + * @param string $data |
|
| 270 | + * @return false|string |
|
| 267 | 271 | */ |
| 268 | 272 | protected function unpad($data) { |
| 269 | 273 | $length = $this->getKeySize(); |
@@ -280,7 +284,7 @@ discard block |
||
| 280 | 284 | * Encrypt a credential |
| 281 | 285 | * |
| 282 | 286 | * @param Credential|array $credential the credential to decrypt |
| 283 | - * @return Credential|array |
|
| 287 | + * @return string |
|
| 284 | 288 | */ |
| 285 | 289 | public function decryptCredential($credential) { |
| 286 | 290 | return $this->handleCredential($credential, EncryptService::OP_DECRYPT); |
@@ -353,7 +357,7 @@ discard block |
||
| 353 | 357 | /** |
| 354 | 358 | * Decrypt a file |
| 355 | 359 | * |
| 356 | - * @param File|array $file |
|
| 360 | + * @param File $file |
|
| 357 | 361 | * @return File|array |
| 358 | 362 | */ |
| 359 | 363 | |
@@ -83,7 +83,7 @@ |
||
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - private function fetchAll($sql){ |
|
| 86 | + private function fetchAll($sql) { |
|
| 87 | 87 | return $this->db->executeQuery($sql)->fetchAll(); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -83,7 +83,7 @@ |
||
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - private function fetchAll($sql){ |
|
| 86 | + private function fetchAll($sql) { |
|
| 87 | 87 | return $this->db->executeQuery($sql)->fetchAll(); |
| 88 | 88 | } |
| 89 | 89 | |