mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-27 13:56:16 +08:00
Scrutinizer Auto-Fixes
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
parent
cee3ea9865
commit
33ef75ac2f
5 changed files with 147 additions and 115 deletions
|
|
@ -43,30 +43,46 @@ class CredentialService {
|
|||
public function updateCredential($credential) {
|
||||
return $this->credentialMapper->updateCredential($credential);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Credential $credential
|
||||
*/
|
||||
public function upd($credential) {
|
||||
return $this->credentialMapper->upd($credential);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Credential $credential
|
||||
*/
|
||||
public function deleteCredential($credential){
|
||||
return $this->credentialMapper->deleteCredential($credential);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $vault_id
|
||||
*/
|
||||
public function getCredentialsByVaultId($vault_id, $user_id) {
|
||||
return $this->credentialMapper->getCredentialsByVaultId($vault_id, $user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $vault_id
|
||||
*/
|
||||
public function getRandomCredentialByVaultId($vault_id, $user_id) {
|
||||
$credentials = $this->credentialMapper->getRandomCredentialByVaultId($vault_id, $user_id);
|
||||
return array_pop($credentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $timestamp
|
||||
*/
|
||||
public function getExpiredCredentials($timestamp) {
|
||||
return $this->credentialMapper->getExpiredCredentials($timestamp);
|
||||
}
|
||||
|
||||
public function getCredentialById($credential_id, $user_id){
|
||||
public function getCredentialById($credential_id, $user_id) {
|
||||
$credential = $this->credentialMapper->getCredentialById($credential_id);
|
||||
if ($credential->getUserId() === $user_id){
|
||||
if ($credential->getUserId() === $user_id) {
|
||||
return $credential;
|
||||
}
|
||||
else {
|
||||
|
|
@ -77,6 +93,10 @@ class CredentialService {
|
|||
|
||||
throw new DoesNotExistException("Did expect one result but found none when executing");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $credential_id
|
||||
*/
|
||||
public function getCredentialLabelById($credential_id){
|
||||
return $this->credentialMapper->getCredentialLabelById($credential_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class CronService {
|
|||
public function expireCredentials() {
|
||||
$this->logger->info('Passman cron test', array('app' => 'passman'));
|
||||
$expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime());
|
||||
foreach($expired_credentials as $credential){
|
||||
foreach ($expired_credentials as $credential) {
|
||||
$link = ''; // @TODO create direct link to credential
|
||||
|
||||
$sql = 'SELECT count(*) as rows from `*PREFIX*notifications` WHERE `subject`= \'credential_expired\' AND object_id=?';
|
||||
|
|
@ -45,9 +45,9 @@ class CronService {
|
|||
$id = $credential->getId();
|
||||
$query->bindParam(1, $id, \PDO::PARAM_INT);
|
||||
$result = $query->execute();
|
||||
$this->logger->debug($credential->getLabel() .' is expired, checking notifications!', array('app' => 'passman'));
|
||||
if($result->fetchRow()['rows'] === 0) {
|
||||
$this->logger->debug($credential->getLabel() .' is expired, adding notification!', array('app' => 'passman'));
|
||||
$this->logger->debug($credential->getLabel() . ' is expired, checking notifications!', array('app' => 'passman'));
|
||||
if ($result->fetchRow()['rows'] === 0) {
|
||||
$this->logger->debug($credential->getLabel() . ' is expired, adding notification!', array('app' => 'passman'));
|
||||
|
||||
$this->activityService->add(
|
||||
Activity::SUBJECT_ITEM_EXPIRED, array($credential->getLabel(), $credential->getUserId()),
|
||||
|
|
@ -55,7 +55,7 @@ class CronService {
|
|||
$link, $credential->getUserId(), Activity::TYPE_ITEM_EXPIRED);
|
||||
$this->notificationService->credentialExpiredNotification($credential);
|
||||
} else {
|
||||
$this->logger->debug($credential->getLabel() .' is expired, already notified!', array('app' => 'passman'));
|
||||
$this->logger->debug($credential->getLabel() . ' is expired, already notified!', array('app' => 'passman'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,9 @@ class ShareService {
|
|||
}
|
||||
|
||||
public function createACLEntry(SharingACL $acl) {
|
||||
if ($acl->getCreated() === null) $acl->setCreated((new \DateTime())->getTimestamp());
|
||||
if ($acl->getCreated() === null) {
|
||||
$acl->setCreated((new \DateTime())->getTimestamp());
|
||||
}
|
||||
return $this->sharingACL->createACLEntry($acl);
|
||||
}
|
||||
|
||||
|
|
@ -124,12 +126,16 @@ class ShareService {
|
|||
$return = [];
|
||||
foreach ($entries as $entry) {
|
||||
// Check if the user can read the credential, probably unnecesary, but just to be sure
|
||||
if (!$entry->hasPermission(SharingACL::READ)) continue;
|
||||
if (!$entry->hasPermission(SharingACL::READ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tmp = $entry->jsonSerialize();
|
||||
$tmp['credential_data'] = $this->credential->getCredentialById($entry->getItemId())->jsonSerialize();
|
||||
|
||||
if (!$entry->hasPermission(SharingACL::FILES)) unset($tmp['credential_data']['files']);
|
||||
if (!$entry->hasPermission(SharingACL::FILES)) {
|
||||
unset($tmp['credential_data']['files']);
|
||||
}
|
||||
unset($tmp['credential_data']['shared_key']);
|
||||
$return[] = $tmp;
|
||||
}
|
||||
|
|
@ -150,12 +156,16 @@ class ShareService {
|
|||
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
|
||||
|
||||
// Check if the user can read the credential, probably unnecesary, but just to be sure
|
||||
if (!$acl->hasPermission(SharingACL::READ)) throw new DoesNotExistException("Item not found or wrong access level");
|
||||
if (!$acl->hasPermission(SharingACL::READ)) {
|
||||
throw new DoesNotExistException("Item not found or wrong access level");
|
||||
}
|
||||
|
||||
$tmp = $acl->jsonSerialize();
|
||||
$tmp['credential_data'] = $this->credential->getCredentialById($acl->getItemId())->jsonSerialize();
|
||||
|
||||
if (!$acl->hasPermission(SharingACL::FILES)) unset($tmp['credential_data']['files']);
|
||||
if (!$acl->hasPermission(SharingACL::FILES)) {
|
||||
unset($tmp['credential_data']['files']);
|
||||
}
|
||||
unset($tmp['credential_data']['shared_key']);
|
||||
|
||||
return $tmp;
|
||||
|
|
@ -170,7 +180,9 @@ class ShareService {
|
|||
*/
|
||||
public function getItemHistory($user_id, $item_guid) {
|
||||
$acl = $this->sharingACL->getItemACL($user_id, $item_guid);
|
||||
if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) return [];
|
||||
if (!$acl->hasPermission(SharingACL::READ | SharingACL::HISTORY)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->revisions->getRevisions($acl->getItemId());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue