Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 0 additions & 126 deletions lib/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use Psr\Log\LoggerInterface;

/**
* @psalm-import-type LibresignAccountFile from ResponseDefinitions
* @psalm-import-type LibresignCertificatePfxData from ResponseDefinitions
* @psalm-import-type LibresignFile from ResponseDefinitions
* @psalm-import-type LibresignPagination from ResponseDefinitions
Expand Down Expand Up @@ -187,73 +186,6 @@ public function signatureGenerate(
}
}

/**
* Add files to account profile
*
* @param LibresignAccountFile[] $files The list of files to add to profile
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{file: ?int, type: 'info'|'warning'|'danger', message: string}, array{}>
*
* 200: Certificate saved with success
* 401: No file provided or other problem with provided file
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])]
public function addFiles(array $files): DataResponse {
try {
$this->accountService->addFilesToAccount($files, $this->userSession->getUser());
return new DataResponse([], Http::STATUS_OK);
} catch (\Exception $exception) {
$exceptionData = json_decode($exception->getMessage());
if (isset($exceptionData->file)) {
$message = [
'file' => $exceptionData->file,
'type' => $exceptionData->type,
'message' => $exceptionData->message
];
} else {
$message = [
'file' => null,
'type' => null,
'message' => $exception->getMessage()
];
}
return new DataResponse(
$message,
Http::STATUS_UNAUTHORIZED
);
}
}

/**
* Delete file from account
*
* @param int $nodeId the nodeId of file to be delete
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{messages: string[]}, array{}>
*
* 200: File deleted with success
* 401: Failure to delete file from account
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])]
public function deleteFile(int $nodeId): DataResponse {
try {
$this->accountService->deleteFileFromAccount($nodeId, $this->userSession->getUser());
return new DataResponse([], Http::STATUS_OK);
} catch (\Exception $exception) {
return new DataResponse(
[
'messages' => [
$exception->getMessage(),
],
],
Http::STATUS_UNAUTHORIZED,
);
}
}

/**
* Who am I
*
Expand Down Expand Up @@ -293,64 +225,6 @@ public function me(): DataResponse {
);
}

/**
* List account files of authenticated account
*
* @param array{approved?: 'yes'}|null $filter Filter params
* @param int|null $page the number of page to return
* @param int|null $length Total of elements to return
* @return DataResponse<Http::STATUS_OK, array{pagination: LibresignPagination, data: LibresignFile[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Certificate saved with success
* 404: No file provided or other problem with provided file
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])]
public function accountFileListToOwner(array $filter = [], ?int $page = null, ?int $length = null): DataResponse {
try {
$filter['userId'] = $this->userSession->getUser()->getUID();
$return = $this->accountFileService->accountFileList($filter, $page, $length);
return new DataResponse($return, Http::STATUS_OK);
} catch (\Throwable $th) {
return new DataResponse(
[
'message' => $th->getMessage()
],
Http::STATUS_NOT_FOUND
);
}
}

/**
* List account files that need to be approved
*
* @param array{approved?: 'yes'}|null $filter Filter params
* @param int|null $page the number of page to return
* @param int|null $length Total of elements to return
* @return DataResponse<Http::STATUS_OK, array{pagination: LibresignPagination, data: ?LibresignFile[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: OK
* 404: Account not found
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/account/files/approval/list', requirements: ['apiVersion' => '(v1)'])]
public function accountFileListToApproval(array $filter = [], ?int $page = null, ?int $length = null): DataResponse {
try {
$this->validateHelper->userCanApproveValidationDocuments($this->userSession->getUser());
$return = $this->accountFileService->accountFileList($filter, $page, $length);
return new DataResponse($return, Http::STATUS_OK);
} catch (\Throwable $th) {
return new DataResponse(
[
'message' => $th->getMessage()
],
Http::STATUS_NOT_FOUND
);
}
}

/**
* Update the account phone number
*
Expand Down
191 changes: 191 additions & 0 deletions lib/Controller/IdDocsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Libresign\Controller;

use Exception;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Helper\ValidateHelper;
use OCA\Libresign\Middleware\Attribute\RequireSignRequestUuid;
use OCA\Libresign\ResponseDefinitions;
use OCA\Libresign\Service\AccountFileService;
use OCA\Libresign\Service\IdDocsService;
use OCA\Libresign\Service\SignFileService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
use OCP\AppFramework\Http\Attribute\ApiRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;

/**
* @psalm-import-type LibresignIdDocs from ResponseDefinitions
*/
class IdDocsController extends AEnvironmentAwareController implements ISignatureUuid {
use LibresignTrait;
public function __construct(
IRequest $request,
protected SignFileService $signFileService,
protected IL10N $l10n,
protected IdDocsService $idDocsService,
protected AccountFileService $accountFileService,
protected IUserSession $userSession,
protected ValidateHelper $validateHelper,
protected LoggerInterface $logger,
) {
parent::__construct(Application::APP_ID, $request);
}

/**
* Add files to account profile
*
* @param LibresignIdDocs[] $files The list of files to add to profile
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{file: ?int, type: 'info'|'warning'|'danger', message: string}, array{}>
*
* 200: Certificate saved with success
* 401: No file provided or other problem with provided file
*/
#[PublicPage]
#[AnonRateLimit(limit: 30, period: 60)]
#[NoAdminRequired]
#[NoCSRFRequired]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])]
public function addFiles(array $files): DataResponse {
try {
if ($user = $this->userSession->getUser()) {
$this->idDocsService->addFilesToAccount($files, $user);
} elseif ($signRequest = $this->getSignRequestEntity()) {
$this->idDocsService->addFilesToDocumentFolder($files, $signRequest);
} else {
throw new Exception('Invalid data');
}
return new DataResponse([], Http::STATUS_OK);
} catch (\Exception $exception) {
$exceptionData = json_decode($exception->getMessage());
if (isset($exceptionData->file)) {
$message = [
'file' => $exceptionData->file,
'type' => $exceptionData->type,
'message' => $exceptionData->message
];
} else {
$message = [
'file' => null,
'type' => null,
'message' => $exception->getMessage()
];
}
return new DataResponse(
$message,
Http::STATUS_UNAUTHORIZED
);
}
}

/**
* Delete file from account
*
* @param int $nodeId the nodeId of file to be delete
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{messages: string[]}, array{}>
*
* 200: File deleted with success
* 401: Failure to delete file from account
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])]
public function deleteFile(int $nodeId): DataResponse {
try {
$this->idDocsService->deleteFileFromAccount($nodeId, $this->userSession->getUser());
return new DataResponse([], Http::STATUS_OK);
} catch (\Exception $exception) {
return new DataResponse(
[
'messages' => [
$exception->getMessage(),
],
],
Http::STATUS_UNAUTHORIZED,
);
}
}

/**
* List files of unauthenticated account
*
* @param array{approved?: 'yes'}|null $filter Filter params
* @param int|null $page the number of page to return
* @param int|null $length Total of elements to return
* @return DataResponse<Http::STATUS_OK, array{pagination: LibresignPagination, data: LibresignFile[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>

Check failure on line 131 in lib/Controller/IdDocsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedDocblockClass

lib/Controller/IdDocsController.php:131:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Libresign\Controller\LibresignPagination does not exist (see https://psalm.dev/200)

Check failure on line 131 in lib/Controller/IdDocsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedDocblockClass

lib/Controller/IdDocsController.php:131:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Libresign\Controller\LibresignFile does not exist (see https://psalm.dev/200)
*
* 200: Certificate saved with success
* 404: No file provided or other problem with provided file
*/
#[PublicPage]
#[AnonRateLimit(limit: 30, period: 60)]
#[NoCSRFRequired]
#[RequireSignRequestUuid(skipIfAuthenticated: true)]
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])]
public function listOfUnauthenticatedSigner(array $filter = [], ?int $page = null, ?int $length = null): DataResponse {
try {
if ($user = $this->userSession->getUser()) {
$filter['userId'] = $user->getUID();
} elseif ($signRequest = $this->getSignRequestEntity()) {
$filter['singRequestId'] = $signRequest->getId();
} else {
throw new Exception('Invalid data');
}

$return = $this->idDocsService->list($filter, $page, $length);
return new DataResponse($return, Http::STATUS_OK);
} catch (\Throwable $th) {
return new DataResponse(
[
'message' => $th->getMessage()
],
Http::STATUS_NOT_FOUND
);
}
}

