revert some method return type declarations that were IDE optimizations

This commit is contained in:
binsky 2021-03-22 23:55:44 +01:00
Родитель 80d76f4697
Коммит 9d47d0f28d
15 изменённых файлов: 175 добавлений и 203 удалений

Просмотреть файл

@ -11,22 +11,20 @@
namespace OCA\Passman\Controller;
use OCA\Passman\Activity;
use OCA\Passman\Db\Credential;
use OCA\Passman\Db\SharingACL;
use OCA\Passman\Service\EncryptService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Utility\NotFoundJSONResponse;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\ApiController;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Activity;
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Service\CredentialRevisionService;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Service\ShareService;
use OCA\Passman\Utility\NotFoundJSONResponse;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class CredentialController extends ApiController {
@ -38,13 +36,13 @@ class CredentialController extends ApiController {
private $settings;
public function __construct($AppName,
IRequest $request,
$userId,
CredentialService $credentialService,
ActivityService $activityService,
CredentialRevisionService $credentialRevisionService,
ShareService $sharingService,
SettingsService $settings
IRequest $request,
$userId,
CredentialService $credentialService,
ActivityService $activityService,
CredentialRevisionService $credentialRevisionService,
ShareService $sharingService,
SettingsService $settings
) {
parent::__construct(
@ -67,10 +65,10 @@ class CredentialController extends ApiController {
* @NoCSRFRequired
*/
public function createCredential($changed, $created,
$credential_id, $custom_fields, $delete_time,
$description, $email, $expire_time, $favicon, $files, $guid,
$hidden, $icon, $label, $otp, $password, $renew_interval,
$tags, $url, $username, $vault_id, $compromised) {
$credential_id, $custom_fields, $delete_time,
$description, $email, $expire_time, $favicon, $files, $guid,
$hidden, $icon, $label, $otp, $password, $renew_interval,
$tags, $url, $username, $vault_id, $compromised) {
$credential = array(
'credential_id' => $credential_id,
'guid' => $guid,
@ -106,7 +104,7 @@ class CredentialController extends ApiController {
$link, $this->userId, Activity::TYPE_ITEM_ACTION);
}
return new JSONResponse($this->credentialService->getCredentialByGUID($credential->getGuid()));
return new JSONResponse($this->credentialService->getCredentialByGUID($credential->getGuid()));
}
/**
@ -123,10 +121,10 @@ class CredentialController extends ApiController {
* @NoCSRFRequired
*/
public function updateCredential($changed, $created,
$credential_id, $custom_fields, $delete_time, $credential_guid,
$description, $email, $expire_time, $icon, $files, $guid,
$hidden, $label, $otp, $password, $renew_interval,
$tags, $url, $username, $vault_id, $revision_created, $shared_key, $acl, $unshare_action, $set_share_key, $skip_revision, $compromised) {
$credential_id, $custom_fields, $delete_time, $credential_guid,
$description, $email, $expire_time, $icon, $files, $guid,
$hidden, $label, $otp, $password, $renew_interval,
$tags, $url, $username, $vault_id, $revision_created, $shared_key, $acl, $unshare_action, $set_share_key, $skip_revision, $compromised) {
$storedCredential = $this->credentialService->getCredentialByGUID($credential_guid);
@ -261,7 +259,7 @@ class CredentialController extends ApiController {
$credential = $this->credentialService->updateCredential($credential);
return new JSONResponse($this->credentialService->getCredentialByGUID($credential->getGuid()));
return new JSONResponse($this->credentialService->getCredentialByGUID($credential->getGuid()));
}
/**
@ -287,6 +285,7 @@ class CredentialController extends ApiController {
/**
* Delete leftovers from a credential
* @param Credential $credential
* @throws \Exception
*/
private function deleteCredentialParts(Credential $credential) {
$this->activityService->add(
@ -295,16 +294,17 @@ class CredentialController extends ApiController {
'', $this->userId, Activity::TYPE_ITEM_ACTION);
$this->sharingService->unshareCredential($credential->getGuid());
foreach ($this->credentialRevisionService->getRevisions($credential->getId()) as $revision) {
$id = $revision['revision_id'];
if(isset($id)){
$this->credentialRevisionService->deleteRevision($id, $this->userId);
}
$id = $revision['revision_id'];
if (isset($id)) {
$this->credentialRevisionService->deleteRevision($id, $this->userId);
}
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @throws \Exception
*/
public function getRevision($credential_guid) {
try {

Просмотреть файл

@ -11,26 +11,26 @@
namespace OCA\Passman\Controller;
use OCA\Passman\Activity;
use OCA\Passman\Db\File;
use OCA\Passman\Db\SharingACL;
use OCA\Passman\Db\Vault;
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Service\FileService;
use OCA\Passman\Service\NotificationService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Service\ShareService;
use OCA\Passman\Service\VaultService;
use OCA\Passman\Utility\NotFoundJSONResponse;
use OCA\Passman\Utility\Utils;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserManager;
use OCA\Passman\Service\VaultService;
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Activity;
use OCP\Notification\IManager;
@ -51,18 +51,18 @@ class ShareController extends ApiController {
private $offset = 0;
public function __construct($AppName,
IRequest $request,
$UserId,
IGroupManager $groupManager,
IUserManager $userManager,
ActivityService $activityService,
VaultService $vaultService,
ShareService $shareService,
CredentialService $credentialService,
NotificationService $notificationService,
FileService $fileService,
SettingsService $config,
IManager $IManager
IRequest $request,
$UserId,
IGroupManager $groupManager,
IUserManager $userManager,
ActivityService $activityService,
VaultService $vaultService,
ShareService $shareService,
CredentialService $credentialService,
NotificationService $notificationService,
FileService $fileService,
SettingsService $config,
IManager $IManager
) {
parent::__construct(
$AppName,
@ -434,9 +434,8 @@ class ShareController extends ApiController {
/**
* @param $item_guid
* @return JSONResponse
* @NoAdminRequired
* @NoCSRFRequired
* @return JSONResponse|NotFoundResponse
* @throws \OCP\DB\Exception
*/
public function getItemAcl($item_guid) {
$acl = $this->shareService->getCredentialAclList($item_guid);
@ -460,10 +459,9 @@ class ShareController extends ApiController {
/**
* @param $item_guid
* @param $file_guid
* @NoAdminRequired
* @PublicPage
* @return mixed
* @return NotFoundJSONResponse
* @return array|File|NotFoundJSONResponse
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function getFile($item_guid, $file_guid) {
try {

Просмотреть файл

@ -46,7 +46,7 @@ class CredentialMapper extends QBMapper {
*
* @param string $vault_id
* @param string $user_id
* @return Credential[]
* @return Entity[]
*/
public function getCredentialsByVaultId(string $vault_id, string $user_id) {
$qb = $this->db->getQueryBuilder();
@ -55,9 +55,7 @@ class CredentialMapper extends QBMapper {
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('vault_id', $qb->createNamedParameter($vault_id, IQueryBuilder::PARAM_STR)));
/** @var Credential[] $credentials */
$credentials = $this->findEntities($qb);
return $credentials;
return $this->findEntities($qb);
}
/**
@ -88,18 +86,16 @@ class CredentialMapper extends QBMapper {
* Get expired credentials
*
* @param int $timestamp
* @return Credential[]
* @return Entity[]
*/
public function getExpiredCredentials(int $timestamp) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from(self::TABLE_NAME)
->where($qb->expr()->gt('expire_time', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->where($qb->expr()->gt('expire_time', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->lt('expire_time', $qb->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT)));
/** @var Credential[] $credentials */
$credentials = $this->findEntities($qb);
return $credentials;
return $this->findEntities($qb);
}
/**
@ -108,7 +104,7 @@ class CredentialMapper extends QBMapper {
*
* @param int $credential_id
* @param string|null $user_id
* @return Credential
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -122,16 +118,14 @@ class CredentialMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var Credential $credential */
$credential = $this->findEntity($qb);
return $credential;
return $this->findEntity($qb);
}
/**
* Get credential label by id
*
* @param int $credential_id
* @return Credential
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -141,9 +135,7 @@ class CredentialMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('id', $qb->createNamedParameter($credential_id, IQueryBuilder::PARAM_INT)));
/** @var Credential $credential */
$credential = $this->findEntity($qb);
return $credential;
return $this->findEntity($qb);
}
/**
@ -236,7 +228,7 @@ class CredentialMapper extends QBMapper {
*
* @param string $credential_guid
* @param string|null $user_id
* @return Credential
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -250,8 +242,6 @@ class CredentialMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var Credential $credential */
$credential = $this->findEntity($qb);
return $credential;
return $this->findEntity($qb);
}
}

Просмотреть файл

@ -25,6 +25,7 @@ namespace OCA\Passman\Db;
use OCA\Passman\Utility\Utils;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
@ -45,7 +46,7 @@ class CredentialRevisionMapper extends QBMapper {
*
* @param int $credential_id
* @param string|null $user_id
* @return CredentialRevision[]
* @return Entity[]
*/
public function getRevisions(int $credential_id, string $user_id = null) {
$qb = $this->db->getQueryBuilder();
@ -57,15 +58,13 @@ class CredentialRevisionMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var CredentialRevision[] $credentialRevisions */
$credentialRevisions = $this->findEntities($qb);
return $credentialRevisions;
return $this->findEntities($qb);
}
/**
* @param int $revision_id
* @param string|null $user_id
* @return CredentialRevision
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -79,9 +78,7 @@ class CredentialRevisionMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var CredentialRevision $credentialRevision */
$credentialRevision = $this->findEntity($qb);
return $credentialRevision;
return $this->findEntity($qb);
}
/**

Просмотреть файл

@ -45,7 +45,7 @@ class FileMapper extends QBMapper {
/**
* @param int $file_id
* @param string|null $user_id
* @return File
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -59,15 +59,13 @@ class FileMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var File $file */
$file = $this->findEntity($qb);
return $file;
return $this->findEntity($qb);
}
/**
* @param string $file_guid
* @param string|null $user_id
* @return File
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -81,9 +79,7 @@ class FileMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var File $file */
$file = $this->findEntity($qb);
return $file;
return $this->findEntity($qb);
}
/**
@ -130,7 +126,7 @@ class FileMapper extends QBMapper {
/**
* @param string $user_id
* @return File[]
* @return Entity[]
*/
public function getFilesFromUser(string $user_id) {
$qb = $this->db->getQueryBuilder();
@ -138,8 +134,6 @@ class FileMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
/** @var File[] $files */
$files = $this->findEntities($qb);
return $files;
return $this->findEntities($qb);
}
}

Просмотреть файл

@ -53,7 +53,7 @@ class ShareRequestMapper extends QBMapper {
*
* @param string $item_guid
* @param string $target_vault_guid
* @return ShareRequest
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -64,16 +64,14 @@ class ShareRequestMapper extends QBMapper {
->where($qb->expr()->eq('item_guid', $qb->createNamedParameter($item_guid, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('target_vault_guid', $qb->createNamedParameter($target_vault_guid, IQueryBuilder::PARAM_STR)));
/** @var ShareRequest $shareRequest */
$shareRequest = $this->findEntity($qb);
return $shareRequest;
return $this->findEntity($qb);
}
/**
* Get shared items for the given item_guid
*
* @param string $item_guid
* @return ShareRequest[]
* @return Entity[]
* @throws Exception
*/
public function getRequestsByItemGuidGroupedByUser(string $item_guid) {
@ -86,9 +84,7 @@ class ShareRequestMapper extends QBMapper {
->where($qb->expr()->eq('item_guid', $qb->createNamedParameter($item_guid, IQueryBuilder::PARAM_STR)))
->groupBy('target_user_id');
/** @var ShareRequest[] $sharedRequests */
$sharedRequests = $this->findEntities($qb);
return $sharedRequests;
return $this->findEntities($qb);
}
/**
@ -111,7 +107,7 @@ class ShareRequestMapper extends QBMapper {
* Obtains all pending share requests for the given user ID
*
* @param string $user_id
* @return ShareRequest[]
* @return Entity[]
*/
public function getUserPendingRequests(string $user_id) {
$qb = $this->db->getQueryBuilder();
@ -119,9 +115,7 @@ class ShareRequestMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('target_user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
/** @var ShareRequest[] $shareRequests */
$shareRequests = $this->findEntities($qb);
return $shareRequests;
return $this->findEntities($qb);
}
/**
@ -137,7 +131,7 @@ class ShareRequestMapper extends QBMapper {
* Gets a share request by it's unique incremental id
*
* @param int $id
* @return ShareRequest
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -147,16 +141,14 @@ class ShareRequestMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
/** @var ShareRequest $shareRequest */
$shareRequest = $this->findEntity($qb);
return $shareRequest;
return $this->findEntity($qb);
}
/**
* Gets all share requests by a given item GUID
*
* @param string $item_guid
* @return ShareRequest[]
* @return Entity[]
*/
public function getShareRequestsByItemGuid(string $item_guid) {
$qb = $this->db->getQueryBuilder();
@ -164,9 +156,7 @@ class ShareRequestMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('item_guid', $qb->createNamedParameter($item_guid, IQueryBuilder::PARAM_STR)));
/** @var ShareRequest[] $shareRequests */
$shareRequests = $this->findEntities($qb);
return $shareRequests;
return $this->findEntities($qb);
}
/**
@ -183,7 +173,7 @@ class ShareRequestMapper extends QBMapper {
*
* @param string $item_guid
* @param string $user_id
* @return ShareRequest[]
* @return Entity[]
*/
public function getPendingShareRequests(string $item_guid, string $user_id) {
$qb = $this->db->getQueryBuilder();
@ -192,9 +182,7 @@ class ShareRequestMapper extends QBMapper {
->where($qb->expr()->eq('item_guid', $qb->createNamedParameter($item_guid, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('target_user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
/** @var ShareRequest[] $shareRequests */
$shareRequests = $this->findEntities($qb);
return $shareRequests;
return $this->findEntities($qb);
}
/**

Просмотреть файл

@ -48,9 +48,10 @@ class SharingACLMapper extends QBMapper {
/**
* Gets the currently accepted share requests from the given user for the given vault guid
* @param $user_id
* @param $vault_guid
* @return SharingACL[]
*
* @param string $user_id
* @param string $vault_guid
* @return Entity[]
*/
public function getVaultEntries(string $user_id, string $vault_guid) {
$qb = $this->db->getQueryBuilder();
@ -59,9 +60,7 @@ class SharingACLMapper extends QBMapper {
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('vault_guid', $qb->createNamedParameter($vault_guid, IQueryBuilder::PARAM_STR)));
/** @var SharingACL[] $entities */
$entities = $this->findEntities($qb);
return $entities;
return $this->findEntities($qb);
}
/**
@ -69,7 +68,7 @@ class SharingACLMapper extends QBMapper {
*
* @param string $user_id
* @param string $item_guid
* @return SharingACL
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -85,9 +84,7 @@ class SharingACLMapper extends QBMapper {
$qb->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
}
/** @var SharingACL $entity */
$entity = $this->findEntity($qb);
return $entity;
return $this->findEntity($qb);
}
/**
@ -104,7 +101,7 @@ class SharingACLMapper extends QBMapper {
* Gets the currently accepted share requests from the given user for the given vault guid
*
* @param string $item_guid
* @return SharingACL[]
* @return Entity[]
*/
public function getCredentialAclList(string $item_guid) {
$qb = $this->db->getQueryBuilder();
@ -112,9 +109,7 @@ class SharingACLMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('item_guid', $qb->createNamedParameter($item_guid, IQueryBuilder::PARAM_STR)));
/** @var SharingACL[] $entities */
$entities = $this->findEntities($qb);
return $entities;
return $this->findEntities($qb);
}
/**

Просмотреть файл

@ -44,7 +44,7 @@ class VaultMapper extends QBMapper {
/**
* @param int $vault_id
* @param string $user_id
* @return Vault[]
* @return Entity[]
*/
public function find(int $vault_id, string $user_id) {
$qb = $this->db->getQueryBuilder();
@ -53,15 +53,13 @@ class VaultMapper extends QBMapper {
->where($qb->expr()->eq('id', $qb->createNamedParameter($vault_id, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
/** @var Vault[] $vaults */
$vaults = $this->findEntities($qb);
return $vaults;
return $this->findEntities($qb);
}
/**
* @param string $vault_guid
* @param string $user_id
* @return Vault
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -72,15 +70,13 @@ class VaultMapper extends QBMapper {
->where($qb->expr()->eq('guid', $qb->createNamedParameter($vault_guid, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
/** @var Vault $vault */
$vault = $this->findEntity($qb);
return $vault;
return $this->findEntity($qb);
}
/**
* @param string $user_id
* @return Vault[]
* @return Entity[]
*/
public function findVaultsFromUser(string $user_id) {
$qb = $this->db->getQueryBuilder();
@ -88,9 +84,7 @@ class VaultMapper extends QBMapper {
->from(self::TABLE_NAME)
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user_id, IQueryBuilder::PARAM_STR)));
/** @var Vault[] $vaults */
$vaults = $this->findEntities($qb);
return $vaults;
return $this->findEntities($qb);
}
/**

Просмотреть файл

@ -25,7 +25,9 @@ namespace OCA\Passman\Service;
use OCA\Passman\Db\CredentialRevision;
use OCA\Passman\Db\CredentialRevisionMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IConfig;
@ -61,7 +63,8 @@ class CredentialRevisionService {
*
* @param int $credential_id
* @param string|null $user_id
* @return CredentialRevision[]
* @return Entity[]
* @throws \Exception
*/
public function getRevisions(int $credential_id, string $user_id = null) {
$result = $this->credentialRevisionMapper->getRevisions($credential_id, $user_id);
@ -76,7 +79,10 @@ class CredentialRevisionService {
/**
* @param int $credential_id
* @param string|null $user_id
* @return CredentialRevision
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws \Exception
*/
public function getRevision(int $credential_id, string $user_id = null) {
$revision = $this->credentialRevisionMapper->getRevision($credential_id, $user_id);

Просмотреть файл

@ -104,7 +104,8 @@ class CredentialService {
*
* @param int $vault_id
* @param string $user_id
* @return Credential[]
* @return Entity[]
* @throws \Exception
*/
public function getCredentialsByVaultId(int $vault_id, string $user_id) {
$credentials = $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
@ -133,7 +134,8 @@ class CredentialService {
* Get expired credentials.
*
* @param int $timestamp
* @return Credential[]
* @return Entity[]
* @throws \Exception
*/
public function getExpiredCredentials(int $timestamp) {
$credentials = $this->credentialMapper->getExpiredCredentials($timestamp);

Просмотреть файл

@ -25,6 +25,7 @@ namespace OCA\Passman\Service;
use OCA\Passman\Db\DeleteVaultRequest;
use OCA\Passman\Db\DeleteVaultRequestMapper;
use OCP\AppFramework\Db\Entity;
class DeleteVaultRequestService {
@ -46,27 +47,23 @@ class DeleteVaultRequestService {
}
/**
* Create a new DeleteVaultRequest
* Create a new DeleteVaultRequest
*
* @return DeleteVaultRequest[]
* @return Entity[]
*/
public function getDeleteRequests() {
/** @var DeleteVaultRequest[] $result */
$result = $this->deleteVaultRequestMapper->getDeleteRequests();
return $result;
return $this->deleteVaultRequestMapper->getDeleteRequests();
}
/**
* Create a new DeleteVaultRequest
*
* @param $vault_guid string The vault guid
* @return bool | DeleteVaultRequest
* @return bool | Entity
*/
public function getDeleteRequestForVault(string $vault_guid) {
try {
/** @var DeleteVaultRequest $result */
$result = $this->deleteVaultRequestMapper->getDeleteRequestsForVault($vault_guid);
return $result;
return $this->deleteVaultRequestMapper->getDeleteRequestsForVault($vault_guid);
} catch (\Exception $e) {
return false;
}
@ -80,5 +77,4 @@ class DeleteVaultRequestService {
public function removeDeleteRequestForVault(DeleteVaultRequest $req) {
$this->deleteVaultRequestMapper->removeDeleteVaultRequest($req);
}
}

Просмотреть файл

@ -26,9 +26,9 @@ namespace OCA\Passman\Service;
// Class copied from http://stackoverflow.com/questions/5089841/two-way-encryption-i-need-to-store-passwords-that-can-be-retrieved?answertab=votes#tab-top
// Upgraded to use openssl
use Icewind\SMB\Exception\Exception;
use OCA\Passman\Db\Credential;
use OCA\Passman\Db\File;
use OCP\AppFramework\Db\Entity;
use OCP\IConfig;
/**
@ -280,8 +280,9 @@ class EncryptService {
/**
* Encrypt a credential
*
* @param Credential|array $credential the credential to decrypt
* @param Credential|Entity|array $credential the credential to decrypt
* @return Credential|array
* @throws \Exception
*/
public function decryptCredential($credential) {
return $this->handleCredential($credential, EncryptService::OP_DECRYPT);
@ -343,10 +344,10 @@ class EncryptService {
/**
* Encrypt a file
*
* @param File|array $file
* @param File|array $file
* @return File|array
* @throws \Exception
*/
public function encryptFile($file) {
return $this->handleFile($file, EncryptService::OP_ENCRYPT);
}
@ -354,10 +355,10 @@ class EncryptService {
/**
* Decrypt a file
*
* @param File|array $file
* @return File|array
* @param File|Entity|array $file
* @return array|File
* @throws \Exception
*/
public function decryptFile($file) {
return $this->handleFile($file, EncryptService::OP_DECRYPT);
}

Просмотреть файл

@ -23,6 +23,7 @@
namespace OCA\Passman\Service;
use Exception;
use OCA\Passman\Db\File;
use OCA\Passman\Db\FileMapper;
use OCP\AppFramework\Db\DoesNotExistException;
@ -51,6 +52,7 @@ class FileService {
* @return array|File
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws Exception
*/
public function getFile(int $fileId, string $userId = null) {
$file = $this->fileMapper->getFile($fileId, $userId);
@ -65,6 +67,7 @@ class FileService {
* @return array|File
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws Exception
*/
public function getFileByGuid(string $file_guid, string $userId = null) {
$file = $this->fileMapper->getFileByGuid($file_guid, $userId);
@ -79,6 +82,7 @@ class FileService {
* @return array|File
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws Exception
*/
public function createFile(array $file, string $userId) {
$file = $this->encryptService->encryptFile($file);
@ -102,6 +106,7 @@ class FileService {
*
* @param File $file
* @return File
* @throws Exception
*/
public function updateFile(File $file) {
$file = $this->encryptService->encryptFile($file);
@ -113,6 +118,7 @@ class FileService {
*
* @param string $userId
* @return File[]
* @throws Exception
*/
public function getFilesFromUser(string $userId) {
$files = $this->fileMapper->getFilesFromUser($userId);

Просмотреть файл

@ -25,7 +25,6 @@ namespace OCA\Passman\Service;
use OCA\Passman\Db\CredentialMapper;
use OCA\Passman\Db\CredentialRevision;
use OCA\Passman\Db\ShareRequest;
use OCA\Passman\Db\ShareRequestMapper;
use OCA\Passman\Db\SharingACL;
@ -138,7 +137,7 @@ class ShareService {
* Obtains pending requests for the given user ID
*
* @param string $user_id
* @return ShareRequest[]
* @return Entity[]
*/
public function getUserPendingRequests(string $user_id) {
return $this->shareRequest->getUserPendingRequests($user_id);
@ -177,7 +176,9 @@ class ShareService {
*
* @param string $user_id
* @param string $item_guid
* @return SharingACL
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function getACL(string $user_id, string $item_guid) {
return $this->sharingACL->getItemACL($user_id, $item_guid);
@ -213,7 +214,10 @@ class ShareService {
*
* @param string $user_id
* @param string $item_guid
* @return CredentialRevision[]
* @return array|Entity[]
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
* @throws \Exception
*/
public function getItemHistory(string $user_id, string $item_guid) {
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
@ -238,7 +242,7 @@ class ShareService {
* Get an share request by id
*
* @param int $id
* @return ShareRequest
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -251,7 +255,7 @@ class ShareService {
*
* @param string $item_guid
* @param string $target_vault_guid
* @return ShareRequest
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -263,7 +267,7 @@ class ShareService {
* Get the access control list by item guid
*
* @param string $item_guid
* @return SharingACL[]
* @return Entity[]
*/
public function getCredentialAclList(string $item_guid) {
return $this->sharingACL->getCredentialAclList($item_guid);
@ -271,7 +275,7 @@ class ShareService {
/**
* @param string $item_guid
* @return ShareRequest[]
* @return Entity[]
* @throws Exception
*/
public function getCredentialPendingAclList(string $item_guid) {
@ -283,7 +287,7 @@ class ShareService {
*
* @param string $user_id
* @param string $item_guid
* @return SharingACL
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
@ -295,7 +299,7 @@ class ShareService {
* Get pending share requests by guid
*
* @param string $item_guid
* @return ShareRequest[]
* @return Entity[]
*/
public function getShareRequestsByGuid(string $item_guid) {
return $this->shareRequest->getShareRequestsByItemGuid($item_guid);
@ -314,7 +318,7 @@ class ShareService {
/**
* Delete ACL
*
* @param SharingACL $ACL
* @param SharingACL|Entity $ACL
* @return SharingACL|Entity
*/
public function deleteShareACL(SharingACL $ACL) {
@ -325,7 +329,7 @@ class ShareService {
* Updates the given ACL entry
*
* @param SharingACL $sharingACL
* @return SharingACL
* @return SharingACL|Entity
*/
public function updateCredentialACL(SharingACL $sharingACL) {
return $this->sharingACL->updateCredentialACL($sharingACL);
@ -345,7 +349,7 @@ class ShareService {
*
* @param string $item_guid
* @param string $user_id
* @return ShareRequest[]
* @return Entity[]
*/
public function getPendingShareRequestsForCredential(string $item_guid, string $user_id) {
return $this->shareRequest->getPendingShareRequests($item_guid, $user_id);

Просмотреть файл

@ -24,11 +24,10 @@
namespace OCA\Passman\Service;
use OCA\Passman\Db\Vault;
use OCP\AppFramework\Db\Entity;
use OCP\IConfig;
use OCP\AppFramework\Db\DoesNotExistException;
use OCA\Passman\Db\VaultMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
class VaultService {
@ -42,7 +41,7 @@ class VaultService {
/**
* Get vaults from a user.
* @param $userId
* @return \OCA\Passman\Db\Vault[]
* @return Entity[]
*/
public function getByUser($userId) {
return $this->vaultMapper->findVaultsFromUser($userId);
@ -52,29 +51,29 @@ class VaultService {
* Get a single vault
* @param $vault_id
* @param $user_id
* @return \OCA\Passman\Db\Vault[]
* @return Entity[]
*/
public function getById($vault_id, $user_id) {
$vault = $this->vaultMapper->find($vault_id, $user_id);
return $vault;
return $this->vaultMapper->find($vault_id, $user_id);
}
/**
* Get a single vault.
* @param $vault_guid
* @param $user_id
* @return \OCA\Passman\Db\Vault
* @return Entity
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function getByGuid($vault_guid, $user_id) {
$vault = $this->vaultMapper->findByGuid($vault_guid, $user_id);
return $vault;
return $this->vaultMapper->findByGuid($vault_guid, $user_id);
}
/**
* Create a new vault.
* @param $vault_name
* @param $userId
* @return \OCA\Passman\Db\Vault
* @return Vault
*/
public function createVault($vault_name, $userId) {
return $this->vaultMapper->create($vault_name, $userId);
@ -95,7 +94,7 @@ class VaultService {
* @param $user_id
* @return Vault|Entity
*/
public function setLastAccess($vault_id, $user_id){
public function setLastAccess($vault_id, $user_id) {
return $this->vaultMapper->setLastAccess($vault_id, $user_id);
}
@ -106,18 +105,20 @@ class VaultService {
* @param $publicKey
* @return Vault|Entity
*/
public function updateSharingKeys($vault_id, $privateKey, $publicKey){
public function updateSharingKeys($vault_id, $privateKey, $publicKey) {
return $this->vaultMapper->updateSharingKeys($vault_id, $privateKey, $publicKey);
}
/**
* Delete a vault from user
* @param string $vault_guid
* @param string $user_id
* @param $vault_guid
* @param $user_id
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function deleteVault($vault_guid, $user_id){
public function deleteVault($vault_guid, $user_id) {
$vault = $this->getByGuid($vault_guid, $user_id);
if($vault instanceof Vault) {
if ($vault instanceof Vault) {
$this->vaultMapper->deleteVault($vault);
}
}