Skip to content

Commit

Permalink
Move method from SignFileService to IdentifyMethodService
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Apr 18, 2023
1 parent cdf0686 commit 7f7e65d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
15 changes: 15 additions & 0 deletions lib/Service/IdentifyMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@

namespace OCA\Libresign\Service;

use OCA\Libresign\AppInfo\Application;
use OCP\IConfig;

class IdentifyMethodService {
public const IDENTIFTY_NEXTCLOUD = 'nextcloud';
public const IDENTIFY_TOKEN = 'token';
public const IDENTIFY_METHODS = [
self::IDENTIFTY_NEXTCLOUD,
self::IDENTIFY_TOKEN,
];

public function __construct(
private IConfig $config
) {
}

public function getUserIdentifyMethod(array $user): string {
if (array_key_exists('identifyMethod', $user)) {
return $user['identifyMethod'];
}
return $this->config->getAppValue(Application::APP_ID, 'identify_method', 'nextcloud') ?? 'nextcloud';
}
}
15 changes: 6 additions & 9 deletions lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class SignFileService {
private $urlGenerator;
/** @var SignMethodService */
private $signMethod;
/** @var IdentifyMethodService */
private $identifyMethod;
/** @var IMimeTypeDetector */
private $mimeTypeDetector;
/** @var PdfParserService */
Expand Down Expand Up @@ -114,6 +116,7 @@ public function __construct(
IEventDispatcher $eventDispatcher,
IURLGenerator $urlGenerator,
SignMethodService $signMethod,
IdentifyMethodService $identifyMethod,
PdfParserService $pdfParserService,
IMimeTypeDetector $mimeTypeDetector,
ITempManager $tempManager
Expand All @@ -138,6 +141,7 @@ public function __construct(
$this->eventDispatcher = $eventDispatcher;
$this->urlGenerator = $urlGenerator;
$this->signMethod = $signMethod;
$this->identifyMethod = $identifyMethod;
$this->pdfParserService = $pdfParserService;
$this->mimeTypeDetector = $mimeTypeDetector;
$this->tempManager = $tempManager;
Expand Down Expand Up @@ -257,13 +261,6 @@ private function associateToUsers(array $data, int $fileId): array {
return $return;
}

public function getUserIdentifyMethod(array $user): string {
if (array_key_exists('identifyMethod', $user)) {
return $user['identifyMethod'];
}
return $this->config->getAppValue(Application::APP_ID, 'identify_method', 'nextcloud') ?? 'nextcloud';
}

/**
* @psalm-suppress MixedReturnStatement
*/
Expand All @@ -284,7 +281,7 @@ private function setDataToUser(FileUserEntity $fileUser, array $user, int $fileI
if (!$fileUser->getUuid()) {
$fileUser->setUuid(UUIDUtil::getUUID());
}
$identifyMethod = $this->getUserIdentifyMethod($user);
$identifyMethod = $this->identifyMethod->getUserIdentifyMethod($user);
$fileUser->setIdentifyMethod($identifyMethod);
$signMethod = $this->signMethod->getUserSignMethod($user);
$fileUser->setSignMethod($signMethod);
Expand Down Expand Up @@ -359,7 +356,7 @@ public function validateUsers(array $data): void {
$emails = [];
foreach ($data['users'] as $index => $user) {
$this->validateHelper->haveValidMail($user);
$identifyMethod = $this->getUserIdentifyMethod($user);
$identifyMethod = $this->identifyMethod->getUserIdentifyMethod($user);
$this->validateHelper->validateIdentifyMethod($identifyMethod);
$signMethod = $this->signMethod->getUserSignMethod($user);
$this->validateHelper->validateSignMethod($signMethod);
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Service/SignFileServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Libresign\Helper\ValidateHelper;
use OCA\Libresign\Service\FileElementService;
use OCA\Libresign\Service\FolderService;
use OCA\Libresign\Service\IdentifyMethodService;
use OCA\Libresign\Service\MailService;
use OCA\Libresign\Service\PdfParserService;
use OCA\Libresign\Service\SignFileService;
Expand Down Expand Up @@ -75,6 +76,8 @@ final class SignFileServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private $urlGenerator;
/** @var SignMethodService|MockObject */
private $signMethod;
/** @var IdentifyMethodService|MockObject */
private $identifyMethod;
/** @var PdfParserService */
private $pdfParserService;
/** @var IMimeTypeDetector|MockObject */
Expand Down Expand Up @@ -108,6 +111,7 @@ public function setUp(): void {
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->signMethod = $this->createMock(SignMethodService::class);
$this->identifyMethod = $this->createMock(IdentifyMethodService::class);
$this->pdfParserService = $this->createMock(PdfParserService::class);
$this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class);
$this->tempManager = $this->createMock(ITempManager::class);
Expand Down Expand Up @@ -135,6 +139,7 @@ private function getService(): SignFileService {
$this->eventDispatcher,
$this->urlGenerator,
$this->signMethod,
$this->identifyMethod,
$this->pdfParserService,
$this->mimeTypeDetector,
$this->tempManager
Expand Down

0 comments on commit 7f7e65d

Please sign in to comment.