/**
* List files that need to be approved
*
* @param array{approved?: 'yes'}|null $filter Filter params
* @param int|null $page the number of page to return
* @param int|null $length Total of elements to return
* @return DataResponse<Http::STATUS_OK, array{pagination: LibresignPagination, data: ?LibresignFile[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>

Check failure on line 169 in lib/Controller/IdDocsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedDocblockClass

lib/Controller/IdDocsController.php:169:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Libresign\Controller\LibresignPagination does not exist (see https://psalm.dev/200)

Check failure on line 169 in lib/Controller/IdDocsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedDocblockClass

lib/Controller/IdDocsController.php:169:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCA\Libresign\Controller\LibresignFile does not exist (see https://psalm.dev/200)
*
* 200: OK
* 404: Account not found
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/id-docs/approval/list', requirements: ['apiVersion' => '(v1)'])]
public function listToApproval(array $filter = [], ?int $page = null, ?int $length = null): DataResponse {
try {
$this->validateHelper->userCanApproveValidationDocuments($this->userSession->getUser());
$return = $this->accountFileService->accountFileList($filter, $page, $length);
return new DataResponse($return, Http::STATUS_OK);
} catch (\Throwable $th) {
return new DataResponse(
[
'message' => $th->getMessage()
],
Http::STATUS_NOT_FOUND
);
}
}
}
7 changes: 7 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,18 @@ public function sign(string $uuid): TemplateResponse {
->setFile($this->getFileEntity())
->setHost($this->request->getServerHost())
->setMe($this->userSession->getUser())
->setSignerIdentified()
->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
->setSignRequest($this->getSignRequestEntity())
->showVisibleElements()
->showSigners()
->showSettings()
->toArray();
$this->initialState->provideInitialState('config', [
'identificationDocumentsFlow' => $file['settings']['needIdentificationDocuments'] ?? false,
]);
$this->initialState->provideInitialState('needIdentificationDocuments', $file['settings']['needIdentificationDocuments'] ?? false);
$this->initialState->provideInitialState('identificationDocumentsWaitingApproval', $file['settings']['identificationDocumentsWaitingApproval'] ?? false);
$this->initialState->provideInitialState('status', $file['status']);
$this->initialState->provideInitialState('statusText', $file['statusText']);
$this->initialState->provideInitialState('signers', $file['signers']);
Expand Down
Loading
Loading