Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion services/Record/RecordUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ function ht_link_data_from_json($e) {
$rv['has_activated_role'] = $htstatus->has_activated_role &&
(!$rv['is_fullview'] &&
(!$open_to_no_one));
$rv['role_name'] = $htstatus->has_activated_role ? array_keys($htstatus->r)[0] : NULL;
# has_activated_role can be true if sssduser, and r will not be set in that case.
# Hence the check on $htstatus->r
$rv['role_name'] = NULL; # default
if (
$htstatus->has_activated_role
&& $htstatus->r
&& count(array_keys($htstatus->r)) > 0
) {
$rv['role_name'] = array_keys($htstatus->r)[0];
}

return $rv;
}
Expand Down
28 changes: 28 additions & 0 deletions test/RecordUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ public function test_ht_link_data_from_json_activated_role(): void {
$this->assertEquals('resourceSharing', $data['role_name']);
}

/**
* @covers RecordUtils::ht_link_data_from_json
* @runInSeparateProcess

ssduser results in activated role set to true but no role name, because ping
Clearly this is not optimal
Comment thread
moseshll marked this conversation as resolved.
*/
public function test_ht_link_data_from_json_ssduser(): void {
global $htstatus;
# Setup for VFSession.php and DSession.php
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
$sample_json = array(
'rights' => 'ic',
'htid' => 'mdp.001',
'collection_code' => 'miu',
'enumcron' => 'v.1',
'heldby' => array('umich'),
);
$utils = new RecordUtils();
$htstatus->r = NULL;
$htstatus->u = true;
$htstatus->has_activated_role = true;
$data = $utils->ht_link_data_from_json($sample_json);
$this->assertEquals(true, $data['has_activated_role']);
$this->assertEquals(NULL, $data['role_name']);
}

/**
* @covers RecordUtils::is_fullview
*/
Expand Down
Loading