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

LibreSign / libresign / 20285715849

16 Dec 2025 11:07PM UTC coverage: 43.714%. First build
20285715849

Pull #6216

github

web-flow
Merge 8f71e6c0c into db13f2cda
Pull Request #6216: feat: custom message for signers

6 of 69 new or added lines in 8 files covered. (8.7%)

5921 of 13545 relevant lines covered (43.71%)

5.1 hits per line

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

16.47
/lib/Db/IdentifyMethodMapper.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\Db;
10

11
use OCP\AppFramework\Db\QBMapper;
12
use OCP\Comments\ICommentsManager;
13
use OCP\DB\QueryBuilder\IQueryBuilder;
14
use OCP\IDBConnection;
15

16
/**
17
 * @template-extends QBMapper<IdentifyMethod>
18
 */
19
class IdentifyMethodMapper extends QBMapper {
20
        /**
21
         * @var IdentifyMethod[][]
22
         */
23
        private array $methodsBySignRequest = [];
24
        public function __construct(IDBConnection $db) {
25
                parent::__construct($db, 'libresign_identify_method');
47✔
26
        }
27

28
        /**
29
         * @return IdentifyMethod[]
30
         */
31
        public function getIdentifyMethodsFromSignRequestId(int $signRequestId): array {
32
                if (!empty($this->methodsBySignRequest[$signRequestId])) {
13✔
33
                        return $this->methodsBySignRequest[$signRequestId];
5✔
34
                }
35
                $qb = $this->db->getQueryBuilder();
13✔
36
                $qb->select('im.*')
13✔
37
                        ->from('libresign_identify_method', 'im')
13✔
38
                        ->where(
13✔
39
                                $qb->expr()->eq('im.sign_request_id', $qb->createNamedParameter($signRequestId, IQueryBuilder::PARAM_INT))
13✔
40
                        );
13✔
41
                $cursor = $qb->executeQuery();
13✔
42
                $this->methodsBySignRequest[$signRequestId] = [];
13✔
43
                while ($row = $cursor->fetch()) {
13✔
44
                        /** @var IdentifyMethod */
45
                        $this->methodsBySignRequest[$signRequestId][] = $this->mapRowToEntity($row);
10✔
46
                }
47
                return $this->methodsBySignRequest[$signRequestId];
13✔
48
        }
49

50
        public function neutralizeDeletedUser(string $userId, string $displayName): void {
51
                $update = $this->db->getQueryBuilder();
×
52
                $qb = $this->db->getQueryBuilder();
×
53
                $qb->select('im.id')
×
54
                        ->addSelect('im.metadata')
×
55
                        ->from('libresign_identify_method', 'im')
×
56
                        ->where($qb->expr()->in('im.identifier_key', $qb->createNamedParameter(['account', 'email'], IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR_ARRAY))
×
57
                        ->andWhere($qb->expr()->eq('im.identifier_value', $qb->createNamedParameter($userId)));
×
58
                $cursor = $qb->executeQuery();
×
59
                while ($row = $cursor->fetch()) {
×
60
                        if (is_string($row['metadata']) && !empty($row['metadata'])) {
×
61
                                $row['metadata'] = json_decode($row['metadata'], true);
×
62
                        } else {
63
                                $row['metadata'] = [];
×
64
                        }
65
                        $row['metadata']['deleted_account'] = [
×
66
                                'account' => $userId,
×
67
                                'display_name' => $displayName,
×
68
                        ];
×
69
                        $update->update('libresign_identify_method')
×
70
                                ->set('identifier_value', $update->createNamedParameter(ICommentsManager::DELETED_USER))
×
71
                                ->set('metadata', $update->createNamedParameter($row['metadata'], IQueryBuilder::PARAM_JSON))
×
72
                                ->where($update->expr()->eq('id', $update->createNamedParameter($row['id'])));
×
73
                        $update->executeStatement();
×
74
                }
75
        }
76

77
        /**
78
         * @return array<string, string>[]
79
         */
80
        public function searchByIdentifierValue(string $search, string $userId, string $method, int $limit = 20, int $offset = 0): array {
81
                $qb = $this->db->getQueryBuilder();
×
82

83
                $latestQb = $this->db->getQueryBuilder();
×
84
                $latestQb->select('im2.identifier_key')
×
85
                        ->addSelect('im2.identifier_value')
×
86
                        ->addSelect($latestQb->func()->max('sr2.created_at', 'created_at'))
×
87
                        ->from('libresign_identify_method', 'im2')
×
88
                        ->join('im2', 'libresign_sign_request', 'sr2',
×
89
                                $latestQb->expr()->eq('sr2.id', 'im2.sign_request_id')
×
90
                        )
×
91
                        ->join('im2', 'libresign_file', 'f2',
×
92
                                $latestQb->expr()->eq('f2.id', 'sr2.file_id')
×
93
                        )
×
94
                        ->where($latestQb->expr()->eq('f2.user_id', $latestQb->createNamedParameter($userId)));
×
95
                if (!empty($method)) {
×
96
                        $latestQb->andWhere($latestQb->expr()->eq('im2.identifier_key', $latestQb->createNamedParameter($method)));
×
97
                }
98
                $latestQb->andWhere(
×
99
                        $latestQb->expr()->orX(
×
100
                                $latestQb->expr()->iLike(
×
101
                                        'im2.identifier_value',
×
102
                                        $latestQb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')
×
103
                                ),
×
104
                                $latestQb->expr()->iLike(
×
105
                                        'sr2.display_name',
×
106
                                        $latestQb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')
×
107
                                )
×
108
                        )
×
109
                )
×
110
                        ->groupBy('im2.identifier_key')
×
111
                        ->addGroupBy('im2.identifier_value');
×
112

113
                foreach ($latestQb->getParameters() as $name => $value) {
×
114
                        $qb->setParameter($name, $value);
×
115
                }
116

117
                $qb->select('im.identifier_key', 'im.identifier_value', 'sr.display_name')
×
118
                        ->from('libresign_identify_method', 'im')
×
119
                        ->join('im', $qb->createFunction('(' . $latestQb->getSQL() . ')'), 'latest',
×
120
                                $qb->expr()->andX(
×
121
                                        $qb->expr()->eq('latest.identifier_key', 'im.identifier_key'),
×
122
                                        $qb->expr()->eq('latest.identifier_value', 'im.identifier_value')
×
123
                                )
×
124
                        )
×
125
                        ->join('im', 'libresign_sign_request', 'sr',
×
126
                                $qb->expr()->eq('sr.id', 'im.sign_request_id'),
×
127
                        )
×
NEW
128
                        ->where($qb->expr()->neq('im.identifier_value', $qb->createNamedParameter('deleted_users')))
×
129
                        ->setMaxResults($limit)
×
130
                        ->setFirstResult($offset);
×
131

132
                $cursor = $qb->executeQuery();
×
133
                $return = [];
×
134
                while ($row = $cursor->fetch()) {
×
135
                        $return[] = $row;
×
136
                }
137
                return $return;
×
138
        }
139
}
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