Skip to content

Commit 6792071

Browse files
authored
Merge pull request #5937 from LibreSign/backport/4464/stable31
[stable31] refactor: attach document
2 parents f5f2c37 + 183b890 commit 6792071

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5305
-4024
lines changed

lib/Controller/AccountController.php

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
use OC\Authentication\Login\Chain;
1313
use OC\Authentication\Login\LoginData;
1414
use OCA\Libresign\AppInfo\Application;
15-
use OCA\Libresign\Db\AccountFileMapper;
1615
use OCA\Libresign\Exception\LibresignException;
1716
use OCA\Libresign\Handler\SignEngine\Pkcs12Handler;
1817
use OCA\Libresign\Helper\JSActions;
1918
use OCA\Libresign\Helper\ValidateHelper;
2019
use OCA\Libresign\ResponseDefinitions;
21-
use OCA\Libresign\Service\AccountFileService;
2220
use OCA\Libresign\Service\AccountService;
2321
use OCA\Libresign\Service\SessionService;
2422
use OCA\Libresign\Service\SignerElementsService;
@@ -40,7 +38,6 @@
4038
use Psr\Log\LoggerInterface;
4139

4240
/**
43-
* @psalm-import-type LibresignAccountFile from ResponseDefinitions
4441
* @psalm-import-type LibresignCertificatePfxData from ResponseDefinitions
4542
* @psalm-import-type LibresignFile from ResponseDefinitions
4643
* @psalm-import-type LibresignPagination from ResponseDefinitions
@@ -52,8 +49,6 @@ public function __construct(
5249
protected IL10N $l10n,
5350
private IAccountManager $accountManager,
5451
private AccountService $accountService,
55-
private AccountFileService $accountFileService,
56-
private AccountFileMapper $accountFileMapper,
5752
protected SignFileService $signFileService,
5853
private SignerElementsService $signerElementsService,
5954
private Pkcs12Handler $pkcs12Handler,
@@ -187,73 +182,6 @@ public function signatureGenerate(
187182
}
188183
}
189184

190-
/**
191-
* Add files to account profile
192-
*
193-
* @param LibresignAccountFile[] $files The list of files to add to profile
194-
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{file: ?int, type: 'info'|'warning'|'danger', message: string}, array{}>
195-
*
196-
* 200: Certificate saved with success
197-
* 401: No file provided or other problem with provided file
198-
*/
199-
#[NoAdminRequired]
200-
#[NoCSRFRequired]
201-
#[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])]
202-
public function addFiles(array $files): DataResponse {
203-
try {
204-
$this->accountService->addFilesToAccount($files, $this->userSession->getUser());
205-
return new DataResponse([], Http::STATUS_OK);
206-
} catch (\Exception $exception) {
207-
$exceptionData = json_decode($exception->getMessage());
208-
if (isset($exceptionData->file)) {
209-
$message = [
210-
'file' => $exceptionData->file,
211-
'type' => $exceptionData->type,
212-
'message' => $exceptionData->message
213-
];
214-
} else {
215-
$message = [
216-
'file' => null,
217-
'type' => null,
218-
'message' => $exception->getMessage()
219-
];
220-
}
221-
return new DataResponse(
222-
$message,
223-
Http::STATUS_UNAUTHORIZED
224-
);
225-
}
226-
}
227-
228-
/**
229-
* Delete file from account
230-
*
231-
* @param int $nodeId the nodeId of file to be delete
232-
*
233-
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{messages: string[]}, array{}>
234-
*
235-
* 200: File deleted with success
236-
* 401: Failure to delete file from account
237-
*/
238-
#[NoAdminRequired]
239-
#[NoCSRFRequired]
240-
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])]
241-
public function deleteFile(int $nodeId): DataResponse {
242-
try {
243-
$this->accountService->deleteFileFromAccount($nodeId, $this->userSession->getUser());
244-
return new DataResponse([], Http::STATUS_OK);
245-
} catch (\Exception $exception) {
246-
return new DataResponse(
247-
[
248-
'messages' => [
249-
$exception->getMessage(),
250-
],
251-
],
252-
Http::STATUS_UNAUTHORIZED,
253-
);
254-
}
255-
}
256-
257185
/**
258186
* Who am I
259187
*
@@ -293,64 +221,6 @@ public function me(): DataResponse {
293221
);
294222
}
295223

296-
/**
297-
* List account files of authenticated account
298-
*
299-
* @param array{approved?: 'yes'}|null $filter Filter params
300-
* @param int|null $page the number of page to return
301-
* @param int|null $length Total of elements to return
302-
* @return DataResponse<Http::STATUS_OK, array{pagination: LibresignPagination, data: LibresignFile[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>
303-
*
304-
* 200: Certificate saved with success
305-
* 404: No file provided or other problem with provided file
306-
*/
307-
#[NoAdminRequired]
308-
#[NoCSRFRequired]
309-
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])]
310-
public function accountFileListToOwner(array $filter = [], ?int $page = null, ?int $length = null): DataResponse {
311-
try {
312-
$filter['userId'] = $this->userSession->getUser()->getUID();
313-
$return = $this->accountFileService->accountFileList($filter, $page, $length);
314-
return new DataResponse($return, Http::STATUS_OK);
315-
} catch (\Throwable $th) {
316-
return new DataResponse(
317-
[
318-
'message' => $th->getMessage()
319-
],
320-
Http::STATUS_NOT_FOUND
321-
);
322-
}
323-
}
324-
325-
/**
326-
* List account files that need to be approved
327-
*
328-
* @param array{approved?: 'yes'}|null $filter Filter params
329-
* @param int|null $page the number of page to return
330-
* @param int|null $length Total of elements to return
331-
* @return DataResponse<Http::STATUS_OK, array{pagination: LibresignPagination, data: ?LibresignFile[]}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>
332-
*
333-
* 200: OK
334-
* 404: Account not found
335-
*/
336-
#[NoAdminRequired]
337-
#[NoCSRFRequired]
338-
#[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/account/files/approval/list', requirements: ['apiVersion' => '(v1)'])]
339-
public function accountFileListToApproval(array $filter = [], ?int $page = null, ?int $length = null): DataResponse {
340-
try {
341-
$this->validateHelper->userCanApproveValidationDocuments($this->userSession->getUser());
342-
$return = $this->accountFileService->accountFileList($filter, $page, $length);
343-
return new DataResponse($return, Http::STATUS_OK);
344-
} catch (\Throwable $th) {
345-
return new DataResponse(
346-
[
347-
'message' => $th->getMessage()
348-
],
349-
Http::STATUS_NOT_FOUND
350-
);
351-
}
352-
}
353-
354224
/**
355225
* Update the account phone number
356226
*

lib/Controller/FileController.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private function validate(?string $type = null, $identifier = null): DataRespons
233233
}
234234

235235
/**
236-
* List account files that need to be approved
236+
* List identification documents that need to be approved
237237
*
238238
* @param string|null $signer_uuid Signer UUID
239239
* @param string|null $nodeId The nodeId (also called fileId). Is the id of a file at Nextcloud
@@ -273,9 +273,24 @@ public function list(
273273
'sortBy' => $sortBy,
274274
'sortDirection' => $sortDirection,
275275
];
276-
$return = $this->fileService
277-
->setMe($this->userSession->getUser())
278-
->listAssociatedFilesOfSignFlow($page, $length, $filter, $sort);
276+
277+
$user = $this->userSession->getUser();
278+
$this->fileService->setMe($user);
279+
$return = $this->fileService->listAssociatedFilesOfSignFlow($page, $length, $filter, $sort);
280+
281+
if ($user && !empty($return['data'])) {
282+
$firstFile = $return['data'][0];
283+
$fileSettings = $this->fileService
284+
->setFileByType('FileId', $firstFile['nodeId'])
285+
->showSettings()
286+
->toArray();
287+
288+
$return['settings'] = [
289+
'needIdentificationDocuments' => $fileSettings['settings']['needIdentificationDocuments'] ?? false,
290+
'identificationDocumentsWaitingApproval' => $fileSettings['settings']['identificationDocumentsWaitingApproval'] ?? false,
291+
];
292+
}
293+
279294
return new DataResponse($return, Http::STATUS_OK);
280295
}
281296

0 commit comments

Comments
 (0)