Skip to content
Merged
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,13 @@ $response = $descopeSDK->management->user->searchAll(
['ssoApp123'], // ssoAppIds
[ // sort
['field' => 'displayName', 'desc' => true]
]
],
null, // tenantRoleIds
null, // tenantRoleNames
1700000000000, // fromCreatedTime (Unix epoch milliseconds)
1800000000000, // toCreatedTime (Unix epoch milliseconds)
1700000000000, // fromModifiedTime (Unix epoch milliseconds)
1800000000000 // toModifiedTime (Unix epoch milliseconds)
);
print_r($response);
```
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<file>src/tests/StaticStateIsolationTest.php</file>
<file>src/tests/EndpointsTest.php</file>
<file>src/tests/Management/ManagementParityTest.php</file>
<file>src/tests/Management/UserSearchMockTest.php</file>
<file>src/tests/Auth/AuthParityTest.php</file>
</testsuite>
</testsuites>
Expand Down
36 changes: 30 additions & 6 deletions src/SDK/Management/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ public function loadByUserId(string $userId): array
* @param string|null $text Optional string, allows free text search among all user's attributes.
* @param array|null $tenantRoleIds Optional map of tenants and list of role IDs to filter by.
* @param array|null $tenantRoleNames Optional map of tenants and list of role names to filter by.
* @param int|null $fromCreatedTime Optional, only include users created after this time (Unix epoch milliseconds).
* @param int|null $toCreatedTime Optional, only include users created on or before this time (Unix epoch milliseconds).
* @param int|null $fromModifiedTime Optional, only include users modified after this time (Unix epoch milliseconds).
* @param int|null $toModifiedTime Optional, only include users modified on or before this time (Unix epoch milliseconds).
* @return array Return dict in the format {"users": []}. "users" contains a list of all of the found users and their information.
* @throws AuthException if search operation fails.
*/
Expand All @@ -567,7 +571,11 @@ public function searchAll(
$ssoAppIds = null,
$sort = null,
$tenantRoleIds = null,
$tenantRoleNames = null
$tenantRoleNames = null,
$fromCreatedTime = null,
$toCreatedTime = null,
$fromModifiedTime = null,
$toModifiedTime = null
) {
// Prepare the request body ensuring PHP 7.x compatibility
$body = [
Expand All @@ -593,13 +601,17 @@ public function searchAll(
}, $sort) : [],
'loginIds' => [],
'tenantRoleIds' => $this->mapToValuesObject($tenantRoleIds),
'tenantRoleNames' => $this->mapToValuesObject($tenantRoleNames)
'tenantRoleNames' => $this->mapToValuesObject($tenantRoleNames),
'fromCreatedTime' => $fromCreatedTime !== null ? (int)$fromCreatedTime : null,
'toCreatedTime' => $toCreatedTime !== null ? (int)$toCreatedTime : null,
'fromModifiedTime' => $fromModifiedTime !== null ? (int)$fromModifiedTime : null,
'toModifiedTime' => $toModifiedTime !== null ? (int)$toModifiedTime : null
];

$body = array_filter($body, function ($value) {
return $value !== null && $value !== '';
});

return $this->api->doPost(
MgmtV1::$USERS_SEARCH_PATH,
$body,
Expand Down Expand Up @@ -1425,6 +1437,10 @@ public function loadUsers(array $userIds, bool $includeInvalidUsers = false): ar
* @param string|null $text Optional free text search.
* @param array|null $tenantRoleIds Optional map of tenants and list of role IDs.
* @param array|null $tenantRoleNames Optional map of tenants and list of role names.
* @param int|null $fromCreatedTime Optional, only include users created after this time (Unix epoch milliseconds).
* @param int|null $toCreatedTime Optional, only include users created on or before this time (Unix epoch milliseconds).
* @param int|null $fromModifiedTime Optional, only include users modified after this time (Unix epoch milliseconds).
* @param int|null $toModifiedTime Optional, only include users modified on or before this time (Unix epoch milliseconds).
* @return array Return dict in the format {"users": []}.
* @throws AuthException
*/
Expand All @@ -1442,7 +1458,11 @@ public function searchAllTestUsers(
$ssoAppIds = null,
$sort = null,
$tenantRoleIds = null,
$tenantRoleNames = null
$tenantRoleNames = null,
$fromCreatedTime = null,
$toCreatedTime = null,
$fromModifiedTime = null,
$toModifiedTime = null
): array {
$body = [
'loginId' => $loginId ?? '',
Expand All @@ -1466,7 +1486,11 @@ public function searchAllTestUsers(
}, $sort) : [],
'loginIds' => [],
'tenantRoleIds' => $this->mapToValuesObject($tenantRoleIds),
'tenantRoleNames' => $this->mapToValuesObject($tenantRoleNames)
'tenantRoleNames' => $this->mapToValuesObject($tenantRoleNames),
'fromCreatedTime' => $fromCreatedTime !== null ? (int)$fromCreatedTime : null,
'toCreatedTime' => $toCreatedTime !== null ? (int)$toCreatedTime : null,
'fromModifiedTime' => $fromModifiedTime !== null ? (int)$fromModifiedTime : null,
'toModifiedTime' => $toModifiedTime !== null ? (int)$toModifiedTime : null
];

$body = array_filter($body, function ($value) {
Expand Down
115 changes: 115 additions & 0 deletions src/tests/Management/UserSearchMockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Descope\Tests\Management;

use PHPUnit\Framework\TestCase;
use Descope\SDK\DescopeSDK;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response;

final class UserSearchMockTest extends TestCase
{
public function testSearchAllUsersSendsTimeFilterParams()
{
$requests = [];
$mock = new MockHandler([new Response(200, [], json_encode(['users' => []]))]);
$stack = HandlerStack::create($mock);
$stack->push(Middleware::history($requests));
$injectedClient = new Client(['handler' => $stack]);

$sdk = new DescopeSDK([
'projectId' => 'test_project_id',
'managementKey' => 'test_management_key',
'httpClient' => $injectedClient,
]);

$fromCreatedTime = 1700000000000;
$toCreatedTime = 1800000000000;
$fromModifiedTime = 1700000000000;
$toModifiedTime = 1800000000000;

$sdk->management->user->searchAll(
null,
null,
null,
0,
null,
0,
false,
false,
false,
null,
null,
null,
null,
null,
null,
null,
null,
$fromCreatedTime,
$toCreatedTime,
$fromModifiedTime,
$toModifiedTime
);

$this->assertCount(1, $requests);
$body = json_decode((string) $requests[0]['request']->getBody(), true);

$this->assertSame($fromCreatedTime, $body['fromCreatedTime']);
$this->assertSame($toCreatedTime, $body['toCreatedTime']);
$this->assertSame($fromModifiedTime, $body['fromModifiedTime']);
$this->assertSame($toModifiedTime, $body['toModifiedTime']);
}

public function testSearchAllTestUsersSendsTimeFilterParams()
{
$requests = [];
$mock = new MockHandler([new Response(200, [], json_encode(['users' => []]))]);
$stack = HandlerStack::create($mock);
$stack->push(Middleware::history($requests));
$injectedClient = new Client(['handler' => $stack]);

$sdk = new DescopeSDK([
'projectId' => 'test_project_id',
'managementKey' => 'test_management_key',
'httpClient' => $injectedClient,
]);

$fromCreatedTime = 1700000000000;
$toCreatedTime = 1800000000000;
$fromModifiedTime = 1700000000000;
$toModifiedTime = 1800000000000;

$sdk->management->user->searchAllTestUsers(
null,
null,
null,
0,
null,
0,
null,
null,
null,
null,
null,
null,
null,
null,
$fromCreatedTime,
$toCreatedTime,
$fromModifiedTime,
$toModifiedTime
);

$this->assertCount(1, $requests);
$body = json_decode((string) $requests[0]['request']->getBody(), true);

$this->assertSame($fromCreatedTime, $body['fromCreatedTime']);
$this->assertSame($toCreatedTime, $body['toCreatedTime']);
$this->assertSame($fromModifiedTime, $body['fromModifiedTime']);
$this->assertSame($toModifiedTime, $body['toModifiedTime']);
}
}