Skip to content

Commit

Permalink
Merge pull request #2817 from LibreSign/backport/2816/stable28
Browse files Browse the repository at this point in the history
[stable28] Chore/split controller
  • Loading branch information
vitormattos authored Apr 19, 2024
2 parents 39fe89a + 524910d commit ed752df
Show file tree
Hide file tree
Showing 23 changed files with 460 additions and 322 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
include(__DIR__ . '/routes/routesPageController.php'),
include(__DIR__ . '/routes/routesRequestSignatureController.php'),
include(__DIR__ . '/routes/routesSettingsController.php'),
include(__DIR__ . '/routes/routesSignatureElementsController.php'),
include(__DIR__ . '/routes/routesSignFileController.php'),
);
6 changes: 0 additions & 6 deletions appinfo/routes/routesAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,5 @@
['name' => 'account#deleteFile', 'url' => '/api/{apiVersion}/account/files', 'verb' => 'DELETE', 'requirements' => $requirements],
['name' => 'account#accountFileListToOwner', 'url' => '/api/{apiVersion}/account/files', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'account#accountFileListToApproval', 'url' => '/api/{apiVersion}/account/files/approval/list', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'account#createSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements', 'verb' => 'POST', 'requirements' => $requirements],
['name' => 'account#getSignatureElements', 'url' => '/api/{apiVersion}/account/signature/elements', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'account#getSignatureElementPreview','url' => '/api/{apiVersion}/account/signature/elements/preview/{nodeId}', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'account#getSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{nodeId}', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'account#patchSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{nodeId}', 'verb' => 'PATCH', 'requirements' => $requirements],
['name' => 'account#deleteSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{nodeId}', 'verb' => 'DELETE', 'requirements' => $requirements],
],
];
16 changes: 16 additions & 0 deletions appinfo/routes/routesSignatureElementsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$requirements = [
'apiVersion' => 'v1',
];

return [
'ocs' => [
['name' => 'SignatureElements#createSignatureElement', 'url' => '/api/{apiVersion}/signature/elements', 'verb' => 'POST', 'requirements' => $requirements],
['name' => 'SignatureElements#getSignatureElements', 'url' => '/api/{apiVersion}/signature/elements', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'SignatureElements#getSignatureElementPreview','url' => '/api/{apiVersion}/signature/elements/preview/{nodeId}', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'SignatureElements#getSignatureElement', 'url' => '/api/{apiVersion}/signature/elements/{nodeId}', 'verb' => 'GET', 'requirements' => $requirements],
['name' => 'SignatureElements#patchSignatureElement', 'url' => '/api/{apiVersion}/signature/elements/{nodeId}', 'verb' => 'PATCH', 'requirements' => $requirements],
['name' => 'SignatureElements#deleteSignatureElement', 'url' => '/api/{apiVersion}/signature/elements/{nodeId}', 'verb' => 'DELETE', 'requirements' => $requirements],
],
];
173 changes: 0 additions & 173 deletions lib/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@
use OCA\Libresign\Service\SignFileService;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\CORS;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\UseSession;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -258,175 +254,6 @@ public function me(): JSONResponse {
);
}

#[NoAdminRequired]
#[NoCSRFRequired]
#[PublicPage]
public function createSignatureElement(array $elements): JSONResponse {
try {
$this->validateHelper->validateVisibleElements($elements, $this->validateHelper::TYPE_VISIBLE_ELEMENT_USER);
$this->accountService->saveVisibleElements(
elements: $elements,
sessionId: $this->sessionService->getSessionId(),
user: $this->userSession->getUser(),
);
} catch (\Throwable $th) {
return new JSONResponse(
[
'message' => $th->getMessage(),
],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
return new JSONResponse(
[
'message' => $this->l10n->n(
'Element created with success',
'Elements created with success',
count($elements)
),
'elements' =>
(
$this->userSession->getUser() instanceof IUser
? $this->signerElementsService->getUserElements($this->userSession->getUser()->getUID())
: $this->signerElementsService->getElementsFromSessionAsArray()
),
],
Http::STATUS_OK
);
}

#[NoAdminRequired]
#[NoCSRFRequired]
#[PublicPage]
public function getSignatureElements(): JSONResponse {
$userId = $this->userSession->getUser()?->getUID();
try {
return new JSONResponse(
[
'elements' =>
(
$userId
? $this->signerElementsService->getUserElements($userId)
: $this->signerElementsService->getElementsFromSessionAsArray()
)
],
Http::STATUS_OK
);
} catch (\Throwable $th) {
return new JSONResponse(
[
'message' => $this->l10n->t('Elements not found')
],
Http::STATUS_NOT_FOUND
);
}
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
public function getSignatureElementPreview(int $nodeId) {
try {
$node = $this->accountService->getFileByNodeIdAndSessionId(
$nodeId,
$this->sessionService->getSessionId()
);
} catch (DoesNotExistException $th) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$preview = $this->preview->getPreview(
file: $node,
width: SignerElementsService::ELEMENT_SIGN_WIDTH,
height: SignerElementsService::ELEMENT_SIGN_HEIGHT,
);
$response = new FileDisplayResponse($preview, Http::STATUS_OK, [
'Content-Type' => $preview->getMimeType(),
]);
return $response;
}

#[NoAdminRequired]
#[NoCSRFRequired]
public function getSignatureElement(int $nodeId): JSONResponse {
$userId = $this->userSession->getUser()->getUID();
try {
return new JSONResponse(
$this->signerElementsService->getUserElementByNodeId($userId, $nodeId),
Http::STATUS_OK
);
} catch (\Throwable $th) {
return new JSONResponse(
[
'message' => $this->l10n->t('Element not found')
],
Http::STATUS_NOT_FOUND
);
}
}

#[NoAdminRequired]
#[NoCSRFRequired]
public function patchSignatureElement($nodeId, string $type = '', array $file = []): JSONResponse {
try {
$element['nodeId'] = $nodeId;
if ($type) {
$element['type'] = $type;
}
if ($file) {
$element['file'] = $file;
}
$this->validateHelper->validateVisibleElement($element, $this->validateHelper::TYPE_VISIBLE_ELEMENT_USER);
$user = $this->userSession->getUser();
if ($user instanceof IUser) {
$userElement = $this->signerElementsService->getUserElementByNodeId(
$user->getUID(),
$nodeId,
);
$element['elementId'] = $userElement['id'];
}
$this->accountService->saveVisibleElement($element, $this->sessionService->getSessionId(), $user);
return new JSONResponse(
[
'message' => $this->l10n->t('Element updated with success')
],
Http::STATUS_OK
);
} catch (\Throwable $th) {
return new JSONResponse(
[
'message' => $th->getMessage()
],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
}

#[NoAdminRequired]
#[NoCSRFRequired]
#[PublicPage]
public function deleteSignatureElement(int $nodeId): JSONResponse {
try {
$this->accountService->deleteSignatureElement(
user: $this->userSession->getUser(),
nodeId: $nodeId,
sessionId: $this->sessionService->getSessionId(),
);
} catch (\Throwable $th) {
return new JSONResponse(
[
'message' => $this->l10n->t('Element not found')
],
Http::STATUS_NOT_FOUND
);
}
return new JSONResponse(
[
'message' => $this->l10n->t('Visible element deleted')
],
Http::STATUS_OK
);
}

#[NoAdminRequired]
#[NoCSRFRequired]
public function accountFileListToOwner(array $filter = [], $page = null, $length = null): JSONResponse {
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public function sign(string $uuid): TemplateResponse {
$this->initialState->provideInitialState('status', $file['status']);
$this->initialState->provideInitialState('statusText', $file['statusText']);
$this->initialState->provideInitialState('signers', $file['signers']);
$this->initialState->provideInitialState('sign_request_uuid', $uuid);
$this->provideSignerSignatues();
$this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH);
$this->initialState->provideInitialState('description', $this->getSignRequestEntity()->getDescription() ?? '');
Expand Down
Loading

0 comments on commit ed752df

Please sign in to comment.