Skip to content

Commit 6e26156

Browse files
Merge pull request #150 from limosa-io/codex/verify-filtering-support-for-extension-schema
Allow enterprise employeeNumber filtering. Fixes #149
2 parents 3187bf8 + 0c639b3 commit 6e26156

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"mikestead.dotenv",
1818
"mehedidracula.php-namespace-resolver",
1919
"recca0120.vscode-phpunit",
20-
"formulahendry.terminal",
2120
"junstyle.php-cs-fixer"
2221
],
2322
"settings": {

src/Attribute/Complex.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,20 @@ public function applyComparison(Builder &$query, Path $path, $parentAttribute =
361361
$attributeNames = $path->getValuePathAttributes();
362362

363363
if (!empty($attributeNames)) {
364-
// TODO: search for schema node
364+
$schemaIdentifier = $path->getValuePath()?->getAttributePath()?->path?->schema ?? null;
365+
366+
if ($schemaIdentifier !== null && $this->parent === null) {
367+
$schemaNode = $this->getSubNode($schemaIdentifier);
368+
369+
if ($schemaNode instanceof Schema) {
370+
$schemaNode->applyComparison($query, $path);
371+
372+
return;
373+
}
374+
375+
throw new SCIMException('Unknown path: ' . (string)$path . ", in object: " . $this->getFullKey());
376+
}
377+
365378
$attribute = $this->getSubNode($attributeNames[0]);
366379
if ($attribute != null) {
367380
// ($operation, $value, $object, $path->shiftValuePathAttributes());
@@ -379,6 +392,20 @@ public function applyComparison(Builder &$query, Path $path, $parentAttribute =
379392
$attributeNames = $path?->getAttributePath()?->getAttributeNames() ?? [];
380393

381394
if (!empty($attributeNames)) {
395+
$schemaIdentifier = $path->getAttributePath()?->path?->schema ?? null;
396+
397+
if ($schemaIdentifier !== null && $this->parent === null) {
398+
$schemaNode = $this->getSubNode($schemaIdentifier);
399+
400+
if ($schemaNode instanceof Schema) {
401+
$schemaNode->applyComparison($query, $path);
402+
403+
return;
404+
}
405+
406+
throw new SCIMException('Unknown path: ' . (string)$path . ", in object: " . $this->getFullKey());
407+
}
408+
382409
$attribute = $this->getSubNode($attributeNames[0]);
383410
if ($attribute != null) {
384411
$attribute->applyComparison($query, $path->shiftAttributePathAttributes());

tests/CustomSchemaTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class CustomSchemaTest extends TestCase
2929
protected function setUp(): void
3030
{
3131
parent::setUp();
32-
33-
Schema::table('users', function (Blueprint $table) {
34-
$table->string('employeeNumber')->nullable();
35-
});
3632
}
3733

3834
protected function getEnvironmentSetUp($app)

tests/FilterQueryTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,32 @@ public function testMultiConditionFilterCombinesCriteriaWithAnd(): void
108108
'User matching only the userName condition should be excluded.'
109109
);
110110
}
111+
112+
public function testExtensionAttributeFilterMatchesEmployeeNumber(): void
113+
{
114+
$matchingUser = factory(User::class)->create([
115+
'employeeNumber' => '1234',
116+
]);
117+
118+
$nonMatchingUser = factory(User::class)->create([
119+
'employeeNumber' => '5678',
120+
]);
121+
122+
$filter = rawurlencode('urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:employeeNumber eq "1234"');
123+
124+
$response = $this->get("/scim/v2/Users?filter={$filter}&count=200");
125+
$response->assertStatus(200);
126+
127+
$ids = collect($response->json('Resources'))->pluck('id');
128+
129+
$this->assertTrue(
130+
$ids->contains((string)$matchingUser->id),
131+
'Expected filter to return the user matching the enterprise extension employeeNumber.'
132+
);
133+
134+
$this->assertFalse(
135+
$ids->contains((string)$nonMatchingUser->id),
136+
'Filter should exclude users whose enterprise extension employeeNumber does not match.'
137+
);
138+
}
111139
}

tests/GroupsTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ class GroupsTest extends TestCase
1212
protected function setUp(): void
1313
{
1414
parent::setUp();
15-
16-
Schema::table('users', function (Blueprint $table) {
17-
$table->string('employeeNumber')->nullable();
18-
});
1915
}
2016

2117
protected function getEnvironmentSetUp($app)

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function setUp(): void
4646
Schema::table('users', function (Blueprint $table) {
4747
$table->string('formatted')->nullable();
4848
$table->boolean('active')->default(false);
49+
$table->string('employeeNumber')->nullable();
4950
});
5051

5152
$this->withFactories(realpath(dirname(__DIR__) . '/database/factories'));

0 commit comments

Comments
 (0)