• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 21228190257

21 Jan 2026 10:35PM UTC coverage: 44.731%. First build
21228190257

Pull #6506

github

web-flow
Merge e7f09754b into 35b6315b1
Pull Request #6506: feat: refactor identify account controller

117 of 165 new or added lines in 5 files covered. (70.91%)

7229 of 16161 relevant lines covered (44.73%)

4.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/Controller/IdentifyController.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Controller;
10

11
use OCA\Libresign\AppInfo\Application;
12
use OCA\Libresign\Collaboration\Collaborators\SignerPlugin;
13
use OCA\Libresign\Middleware\Attribute\RequireManager;
14
use OCA\Libresign\ResponseDefinitions;
15
use OCA\Libresign\Service\Identify\ResultEnricher;
16
use OCA\Libresign\Service\Identify\ResultFilter;
17
use OCA\Libresign\Service\Identify\ResultFormatter;
18
use OCA\Libresign\Service\Identify\SearchNormalizer;
19
use OCA\Libresign\Service\IdentifyMethod\Account;
20
use OCA\Libresign\Service\IdentifyMethod\Email;
21
use OCP\AppFramework\Http;
22
use OCP\AppFramework\Http\Attribute\ApiRoute;
23
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
24
use OCP\AppFramework\Http\DataResponse;
25
use OCP\Collaboration\Collaborators\ISearch;
26
use OCP\IRequest;
27
use OCP\Share\IShare;
28

29
/**
30
 * @psalm-import-type LibresignIdentifyAccount from ResponseDefinitions
31
 */
32
class IdentifyController extends AEnvironmentAwareController {
33
        private array $shareTypes = [];
34

35
        public function __construct(
36
                IRequest $request,
37
                private ISearch $collaboratorSearch,
38
                private Email $identifyEmailMethod,
39
                private Account $identifyAccountMethod,
40
                private SearchNormalizer $searchNormalizer,
41
                private ResultFilter $resultFilter,
42
                private ResultFormatter $resultFormatter,
43
                private ResultEnricher $resultEnricher,
44
        ) {
NEW
45
                parent::__construct(Application::APP_ID, $request);
×
46
        }
47

48
        /**
49
         * List possible signers
50
         *
51
         * Used to identify who can sign the document. The return of this endpoint is related with Administration Settiongs > LibreSign > Identify method.
52
         *
53
         * @param string $search search params
54
         * @param string $method filter by method (email, account, sms, signal, telegram, whatsapp, xmpp)
55
         * @param int $page the number of page to return. Default: 1
56
         * @param int $limit Total of elements to return. Default: 25
57
         * @return DataResponse<Http::STATUS_OK, LibresignIdentifyAccount[], array{}>
58
         *
59
         * 200: Certificate saved with success
60
         * 400: No file provided or other problem with provided file
61
         */
62
        #[NoAdminRequired]
63
        #[RequireManager]
64
        #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/identify-account/search', requirements: ['apiVersion' => '(v1)'])]
65
        public function search(string $search = '', string $method = '', int $page = 1, int $limit = 25): DataResponse {
NEW
66
                $search = $this->searchNormalizer->normalize($search, $method);
×
67

68
                // Only search for string larger than a minimum length
NEW
69
                if (strlen($search) < 1) {
×
NEW
70
                        return new DataResponse([]);
×
71
                }
72

NEW
73
                $shareTypes = $this->getShareTypes();
×
NEW
74
                $offset = $limit * ($page - 1);
×
75

NEW
76
                $this->registerPlugin($method);
×
NEW
77
                [$result] = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, $offset);
×
78

79
                // Process results through filters and formatters
NEW
80
                $result['exact'] = $this->resultFilter->unify($result['exact']);
×
NEW
81
                $result = $this->resultFilter->unify($result);
×
NEW
82
                $result = $this->resultFilter->excludeEmpty($result);
×
83

NEW
84
                $return = $this->resultFormatter->formatForNcSelect($result);
×
NEW
85
                $return = $this->resultEnricher->addHerselfAccount($return, $search);
×
NEW
86
                $return = $this->resultEnricher->addHerselfEmail($return, $search);
×
NEW
87
                $return = $this->resultFormatter->replaceShareTypeWithMethod($return);
×
NEW
88
                $return = $this->resultEnricher->addEmailNotificationPreference($return);
×
NEW
89
                $return = $this->resultFilter->excludeNotAllowed($return);
×
90

NEW
91
                return new DataResponse($return);
×
92
        }
93

94
        private function registerPlugin(string $method): void {
NEW
95
                SignerPlugin::setMethod($method);
×
96

NEW
97
                $refObject = new \ReflectionObject($this->collaboratorSearch);
×
NEW
98
                $refProperty = $refObject->getProperty('pluginList');
×
99

NEW
100
                $plugins = $refProperty->getValue($this->collaboratorSearch);
×
NEW
101
                $plugins[SignerPlugin::TYPE_SIGNER] = [SignerPlugin::class];
×
102

NEW
103
                $refProperty->setValue($this->collaboratorSearch, $plugins);
×
104
        }
105

106
        private function getShareTypes(): array {
NEW
107
                if (count($this->shareTypes) > 0) {
×
NEW
108
                        return $this->shareTypes;
×
109
                }
NEW
110
                $settings = $this->identifyEmailMethod->getSettings();
×
NEW
111
                if ($settings['enabled']) {
×
NEW
112
                        $this->shareTypes[] = IShare::TYPE_EMAIL;
×
113
                }
NEW
114
                $settings = $this->identifyAccountMethod->getSettings();
×
NEW
115
                if ($settings['enabled']) {
×
NEW
116
                        $this->shareTypes[] = IShare::TYPE_USER;
×
117
                }
118

NEW
119
                $this->shareTypes[] = SignerPlugin::TYPE_SIGNER;
×
NEW
120
                return $this->shareTypes;
×
121
        }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc