mirror of
https://github.com/nextcloud/passman.git
synced 2025-02-25 07:53:32 +08:00
move credential edit link generation into CredentialService
This commit is contained in:
parent
2fc9844ac7
commit
594583bd00
3 changed files with 19 additions and 8 deletions
|
@ -32,6 +32,7 @@ use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Db\Entity;
|
use OCP\AppFramework\Db\Entity;
|
||||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
|
|
||||||
class CredentialService {
|
class CredentialService {
|
||||||
|
@ -45,6 +46,8 @@ class CredentialService {
|
||||||
private ShareService $shareService,
|
private ShareService $shareService,
|
||||||
private EncryptService $encryptService,
|
private EncryptService $encryptService,
|
||||||
private CredentialRevisionService $credentialRevisionService,
|
private CredentialRevisionService $credentialRevisionService,
|
||||||
|
private IURLGenerator $urlGenerator,
|
||||||
|
private VaultService $vaultService,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
) {
|
) {
|
||||||
$this->server_key = $config->getSystemValue('passwordsalt', '');
|
$this->server_key = $config->getSystemValue('passwordsalt', '');
|
||||||
|
@ -214,4 +217,14 @@ class CredentialService {
|
||||||
$credential = $this->credentialMapper->getCredentialByGUID($credential_guid, $user_id);
|
$credential = $this->credentialMapper->getCredentialByGUID($credential_guid, $user_id);
|
||||||
return $this->encryptService->decryptCredential($credential);
|
return $this->encryptService->decryptCredential($credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDirectEditLink(Credential $credential): string {
|
||||||
|
$vaults = $this->vaultService->getById($credential->getVaultId(), $credential->getUserId());
|
||||||
|
return $this->urlGenerator->getAbsoluteURL(
|
||||||
|
$this->urlGenerator->linkTo(
|
||||||
|
'',
|
||||||
|
'index.php/apps/passman/#/vault/' . $vaults[0]->getGuid() . '/edit/' . $credential->getGuid()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
namespace OCA\Passman\Service;
|
namespace OCA\Passman\Service;
|
||||||
|
|
||||||
use OCA\Passman\Activity;
|
use OCA\Passman\Activity;
|
||||||
|
use OCA\Passman\Db\Credential;
|
||||||
use OCA\Passman\Utility\Utils;
|
use OCA\Passman\Utility\Utils;
|
||||||
use OCP\DB\Exception;
|
use OCP\DB\Exception;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -40,19 +41,19 @@ class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function expireCredentials() {
|
public function expireCredentials() {
|
||||||
|
/** @var Credential[] $expired_credentials */
|
||||||
$expired_credentials = $this->credentialService->getExpiredCredentials($this->utils->getTime());
|
$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
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->logger->debug($credential->getLabel() . ' is expired, checking notifications!', ['app' => 'passman']);
|
$this->logger->debug($credential->getLabel() . ' is expired, checking notifications!', ['app' => 'passman']);
|
||||||
if (!$this->notificationService->hasCredentialExpirationNotification($credential)) {
|
if (!$this->notificationService->hasCredentialExpirationNotification($credential)) {
|
||||||
|
$link = $this->credentialService->getDirectEditLink($credential);
|
||||||
$this->logger->debug($credential->getLabel() . ' is expired, adding notification!', ['app' => 'passman']);
|
$this->logger->debug($credential->getLabel() . ' is expired, adding notification!', ['app' => 'passman']);
|
||||||
$this->activityService->add(
|
$this->activityService->add(
|
||||||
Activity::SUBJECT_ITEM_EXPIRED, [$credential->getLabel(), $credential->getUserId()],
|
Activity::SUBJECT_ITEM_EXPIRED, [$credential->getLabel(), $credential->getUserId()],
|
||||||
'', [],
|
'', [],
|
||||||
$link, $credential->getUserId(), Activity::TYPE_ITEM_EXPIRED);
|
$link, $credential->getUserId(), Activity::TYPE_ITEM_EXPIRED);
|
||||||
$this->notificationService->credentialExpiredNotification($credential);
|
$this->notificationService->credentialExpiredNotification($credential, $link);
|
||||||
}
|
}
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$this->logger->error('Error while creating a notification: ' . $exception->getMessage(), ['app' => 'passman']);
|
$this->logger->error('Error while creating a notification: ' . $exception->getMessage(), ['app' => 'passman']);
|
||||||
|
|
|
@ -34,13 +34,10 @@ class NotificationService {
|
||||||
private IManager $manager,
|
private IManager $manager,
|
||||||
private IURLGenerator $urlGenerator,
|
private IURLGenerator $urlGenerator,
|
||||||
private IDBConnection $db,
|
private IDBConnection $db,
|
||||||
private VaultService $vaultService,
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function credentialExpiredNotification($credential) {
|
function credentialExpiredNotification($credential, $link) {
|
||||||
$vaults = $this->vaultService->getById($credential->getVaultId(), $credential->getUserId());
|
|
||||||
$link = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman/#/vault/' . $vaults[0]->getGuid() . '/edit/' . $credential->getGuid()));
|
|
||||||
$api = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman'));
|
$api = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'index.php/apps/passman'));
|
||||||
$notification = $this->manager->createNotification();
|
$notification = $this->manager->createNotification();
|
||||||
$remindAction = $notification->createAction();
|
$remindAction = $notification->createAction();
|
||||||
|
@ -106,7 +103,7 @@ class NotificationService {
|
||||||
$this->manager->notify($notification);
|
$this->manager->notify($notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCredentialExpirationNotification($credential) {
|
function hasCredentialExpirationNotification($credential): bool {
|
||||||
$qb = $this->db->getQueryBuilder();
|
$qb = $this->db->getQueryBuilder();
|
||||||
$qb->select('*')
|
$qb->select('*')
|
||||||
->from('notifications')
|
->from('notifications')
|
||||||
|
|
Loading…
Reference in a new issue