Skip to content

Commit 2b4a5a1

Browse files
committed
Merge commit '7ace38332357344358eca1935f43ae2a30c23fa4' into f/OS-110
* commit '7ace38332357344358eca1935f43ae2a30c23fa4': (31 commits) Release 3.22.1 Preparing 3.22.0 release OS-143 - Removed image_widget_crop Simplified validation Changed validation to check for empty string instead of null Conditional inclusion of patron phone number, since field is not required Updated changelog renamed fbs class Coding standards Add barn_tlf as an incoming field in FbsWebformHandler Handle phoneNumber assignment in advanced queue job Make phoneNumber a writeable property in Patron model Add support for phone numbers in FBS payloads Updating os2web_simplesaml to D10 compatible version Prepare release 3.21.2 Add missing iterable type specifications Run code analysis on fbs handler Add and use http-message-util Release 3.21.1 ITKDEV: Used configured format in maestro notification ...
2 parents 43e5a04 + 7ace383 commit 2b4a5a1

File tree

10 files changed

+214
-65
lines changed

10 files changed

+214
-65
lines changed

CHANGELOG.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1111

1212
## [Unreleased]
1313

14+
## [3.22.1] 2025-02-10
15+
16+
- Updated `os2forms_fbs_handler` to include and correct set phone number [#161](https://github.com/OS2Forms/os2forms/pull/161)
17+
18+
## [3.22.0] 2025-02-03
19+
20+
- Removed modules ldap_auth, logging_alerts, maillog [#151](https://github.com/OS2Forms/os2forms/pull/151)
21+
- Removed module image_widget_crop [#OS-143](https://github.com/OS2Forms/os2forms/pull/159)
22+
23+
## [3.21.2] 2025-01-07
24+
25+
- Adds missing `http-message-util` requirement and use statement.
26+
- Runs code-analysis on `os2forms_fbs_handler` module.
27+
28+
## [3.21.1] 2025-01-06
29+
30+
- Updated Maestro notification handler assignment message format.
31+
- Updated `os2forms_fbs_handler` to use latest endpoints and operations.
32+
33+
## [3.21.0] 2024-12-17
34+
35+
- Updated `os2web_audit`.
36+
- Added patch to get `hook_webform_post_load_data` in webform submissions.
37+
38+
## [3.20.1] 2024-12-10
39+
40+
- Avoided accessing non-initialized property when logging in `os2forms_nemid`.
41+
1442
## [3.20.0] 2024-12-09
1543

1644
- Added webform ID to digital post audit logging messages.
@@ -314,7 +342,13 @@ before starting to add changes. Use example [placed in the end of the page](#exa
314342
- Security in case of vulnerabilities.
315343
```
316344

317-
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.20.0...HEAD
345+
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.22.1...HEAD
346+
[3.22.1]: https://github.com/OS2Forms/os2forms/compare/3.22.0...3.22.1
347+
[3.22.0]: https://github.com/OS2Forms/os2forms/compare/3.21.2...3.22.0
348+
[3.21.2]: https://github.com/OS2Forms/os2forms/compare/3.21.1...3.21.2
349+
[3.21.1]: https://github.com/OS2Forms/os2forms/compare/3.21.0...3.21.1
350+
[3.21.0]: https://github.com/OS2Forms/os2forms/compare/3.20.1...3.21.0
351+
[3.20.1]: https://github.com/OS2Forms/os2forms/compare/3.20.0...3.20.1
318352
[3.20.0]: https://github.com/OS2Forms/os2forms/compare/3.19.0...3.20.0
319353
[3.19.0]: https://github.com/OS2Forms/os2forms/compare/3.18.0...3.19.0
320354
[3.18.0]: https://github.com/OS2Forms/os2forms/compare/3.17.0...3.18.0

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dompdf/dompdf": "^2.0",
2424
"drupal/admin_toolbar": "^3.0",
2525
"drupal/advancedqueue": "^1.0",
26+
"drupal/cache_control_override": "^1.1|^2.0",
2627
"drupal/clientside_validation": "^4.0",
2728
"drupal/coc_forms_auto_export": "^2.0@alpha",
2829
"drupal/config_entity_revisions": "dev-2.0.x",
@@ -31,14 +32,12 @@
3132
"drupal/entity_print": "^2.1",
3233
"drupal/eu_cookie_compliance": "^1.8",
3334
"drupal/events_logging": "^2.0@beta",
35+
"drupal/gin": "^3.0-rc",
3436
"drupal/honeypot": "^2.0",
35-
"drupal/image_widget_crop": "^2.3",
3637
"drupal/ldap": "^4.2",
37-
"drupal/ldap_auth": "^1.17",
3838
"drupal/leaflet": "^10.0",
3939
"drupal/leaflet_layers": "^1.1",
4040
"drupal/libraries": "^4.0",
41-
"drupal/logging_alerts": "^2.0",
4241
"drupal/maestro": "^3.1",
4342
"drupal/mailsystem": "^4.1",
4443
"drupal/masquerade": "^2.0@RC",
@@ -65,12 +64,14 @@
6564
"drupal/webform_validation": "^2.0",
6665
"drupal/webform_views": "^5.0@alpha",
6766
"drupal/workflow_participants": "^3.0@RC",
67+
"fig/http-message-util": "^1.1",
6868
"http-interop/http-factory-guzzle": "^1.0.0",
6969
"itk-dev/beskedfordeler-drupal": "^1.0",
7070
"itk-dev/serviceplatformen": "^1.5",
71-
"os2web/os2web_audit": "^0.1.1",
71+
"os2web/os2web_audit": "^0.1.6",
7272
"os2web/os2web_datalookup": "^2.0",
7373
"os2web/os2web_nemlogin": "^1.0",
74+
"os2web/os2web_simplesaml": "dev-master",
7475
"php-http/guzzle7-adapter": "^1.0",
7576
"phpoffice/phpword": "^0.18.2",
7677
"symfony/options-resolver": "^5.4 || ^6.0",
@@ -82,7 +83,6 @@
8283
"require-dev": {
8384
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
8485
"drupal/coder": "^8.3",
85-
"drupal/maillog": "^1.0",
8686
"mglaman/phpstan-drupal": "^1.1",
8787
"phpstan/extension-installer": "^1.3",
8888
"phpstan/phpstan-deprecation-rules": "^1.1",
@@ -98,7 +98,9 @@
9898
},
9999
"drupal/webform": {
100100
"Unlock possibility of using Entity print module export to Word": "https://www.drupal.org/files/issues/2020-02-29/3096552-6.patch",
101-
"Webform computed element post save alter": "https://www.drupal.org/files/issues/2024-06-25/webform_computed_post_save_field_alter.patch"
101+
"Webform computed element post save alter": "https://www.drupal.org/files/issues/2024-06-25/webform_computed_post_save_field_alter.patch",
102+
"Add custom hook (hook_webform_post_load_data) for audit logging": "https://gist.githubusercontent.com/cableman/d26898fc8f65ee0a31001bf391583b59/raw/6189dc4c2ceaabb19d25cc4b98b0b3028a6b0e1e/gistfile1.txt"
103+
102104
},
103105
"drupal/coc_forms_auto_export": {
104106
"3240592 - Problem with phpseclib requirement in 2.x (https://www.drupal.org/project/coc_forms_auto_export/issues/3240592)": "https://www.drupal.org/files/issues/2021-10-04/requirement-namespace-3240592-1.patch",

modules/os2forms_fbs_handler/src/Client/FBS.php renamed to modules/os2forms_fbs_handler/src/Client/Fbs.php

Lines changed: 85 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
use Drupal\os2forms_fbs_handler\Client\Model\Guardian;
66
use Drupal\os2forms_fbs_handler\Client\Model\Patron;
7+
use Fig\Http\Message\RequestMethodInterface;
78
use GuzzleHttp\Client;
89
use Symfony\Component\HttpFoundation\Request;
910

1011
/**
1112
* Minimalistic client to create user with guardians at FBS.
1213
*/
13-
class FBS {
14+
class Fbs {
1415

1516
/**
1617
* FBS session key.
@@ -75,34 +76,22 @@ public function isLoggedIn(): bool {
7576
* @param string $cpr
7677
* The users personal security number.
7778
*
78-
* @return \Drupal\os2forms_fbs_handler\Client\Model\Patron|null
79-
* NULL if not else the Patron.
79+
* @return string|null
80+
* NULL if not else the PatronId.
8081
*
8182
* @throws \GuzzleHttp\Exception\GuzzleException
8283
* @throws \JsonException
8384
*/
84-
public function doUserExists(string $cpr): ?Patron {
85+
public function authenticatePatron(string $cpr): ?string {
8586
// Check if session has been created with FBS and if not creates it.
8687
if (!$this->isLoggedIn()) {
8788
$this->login();
8889
}
8990

90-
// Try pre-authenticate the user/parent.
91-
$json = $this->request('/external/{agency_id}/patrons/preauthenticated/v9', $cpr);
91+
// Authenticate the patron.
92+
$json = $this->request('/external/{agency_id}/patrons/preauthenticated/v10', $cpr);
9293
if ($json->authenticateStatus === $this::AUTHENTICATE_STATUS_VALID) {
93-
return new Patron(
94-
$json->patron->patronId,
95-
(bool) $json->patron->receiveSms,
96-
(bool) $json->patron->receivePostalMail,
97-
$json->patron->notificationProtocols,
98-
$json->patron->phoneNumber,
99-
is_null($json->patron->onHold) ? $json->patron->onHold : (array) $json->patron->onHold,
100-
$json->patron->preferredLanguage,
101-
(bool) $json->patron->guardianVisibility,
102-
$json->patron->emailAddress,
103-
(bool) $json->patron->receiveEmail,
104-
$json->patron->preferredPickupBranch
105-
);
94+
return $json->patronId;
10695
}
10796

10897
return NULL;
@@ -123,17 +112,67 @@ public function doUserExists(string $cpr): ?Patron {
123112
* @throws \JsonException
124113
*/
125114
public function createPatronWithGuardian(Patron $patron, Guardian $guardian) {
126-
$uri = '/external/{agency_id}/patrons/withGuardian/v1';
115+
$uri = '/external/{agency_id}/patrons/withGuardian/v4';
127116
$payload = [
128-
'cprNumber' => $patron->cpr,
117+
'personId' => $patron->personId,
129118
'pincode' => $patron->pincode,
130119
'preferredPickupBranch' => $patron->preferredPickupBranch,
131120
'name' => 'Unknown Name',
132-
'email' => $patron->emailAddress,
121+
'emailAddresses' => $patron->emailAddresses ?? [],
133122
'guardian' => $guardian->toArray(),
123+
'phoneNumbers' => $patron->phoneNumber ? [
124+
[
125+
'receiveNotification' => TRUE,
126+
'phoneNumber' => $patron->phoneNumber,
127+
],
128+
] : [],
134129
];
135130

136-
return $this->request($uri, $payload,);
131+
return $this->request($uri, $payload);
132+
}
133+
134+
/**
135+
* Get patron information.
136+
*
137+
* @param string $patronId
138+
* The patron to update.
139+
*
140+
* @return \Drupal\os2forms_fbs_handler\Client\Model\Patron
141+
* Patron object
142+
*
143+
* @throws \GuzzleHttp\Exception\GuzzleException
144+
* @throws \JsonException
145+
*/
146+
public function getPatron(string $patronId): ?Patron {
147+
$uri = '/external/{agency_id}/patrons/' . $patronId . '/v4';
148+
149+
$json = $this->request($uri, [], RequestMethodInterface::METHOD_GET);
150+
151+
if ($json->authenticateStatus === "VALID") {
152+
return new Patron(
153+
$json->patron->patronId,
154+
(bool) $json->patron->receiveSms,
155+
(bool) $json->patron->receivePostalMail,
156+
$json->patron->notificationProtocols,
157+
is_null($json->patron->onHold) ? $json->patron->onHold : (array) $json->patron->onHold,
158+
$json->patron->preferredLanguage,
159+
(bool) $json->patron->guardianVisibility,
160+
$json->patron->defaultInterestPeriod,
161+
(bool) $json->patron->resident,
162+
$json->patron->phoneNumber,
163+
164+
[
165+
[
166+
'emailAddress' => $json->patron->emailAddress,
167+
'receiveNotification' => $json->patron->receiveEmail,
168+
],
169+
],
170+
(bool) $json->patron->receiveEmail,
171+
$json->patron->preferredPickupBranch
172+
);
173+
}
174+
175+
return NULL;
137176
}
138177

139178
/**
@@ -149,19 +188,27 @@ public function createPatronWithGuardian(Patron $patron, Guardian $guardian) {
149188
* @throws \JsonException
150189
*/
151190
public function updatePatron(Patron $patron): bool {
152-
$uri = '/external/{agency_id}/patrons/' . $patron->patronId . '/v6';
191+
$uri = '/external/{agency_id}/patrons/' . $patron->patronId . '/v8';
153192
$payload = [
154-
'patronid' => $patron->patronId,
155-
'patron' => $patron->toArray(),
193+
'patron' => [
194+
'preferredPickupBranch' => $patron->preferredPickupBranch,
195+
'emailAddresses' => $patron->emailAddresses ?? [],
196+
'guardianVisibility' => $patron->guardianVisibility,
197+
'receivePostalMail' => $patron->receiveEmail,
198+
'phoneNumbers' => $patron->phoneNumber ? [
199+
[
200+
'receiveNotification' => TRUE,
201+
'phoneNumber' => $patron->phoneNumber,
202+
],
203+
] : [],
204+
],
156205
'pincodeChange' => [
157206
'pincode' => $patron->pincode,
158-
'libraryCardNumber' => $patron->cpr,
207+
'libraryCardNumber' => $patron->personId,
159208
],
160209
];
161210

162-
$json = $this->request($uri, $payload, Request::METHOD_PUT);
163-
164-
return $json->authenticateStatus === $this::AUTHENTICATE_STATUS_VALID;
211+
return $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT);
165212
}
166213

167214
/**
@@ -179,7 +226,7 @@ public function updatePatron(Patron $patron): bool {
179226
* @throws \JsonException
180227
*/
181228
public function createGuardian(Patron $patron, Guardian $guardian): int {
182-
$uri = '/external/{agency_id}/patrons/withGuardian/v1';
229+
$uri = '/external/{agency_id}/patrons/withGuardian/v2';
183230
$payload = [
184231
'patronId' => $patron->patronId,
185232
'guardian' => $guardian->toArray(),
@@ -199,10 +246,12 @@ public function createGuardian(Patron $patron, Guardian $guardian): int {
199246
* The type of request to send (Default: POST).
200247
*
201248
* @return mixed
202-
* Json response from FBS.
249+
* Json response from FBS or TRUE on updatePatron response.
203250
*
204251
* @throws \GuzzleHttp\Exception\GuzzleException
205252
* @throws \JsonException
253+
*
254+
* @phpstan-param array<mixed>|string $data
206255
*/
207256
private function request(string $uri, array|string $data, string $method = Request::METHOD_POST): mixed {
208257
$url = rtrim($this->endpoint, '/\\');
@@ -230,6 +279,10 @@ private function request(string $uri, array|string $data, string $method = Reque
230279

231280
$response = $this->client->request($method, $url, $options);
232281

282+
if ($response->getStatusCode() === 204) {
283+
return TRUE;
284+
}
285+
233286
return json_decode($response->getBody(), FALSE, 512, JSON_THROW_ON_ERROR);
234287
}
235288

modules/os2forms_fbs_handler/src/Client/Model/Guardian.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public function __construct(
2222
*
2323
* @return array
2424
* Array with field required by FBS calls.
25+
*
26+
* @phpstan-return array<string, string>
2527
*/
2628
public function toArray(): array {
2729
return [
28-
'cprNumber' => $this->cpr,
30+
'personIdentifier' => $this->cpr,
2931
'name' => $this->name,
3032
'email' => $this->email,
3133
];

modules/os2forms_fbs_handler/src/Client/Model/Patron.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@ final class Patron {
99

1010
/**
1111
* Default constructor.
12+
*
13+
* @phpstan-param array<mixed>|null $notificationProtocols
14+
* @phpstan-param array<mixed>|null $onHold
15+
* @phpstan-param array<mixed>|null $emailAddresses
1216
*/
1317
public function __construct(
1418
public readonly ?string $patronId = NULL,
1519
public readonly ?bool $receiveSms = FALSE,
1620
public readonly ?bool $receivePostalMail = FALSE,
1721
public readonly ?array $notificationProtocols = NULL,
18-
public readonly ?string $phoneNumber = NULL,
1922
public readonly ?array $onHold = NULL,
2023
public readonly ?string $preferredLanguage = NULL,
2124
public readonly ?bool $guardianVisibility = NULL,
25+
public readonly ?int $defaultInterestPeriod = NULL,
26+
public readonly ?bool $resident = NULL,
2227
// Allow these properties below to be updatable.
23-
public ?string $emailAddress = NULL,
28+
public ?string $phoneNumber = NULL,
29+
public ?array $emailAddresses = NULL,
2430
public ?bool $receiveEmail = NULL,
2531
public ?string $preferredPickupBranch = NULL,
26-
public ?string $cpr = NULL,
32+
public ?string $personId = NULL,
2733
public ?string $pincode = NULL,
2834
) {
2935
}
@@ -33,19 +39,24 @@ public function __construct(
3339
*
3440
* @return array
3541
* Array with field required by FBS calls.
42+
*
43+
* @phpstan-return array<string, string>
3644
*/
3745
public function toArray(): array {
3846
return [
47+
'patronId' => $this->patronId,
3948
'receiveEmail' => $this->receiveEmail,
4049
'receiveSms' => $this->receiveSms,
4150
'receivePostalMail' => $this->receivePostalMail,
42-
'emailAddress' => $this->emailAddress,
51+
'emailAddresses' => $this->emailAddresses,
4352
'notificationProtocols' => $this->notificationProtocols,
4453
'phoneNumber' => $this->phoneNumber,
4554
'preferredPickupBranch' => $this->preferredPickupBranch,
4655
'onHold' => $this->onHold,
4756
'preferredLanguage' => $this->preferredLanguage,
4857
'guardianVisibility' => $this->guardianVisibility,
58+
'defaultInterestPeriod' => $this->defaultInterestPeriod,
59+
'resident' => $this->resident,
4960
];
5061
}
5162

0 commit comments

Comments
 (0)