Skip to content

Commit

Permalink
Merge pull request #143 from multnomah-county-it/dev
Browse files Browse the repository at this point in the history
Support use of multiple client IDs associated with different roles
  • Loading branch information
john-c-houser authored Feb 20, 2024
2 parents 28b39b4 + d83d0f1 commit ebac45d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ or evaluating data from the Symphony system.
- get_patron_checkouts($token, $patron_key, $include_fields)
- get_patron_indexes($token)
- prepare_search($terms)
- register_patron($patron, $token, $addr_num, $role, $template, $subject)
- reset_patron_password($token, $patron_id, $url, $email)
- register_patron($patron, $token, $addr_num, $role, $client_id, $template, $subject)
- reset_patron_password($token, $patron_id, $url, $email, $role, $client_id)
- search_authenticate($token, $index, $search, $password)
- search_bib($token, $index, $value, $params)
- update_patron($patron, $token, $patron_key, $addr_num)
Expand Down Expand Up @@ -165,7 +165,10 @@ $patron = [
];
$addr_num = 1;
$response = $ilsws->register_patron($patron, $token, $addr_num, $template);
$role = 'STAFF';
$client_id = 'StaffClient';
$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $client_id, $template);
```

### Update Patron Record
Expand Down
37 changes: 28 additions & 9 deletions src/Libilsws.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,19 @@ public function send_get ($url = null, $token = null, $params = null)
* @return object $response Associative array containing the response from ILSWS
*/

public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'STAFF', $header = '')
public function send_query ($url = null, $token = null, $query_json = null, $query_type = null, $role = 'PATRON', $client_id = '', $header = '')
{
$this->validate('url', $url, 'u');
$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('query_type', $query_type, 'v:POST|PUT|DELETE');
$this->validate('header', $header, 's:40');
$this->validate('role', $role, 'v:STAFF|PATRON');
$this->validate('role', $role, 'v:STAFF|PATRON|GUEST');

if ( $client_id ) {
$this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#');
} else {
$client_id = $this->config['ilsws']['client_id'];
}

if ( $query_json ) {
$this->validate('query_json', $query_json, 'j');
Expand All @@ -322,7 +328,7 @@ public function send_query ($url = null, $token = null, $query_json = null, $que
"SD-Response-Tracker: $req_num",
"SD-Preferred-Role: $role",
'SD-Prompt-Return: USER_PRIVILEGE_OVRCD/' . $this->config['ilsws']['user_privilege_override'],
'x-sirs-clientID: ' . $this->config['ilsws']['client_id'],
"x-sirs-clientID: $client_id",
"x-sirs-sessionToken: $token",
];

Expand Down Expand Up @@ -1285,13 +1291,20 @@ public function delete_patron ($token = null, $patron_key = null)
* @return object Associative array containing response from ILSWS
*/

public function change_patron_password ($token = null, $json = null)
public function change_patron_password ($token = null, $json = null, $role = 'PATRON', $client_id = '')
{

$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('json', $json, 'j');
$this->validate('role', $role, 'v:PATRON|STAFF|GUEST');

if ( $client_id ) {
$this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#');
} else {
$client_id = $this->config['ilsws']['client_id'];
}

return $this->send_query("$this->base_url/user/patron/changeMyPassword", $token, $json, 'POST');
return $this->send_query("$this->base_url/user/patron/changeMyPassword", $token, $json, $role, $client_id);
}

/**
Expand Down Expand Up @@ -1326,7 +1339,7 @@ public function reset_patron_password ($token = null, $patron_id = null, $url =

$json = json_encode($data);

return $this->send_query("$this->base_url/user/patron/resetMyPassword", $token, $json, 'POST');
return $this->send_query("$this->base_url/user/patron/resetMyPassword", $token, $json, 'POST', 'STAFF');
}

/**
Expand Down Expand Up @@ -2259,12 +2272,18 @@ private function create_register_json ($patron, $token = null, $addr_num = 1)
* @return object $response Associative array containing response from ILSWS
*/

public function register_patron ($patron, $token = null, $addr_num = null, $role = null, $template = '', $subject = '')
public function register_patron ($patron, $token = null, $addr_num = null, $role = 'PATRON', $client_id = '', $template = '', $subject = '')
{
$this->validate('token', $token, 'r:#^[a-z0-9\-]{36}$#');
$this->validate('addr_num', $addr_num, 'r:#^[123]{1}$#');
$this->validate('template', $template, 'r:#^([a-zA-Z0-9]{1,40})(\.)(html|text)(\.)(twig)$#');
$this->validate('role', $role, 'v:STAFF|PATRON');
$this->validate('role', $role, 'v:STAFF|PATRON|GUEST');

if ( $client_id ) {
$this->validate('client_id', $client_id, 'r:#^[A-Za-z]{4,20}$#');
} else {
$client_id = $this->config['ilsws']['client_id'];
}

$response = [];

Expand Down Expand Up @@ -2315,7 +2334,7 @@ public function register_patron ($patron, $token = null, $addr_num = null, $role
}

// Send initial registration (and generate email)
$response = $this->send_query("$this->base_url/user/patron", $token, $json, 'POST', $role);
$response = $this->send_query("$this->base_url/user/patron", $token, $json, 'POST', $role, $client_id);

if ( !empty($response['key']) ) {
$patron_key = $response['key'];
Expand Down
6 changes: 4 additions & 2 deletions test/register_patron.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@

$addr_num = 1;
$template = 'registration_email.html.twig';
$role = 'STAFF';
$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $template, 'Waffles are good');
$role = 'STAFF'; // Used in the SD-Preferred-Role HTTP header
$client_id = 'QUIPU'; // Used in the x-sirs-clientID HTTP header

$response = $ilsws->register_patron($patron, $token, $addr_num, $role, $client_id, $template, 'Waffles are good');
print json_encode($response, JSON_PRETTY_PRINT) . "\n";

// EOF
2 changes: 1 addition & 1 deletion test/register_staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'city_state' => 'Portland, OR',
'county' => '0_MULT',
'profile' => '0_MULT',
'patron_id' => '99999999999997',
'patron_id' => '99999999999996',
'email' => '[email protected]',
'firstName' => 'Bogus',
'friends_notices' => 'YES',
Expand Down
5 changes: 4 additions & 1 deletion test/reset_patron_password.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
// Connect and get token
$token = $ilsws->connect();

$response = $ilsws->reset_patron_password($token, $barcode, $url, $email);
$role = 'PATRON'; // Used in the SD-Preferred-Role HTTP header
$client_id = 'QUIPU'; // Used in the x-sirs-clientID HTTP header

$response = $ilsws->reset_patron_password($token, $barcode, $url, $email, $role, $client_id);
$json = json_encode($response, JSON_PRETTY_PRINT);
print "$json\n\n";

Expand Down

0 comments on commit ebac45d

Please sign in to comment.