Skip to content

Commit b6f79ec

Browse files
committed
Merge branch 'release/3.21.1'
2 parents 8f4bbfa + 6374b37 commit b6f79ec

File tree

6 files changed

+121
-52
lines changed

6 files changed

+121
-52
lines changed

CHANGELOG.md

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

1212
## [Unreleased]
1313

14+
## [3.21.1] 2025-01-06
15+
16+
- Updated Maestro notification handler assignment message format.
17+
- Updated `os2forms_fbs_handler` to use latest endpoints and operations.
18+
1419
## [3.21.0] 2024-12-17
1520

1621
- Updated `os2web_audit`.
@@ -323,7 +328,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa
323328
- Security in case of vulnerabilities.
324329
```
325330

326-
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.21.0...HEAD
331+
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.21.1...HEAD
332+
[3.21.1]: https://github.com/OS2Forms/os2forms/compare/3.21.0...3.21.1
327333
[3.21.0]: https://github.com/OS2Forms/os2forms/compare/3.20.1...3.21.0
328334
[3.20.1]: https://github.com/OS2Forms/os2forms/compare/3.20.0...3.20.1
329335
[3.20.0]: https://github.com/OS2Forms/os2forms/compare/3.19.0...3.20.0

modules/os2forms_fbs_handler/src/Client/FBS.php

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,22 @@ public function isLoggedIn(): bool {
7575
* @param string $cpr
7676
* The users personal security number.
7777
*
78-
* @return \Drupal\os2forms_fbs_handler\Client\Model\Patron|null
79-
* NULL if not else the Patron.
78+
* @return string|null
79+
* NULL if not else the PatronId.
8080
*
8181
* @throws \GuzzleHttp\Exception\GuzzleException
8282
* @throws \JsonException
8383
*/
84-
public function doUserExists(string $cpr): ?Patron {
84+
public function authenticatePatron(string $cpr): ?string {
8585
// Check if session has been created with FBS and if not creates it.
8686
if (!$this->isLoggedIn()) {
8787
$this->login();
8888
}
8989

90-
// Try pre-authenticate the user/parent.
91-
$json = $this->request('/external/{agency_id}/patrons/preauthenticated/v9', $cpr);
90+
// Authenticate the patron.
91+
$json = $this->request('/external/{agency_id}/patrons/preauthenticated/v10', $cpr);
9292
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-
);
93+
return $json->patronId;
10694
}
10795

10896
return NULL;
@@ -123,17 +111,60 @@ public function doUserExists(string $cpr): ?Patron {
123111
* @throws \JsonException
124112
*/
125113
public function createPatronWithGuardian(Patron $patron, Guardian $guardian) {
126-
$uri = '/external/{agency_id}/patrons/withGuardian/v1';
114+
$uri = '/external/{agency_id}/patrons/withGuardian/v4';
127115
$payload = [
128-
'cprNumber' => $patron->cpr,
116+
'personId' => $patron->personId,
129117
'pincode' => $patron->pincode,
130118
'preferredPickupBranch' => $patron->preferredPickupBranch,
131119
'name' => 'Unknown Name',
132-
'email' => $patron->emailAddress,
120+
'emailAddresses' => $patron->emailAddresses,
133121
'guardian' => $guardian->toArray(),
134122
];
135123

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

139170
/**
@@ -149,19 +180,27 @@ public function createPatronWithGuardian(Patron $patron, Guardian $guardian) {
149180
* @throws \JsonException
150181
*/
151182
public function updatePatron(Patron $patron): bool {
152-
$uri = '/external/{agency_id}/patrons/' . $patron->patronId . '/v6';
183+
$uri = '/external/{agency_id}/patrons/' . $patron->patronId . '/v8';
153184
$payload = [
154-
'patronid' => $patron->patronId,
155-
'patron' => $patron->toArray(),
185+
'patron' => [
186+
'preferredPickupBranch' => $patron->preferredPickupBranch,
187+
'emailAddresses' => $patron->emailAddresses,
188+
'guardianVisibility' => $patron->guardianVisibility,
189+
'receivePostalMail' => $patron->receiveEmail,
190+
'phoneNumbers' => [
191+
[
192+
'receiveNotification' => TRUE,
193+
'phoneNumber' => $patron->phoneNumber,
194+
],
195+
],
196+
],
156197
'pincodeChange' => [
157198
'pincode' => $patron->pincode,
158-
'libraryCardNumber' => $patron->cpr,
199+
'libraryCardNumber' => $patron->personId,
159200
],
160201
];
161202

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

167206
/**
@@ -179,7 +218,7 @@ public function updatePatron(Patron $patron): bool {
179218
* @throws \JsonException
180219
*/
181220
public function createGuardian(Patron $patron, Guardian $guardian): int {
182-
$uri = '/external/{agency_id}/patrons/withGuardian/v1';
221+
$uri = '/external/{agency_id}/patrons/withGuardian/v2';
183222
$payload = [
184223
'patronId' => $patron->patronId,
185224
'guardian' => $guardian->toArray(),
@@ -199,7 +238,7 @@ public function createGuardian(Patron $patron, Guardian $guardian): int {
199238
* The type of request to send (Default: POST).
200239
*
201240
* @return mixed
202-
* Json response from FBS.
241+
* Json response from FBS or TRUE on updatePatron response.
203242
*
204243
* @throws \GuzzleHttp\Exception\GuzzleException
205244
* @throws \JsonException
@@ -230,6 +269,10 @@ private function request(string $uri, array|string $data, string $method = Reque
230269

231270
$response = $this->client->request($method, $url, $options);
232271

272+
if ($response->getStatusCode() === 204) {
273+
return TRUE;
274+
}
275+
233276
return json_decode($response->getBody(), FALSE, 512, JSON_THROW_ON_ERROR);
234277
}
235278

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
*/
2626
public function toArray(): array {
2727
return [
28-
'cprNumber' => $this->cpr,
28+
'personIdentifier' => $this->cpr,
2929
'name' => $this->name,
3030
'email' => $this->email,
3131
];

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ public function __construct(
1919
public readonly ?array $onHold = NULL,
2020
public readonly ?string $preferredLanguage = NULL,
2121
public readonly ?bool $guardianVisibility = NULL,
22+
public readonly ?int $defaultInterestPeriod = NULL,
23+
public readonly ?bool $resident = NULL,
2224
// Allow these properties below to be updatable.
23-
public ?string $emailAddress = NULL,
25+
public ?array $emailAddresses = NULL,
2426
public ?bool $receiveEmail = NULL,
2527
public ?string $preferredPickupBranch = NULL,
26-
public ?string $cpr = NULL,
28+
public ?string $personId = NULL,
2729
public ?string $pincode = NULL,
2830
) {
2931
}
@@ -36,16 +38,19 @@ public function __construct(
3638
*/
3739
public function toArray(): array {
3840
return [
41+
'patronId' => $this->patronId,
3942
'receiveEmail' => $this->receiveEmail,
4043
'receiveSms' => $this->receiveSms,
4144
'receivePostalMail' => $this->receivePostalMail,
42-
'emailAddress' => $this->emailAddress,
45+
'emailAddresses' => $this->emailAddresses,
4346
'notificationProtocols' => $this->notificationProtocols,
4447
'phoneNumber' => $this->phoneNumber,
4548
'preferredPickupBranch' => $this->preferredPickupBranch,
4649
'onHold' => $this->onHold,
4750
'preferredLanguage' => $this->preferredLanguage,
4851
'guardianVisibility' => $this->guardianVisibility,
52+
'defaultInterestPeriod' => $this->defaultInterestPeriod,
53+
'resident' => $this->resident,
4954
];
5055
}
5156

modules/os2forms_fbs_handler/src/Plugin/AdvancedQueue/JobType/FbsCreateUser.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,36 +87,50 @@ public function process(Job $job): JobResult {
8787

8888
$data = $webformSubmission->getData();
8989

90-
// Checker child patron exists.
91-
$patron = $fbs->doUserExists($data['barn_cpr']);
92-
9390
// Create Guardian.
9491
$guardian = new Guardian(
9592
$data['cpr'],
9693
$data['navn'],
9794
$data['email']
9895
);
9996

97+
// Check if child patron exists.
98+
$patronId = $fbs->authenticatePatron($data['barn_cpr']);
99+
100100
// If "yes" update the child patron and create the guardian (the
101101
// guardian is not another patron user).
102-
if (!is_null($patron)) {
103-
// Create Patron object with updated values.
104-
$patron->preferredPickupBranch = $data['afhentningssted'];
105-
$patron->emailAddress = $data['barn_mail'];
106-
$patron->receiveEmail = TRUE;
107-
$patron->cpr = $data['barn_cpr'];
108-
$patron->pincode = $data['pinkode'];
109-
110-
$fbs->updatePatron($patron);
111-
$fbs->createGuardian($patron, $guardian);
102+
if (!is_null($patronId)) {
103+
// Fetch patron.
104+
$patron = $fbs->getPatron($patronId);
105+
106+
if (!is_null($patron)) {
107+
// Create Patron object with updated values.
108+
$patron->preferredPickupBranch = $data['afhentningssted'];
109+
$patron->emailAddresses = [
110+
[
111+
'emailAddress' => $data['barn_mail'],
112+
'receiveNotification' => TRUE,
113+
],
114+
];
115+
$patron->receiveEmail = TRUE;
116+
$patron->pincode = $data['pinkode'];
117+
118+
$fbs->updatePatron($patron);
119+
$fbs->createGuardian($patron, $guardian);
120+
}
112121
}
113122
else {
114123
// If "no" create child patron and guardian.
115124
$patron = new Patron();
116125
$patron->preferredPickupBranch = $data['afhentningssted'];
117-
$patron->emailAddress = $data['barn_mail'];
126+
$patron->emailAddresses = [
127+
[
128+
'emailAddress' => $data['barn_mail'],
129+
'receiveNotification' => TRUE,
130+
],
131+
];
118132
$patron->receiveEmail = TRUE;
119-
$patron->cpr = $data['barn_cpr'];
133+
$patron->personId = $data['barn_cpr'];
120134
$patron->pincode = $data['pinkode'];
121135

122136
$fbs->createPatronWithGuardian($patron, $guardian);

modules/os2forms_forloeb/src/Plugin/WebformHandler/MaestroNotificationHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class MaestroNotificationHandler extends WebformHandlerBase {
2424
public const NOTIFICATION = 'notification';
2525

2626
public const TYPE = 'type';
27+
public const FORMAT = 'format';
2728
public const SENDER_LABEL = 'sender_label';
2829
public const NOTIFICATION_ENABLE = 'notification_enable';
2930
public const NOTIFICATION_RECIPIENT = 'notification_recipient';
@@ -153,7 +154,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
153154
}
154155
$form[self::NOTIFICATION][$notificationType][self::NOTIFICATION_CONTENT] = [
155156
'#type' => 'text_format',
156-
'#format' => 'restricted_html',
157+
'#format' => $this->configuration[self::NOTIFICATION][$notificationType][self::NOTIFICATION_CONTENT][self::FORMAT] ?? 'restricted_html',
157158
'#title' => $this->t('Message'),
158159
'#default_value' => $content ?? self::TOKEN_MAESTRO_TASK_URL,
159160
'#description' => $this->t('The actual notification content. Must contain the <code>@token_maestro_task_url</code> token which is the URL to the Maestro task.',

0 commit comments

Comments
 (0)