From a84e669a1f85f2bcbf28a730aa4a9c2d6c420f41 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 22 Aug 2023 21:34:23 -0400 Subject: [PATCH] Add missing accessedAt values when creating users --- app/controllers/api/account.php | 21 ++++++++++++------- app/controllers/api/users.php | 3 ++- .../Account/AccountCustomClientTest.php | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index ca8048121..0ef4c002c 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -128,9 +128,10 @@ App::post('/v1/account/invite') 'sessions' => null, 'tokens' => null, 'memberships' => null, - 'search' => implode(' ', [$userId, $email, $name]) + 'search' => implode(' ', [$userId, $email, $name]), + 'accessedAt' => DateTime::now(), ]))); - } catch (Duplicate $th) { + } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -240,10 +241,10 @@ App::post('/v1/account') 'tokens' => null, 'memberships' => null, 'search' => implode(' ', [$userId, $email, $name]), - 'accessedAt' => DateTime::now(), // Add this here to make sure it's returned in the response + 'accessedAt' => DateTime::now(), ]); Authorization::skip(fn() => $dbForProject->createDocument('users', $user)); - } catch (Duplicate $th) { + } catch (Duplicate) { throw new Exception(Exception::USER_ALREADY_EXISTS); } @@ -746,10 +747,11 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') 'sessions' => null, 'tokens' => null, 'memberships' => null, - 'search' => implode(' ', [$userId, $email, $name]) + 'search' => implode(' ', [$userId, $email, $name]), + 'accessedAt' => DateTime::now(), ]); Authorization::skip(fn() => $dbForProject->createDocument('users', $user)); - } catch (Duplicate $th) { + } catch (Duplicate) { $failureRedirect(Exception::USER_ALREADY_EXISTS); } } @@ -1046,7 +1048,8 @@ App::post('/v1/account/sessions/magic-url') 'sessions' => null, 'tokens' => null, 'memberships' => null, - 'search' => implode(' ', [$userId, $email]) + 'search' => implode(' ', [$userId, $email]), + 'accessedAt' => DateTime::now(), ]); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); @@ -1335,7 +1338,8 @@ App::post('/v1/account/sessions/phone') 'sessions' => null, 'tokens' => null, 'memberships' => null, - 'search' => implode(' ', [$userId, $phone]) + 'search' => implode(' ', [$userId, $phone]), + 'accessedAt' => DateTime::now(), ]); Authorization::skip(fn () => $dbForProject->createDocument('users', $user)); @@ -1586,6 +1590,7 @@ App::post('/v1/account/sessions/anonymous') 'tokens' => null, 'memberships' => null, 'search' => $userId, + 'accessedAt' => DateTime::now(), ]); Authorization::skip(fn() => $dbForProject->createDocument('users', $user)); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index a6fc90d97..d017ef1c0 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -96,7 +96,8 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e 'sessions' => null, 'tokens' => null, 'memberships' => null, - 'search' => implode(' ', [$userId, $email, $phone, $name]) + 'search' => implode(' ', [$userId, $email, $phone, $name]), + 'accessedAt' => DateTime::now(), ])); } catch (Duplicate $th) { throw new Exception(Exception::USER_ALREADY_EXISTS); diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index d225496a6..2c6c46857 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -408,6 +408,7 @@ class AccountCustomClientTest extends Scope ])); $this->assertEquals($response['headers']['status-code'], 200); $this->assertArrayHasKey('accessedAt', $response['body']); + $this->assertNotEmpty($response['body']['accessedAt']); /**