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
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"mikestead.dotenv",
"mehedidracula.php-namespace-resolver",
"recca0120.vscode-phpunit",
"formulahendry.terminal",
"junstyle.php-cs-fixer"
],
"settings": {
Expand Down
29 changes: 28 additions & 1 deletion src/Attribute/Complex.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,20 @@ public function applyComparison(Builder &$query, Path $path, $parentAttribute =
$attributeNames = $path->getValuePathAttributes();

if (!empty($attributeNames)) {
// TODO: search for schema node
$schemaIdentifier = $path->getValuePath()?->getAttributePath()?->path?->schema ?? null;

if ($schemaIdentifier !== null && $this->parent === null) {
$schemaNode = $this->getSubNode($schemaIdentifier);

if ($schemaNode instanceof Schema) {
$schemaNode->applyComparison($query, $path);

return;
}

throw new SCIMException('Unknown path: ' . (string)$path . ", in object: " . $this->getFullKey());
}

$attribute = $this->getSubNode($attributeNames[0]);
if ($attribute != null) {
// ($operation, $value, $object, $path->shiftValuePathAttributes());
Expand All @@ -379,6 +392,20 @@ public function applyComparison(Builder &$query, Path $path, $parentAttribute =
$attributeNames = $path?->getAttributePath()?->getAttributeNames() ?? [];

if (!empty($attributeNames)) {
$schemaIdentifier = $path->getAttributePath()?->path?->schema ?? null;

if ($schemaIdentifier !== null && $this->parent === null) {
$schemaNode = $this->getSubNode($schemaIdentifier);

if ($schemaNode instanceof Schema) {
$schemaNode->applyComparison($query, $path);

return;
}

throw new SCIMException('Unknown path: ' . (string)$path . ", in object: " . $this->getFullKey());
}

$attribute = $this->getSubNode($attributeNames[0]);
if ($attribute != null) {
$attribute->applyComparison($query, $path->shiftAttributePathAttributes());
Expand Down
4 changes: 0 additions & 4 deletions tests/CustomSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class CustomSchemaTest extends TestCase
protected function setUp(): void
{
parent::setUp();

Schema::table('users', function (Blueprint $table) {
$table->string('employeeNumber')->nullable();
});
}

protected function getEnvironmentSetUp($app)
Expand Down
28 changes: 28 additions & 0 deletions tests/FilterQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,32 @@ public function testMultiConditionFilterCombinesCriteriaWithAnd(): void
'User matching only the userName condition should be excluded.'
);
}

public function testExtensionAttributeFilterMatchesEmployeeNumber(): void
{
$matchingUser = factory(User::class)->create([
'employeeNumber' => '1234',
]);

$nonMatchingUser = factory(User::class)->create([
'employeeNumber' => '5678',
]);

$filter = rawurlencode('urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:employeeNumber eq "1234"');

$response = $this->get("/scim/v2/Users?filter={$filter}&count=200");
$response->assertStatus(200);

$ids = collect($response->json('Resources'))->pluck('id');

$this->assertTrue(
$ids->contains((string)$matchingUser->id),
'Expected filter to return the user matching the enterprise extension employeeNumber.'
);

$this->assertFalse(
$ids->contains((string)$nonMatchingUser->id),
'Filter should exclude users whose enterprise extension employeeNumber does not match.'
);
}
}
4 changes: 0 additions & 4 deletions tests/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class GroupsTest extends TestCase
protected function setUp(): void
{
parent::setUp();

Schema::table('users', function (Blueprint $table) {
$table->string('employeeNumber')->nullable();
});
}

protected function getEnvironmentSetUp($app)
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected function setUp(): void
Schema::table('users', function (Blueprint $table) {
$table->string('formatted')->nullable();
$table->boolean('active')->default(false);
$table->string('employeeNumber')->nullable();
});

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