Skip to content

Commit

Permalink
Rename class to prevent duplicated class name in different namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>

[skip ci]
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Mar 25, 2024
1 parent bc57a71 commit 8a67a04
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions lib/Listener/MailNotifyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use OCA\Libresign\Db\File as FileEntity;
use OCA\Libresign\Db\SignRequest;
use OCA\Libresign\Events\SendSignNotificationEvent;
use OCA\Libresign\Service\IdentifyMethod\IdentifyMethodService;
use OCA\Libresign\Service\IdentifyMethod\IdentifyService;
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
use OCA\Libresign\Service\MailService;
use OCP\EventDispatcher\Event;
Expand All @@ -41,7 +41,7 @@ class MailNotifyListener implements IEventListener {
public function __construct(
protected IUserSession $userSession,
protected IUserManager $userManager,
protected IdentifyMethodService $identifyMethodService,
protected IdentifyService $identifyService,
protected MailService $mail,
private LoggerInterface $logger,
) {
Expand Down
70 changes: 35 additions & 35 deletions lib/Service/IdentifyMethod/AbstractIdentifyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class AbstractIdentifyMethod implements IIdentifyMethod {
*/
protected array $signatureMethods = [];
public function __construct(
protected IdentifyMethodService $identifyMethodService,
protected IdentifyService $identifyService,
) {
$className = (new \ReflectionClass($this))->getShortName();
$this->name = lcfirst($className);
Expand Down Expand Up @@ -107,9 +107,9 @@ public function notify(bool $isNew): bool {
if (!$this->willNotify) {
return false;
}
$signRequest = $this->identifyMethodService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$libresignFile = $this->identifyMethodService->getFileMapper()->getById($signRequest->getFileId());
$this->identifyMethodService->getEventDispatcher()->dispatchTyped(new SendSignNotificationEvent(
$signRequest = $this->identifyService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$libresignFile = $this->identifyService->getFileMapper()->getById($signRequest->getFileId());
$this->identifyService->getEventDispatcher()->dispatchTyped(new SendSignNotificationEvent(
$signRequest,
$libresignFile,
$this,
Expand All @@ -132,35 +132,35 @@ public function validateToIdentify(): void {
}

protected function throwIfFileNotFound(): void {
$signRequest = $this->identifyMethodService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$fileEntity = $this->identifyMethodService->getFileMapper()->getById($signRequest->getFileId());
$signRequest = $this->identifyService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$fileEntity = $this->identifyService->getFileMapper()->getById($signRequest->getFileId());

$nodeId = $fileEntity->getNodeId();

$mountsContainingFile = $this->identifyMethodService->getUserMountCache()->getMountsForFileId($nodeId);
$mountsContainingFile = $this->identifyService->getUserMountCache()->getMountsForFileId($nodeId);
foreach ($mountsContainingFile as $fileInfo) {
$this->identifyMethodService->getRootFolder()->getByIdInPath($nodeId, $fileInfo->getMountPoint());
$this->identifyService->getRootFolder()->getByIdInPath($nodeId, $fileInfo->getMountPoint());
}
$fileToSign = $this->identifyMethodService->getRootFolder()->getById($nodeId);
$fileToSign = $this->identifyService->getRootFolder()->getById($nodeId);
if (count($fileToSign) < 1) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_DO_NOTHING,
'errors' => [$this->identifyMethodService->getL10n()->t('File not found')],
'errors' => [$this->identifyService->getL10n()->t('File not found')],
]));
}
}

protected function throwIfMaximumValidityExpired(): void {
$maximumValidity = (int) $this->identifyMethodService->getAppConfig()->getAppValue('maximum_validity', (string) SessionService::NO_MAXIMUM_VALIDITY);
$maximumValidity = (int) $this->identifyService->getAppConfig()->getAppValue('maximum_validity', (string) SessionService::NO_MAXIMUM_VALIDITY);
if ($maximumValidity <= 0) {
return;
}
$signRequest = $this->identifyMethodService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$now = $this->identifyMethodService->getTimeFactory()->getTime();
$signRequest = $this->identifyService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$now = $this->identifyService->getTimeFactory()->getTime();
if ($signRequest->getCreatedAt() + $maximumValidity < $now) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_DO_NOTHING,
'errors' => [$this->identifyMethodService->getL10n()->t('Link expired.')],
'errors' => [$this->identifyService->getL10n()->t('Link expired.')],
]));
}
}
Expand All @@ -169,46 +169,46 @@ protected function throwIfInvalidToken(): void {
if (empty($this->codeSentByUser)) {
return;
}
if (!$this->identifyMethodService->getHasher()->verify($this->codeSentByUser, $this->getEntity()->getCode())) {
throw new LibresignException($this->identifyMethodService->getL10n()->t('Invalid code.'));
if (!$this->identifyService->getHasher()->verify($this->codeSentByUser, $this->getEntity()->getCode())) {
throw new LibresignException($this->identifyService->getL10n()->t('Invalid code.'));
}
}

protected function renewSession(): void {
$this->identifyMethodService->getSessionService()->setIdentifyMethodId($this->getEntity()->getId());
$renewalInterval = (int) $this->identifyMethodService->getAppConfig()->getAppValue('renewal_interval', (string) SessionService::NO_RENEWAL_INTERVAL);
$this->identifyService->getSessionService()->setIdentifyMethodId($this->getEntity()->getId());
$renewalInterval = (int) $this->identifyService->getAppConfig()->getAppValue('renewal_interval', (string) SessionService::NO_RENEWAL_INTERVAL);
if ($renewalInterval <= 0) {
return;
}
$this->identifyMethodService->getSessionService()->resetDurationOfSignPage();
$this->identifyService->getSessionService()->resetDurationOfSignPage();
}

protected function updateIdentifiedAt(): void {
if ($this->getEntity()->getCode() && !$this->getEntity()->getIdentifiedAtDate()) {
return;
}
$this->getEntity()->setIdentifiedAtDate($this->identifyMethodService->getTimeFactory()->getDateTime());
$this->getEntity()->setIdentifiedAtDate($this->identifyService->getTimeFactory()->getDateTime());
$this->willNotify = false;
$isNew = $this->identifyMethodService->save($this->getEntity());
$this->notify($isNew);
}

protected function throwIfRenewalIntervalExpired(): void {
$renewalInterval = (int) $this->identifyMethodService->getAppConfig()->getAppValue('renewal_interval', (string) SessionService::NO_RENEWAL_INTERVAL);
$renewalInterval = (int) $this->identifyService->getAppConfig()->getAppValue('renewal_interval', (string) SessionService::NO_RENEWAL_INTERVAL);
if ($renewalInterval <= 0) {
return;
}
$signRequest = $this->identifyMethodService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$startTime = $this->identifyMethodService->getSessionService()->getSignStartTime();
$signRequest = $this->identifyService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$startTime = $this->identifyService->getSessionService()->getSignStartTime();
$createdAt = $signRequest->getCreatedAt();
$lastAttempt = $this->getEntity()->getLastAttemptDate()?->format('U');
$lastActionDate = max(
$startTime,
$createdAt,
$lastAttempt,
);
$now = $this->identifyMethodService->getTimeFactory()->getTime();
$this->identifyMethodService->getLogger()->debug('AbstractIdentifyMethod::throwIfRenewalIntervalExpired Times', [
$now = $this->identifyService->getTimeFactory()->getTime();
$this->identifyService->getLogger()->debug('AbstractIdentifyMethod::throwIfRenewalIntervalExpired Times', [
'renewalInterval' => $renewalInterval,
'startTime' => $startTime,
'createdAt' => $createdAt,
Expand All @@ -217,13 +217,13 @@ protected function throwIfRenewalIntervalExpired(): void {
'now' => $now,
]);
if ($lastActionDate + $renewalInterval < $now) {
$this->identifyMethodService->getLogger()->debug('AbstractIdentifyMethod::throwIfRenewalIntervalExpired Exception');
$this->identifyService->getLogger()->debug('AbstractIdentifyMethod::throwIfRenewalIntervalExpired Exception');
$blur = new Blur($this->getEntity()->getIdentifierValue());
throw new LibresignException(json_encode([
'action' => $this->getRenewAction(),
// TRANSLATORS title that is displayed at screen to notify the signer that the link to sign the document expired
'title' => $this->identifyMethodService->getL10n()->t('Link expired'),
'body' => $this->identifyMethodService->getL10n()->t(<<<'BODY'
'title' => $this->identifyService->getL10n()->t('Link expired'),
'body' => $this->identifyService->getL10n()->t(<<<'BODY'
The link to sign the document has expired.
We will send a new link to the email %1$s.
Click below to receive the new link and be able to sign the document.
Expand All @@ -232,7 +232,7 @@ protected function throwIfRenewalIntervalExpired(): void {
),
'uuid' => $signRequest->getUuid(),
// TRANSLATORS Button to renew the link to sign the document. Renew is the action to generate a new sign link when the link expired.
'renewButton' => $this->identifyMethodService->getL10n()->t('Renew'),
'renewButton' => $this->identifyService->getL10n()->t('Renew'),
]));
}
}
Expand All @@ -246,15 +246,15 @@ private function getRenewAction(): int {
}

protected function throwIfAlreadySigned(): void {
$signRequest = $this->identifyMethodService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$fileEntity = $this->identifyMethodService->getFileMapper()->getById($signRequest->getFileId());
$signRequest = $this->identifyService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$fileEntity = $this->identifyService->getFileMapper()->getById($signRequest->getFileId());
if ($fileEntity->getStatus() === FileEntity::STATUS_SIGNED
|| (!is_null($signRequest) && $signRequest->getSigned())
) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_REDIRECT,
'errors' => [$this->identifyMethodService->getL10n()->t('File already signed.')],
'redirect' => $this->identifyMethodService->getUrlGenerator()->linkToRoute(
'errors' => [$this->identifyService->getL10n()->t('File already signed.')],
'redirect' => $this->identifyService->getUrlGenerator()->linkToRoute(
'libresign.page.validationFile',
['uuid' => $signRequest->getUuid()]
),
Expand Down Expand Up @@ -288,7 +288,7 @@ private function overrideImmutable(array $immutable): void {
}

private function loadSavedSettings(): void {
$config = $this->identifyMethodService->getSavedSettings();
$config = $this->identifyService->getSavedSettings();
$this->settings = array_reduce($config, function ($carry, $config) {
if ($config['name'] === $this->name) {
return $config;
Expand Down Expand Up @@ -325,7 +325,7 @@ public function save(): void {
}

public function delete(): void {
$this->identifyMethodService->delete($this->getEntity());
$this->identifyService->delete($this->getEntity());
}

private function removeKeysThatDontExists(array $default): void {
Expand Down
18 changes: 9 additions & 9 deletions lib/Service/IdentifyMethod/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

class Account extends AbstractIdentifyMethod {
public function __construct(
protected IdentifyMethodService $identifyMethodService,
protected IdentifyService $identifyService,
private IUserManager $userManager,
private IEventDispatcher $eventDispatcher,
private IdentifyMethodMapper $identifyMethodMapper,
Expand All @@ -61,21 +61,21 @@ public function __construct(
private EmailToken $emailToken,
) {
// TRANSLATORS Name of possible authenticator method. This signalize that the signer could be identified by Nextcloud acccount
$this->friendlyName = $this->identifyMethodService->getL10n()->t('Account');
$this->friendlyName = $this->identifyService->getL10n()->t('Account');
$this->signatureMethods = [
$this->password->getName() => $this->password,
$this->clickToSign->getName() => $this->clickToSign,
$this->emailToken->getName() => $this->emailToken,
];
parent::__construct(
$identifyMethodService,
$identifyService,
);
}

public function validateToRequest(): void {
$signer = $this->userManager->get($this->entity->getIdentifierValue());
if (!$signer) {
throw new LibresignException($this->identifyMethodService->getL10n()->t('User not found.'));
throw new LibresignException($this->identifyService->getL10n()->t('User not found.'));
}
}

Expand All @@ -100,7 +100,7 @@ private function getSigner(): IUser {
if (empty($signer) || count($signer) > 1) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_DO_NOTHING,
'errors' => [$this->identifyMethodService->getL10n()->t('Invalid user')],
'errors' => [$this->identifyService->getL10n()->t('Invalid user')],
]));
}
$signer = current($signer);
Expand All @@ -112,17 +112,17 @@ private function authenticatedUserIsTheSigner(IUser $signer): void {
if ($this->userSession->getUser() !== $signer) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_DO_NOTHING,
'errors' => [$this->identifyMethodService->getL10n()->t('Invalid user')],
'errors' => [$this->identifyService->getL10n()->t('Invalid user')],
]));
}
}

private function throwIfNotAuthenticated(): void {
if (!$this->userSession->getUser() instanceof IUser) {
$signRequest = $this->identifyMethodService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
$signRequest = $this->identifyService->getSignRequestMapper()->getById($this->getEntity()->getSignRequestId());
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_REDIRECT,
'errors' => [$this->identifyMethodService->getL10n()->t('You are not logged in. Please log in.')],
'errors' => [$this->identifyService->getL10n()->t('You are not logged in. Please log in.')],
'redirect' => $this->urlGenerator->linkToRoute('core.login.showLoginForm', [
'redirect_url' => $this->urlGenerator->linkToRoute(
'libresign.page.sign',
Expand All @@ -146,7 +146,7 @@ public function getSettings(): array {
}

private function isEnabledByDefault(): bool {
$config = $this->identifyMethodService->getAppConfig()->getAppValue('identify_methods', '[]');
$config = $this->identifyService->getAppConfig()->getAppValue('identify_methods', '[]');
$config = json_decode($config, true);
if (json_last_error() !== JSON_ERROR_NONE || !is_array($config)) {
return true;
Expand Down
Loading

0 comments on commit 8a67a04

Please sign in to comment.