Skip to content

A free open source IT asset/license management system

Fixed mapping for Jamf School owner - #19856

snipe8cde96647def
diff --git a/app/SyncAdapters/JamfSchool/JamfSchoolAdapter.php b/app/SyncAdapters/JamfSchool/JamfSchoolAdapter.php
index 3c90668df2..8edba1c89d 100644
--- a/app/SyncAdapters/JamfSchool/JamfSchoolAdapter.php
+++ b/app/SyncAdapters/JamfSchool/JamfSchoolAdapter.php
@@ -125,6 +125,12 @@ class JamfSchoolAdapter extends SyncAdapter
osVersion: Arr::get($device, 'os.version'),
lastSeen: $this->parseTimestamp(Arr::get($device, 'lastCheckin')),
assetTag: Arr::get($device, 'assetTag'),
+ // Jamf School nests the device's assigned user under
+ // `owner`. Pipeline user-lookup matches on either email or
+ // username per adapter config, so populate both when the
+ // vendor emits them.
+ assignedUserEmail: Arr::get($device, 'owner.email'),
+ assignedUserName: Arr::get($device, 'owner.username'),
vendorGroupId: Arr::has($device, 'locationId') ? (string) Arr::get($device, 'locationId') : null,
extra: [
'jamf_school_model_identifier' => Arr::get($device, 'model.identifier'),
diff --git a/tests/Feature/SyncAdapters/JamfSchool/JamfSchoolAdapterTest.php b/tests/Feature/SyncAdapters/JamfSchool/JamfSchoolAdapterTest.php
index e27662c1c9..51c0549903 100644
--- a/tests/Feature/SyncAdapters/JamfSchool/JamfSchoolAdapterTest.php
+++ b/tests/Feature/SyncAdapters/JamfSchool/JamfSchoolAdapterTest.php
@@ -108,6 +108,54 @@ class JamfSchoolAdapterTest extends TestCase
$this->assertNotNull($record->lastSeen);
}
+ public function test_owner_block_populates_assigned_user_fields()
+ {
+ // Regression test for issue #19856. Jamf School carries the
+ // device's assigned user under `owner`. The adapter has to
+ // surface email + username so the pipeline's user-lookup can
+ // resolve them.
+ $adapter = $this->configuredJamfSchoolAdapter();
+
+ Http::fake([
+ '*/devices*' => Http::response([
+ 'count' => 1,
+ 'devices' => [
+ $this->jamfSchoolDevice(
+ udid: 'edu-udid-9',
+ owner: [
+ 'username' => 'edu-staff-1',
+ 'email' => '[email protected]',
+ ],
+ ),
+ ],
+ ]),
+ ]);
+
+ $records = iterator_to_array($adapter->pull());
+
+ $this->assertSame('[email protected]', $records[0]->assignedUserEmail);
+ $this->assertSame('edu-staff-1', $records[0]->assignedUserName);
+ }
+
+ public function test_absent_owner_block_leaves_assigned_user_null()
+ {
+ $adapter = $this->configuredJamfSchoolAdapter();
+
+ Http::fake([
+ '*/devices*' => Http::response([
+ 'count' => 1,
+ 'devices' => [
+ $this->jamfSchoolDevice(udid: 'edu-udid-10'),
+ ],
+ ]),
+ ]);
+
+ $records = iterator_to_array($adapter->pull());
+
+ $this->assertNull($records[0]->assignedUserEmail);
+ $this->assertNull($records[0]->assignedUserName);
+ }
+
private function configuredJamfSchoolAdapter(): JamfSchoolAdapter
{
$instance = SyncAdapterInstance::where('slug', 'jamf_school')->firstOrFail();
@@ -123,6 +171,9 @@ class JamfSchoolAdapterTest extends TestCase
/**
* @return array<string, mixed>
*/
+ /**
+ * @param array<string, mixed>|null $owner
+ */
private function jamfSchoolDevice(
string $udid,
string $name = 'device',
@@ -132,8 +183,9 @@ class JamfSchoolAdapterTest extends TestCase
?string $os = 'iPadOS',
?string $osVersion = null,
?string $lastCheckin = null,
+ ?array $owner = null,
): array {
- return [
+ $device = [
'UDID' => $udid,
'name' => $name,
'serialNumber' => $serial,
@@ -151,5 +203,11 @@ class JamfSchoolAdapterTest extends TestCase
'assetTag' => null,
'locationId' => 1,
];
+
+ if ($owner !== null) {
+ $device['owner'] = $owner;
+ }
+
+ return $device;
}
}