Skip to content

Commit c8c593f

Browse files
committed
chore: replace shareType by method
At context of LibreSign search, the field shareType need to be the sign method. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 73814be commit c8c593f

4 files changed

Lines changed: 43 additions & 15 deletions

File tree

lib/Collaboration/Collaborators/SignerPlugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
6666
$result['exact'][] = [
6767
'label' => $search,
6868
'shareWithDisplayNameUnique' => $search,
69-
'key' => self::$method,
69+
'method' => self::$method,
7070
'value' => [
7171
'shareWith' => $search,
7272
'shareType' => self::TYPE_SIGNER,
@@ -88,7 +88,7 @@ private function rowToSearchResultItem(array $row): array {
8888
$item = [
8989
'label' => $row['display_name'],
9090
'shareWithDisplayNameUnique' => $row['identifier_value'],
91-
'key' => $row['identifier_key'],
91+
'method' => $row['identifier_key'],
9292
'value' => [
9393
'shareWith' => $row['identifier_value'],
9494
'shareType' => self::TYPE_SIGNER,

lib/Controller/IdentifyAccountController.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function search(string $search = '', string $method = '', int $page = 1,
7575
$return = $this->formatForNcSelect($result);
7676
$return = $this->addHerselfAccount($return, $search);
7777
$return = $this->addHerselfEmail($return, $search);
78+
$return = $this->replaceShareTypeByMethod($return);
7879
$return = $this->excludeNotAllowed($return);
7980

8081
return new DataResponse($return);
@@ -130,7 +131,9 @@ private function formatForNcSelect(array $list): array {
130131
foreach ($list as $key => $item) {
131132
$return[$key] = [
132133
'id' => $item['value']['shareWith'],
133-
'isNoUser' => $item['value']['shareType'] !== IShare::TYPE_USER,
134+
'isNoUser' => $item['value']['shareType'] !== IShare::TYPE_USER
135+
&& isset($item['method'])
136+
&& $item['method'] !== 'account',
134137
'displayName' => $item['label'],
135138
'subname' => $item['shareWithDisplayNameUnique'] ?? '',
136139
];
@@ -141,7 +144,13 @@ private function formatForNcSelect(array $list): array {
141144
$return[$key]['method'] = 'account';
142145
$return[$key]['icon'] = 'icon-user';
143146
} elseif ($item['value']['shareType'] === SignerPlugin::TYPE_SIGNER) {
144-
$return[$key]['method'] = $item['key'];
147+
if (
148+
!isset($return[$key]['method'])
149+
&& empty($return[$key]['method'])
150+
&& !empty($item['key'])
151+
) {
152+
$return[$key]['method'] = $item['key'];
153+
}
145154
if ($item['key'] === 'email') {
146155
$return[$key]['icon'] = 'icon-mail';
147156
} elseif ($item['key'] === 'account') {
@@ -177,7 +186,7 @@ private function addHerselfAccount(array $return, string $search): array {
177186
'displayName' => $user->getDisplayName(),
178187
'subname' => $user->getEMailAddress(),
179188
'icon' => 'icon-user',
180-
'shareType' => IShare::TYPE_USER,
189+
'method' => 'account',
181190
];
182191
return $return;
183192
}
@@ -206,7 +215,7 @@ private function addHerselfEmail(array $return, string $search): array {
206215
'displayName' => $user->getDisplayName(),
207216
'subname' => $user->getEMailAddress(),
208217
'icon' => 'icon-mail',
209-
'shareType' => IShare::TYPE_EMAIL,
218+
'method' => 'email',
210219
];
211220
return $return;
212221
}
@@ -219,4 +228,19 @@ private function excludeNotAllowed(array $list): array {
219228
$shareTypes = $this->getShareTypes();
220229
return array_filter($list, fn ($result) => in_array($result['shareType'], $shareTypes));
221230
}
231+
232+
private function replaceShareTypeByMethod(array $list): array {
233+
foreach ($list as $key => $item) {
234+
if (!empty($item['method'])) {
235+
continue;
236+
}
237+
match ($item['shareType']) {
238+
IShare::TYPE_EMAIL => $item['method'] = 'email',
239+
IShare::TYPE_USER => $item['method'] = 'account',
240+
default => $item['method'] = '',
241+
};
242+
unset($list[$key]['shareType']);
243+
}
244+
return $list;
245+
}
222246
}

tests/integration/features/identify-account/search.feature

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Feature: search
1313
| (jq).ocs.data[0].displayName | search-signer1-displayname |
1414
| (jq).ocs.data[0].subname | search-signer1 |
1515
| (jq).ocs.data[0].icon | icon-user |
16-
| (jq).ocs.data[0].shareType | 0 |
16+
| (jq).ocs.data[0].method | account |
1717

1818
Scenario: Search account by multiple users
1919
Given as user "admin"
@@ -29,13 +29,13 @@ Feature: search
2929
| (jq).ocs.data[0].displayName | search-signer1-displayname |
3030
| (jq).ocs.data[0].subname | search-signer1 |
3131
| (jq).ocs.data[0].icon | icon-user |
32-
| (jq).ocs.data[0].shareType | 0 |
32+
| (jq).ocs.data[0].method | account |
3333
| (jq).ocs.data[1].id | search-signer2 |
3434
| (jq).ocs.data[1].isNoUser | false |
3535
| (jq).ocs.data[1].displayName | search-signer2-displayname |
3636
| (jq).ocs.data[1].subname | search-signer2 |
3737
| (jq).ocs.data[1].icon | icon-user |
38-
| (jq).ocs.data[1].shareType | 0 |
38+
| (jq).ocs.data[1].method | account |
3939

4040

4141
Scenario: Search account by herself with partial name search
@@ -55,7 +55,7 @@ Feature: search
5555
| (jq).ocs.data[0].displayName | can-find-myself-displayname |
5656
| (jq).ocs.data[0].subname | my@email.tld |
5757
| (jq).ocs.data[0].icon | icon-user |
58-
| (jq).ocs.data[0].shareType | 0 |
58+
| (jq).ocs.data[0].method | account |
5959

6060
Scenario: Search account by herself without permission to identify by account
6161
Given as user "admin"
@@ -88,7 +88,7 @@ Feature: search
8888
| (jq).ocs.data[0].displayName | admin |
8989
| (jq).ocs.data[0].subname | admin@email.tld |
9090
| (jq).ocs.data[0].icon | icon-user |
91-
| (jq).ocs.data[0].shareType | 0 |
91+
| (jq).ocs.data[0].method | account |
9292

9393
Scenario: Search account by herself without permission to identify by email
9494
Given as user "admin"
@@ -99,9 +99,8 @@ Feature: search
9999
When sending "get" to ocs "/apps/libresign/api/v1/identify-account/search?search=admin@email.tld"
100100
Then the response should have a status code 200
101101
And the response should be a JSON array with the following mandatory values
102-
| key | value |
103-
# ShareType equals to email is 4. Zero is the sharetype of account.
104-
| (jq).ocs.data[0].shareType | 0 |
102+
| key | value |
103+
| (jq).ocs.data[0].method | account |
105104

106105
Scenario: Search account by herself with permission to identify by email
107106
Given as user "admin"
@@ -118,4 +117,4 @@ Feature: search
118117
| (jq).ocs.data[0].displayName | admin |
119118
| (jq).ocs.data[0].subname | admin@email.tld |
120119
| (jq).ocs.data[0].icon | icon-mail |
121-
| (jq).ocs.data[0].shareType | 4 |
120+
| (jq).ocs.data[0].method | email |

tests/psalm-baseline.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
<code><![CDATA[$storage]]></code>
4848
</UndefinedDocblockClass>
4949
</file>
50+
<file src="lib/Controller/IdentifyAccountController.php">
51+
<InvalidArrayOffset>
52+
<code><![CDATA[$return[$key]['method']]]></code>
53+
</InvalidArrayOffset>
54+
</file>
5055
<file src="lib/Db/PagerFantaQueryAdapter.php">
5156
<MissingTemplateParam>
5257
<code><![CDATA[AdapterInterface]]></code>

0 commit comments

Comments
 (0)