mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge remote-tracking branch 'origin/fix-datetime-attributes' into refactor-permissions-inc-queries-update-datetime-fixes
# Conflicts: # app/config/collections.php # app/controllers/api/databases.php # app/controllers/api/projects.php # app/controllers/api/teams.php # composer.json # composer.lock # tests/e2e/Services/Account/AccountBase.php # tests/e2e/Services/Databases/DatabasesBase.php # tests/e2e/Services/Functions/FunctionsCustomServerTest.php # tests/e2e/Services/Projects/ProjectsConsoleClientTest.php # tests/e2e/Services/Storage/StorageBase.php # tests/e2e/Services/Storage/StorageCustomClientTest.php # tests/e2e/Services/Storage/StorageCustomServerTest.php # tests/e2e/Services/Teams/TeamsBase.php # tests/e2e/Services/Webhooks/WebhooksBase.php # tests/e2e/Services/Webhooks/WebhooksCustomClientTest.php # tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php # tests/unit/Auth/AuthTest.php
This commit is contained in:
commit
6a5de3e0b6
63 files changed
+872
-579
No files matched your search
+40
-40
@@ -827,10 +827,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('updated'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -965,12 +965,12 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('expire'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => 0,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
@@ -1164,10 +1164,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('passwordUpdate'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1186,10 +1186,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('registration'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1349,10 +1349,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('expire'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1454,10 +1454,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('providerAccessTokenExpiry'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1487,10 +1487,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('expire'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1792,10 +1792,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('invited'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1803,10 +1803,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('joined'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1973,10 +1973,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('schedulePrevious'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -1984,10 +1984,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('scheduleNext'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -2186,10 +2186,10 @@ $collections = [
|
||||
'attributes' => [
|
||||
[
|
||||
'$id' => ID::custom('startTime'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -2197,10 +2197,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('endTime'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -2461,10 +2461,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('issueDate'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -2472,10 +2472,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('renewDate'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -2505,10 +2505,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('updated'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
@@ -2660,11 +2660,11 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('time'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => false,
|
||||
'required' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
@@ -2701,16 +2701,16 @@ $collections = [
|
||||
'orders' => [Database::ORDER_DESC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_metric'),
|
||||
'$id' => ID::custom('_key_period_time'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['metric'],
|
||||
'attributes' => ['period', 'time'],
|
||||
'lengths' => [],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_metric_period'),
|
||||
'$id' => ID::custom('_key_metric_period_time'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['metric', 'period'],
|
||||
'attributes' => ['metric', 'period', 'time'],
|
||||
'lengths' => [],
|
||||
'orders' => [Database::ORDER_DESC],
|
||||
],
|
||||
@@ -2735,10 +2735,10 @@ $collections = [
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('timestamp'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
|
||||
@@ -26,6 +26,7 @@ use Utopia\Audit\Audit as EventAudit;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Permission;
|
||||
@@ -108,8 +109,8 @@ App::post('/v1/account')
|
||||
'emailVerification' => false,
|
||||
'status' => true,
|
||||
'password' => Auth::passwordHash($password),
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => DateTime::now(),
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
'prefs' => new \stdClass(),
|
||||
@@ -182,7 +183,7 @@ App::post('/v1/account/sessions/email')
|
||||
|
||||
$detector = new Detector($request->getUserAgent('UNKNOWN'));
|
||||
$record = $geodb->get($request->getIP());
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG);
|
||||
$secret = Auth::tokenGenerator();
|
||||
$session = new Document(array_merge(
|
||||
[
|
||||
@@ -192,7 +193,7 @@ App::post('/v1/account/sessions/email')
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => $email,
|
||||
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
|
||||
'expire' => $expiry,
|
||||
'expire' => $expire,
|
||||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
@@ -224,8 +225,8 @@ App::post('/v1/account/sessions/email')
|
||||
}
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($profile->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($profile->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
;
|
||||
|
||||
@@ -495,8 +496,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
'emailVerification' => true,
|
||||
'status' => true, // Email should already be authenticated by OAuth2 provider
|
||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||
'passwordUpdate' => 0,
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => null,
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
'prefs' => new \stdClass(),
|
||||
@@ -519,7 +520,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
$detector = new Detector($request->getUserAgent('UNKNOWN'));
|
||||
$record = $geodb->get($request->getIP());
|
||||
$secret = Auth::tokenGenerator();
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG);
|
||||
|
||||
$session = new Document(array_merge([
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
'userId' => ID::custom($user->getId()),
|
||||
@@ -528,9 +530,9 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
'providerUid' => $oauth2ID,
|
||||
'providerAccessToken' => $accessToken,
|
||||
'providerRefreshToken' => $refreshToken,
|
||||
'providerAccessTokenExpiry' => \time() + (int) $accessTokenExpiry,
|
||||
'providerAccessTokenExpiry' => DateTime::addSeconds(new \DateTime(), (int)$accessTokenExpiry),
|
||||
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
|
||||
'expire' => $expiry,
|
||||
'expire' => $expire,
|
||||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
@@ -597,8 +599,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
$response
|
||||
->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
||||
->addHeader('Pragma', 'no-cache')
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->redirect($state['success'])
|
||||
;
|
||||
});
|
||||
@@ -665,8 +667,8 @@ App::post('/v1/account/sessions/magic-url')
|
||||
'emailVerification' => false,
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'passwordUpdate' => 0,
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => null,
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'prefs' => new \stdClass(),
|
||||
'sessions' => null,
|
||||
@@ -677,8 +679,7 @@ App::post('/v1/account/sessions/magic-url')
|
||||
}
|
||||
|
||||
$loginSecret = Auth::tokenGenerator();
|
||||
|
||||
$expire = \time() + Auth::TOKEN_EXPIRATION_CONFIRM;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM);
|
||||
|
||||
$token = new Document([
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -781,7 +782,8 @@ App::put('/v1/account/sessions/magic-url')
|
||||
$detector = new Detector($request->getUserAgent('UNKNOWN'));
|
||||
$record = $geodb->get($request->getIP());
|
||||
$secret = Auth::tokenGenerator();
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG);
|
||||
|
||||
$session = new Document(array_merge(
|
||||
[
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -789,7 +791,7 @@ App::put('/v1/account/sessions/magic-url')
|
||||
'userInternalId' => $user->getInternalId(),
|
||||
'provider' => Auth::SESSION_PROVIDER_MAGIC_URL,
|
||||
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
|
||||
'expire' => $expiry,
|
||||
'expire' => $expire,
|
||||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
@@ -841,8 +843,8 @@ App::put('/v1/account/sessions/magic-url')
|
||||
$protocol = $request->getProtocol();
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
;
|
||||
|
||||
@@ -917,8 +919,8 @@ App::post('/v1/account/sessions/phone')
|
||||
'phoneVerification' => false,
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'passwordUpdate' => 0,
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => null,
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'prefs' => new \stdClass(),
|
||||
'sessions' => null,
|
||||
@@ -929,8 +931,7 @@ App::post('/v1/account/sessions/phone')
|
||||
}
|
||||
|
||||
$secret = $phone->generateSecretDigits();
|
||||
|
||||
$expire = \time() + Auth::TOKEN_EXPIRATION_PHONE;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_PHONE);
|
||||
|
||||
$token = new Document([
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -1020,7 +1021,8 @@ App::put('/v1/account/sessions/phone')
|
||||
$detector = new Detector($request->getUserAgent('UNKNOWN'));
|
||||
$record = $geodb->get($request->getIP());
|
||||
$secret = Auth::tokenGenerator();
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG);
|
||||
|
||||
$session = new Document(array_merge(
|
||||
[
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -1028,7 +1030,7 @@ App::put('/v1/account/sessions/phone')
|
||||
'userInternalId' => $user->getInternalId(),
|
||||
'provider' => Auth::SESSION_PROVIDER_PHONE,
|
||||
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
|
||||
'expire' => $expiry,
|
||||
'expire' => $expire,
|
||||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
@@ -1078,8 +1080,8 @@ App::put('/v1/account/sessions/phone')
|
||||
$protocol = $request->getProtocol();
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
;
|
||||
|
||||
@@ -1152,8 +1154,8 @@ App::post('/v1/account/sessions/anonymous')
|
||||
'emailVerification' => false,
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'passwordUpdate' => 0,
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => null,
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'name' => null,
|
||||
'prefs' => new \stdClass(),
|
||||
@@ -1168,7 +1170,8 @@ App::post('/v1/account/sessions/anonymous')
|
||||
$detector = new Detector($request->getUserAgent('UNKNOWN'));
|
||||
$record = $geodb->get($request->getIP());
|
||||
$secret = Auth::tokenGenerator();
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG);
|
||||
|
||||
$session = new Document(array_merge(
|
||||
[
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -1176,7 +1179,7 @@ App::post('/v1/account/sessions/anonymous')
|
||||
'userInternalId' => $user->getInternalId(),
|
||||
'provider' => Auth::SESSION_PROVIDER_ANONYMOUS,
|
||||
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
|
||||
'expire' => $expiry,
|
||||
'expire' => $expire,
|
||||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
@@ -1213,8 +1216,8 @@ App::post('/v1/account/sessions/anonymous')
|
||||
}
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
;
|
||||
|
||||
@@ -1515,7 +1518,7 @@ App::patch('/v1/account/password')
|
||||
->action(function (string $password, string $oldPassword, Response $response, Document $user, Database $dbForProject, Audit $audits, Stats $usage, Event $events) {
|
||||
|
||||
// Check old password only if its an existing user.
|
||||
if ($user->getAttribute('passwordUpdate') !== 0 && !Auth::passwordVerify($oldPassword, $user->getAttribute('password'))) { // Double check user password
|
||||
if ($user->getAttribute('passwordUpdate') !== null && !Auth::passwordVerify($oldPassword, $user->getAttribute('password'))) { // Double check user password
|
||||
throw new Exception('Invalid credentials', 401, Exception::USER_INVALID_CREDENTIALS);
|
||||
}
|
||||
|
||||
@@ -1524,7 +1527,7 @@ App::patch('/v1/account/password')
|
||||
$user->getId(),
|
||||
$user
|
||||
->setAttribute('password', Auth::passwordHash($password))
|
||||
->setAttribute('passwordUpdate', \time())
|
||||
->setAttribute('passwordUpdate', DateTime::now())
|
||||
);
|
||||
|
||||
$audits
|
||||
@@ -1855,7 +1858,7 @@ App::patch('/v1/account/sessions/:sessionId')
|
||||
$session
|
||||
->setAttribute('providerAccessToken', $oauth2->getAccessToken(''))
|
||||
->setAttribute('providerRefreshToken', $oauth2->getRefreshToken(''))
|
||||
->setAttribute('providerAccessTokenExpiry', \time() + (int) $oauth2->getAccessTokenExpiry(''));
|
||||
->setAttribute('providerAccessTokenExpiry', DateTime::addSeconds(new \DateTime(), (int)$oauth2->getAccessTokenExpiry('')));
|
||||
|
||||
$dbForProject->updateDocument('sessions', $sessionId, $session);
|
||||
|
||||
@@ -1998,7 +2001,7 @@ App::post('/v1/account/recovery')
|
||||
throw new Exception('Invalid credentials. User is blocked', 401, Exception::USER_BLOCKED);
|
||||
}
|
||||
|
||||
$expire = \time() + Auth::TOKEN_EXPIRATION_RECOVERY;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_RECOVERY);
|
||||
|
||||
$secret = Auth::tokenGenerator();
|
||||
$recovery = new Document([
|
||||
@@ -2102,7 +2105,7 @@ App::put('/v1/account/recovery')
|
||||
|
||||
$profile = $dbForProject->updateDocument('users', $profile->getId(), $profile
|
||||
->setAttribute('password', Auth::passwordHash($password))
|
||||
->setAttribute('passwordUpdate', \time())
|
||||
->setAttribute('passwordUpdate', DateTime::now())
|
||||
->setAttribute('emailVerification', true));
|
||||
|
||||
$recoveryDocument = $dbForProject->getDocument('tokens', $recovery);
|
||||
@@ -2160,10 +2163,8 @@ App::post('/v1/account/verification')
|
||||
$roles = Authorization::getRoles();
|
||||
$isPrivilegedUser = Auth::isPrivilegedUser($roles);
|
||||
$isAppUser = Auth::isAppUser($roles);
|
||||
|
||||
$verificationSecret = Auth::tokenGenerator();
|
||||
|
||||
$expire = \time() + Auth::TOKEN_EXPIRATION_CONFIRM;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM);
|
||||
|
||||
$verification = new Document([
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -2317,11 +2318,9 @@ App::post('/v1/account/verification/phone')
|
||||
$roles = Authorization::getRoles();
|
||||
$isPrivilegedUser = Auth::isPrivilegedUser($roles);
|
||||
$isAppUser = Auth::isAppUser($roles);
|
||||
|
||||
$verificationSecret = Auth::tokenGenerator();
|
||||
|
||||
$secret = $phone->generateSecretDigits();
|
||||
$expire = \time() + Auth::TOKEN_EXPIRATION_CONFIRM;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_CONFIRM);
|
||||
|
||||
$verification = new Document([
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
|
||||
@@ -5,6 +5,7 @@ use Utopia\App;
|
||||
use Appwrite\Event\Delete;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Utopia\Audit\Audit;
|
||||
use Utopia\Database\Validator\DatetimeValidator;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\FloatValidator;
|
||||
@@ -16,6 +17,7 @@ use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\JSON;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Adapter\MariaDB;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
@@ -1284,6 +1286,48 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/boolea
|
||||
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_BOOLEAN);
|
||||
});
|
||||
|
||||
|
||||
App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/datetime')
|
||||
->alias('/v1/database/collections/:collectionId/attributes/datetime', ['databaseId' => 'default'])
|
||||
->desc('Create datetime Attribute')
|
||||
->groups(['api', 'database'])
|
||||
->label('event', 'databases.[databaseId].collections.[collectionId].attributes.[attributeId].create')
|
||||
->label('scope', 'collections.write')
|
||||
->label('sdk.namespace', 'databases')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||
->label('sdk.method', 'createDatetimeAttribute')
|
||||
->label('sdk.description', '/docs/references/databases/create-datetime-attribute.md')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_ATTRIBUTE_DATETIME)
|
||||
->param('databaseId', '', new UID(), 'Database ID.')
|
||||
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection).')
|
||||
->param('key', '', new Key(), 'Attribute Key.')
|
||||
->param('required', null, new Boolean(), 'Is attribute required?')
|
||||
->param('default', null, new DatetimeValidator(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
|
||||
->param('array', false, new Boolean(), 'Is attribute an array?', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('database')
|
||||
->inject('audits')
|
||||
->inject('usage')
|
||||
->inject('events')
|
||||
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, EventAudit $audits, Stats $usage, Event $events) {
|
||||
|
||||
$attribute = createAttribute($databaseId, $collectionId, new Document([
|
||||
'key' => $key,
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'size' => 0,
|
||||
'required' => $required,
|
||||
'default' => $default,
|
||||
'array' => $array,
|
||||
'filters' => ['datetime']
|
||||
]), $response, $dbForProject, $database, $audits, $events, $usage);
|
||||
|
||||
$response->dynamic($attribute, Response::MODEL_ATTRIBUTE_DATETIME);
|
||||
});
|
||||
|
||||
|
||||
App::get('/v1/databases/:databaseId/collections/:collectionId/attributes')
|
||||
->alias('/v1/database/collections/:collectionId/attributes', ['databaseId' => 'default'])
|
||||
->desc('List Attributes')
|
||||
@@ -1338,6 +1382,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', [
|
||||
Response::MODEL_ATTRIBUTE_DATETIME,
|
||||
Response::MODEL_ATTRIBUTE_BOOLEAN,
|
||||
Response::MODEL_ATTRIBUTE_INTEGER,
|
||||
Response::MODEL_ATTRIBUTE_FLOAT,
|
||||
@@ -1377,6 +1422,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key')
|
||||
$format = $attribute->getAttribute('format');
|
||||
|
||||
$model = match ($type) {
|
||||
Database::VAR_DATETIME => Response::MODEL_ATTRIBUTE_DATETIME,
|
||||
Database::VAR_BOOLEAN => Response::MODEL_ATTRIBUTE_BOOLEAN,
|
||||
Database::VAR_INTEGER => Response::MODEL_ATTRIBUTE_INTEGER,
|
||||
Database::VAR_FLOAT => Response::MODEL_ATTRIBUTE_FLOAT,
|
||||
@@ -1461,6 +1507,7 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key
|
||||
$format = $attribute->getAttribute('format');
|
||||
|
||||
$model = match ($type) {
|
||||
Database::VAR_DATETIME => Response::MODEL_ATTRIBUTE_DATETIME,
|
||||
Database::VAR_BOOLEAN => Response::MODEL_ATTRIBUTE_BOOLEAN,
|
||||
Database::VAR_INTEGER => Response::MODEL_ATTRIBUTE_INTEGER,
|
||||
Database::VAR_FLOAT => Response::MODEL_ATTRIBUTE_FLOAT,
|
||||
@@ -1555,7 +1602,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
|
||||
|
||||
$oldAttributes[] = [
|
||||
'key' => '$createdAt',
|
||||
'type' => 'integer',
|
||||
'type' => 'string',
|
||||
'status' => 'available',
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
@@ -1566,7 +1613,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
|
||||
|
||||
$oldAttributes[] = [
|
||||
'key' => '$updatedAt',
|
||||
'type' => 'integer',
|
||||
'type' => 'string',
|
||||
'status' => 'available',
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
@@ -2504,11 +2551,11 @@ App::get('/v1/databases/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
// TODO@kodumbeats explore performance if query is ordered by time ASC
|
||||
// Added 3'rd level to Index [period, metric, time] because of order by.
|
||||
$stats[$metric] = array_reverse($stats[$metric]);
|
||||
}
|
||||
});
|
||||
@@ -2616,7 +2663,7 @@ App::get('/v1/databases/:databaseId/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
@@ -2729,7 +2776,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use Appwrite\Task\Validator\Cron;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Validator\ArrayList;
|
||||
@@ -77,8 +78,8 @@ App::post('/v1/functions')
|
||||
'vars' => $vars,
|
||||
'events' => $events,
|
||||
'schedule' => $schedule,
|
||||
'schedulePrevious' => 0,
|
||||
'scheduleNext' => 0,
|
||||
'schedulePrevious' => null,
|
||||
'scheduleNext' => null,
|
||||
'timeout' => $timeout,
|
||||
'search' => implode(' ', [$functionId, $name, $runtime]),
|
||||
]));
|
||||
@@ -260,7 +261,7 @@ App::get('/v1/functions/:functionId/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
@@ -312,8 +313,8 @@ App::put('/v1/functions/:functionId')
|
||||
}
|
||||
|
||||
$original = $function->getAttribute('schedule', '');
|
||||
$cron = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? new CronExpression($schedule) : null;
|
||||
$next = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
|
||||
$cron = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
|
||||
$next = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? DateTime::format($cron->getNextRunDate()) : null;
|
||||
|
||||
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
|
||||
'execute' => $execute,
|
||||
@@ -321,7 +322,7 @@ App::put('/v1/functions/:functionId')
|
||||
'vars' => $vars,
|
||||
'events' => $events,
|
||||
'schedule' => $schedule,
|
||||
'scheduleNext' => (int)$next,
|
||||
'scheduleNext' => $next,
|
||||
'timeout' => $timeout,
|
||||
'search' => implode(' ', [$functionId, $name, $function->getAttribute('runtime')]),
|
||||
])));
|
||||
@@ -333,9 +334,8 @@ App::put('/v1/functions/:functionId')
|
||||
->setFunction($function)
|
||||
->setType('schedule')
|
||||
->setUser($user)
|
||||
->setProject($project);
|
||||
|
||||
$functionEvent->schedule($next);
|
||||
->setProject($project)
|
||||
->schedule(new \DateTime($next));
|
||||
}
|
||||
|
||||
$eventsInstance->setParam('functionId', $function->getId());
|
||||
@@ -385,11 +385,11 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId')
|
||||
|
||||
$schedule = $function->getAttribute('schedule', '');
|
||||
$cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
|
||||
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
|
||||
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? DateTime::format($cron->getNextRunDate()) : null;
|
||||
|
||||
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
|
||||
'deployment' => $deployment->getId(),
|
||||
'scheduleNext' => (int)$next,
|
||||
'scheduleNext' => $next,
|
||||
])));
|
||||
|
||||
if ($next) { // Init first schedule
|
||||
@@ -397,8 +397,8 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId')
|
||||
$functionEvent
|
||||
->setType('schedule')
|
||||
->setFunction($function)
|
||||
->setProject($project);
|
||||
$functionEvent->schedule($next);
|
||||
->setProject($project)
|
||||
->schedule(new \DateTime($next));
|
||||
}
|
||||
|
||||
$events
|
||||
@@ -935,7 +935,6 @@ App::post('/v1/functions/:functionId/executions')
|
||||
|
||||
/** Execute function */
|
||||
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
|
||||
$executionResponse = [];
|
||||
try {
|
||||
$executionResponse = $executor->createExecution(
|
||||
projectId: $project->getId(),
|
||||
@@ -956,12 +955,12 @@ App::post('/v1/functions/:functionId/executions')
|
||||
$execution->setAttribute('stderr', $executionResponse['stderr']);
|
||||
$execution->setAttribute('time', $executionResponse['time']);
|
||||
} catch (\Throwable $th) {
|
||||
$endtime = \microtime(true);
|
||||
$time = $endtime - $execution->getCreatedAt();
|
||||
$execution->setAttribute('time', $time);
|
||||
$execution->setAttribute('status', 'failed');
|
||||
$execution->setAttribute('statusCode', $th->getCode());
|
||||
$execution->setAttribute('stderr', $th->getMessage());
|
||||
$interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt()));
|
||||
$execution
|
||||
->setAttribute('time', (float)$interval->format('%s.%f'))
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('statusCode', $th->getCode())
|
||||
->setAttribute('stderr', $th->getMessage());
|
||||
Console::error($th->getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,12 @@ use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Role;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\DatetimeValidator;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Domains\Domain;
|
||||
use Utopia\Registry\Registry;
|
||||
@@ -29,7 +31,6 @@ use Appwrite\Extend\Exception;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\Hostname;
|
||||
use Utopia\Validator\Integer;
|
||||
use Utopia\Validator\Range;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
@@ -323,7 +324,7 @@ App::get('/v1/projects/:projectId/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
@@ -832,10 +833,10 @@ App::post('/v1/projects/:projectId/keys')
|
||||
->param('projectId', null, new UID(), 'Project unique ID.')
|
||||
->param('name', null, new Text(128), 'Key name. Max length: 128 chars.')
|
||||
->param('scopes', null, new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.')
|
||||
->param('expire', 0, new Integer(), 'Key expiration time in Unix timestamp. Use 0 for unlimited expiration.', true)
|
||||
->param('expire', null, new DatetimeValidator(), 'Expiration time in DateTime. Use null for unlimited expiration.', true)
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $projectId, string $name, array $scopes, int $expire, Response $response, Database $dbForConsole) {
|
||||
->action(function (string $projectId, string $name, array $scopes, ?string $expire, Response $response, Database $dbForConsole) {
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
@@ -945,10 +946,10 @@ App::put('/v1/projects/:projectId/keys/:keyId')
|
||||
->param('keyId', null, new UID(), 'Key unique ID.')
|
||||
->param('name', null, new Text(128), 'Key name. Max length: 128 chars.')
|
||||
->param('scopes', null, new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.')
|
||||
->param('expire', 0, new Integer(), 'Key expiration time in Unix timestamp. Use 0 for unlimited expiration.', true)
|
||||
->param('expire', null, new DatetimeValidator(), 'Expiration time in DateTime. Use null for unlimited expiration.', true)
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $projectId, string $keyId, string $name, array $scopes, int $expire, Response $response, Database $dbForConsole) {
|
||||
->action(function (string $projectId, string $keyId, string $name, array $scopes, ?string $expire, Response $response, Database $dbForConsole) {
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
@@ -1266,7 +1267,7 @@ App::post('/v1/projects/:projectId/domains')
|
||||
],
|
||||
'projectInternalId' => $project->getInternalId(),
|
||||
'projectId' => $project->getId(),
|
||||
'updated' => \time(),
|
||||
'updated' => DateTime::now(),
|
||||
'domain' => $domain->get(),
|
||||
'tld' => $domain->getSuffix(),
|
||||
'registerable' => $domain->getRegisterable(),
|
||||
|
||||
@@ -16,6 +16,7 @@ use Utopia\Cache\Cache;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Exception\Duplicate as DuplicateException;
|
||||
use Utopia\Database\Exception\Structure as StructureException;
|
||||
@@ -1480,7 +1481,7 @@ App::get('/v1/storage/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
@@ -1589,7 +1590,7 @@ App::get('/v1/storage/:bucketId/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Appwrite\Utopia\Response;
|
||||
use MaxMind\Db\Reader;
|
||||
use Utopia\App;
|
||||
use Utopia\Audit\Audit;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
@@ -24,6 +25,7 @@ use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Role;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\Key;
|
||||
@@ -89,8 +91,8 @@ App::post('/v1/teams')
|
||||
'teamId' => ID::custom($team->getId()),
|
||||
'teamInternalId' => ID::custom($team->getInternalId()),
|
||||
'roles' => $roles,
|
||||
'invited' => \time(),
|
||||
'joined' => \time(),
|
||||
'invited' => DateTime::now(),
|
||||
'joined' => DateTime::now(),
|
||||
'confirm' => true,
|
||||
'secret' => '',
|
||||
'search' => implode(' ', [$membershipId, $user->getId()])
|
||||
@@ -355,8 +357,8 @@ App::post('/v1/teams/:teamId/memberships')
|
||||
* team invite and OAuth to allow password updates without an
|
||||
* old password
|
||||
*/
|
||||
'passwordUpdate' => 0,
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => null,
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
'prefs' => new \stdClass(),
|
||||
@@ -393,8 +395,8 @@ App::post('/v1/teams/:teamId/memberships')
|
||||
'teamId' => ID::custom($team->getId()),
|
||||
'teamInternalId' => ID::custom($team->getInternalId()),
|
||||
'roles' => $roles,
|
||||
'invited' => \time(),
|
||||
'joined' => ($isPrivilegedUser || $isAppUser) ? \time() : 0,
|
||||
'invited' => DateTime::now(),
|
||||
'joined' => ($isPrivilegedUser || $isAppUser) ? DateTime::now() : null,
|
||||
'confirm' => ($isPrivilegedUser || $isAppUser),
|
||||
'secret' => Auth::hash($secret),
|
||||
'search' => implode(' ', [$membershipId, $invitee->getId()])
|
||||
@@ -707,7 +709,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status')
|
||||
}
|
||||
|
||||
$membership // Attach user to team
|
||||
->setAttribute('joined', \time())
|
||||
->setAttribute('joined', DateTime::now())
|
||||
->setAttribute('confirm', true)
|
||||
;
|
||||
|
||||
@@ -721,7 +723,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status')
|
||||
|
||||
$detector = new Detector($request->getUserAgent('UNKNOWN'));
|
||||
$record = $geodb->get($request->getIP());
|
||||
$expiry = \time() + Auth::TOKEN_EXPIRATION_LOGIN_LONG;
|
||||
$expire = DateTime::addSeconds(new \DateTime(), Auth::TOKEN_EXPIRATION_LOGIN_LONG);
|
||||
$secret = Auth::tokenGenerator();
|
||||
$session = new Document(array_merge([
|
||||
'$id' => ID::custom($dbForProject->getId()),
|
||||
@@ -730,7 +732,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status')
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => $user->getAttribute('email'),
|
||||
'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak
|
||||
'expire' => $expiry,
|
||||
'expire' => $expire,
|
||||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
@@ -767,8 +769,8 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status')
|
||||
}
|
||||
|
||||
$response
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
->addCookie(Auth::$cookieName . '_legacy', Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, null)
|
||||
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), (new \DateTime($expire))->getTimestamp(), '/', Config::getParam('cookieDomain'), ('https' == $protocol), true, Config::getParam('cookieSamesite'))
|
||||
;
|
||||
|
||||
$response->dynamic(
|
||||
|
||||
@@ -20,6 +20,7 @@ use Utopia\Database\Role;
|
||||
use Utopia\Locale\Locale;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Database\Database;
|
||||
@@ -69,8 +70,8 @@ App::post('/v1/users')
|
||||
'emailVerification' => false,
|
||||
'status' => true,
|
||||
'password' => Auth::passwordHash($password),
|
||||
'passwordUpdate' => \time(),
|
||||
'registration' => \time(),
|
||||
'passwordUpdate' => DateTime::now(),
|
||||
'registration' => DateTime::now(),
|
||||
'reset' => false,
|
||||
'name' => $name,
|
||||
'prefs' => new \stdClass(),
|
||||
@@ -556,7 +557,7 @@ App::patch('/v1/users/:userId/password')
|
||||
|
||||
$user
|
||||
->setAttribute('password', Auth::passwordHash($password))
|
||||
->setAttribute('passwordUpdate', \time());
|
||||
->setAttribute('passwordUpdate', DateTime::now());
|
||||
|
||||
$user = $dbForProject->updateDocument('users', $user->getId(), $user);
|
||||
|
||||
@@ -932,7 +933,7 @@ App::get('/v1/users/usage')
|
||||
};
|
||||
$stats[$metric][] = [
|
||||
'value' => 0,
|
||||
'date' => ($stats[$metric][$last]['date'] ?? \time()) - $diff, // time of last metric minus period
|
||||
'date' => DateTime::addSeconds(new \DateTime($stats[$metric][$last]['date'] ?? null), -1 * $diff),
|
||||
];
|
||||
$backfill--;
|
||||
}
|
||||
|
||||
@@ -292,9 +292,9 @@ App::init()
|
||||
$role = Auth::USER_ROLE_APP;
|
||||
$scopes = \array_merge($roles[$role]['scopes'], $key->getAttribute('scopes', []));
|
||||
|
||||
$expire = $key->getAttribute('expire', 0);
|
||||
$expire = $key->getAttribute('expire');
|
||||
|
||||
if (!empty($expire) && $expire < \time()) {
|
||||
if (!empty($expire) && $expire < DateTime::now()) {
|
||||
throw new AppwriteException('Project key expired', 401, AppwriteException:: PROJECT_KEY_EXPIRED);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,13 +74,16 @@ App::init()
|
||||
}
|
||||
|
||||
$abuse = new Abuse($timeLimit);
|
||||
$remaining = $timeLimit->remaining();
|
||||
$limit = $timeLimit->limit();
|
||||
$time = (new DateTime($timeLimit->time()))->getTimestamp() + $route->getLabel('abuse-time', 3600);
|
||||
|
||||
if ($timeLimit->limit() && ($timeLimit->remaining() < $closestLimit || is_null($closestLimit))) {
|
||||
$closestLimit = $timeLimit->remaining();
|
||||
if ($limit && ($remaining < $closestLimit || is_null($closestLimit))) {
|
||||
$closestLimit = $remaining;
|
||||
$response
|
||||
->addHeader('X-RateLimit-Limit', $timeLimit->limit())
|
||||
->addHeader('X-RateLimit-Remaining', $timeLimit->remaining())
|
||||
->addHeader('X-RateLimit-Reset', $timeLimit->time() + $route->getLabel('abuse-time', 3600))
|
||||
->addHeader('X-RateLimit-Limit', $limit)
|
||||
->addHeader('X-RateLimit-Remaining', $remaining)
|
||||
->addHeader('X-RateLimit-Reset', $time)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -181,7 +184,6 @@ App::init()
|
||||
|
||||
default:
|
||||
throw new Exception('Unsupported authentication route', 501, Exception::USER_AUTH_METHOD_UNSUPPORTED);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+17
-11
@@ -12,6 +12,7 @@ use Swoole\Runtime;
|
||||
use Swoole\Timer;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Logger\Logger;
|
||||
use Utopia\Orchestration\Adapter\DockerCLI;
|
||||
@@ -188,8 +189,9 @@ App::post('/v1/runtimes')
|
||||
$containerId = '';
|
||||
$stdout = '';
|
||||
$stderr = '';
|
||||
$startTime = \time();
|
||||
$endTime = 0;
|
||||
$startTime = DateTime::now();
|
||||
$startTimeUnix = (new \DateTime($startTime))->getTimestamp();
|
||||
$endTimeUnix = 0;
|
||||
$orchestration = $orchestrationPool->get();
|
||||
|
||||
$secret = \bin2hex(\random_bytes(16));
|
||||
@@ -198,8 +200,8 @@ App::post('/v1/runtimes')
|
||||
$activeRuntimes->set($runtimeId, [
|
||||
'id' => $containerId,
|
||||
'name' => $runtimeId,
|
||||
'created' => $startTime,
|
||||
'updated' => $endTime,
|
||||
'created' => $startTimeUnix,
|
||||
'updated' => $endTimeUnix,
|
||||
'status' => 'pending',
|
||||
'key' => $secret,
|
||||
]);
|
||||
@@ -262,7 +264,7 @@ App::post('/v1/runtimes')
|
||||
labels: [
|
||||
'openruntimes-id' => $runtimeId,
|
||||
'openruntimes-type' => 'runtime',
|
||||
'openruntimes-created' => strval($startTime),
|
||||
'openruntimes-created' => strval($startTimeUnix),
|
||||
'openruntimes-runtime' => $runtime,
|
||||
],
|
||||
workdir: $workdir,
|
||||
@@ -319,28 +321,32 @@ App::post('/v1/runtimes')
|
||||
$stdout = 'Build Successful!';
|
||||
}
|
||||
|
||||
$endTime = \time();
|
||||
$endTime = DateTime::now();
|
||||
$endTimeUnix = (new \DateTime($endTime))->getTimestamp();
|
||||
$duration = $endTimeUnix - $startTimeUnix;
|
||||
|
||||
$container = array_merge($container, [
|
||||
'status' => 'ready',
|
||||
'response' => \mb_strcut($stdout, 0, 1000000), // Limit to 1MB
|
||||
'stderr' => \mb_strcut($stderr, 0, 1000000), // Limit to 1MB
|
||||
'startTime' => $startTime,
|
||||
'endTime' => $endTime,
|
||||
'duration' => $endTime - $startTime,
|
||||
'duration' => $duration,
|
||||
]);
|
||||
|
||||
|
||||
if (!$remove) {
|
||||
$activeRuntimes->set($runtimeId, [
|
||||
'id' => $containerId,
|
||||
'name' => $runtimeId,
|
||||
'created' => $startTime,
|
||||
'updated' => $endTime,
|
||||
'status' => 'Up ' . \round($endTime - $startTime, 2) . 's',
|
||||
'created' => $startTimeUnix,
|
||||
'updated' => $endTimeUnix,
|
||||
'status' => 'Up ' . \round($duration, 2) . 's',
|
||||
'key' => $secret,
|
||||
]);
|
||||
}
|
||||
|
||||
Console::success('Build Stage completed in ' . ($endTime - $startTime) . ' seconds');
|
||||
Console::success('Build Stage completed in ' . ($duration) . ' seconds');
|
||||
} catch (Throwable $th) {
|
||||
Console::error('Build failed: ' . $th->getMessage() . $stdout);
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ const APP_VERSION_STABLE = '0.15.3';
|
||||
const APP_DATABASE_ATTRIBUTE_EMAIL = 'email';
|
||||
const APP_DATABASE_ATTRIBUTE_ENUM = 'enum';
|
||||
const APP_DATABASE_ATTRIBUTE_IP = 'ip';
|
||||
const APP_DATABASE_ATTRIBUTE_DATETIME = 'datetime';
|
||||
const APP_DATABASE_ATTRIBUTE_URL = 'url';
|
||||
const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange';
|
||||
const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange';
|
||||
|
||||
+6
-6
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Appwrite\Auth\Auth;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Messaging\Adapter\Realtime;
|
||||
use Appwrite\Network\Validator\Origin;
|
||||
use Appwrite\Utopia\Response;
|
||||
@@ -16,6 +15,7 @@ use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Cache\Adapter\Redis as RedisCache;
|
||||
use Utopia\Cache\Cache;
|
||||
use Utopia\Database\Adapter\MariaDB;
|
||||
@@ -150,7 +150,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume
|
||||
'$collection' => ID::custom('realtime'),
|
||||
'$permissions' => [],
|
||||
'container' => $containerId,
|
||||
'timestamp' => time(),
|
||||
'timestamp' => DateTime::now(),
|
||||
'value' => '{}'
|
||||
]);
|
||||
|
||||
@@ -180,7 +180,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume
|
||||
[$database, $returnDatabase] = getDatabase($register, '_console');
|
||||
|
||||
$statsDocument
|
||||
->setAttribute('timestamp', time())
|
||||
->setAttribute('timestamp', DateTime::now())
|
||||
->setAttribute('value', json_encode($payload));
|
||||
|
||||
Authorization::skip(fn () => $database->updateDocument('realtime', $statsDocument->getId(), $statsDocument));
|
||||
@@ -208,7 +208,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
|
||||
$payload = [];
|
||||
|
||||
$list = Authorization::skip(fn () => $database->find('realtime', [
|
||||
new Query('timestamp', Query::TYPE_GREATER, [(time() - 15)])
|
||||
new Query('timestamp', Query::TYPE_GREATER, [DateTime::addSeconds(new \DateTime(), -15)])
|
||||
]));
|
||||
|
||||
/**
|
||||
@@ -235,7 +235,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
|
||||
'data' => [
|
||||
'events' => ['stats.connections'],
|
||||
'channels' => ['project'],
|
||||
'timestamp' => time(),
|
||||
'timestamp' => DateTime::now(),
|
||||
'payload' => [
|
||||
$projectId => $payload[$projectId]
|
||||
]
|
||||
@@ -262,7 +262,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats,
|
||||
'data' => [
|
||||
'events' => ['test.event'],
|
||||
'channels' => ['tests'],
|
||||
'timestamp' => time(),
|
||||
'timestamp' => DateTime::now(),
|
||||
'payload' => $payload
|
||||
]
|
||||
];
|
||||
|
||||
+13
-10
@@ -11,6 +11,7 @@ use Utopia\Cache\Cache;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Adapter\MariaDB;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Cache\Adapter\Redis as RedisCache;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
@@ -57,7 +58,7 @@ $cli
|
||||
{
|
||||
(new Delete())
|
||||
->setType(DELETE_TYPE_EXECUTIONS)
|
||||
->setTimestamp(time() - $interval)
|
||||
->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * $interval))
|
||||
->trigger();
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ $cli
|
||||
{
|
||||
(new Delete())
|
||||
->setType(DELETE_TYPE_ABUSE)
|
||||
->setTimestamp(time() - $interval)
|
||||
->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * $interval))
|
||||
->trigger();
|
||||
}
|
||||
|
||||
@@ -73,7 +74,7 @@ $cli
|
||||
{
|
||||
(new Delete())
|
||||
->setType(DELETE_TYPE_AUDIT)
|
||||
->setTimestamp(time() - $interval)
|
||||
->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * $interval))
|
||||
->trigger();
|
||||
}
|
||||
|
||||
@@ -81,8 +82,8 @@ $cli
|
||||
{
|
||||
(new Delete())
|
||||
->setType(DELETE_TYPE_USAGE)
|
||||
->setTimestamp1d(time() - $interval1d)
|
||||
->setTimestamp30m(time() - $interval30m)
|
||||
->setDateTime1d(DateTime::addSeconds(new \DateTime(), -1 * $interval1d))
|
||||
->setDateTime30m(DateTime::addSeconds(new \DateTime(), -1 * $interval30m))
|
||||
->trigger();
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ $cli
|
||||
{
|
||||
(new Delete())
|
||||
->setType(DELETE_TYPE_REALTIME)
|
||||
->setTimestamp(time() - 60)
|
||||
->setDatetime(DateTime::addSeconds(new \DateTime(), -60))
|
||||
->trigger();
|
||||
}
|
||||
|
||||
@@ -98,16 +99,17 @@ $cli
|
||||
{
|
||||
(new Delete())
|
||||
->setType(DELETE_TYPE_SESSIONS)
|
||||
->setTimestamp(time() - Auth::TOKEN_EXPIRATION_LOGIN_LONG)
|
||||
->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * Auth::TOKEN_EXPIRATION_LOGIN_LONG))
|
||||
->trigger();
|
||||
}
|
||||
|
||||
function renewCertificates($dbForConsole)
|
||||
{
|
||||
$time = date('d-m-Y H:i:s', time());
|
||||
$time = DateTime::now();
|
||||
|
||||
$certificates = $dbForConsole->find('certificates', [
|
||||
new Query('attempts', Query::TYPE_LESSEREQUAL, [5]), // Maximum 5 attempts
|
||||
new Query('renewDate', Query::TYPE_LESSEREQUAL, [\time()]) // includes 60 days cooldown (we have 30 days to renew)
|
||||
new Query('renewDate', Query::TYPE_LESSEREQUAL, [$time]) // includes 60 days cooldown (we have 30 days to renew)
|
||||
], 200); // Limit 200 comes from LetsEncrypt (300 orders per 3 hours, keeping some for new domains)
|
||||
|
||||
|
||||
@@ -138,7 +140,8 @@ $cli
|
||||
Console::loop(function () use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention30m, $usageStatsRetention1d) {
|
||||
$database = getConsoleDB();
|
||||
|
||||
$time = date('d-m-Y H:i:s', time());
|
||||
$time = DateTime::now();
|
||||
|
||||
Console::info("[{$time}] Notifying workers with maintenance tasks every {$interval} seconds");
|
||||
notifyDeleteExecutionLogs($executionLogsRetention);
|
||||
notifyDeleteAbuseLogs($abuseLogsRetention);
|
||||
|
||||
@@ -6,7 +6,8 @@ use Appwrite\Resque\Worker;
|
||||
use Appwrite\Utopia\Response\Model\Deployment;
|
||||
use Cron\CronExpression;
|
||||
use Executor\Executor;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Storage\Storage;
|
||||
@@ -75,8 +76,7 @@ class BuildsV1 extends Worker
|
||||
}
|
||||
|
||||
$buildId = $deployment->getAttribute('buildId', '');
|
||||
$build = null;
|
||||
$startTime = \time();
|
||||
$startTime = DateTime::now();
|
||||
if (empty($buildId)) {
|
||||
$buildId = $dbForProject->getId();
|
||||
$build = $dbForProject->createDocument('builds', new Document([
|
||||
@@ -91,7 +91,7 @@ class BuildsV1 extends Worker
|
||||
'sourceType' => App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL),
|
||||
'stdout' => '',
|
||||
'stderr' => '',
|
||||
'endTime' => 0,
|
||||
'endTime' => null,
|
||||
'duration' => 0
|
||||
]));
|
||||
$deployment->setAttribute('buildId', $buildId);
|
||||
@@ -183,13 +183,14 @@ class BuildsV1 extends Worker
|
||||
/** Update function schedule */
|
||||
$schedule = $function->getAttribute('schedule', '');
|
||||
$cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
|
||||
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
|
||||
$function->setAttribute('scheduleNext', (int)$next);
|
||||
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? DateTime::format($cron->getNextRunDate()) : null;
|
||||
$function->setAttribute('scheduleNext', $next);
|
||||
$function = $dbForProject->updateDocument('functions', $function->getId(), $function);
|
||||
} catch (\Throwable $th) {
|
||||
$endtime = \time();
|
||||
$endtime = DateTime::now();
|
||||
$interval = (new \DateTime($endtime))->diff(new \DateTime($startTime));
|
||||
$build->setAttribute('endTime', $endtime);
|
||||
$build->setAttribute('duration', $endtime - $startTime);
|
||||
$build->setAttribute('duration', $interval->format('%s'));
|
||||
$build->setAttribute('status', 'failed');
|
||||
$build->setAttribute('stderr', $th->getMessage());
|
||||
Console::error($th->getMessage());
|
||||
|
||||
@@ -7,8 +7,8 @@ use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Domains\Domain;
|
||||
|
||||
require_once __DIR__ . '/../init.php';
|
||||
@@ -116,7 +116,7 @@ class CertificatesV1 extends Worker
|
||||
// Update certificate info stored in database
|
||||
$certificate->setAttribute('renewDate', $this->getRenewDate($domain->get()));
|
||||
$certificate->setAttribute('attempts', 0);
|
||||
$certificate->setAttribute('issueDate', \time());
|
||||
$certificate->setAttribute('issueDate', DateTime::now());
|
||||
} catch (Throwable $e) {
|
||||
// Set exception as log in certificate document
|
||||
$certificate->setAttribute('log', $e->getMessage());
|
||||
@@ -129,7 +129,7 @@ class CertificatesV1 extends Worker
|
||||
$this->notifyError($domain->get(), $e->getMessage(), $attempts);
|
||||
} finally {
|
||||
// All actions result in new updatedAt date
|
||||
$certificate->setAttribute('updated', \time());
|
||||
$certificate->setAttribute('updated', DateTime::now());
|
||||
|
||||
// Save all changes we made to certificate document into database
|
||||
$this->saveCertificateDocument($domain->get(), $certificate);
|
||||
@@ -296,10 +296,9 @@ class CertificatesV1 extends Worker
|
||||
{
|
||||
$certPath = APP_STORAGE_CERTIFICATES . '/' . $domain . '/cert.pem';
|
||||
$certData = openssl_x509_parse(file_get_contents($certPath));
|
||||
$validTo = $certData['validTo_time_t'] ?? 0;
|
||||
$expiryInAdvance = (60 * 60 * 24 * 30); // 30 days
|
||||
|
||||
return $validTo - $expiryInAdvance;
|
||||
$validTo = $certData['validTo_time_t'] ?? null;
|
||||
$dt = (new \DateTime())->setTimestamp($validTo);
|
||||
return DateTime::addSeconds($dt, -60 * 60 * 24 * 30); // -30 days
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +398,7 @@ class CertificatesV1 extends Worker
|
||||
], 1000);
|
||||
|
||||
foreach ($domains as $domainDocument) {
|
||||
$domainDocument->setAttribute('updated', \time());
|
||||
$domainDocument->setAttribute('updated', DateTime::now());
|
||||
$domainDocument->setAttribute('certificateId', $certificateId);
|
||||
|
||||
$this->dbForConsole->updateDocument('domains', $domainDocument->getId(), $domainDocument);
|
||||
|
||||
+45
-43
@@ -4,7 +4,6 @@ use Utopia\App;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Appwrite\Resque\Worker;
|
||||
use Executor\Executor;
|
||||
use Utopia\Storage\Device\Local;
|
||||
@@ -70,17 +69,17 @@ class DeletesV1 extends Worker
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_EXECUTIONS:
|
||||
$this->deleteExecutionLogs($this->args['timestamp']);
|
||||
$this->deleteExecutionLogs($this->args['datetime']);
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_AUDIT:
|
||||
$timestamp = $this->args['timestamp'] ?? 0;
|
||||
$document = new Document($this->args['document'] ?? []);
|
||||
|
||||
if (!empty($timestamp)) {
|
||||
$this->deleteAuditLogs($this->args['timestamp']);
|
||||
$datetime = $this->args['datetime'] ?? null;
|
||||
if (!empty($datetime)) {
|
||||
$this->deleteAuditLogs($datetime);
|
||||
}
|
||||
|
||||
$document = new Document($this->args['document'] ?? []);
|
||||
|
||||
if (!$document->isEmpty()) {
|
||||
$this->deleteAuditLogsByResource('document/' . $document->getId(), $project->getId());
|
||||
}
|
||||
@@ -88,15 +87,15 @@ class DeletesV1 extends Worker
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_ABUSE:
|
||||
$this->deleteAbuseLogs($this->args['timestamp']);
|
||||
$this->deleteAbuseLogs($this->args['datetime']);
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_REALTIME:
|
||||
$this->deleteRealtimeUsage($this->args['timestamp']);
|
||||
$this->deleteRealtimeUsage($this->args['datetime']);
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_SESSIONS:
|
||||
$this->deleteExpiredSessions($this->args['timestamp']);
|
||||
$this->deleteExpiredSessions($this->args['datetime']);
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_CERTIFICATES:
|
||||
@@ -105,7 +104,7 @@ class DeletesV1 extends Worker
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_USAGE:
|
||||
$this->deleteUsageStats($this->args['timestamp1d'], $this->args['timestamp30m']);
|
||||
$this->deleteUsageStats($this->args['dateTime1d'], $this->args['dateTime30m']);
|
||||
break;
|
||||
default:
|
||||
Console::error('No delete operation for type: ' . $type);
|
||||
@@ -161,21 +160,21 @@ class DeletesV1 extends Worker
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp1d
|
||||
* @param int $timestamp30m
|
||||
* @param string $datetime1d
|
||||
* @param string $datetime30m
|
||||
*/
|
||||
protected function deleteUsageStats(int $timestamp1d, int $timestamp30m)
|
||||
protected function deleteUsageStats(string $datetime1d, string $datetime30m)
|
||||
{
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp1d, $timestamp30m) {
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($datetime1d, $datetime30m) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
// Delete Usage stats
|
||||
$this->deleteByGroup('stats', [
|
||||
new Query('time', Query::TYPE_LESSER, [$timestamp1d]),
|
||||
new Query('time', Query::TYPE_LESSER, [$datetime1d]),
|
||||
new Query('period', Query::TYPE_EQUAL, ['1d']),
|
||||
], $dbForProject);
|
||||
|
||||
$this->deleteByGroup('stats', [
|
||||
new Query('time', Query::TYPE_LESSER, [$timestamp30m]),
|
||||
new Query('time', Query::TYPE_LESSER, [$datetime30m]),
|
||||
new Query('period', Query::TYPE_EQUAL, ['30m']),
|
||||
], $dbForProject);
|
||||
});
|
||||
@@ -256,62 +255,62 @@ class DeletesV1 extends Worker
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
*/
|
||||
protected function deleteExecutionLogs(int $timestamp): void
|
||||
protected function deleteExecutionLogs(string $datetime): void
|
||||
{
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($datetime) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
// Delete Executions
|
||||
$this->deleteByGroup('executions', [
|
||||
new Query('$createdAt', Query::TYPE_LESSER, [$timestamp])
|
||||
new Query('$createdAt', Query::TYPE_LESSER, [$datetime])
|
||||
], $dbForProject);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
*/
|
||||
protected function deleteExpiredSessions(int $timestamp): void
|
||||
protected function deleteExpiredSessions(string $datetime): void
|
||||
{
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($datetime) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
// Delete Sessions
|
||||
$this->deleteByGroup('sessions', [
|
||||
new Query('expire', Query::TYPE_LESSER, [$timestamp])
|
||||
new Query('expire', Query::TYPE_LESSER, [$datetime])
|
||||
], $dbForProject);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
*/
|
||||
protected function deleteRealtimeUsage(int $timestamp): void
|
||||
protected function deleteRealtimeUsage(string $datetime): void
|
||||
{
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($datetime) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
// Delete Dead Realtime Logs
|
||||
$this->deleteByGroup('realtime', [
|
||||
new Query('timestamp', Query::TYPE_LESSER, [$timestamp])
|
||||
new Query('timestamp', Query::TYPE_LESSER, [$datetime])
|
||||
], $dbForProject);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function deleteAbuseLogs(int $timestamp): void
|
||||
protected function deleteAbuseLogs(string $datetime): void
|
||||
{
|
||||
if ($timestamp == 0) {
|
||||
throw new Exception('Failed to delete audit logs. No timestamp provided');
|
||||
if (empty($datetime)) {
|
||||
throw new Exception('Failed to delete audit logs. No datetime provided');
|
||||
}
|
||||
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($datetime) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
$timeLimit = new TimeLimit("", 0, 1, $dbForProject);
|
||||
$abuse = new Abuse($timeLimit);
|
||||
|
||||
$status = $abuse->cleanup($timestamp);
|
||||
$status = $abuse->cleanup($datetime);
|
||||
if (!$status) {
|
||||
throw new Exception('Failed to delete Abuse logs for project ' . $projectId);
|
||||
}
|
||||
@@ -319,17 +318,19 @@ class DeletesV1 extends Worker
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function deleteAuditLogs(int $timestamp): void
|
||||
protected function deleteAuditLogs(string $datetime): void
|
||||
{
|
||||
if ($timestamp == 0) {
|
||||
throw new Exception('Failed to delete audit logs. No timestamp provided');
|
||||
if (empty($datetime)) {
|
||||
throw new Exception('Failed to delete audit logs. No datetime provided');
|
||||
}
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($timestamp) {
|
||||
|
||||
$this->deleteForProjectIds(function (string $projectId) use ($datetime) {
|
||||
$dbForProject = $this->getProjectDB($projectId);
|
||||
$audit = new Audit($dbForProject);
|
||||
$status = $audit->cleanup($timestamp);
|
||||
$status = $audit->cleanup($datetime);
|
||||
if (!$status) {
|
||||
throw new Exception('Failed to delete Audit logs for project' . $projectId);
|
||||
}
|
||||
@@ -337,7 +338,8 @@ class DeletesV1 extends Worker
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp
|
||||
* @param string $resource
|
||||
* @param string $projectId
|
||||
*/
|
||||
protected function deleteAuditLogsByResource(string $resource, string $projectId): void
|
||||
{
|
||||
|
||||
@@ -12,8 +12,8 @@ use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
|
||||
require_once __DIR__ . '/../init.php';
|
||||
|
||||
@@ -147,31 +147,26 @@ class FunctionsV1 extends Worker
|
||||
}
|
||||
|
||||
$cron = new CronExpression($function->getAttribute('schedule'));
|
||||
$next = (int) $cron->getNextRunDate()->format('U');
|
||||
$next = DateTime::format($cron->getNextRunDate());
|
||||
|
||||
$function
|
||||
->setAttribute('scheduleNext', $next)
|
||||
->setAttribute('schedulePrevious', \time());
|
||||
->setAttribute('schedulePrevious', DateTime::now());
|
||||
|
||||
$function = $database->updateDocument(
|
||||
'functions',
|
||||
$function->getId(),
|
||||
$function->setAttribute('scheduleNext', (int) $next)
|
||||
$function->setAttribute('scheduleNext', $next)
|
||||
);
|
||||
|
||||
if ($function === false) {
|
||||
throw new Exception('Function update failed.');
|
||||
}
|
||||
|
||||
$reschedule = new Func();
|
||||
$reschedule
|
||||
->setFunction($function)
|
||||
->setType('schedule')
|
||||
->setUser($user)
|
||||
->setProject($project);
|
||||
|
||||
// Async task reschedule
|
||||
$reschedule->schedule($next);
|
||||
->setProject($project)
|
||||
->schedule(new \DateTime($next));
|
||||
;
|
||||
|
||||
$this->execute(
|
||||
project: $project,
|
||||
@@ -295,10 +290,9 @@ class FunctionsV1 extends Worker
|
||||
->setAttribute('stderr', $executionResponse['stderr'])
|
||||
->setAttribute('time', $executionResponse['time']);
|
||||
} catch (\Throwable $th) {
|
||||
$endtime = \microtime(true);
|
||||
$time = $endtime - $execution->getCreatedAt();
|
||||
$interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt()));
|
||||
$execution
|
||||
->setAttribute('time', $time)
|
||||
->setAttribute('time', (float)$interval->format('%s.%f'))
|
||||
->setAttribute('status', 'failed')
|
||||
->setAttribute('statusCode', $th->getCode())
|
||||
->setAttribute('stderr', $th->getMessage());
|
||||
|
||||
+3
-2
@@ -103,7 +103,7 @@ services:
|
||||
- ./phpunit.xml:/usr/src/code/phpunit.xml
|
||||
- ./tests:/usr/src/code/tests
|
||||
- ./app:/usr/src/code/app
|
||||
# - ./vendor/utopia/database:/usr/src/code/vendor/utopia/database
|
||||
- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
- ./docs:/usr/src/code/docs
|
||||
- ./public:/usr/src/code/public
|
||||
- ./src:/usr/src/code/src
|
||||
@@ -330,7 +330,7 @@ services:
|
||||
volumes:
|
||||
- ./app:/usr/src/code/app
|
||||
- ./src:/usr/src/code/src
|
||||
# - ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
depends_on:
|
||||
- redis
|
||||
- mariadb
|
||||
@@ -561,6 +561,7 @@ services:
|
||||
volumes:
|
||||
- ./app:/usr/src/code/app
|
||||
- ./src:/usr/src/code/src
|
||||
#- ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database
|
||||
depends_on:
|
||||
- redis
|
||||
environment:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Auth;
|
||||
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
|
||||
class Auth
|
||||
@@ -206,7 +207,7 @@ class Auth
|
||||
$token->isSet('expire') &&
|
||||
$token->getAttribute('type') == $type &&
|
||||
$token->getAttribute('secret') === self::hash($secret) &&
|
||||
$token->getAttribute('expire') >= \time()
|
||||
$token->getAttribute('expire') >= DateTime::now()
|
||||
) {
|
||||
return (string)$token->getId();
|
||||
}
|
||||
@@ -225,7 +226,7 @@ class Auth
|
||||
$token->isSet('expire') &&
|
||||
$token->getAttribute('type') == Auth::TOKEN_TYPE_PHONE &&
|
||||
$token->getAttribute('secret') === $secret &&
|
||||
$token->getAttribute('expire') >= \time()
|
||||
$token->getAttribute('expire') >= DateTime::now()
|
||||
) {
|
||||
return (string) $token->getId();
|
||||
}
|
||||
@@ -251,9 +252,9 @@ class Auth
|
||||
$session->isSet('expire') &&
|
||||
$session->isSet('provider') &&
|
||||
$session->getAttribute('secret') === self::hash($secret) &&
|
||||
$session->getAttribute('expire') >= \time()
|
||||
$session->getAttribute('expire') >= DateTime::now()
|
||||
) {
|
||||
return (string)$session->getId();
|
||||
return $session->getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ use Utopia\Database\Document;
|
||||
class Delete extends Event
|
||||
{
|
||||
protected string $type = '';
|
||||
protected ?int $timestamp = null;
|
||||
protected ?int $timestamp1d = null;
|
||||
protected ?int $timestamp30m = null;
|
||||
protected ?Document $document = null;
|
||||
protected ?string $datetime = null;
|
||||
protected ?string $datetime1d = null;
|
||||
protected ?string $datetime30m = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -42,41 +42,38 @@ class Delete extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timestamp.
|
||||
* set Datetime.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
* @return self
|
||||
*/
|
||||
public function setTimestamp(int $timestamp): self
|
||||
public function setDatetime(string $datetime): self
|
||||
{
|
||||
$this->timestamp = $timestamp;
|
||||
|
||||
$this->datetime = $datetime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timestamp for 1 day interval.
|
||||
* Set datetime for 1 day interval.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
* @return self
|
||||
*/
|
||||
public function setTimestamp1d(int $timestamp): self
|
||||
public function setDatetime1d(string $datetime): self
|
||||
{
|
||||
$this->timestamp1d = $timestamp;
|
||||
|
||||
$this->datetime1d = $datetime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets timestamp for 30m interval.
|
||||
* Sets datetime for 30m interval.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* @param string $datetime
|
||||
* @return self
|
||||
*/
|
||||
public function setTimestamp30m(int $timestamp): self
|
||||
public function setDatetime30m(string $datetime): self
|
||||
{
|
||||
$this->timestamp30m = $timestamp;
|
||||
|
||||
$this->datetime30m = $datetime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -115,9 +112,9 @@ class Delete extends Event
|
||||
'project' => $this->project,
|
||||
'type' => $this->type,
|
||||
'document' => $this->document,
|
||||
'timestamp' => $this->timestamp,
|
||||
'timestamp1d' => $this->timestamp1d,
|
||||
'timestamp30m' => $this->timestamp30m
|
||||
'datetime' => $this->datetime,
|
||||
'datetime1d' => $this->datetime1d,
|
||||
'datetime30m' => $this->datetime30m
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Appwrite\Messaging\Adapter;
|
||||
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Appwrite\Messaging\Adapter;
|
||||
use Utopia\App;
|
||||
@@ -146,7 +147,7 @@ class Realtime extends Adapter
|
||||
'data' => [
|
||||
'events' => $events,
|
||||
'channels' => $channels,
|
||||
'timestamp' => time(),
|
||||
'timestamp' => DateTime::now(),
|
||||
'payload' => $payload
|
||||
]
|
||||
]));
|
||||
|
||||
@@ -191,12 +191,10 @@ class Usage
|
||||
protected array $periods = [
|
||||
[
|
||||
'key' => '30m',
|
||||
'multiplier' => 1800,
|
||||
'startTime' => '-24 hours',
|
||||
],
|
||||
[
|
||||
'key' => '1d',
|
||||
'multiplier' => 86400,
|
||||
'startTime' => '-90 days',
|
||||
],
|
||||
];
|
||||
@@ -213,7 +211,7 @@ class Usage
|
||||
* Create or update each metric in the stats collection for the given project
|
||||
*
|
||||
* @param string $projectId
|
||||
* @param int $time
|
||||
* @param string $time
|
||||
* @param string $period
|
||||
* @param string $metric
|
||||
* @param int $value
|
||||
@@ -221,7 +219,7 @@ class Usage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createOrUpdateMetric(string $projectId, int $time, string $period, string $metric, int $value, int $type): void
|
||||
private function createOrUpdateMetric(string $projectId, string $time, string $period, string $metric, int $value, int $type): void
|
||||
{
|
||||
$id = \md5("{$time}_{$period}_{$metric}");
|
||||
$this->database->setNamespace('_console');
|
||||
@@ -246,6 +244,8 @@ class Usage
|
||||
$document->setAttribute('value', $value)
|
||||
);
|
||||
}
|
||||
|
||||
$time = (new \DateTime($time))->getTimestamp(); //todo: What about this timestamp?
|
||||
$this->latestTime[$metric][$period] = $time;
|
||||
} catch (\Exception $e) { // if projects are deleted this might fail
|
||||
if (is_callable($this->errorHandler)) {
|
||||
@@ -311,7 +311,7 @@ class Usage
|
||||
}
|
||||
}
|
||||
|
||||
$time = \strtotime($point['time']);
|
||||
$time = $point['time']; //todo: check is this datetime format?
|
||||
$value = (!empty($point['value'])) ? $point['value'] : 0;
|
||||
|
||||
$this->createOrUpdateMetric(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Appwrite\Stats;
|
||||
|
||||
use Exception;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
|
||||
@@ -12,6 +13,7 @@ class UsageDB extends Usage
|
||||
$this->database = $database;
|
||||
$this->errorHandler = $errorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or Update Mertic
|
||||
* Create or update each metric in the stats collection for the given project
|
||||
@@ -21,12 +23,22 @@ class UsageDB extends Usage
|
||||
* @param int $value
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function createOrUpdateMetric(string $projectId, string $metric, int $value): void
|
||||
{
|
||||
foreach ($this->periods as $options) {
|
||||
$period = $options['key'];
|
||||
$time = (int) (floor(time() / $options['multiplier']) * $options['multiplier']);
|
||||
$date = new \DateTime();
|
||||
if ($period === '30m') {
|
||||
$minutes = $date->format('i') >= '30' ? "30" : "00";
|
||||
$time = $date->format('Y-m-d H:' . $minutes . ':00');
|
||||
} elseif ($period === '1d') {
|
||||
$time = $date->format('Y-m-d 00:00:00');
|
||||
} else {
|
||||
throw new Exception("Period type not found", 500);
|
||||
}
|
||||
|
||||
$id = \md5("{$time}_{$period}_{$metric}");
|
||||
$this->database->setNamespace('_' . $projectId);
|
||||
|
||||
@@ -48,7 +60,7 @@ class UsageDB extends Usage
|
||||
$document->setAttribute('value', $value)
|
||||
);
|
||||
}
|
||||
} catch (\Exception$e) { // if projects are deleted this might fail
|
||||
} catch (Exception$e) { // if projects are deleted this might fail
|
||||
if (is_callable($this->errorHandler)) {
|
||||
call_user_func($this->errorHandler, $e, "sync_project_{$projectId}_metric_{$metric}");
|
||||
} else {
|
||||
@@ -80,7 +92,7 @@ class UsageDB extends Usage
|
||||
while ($sum === $limit) {
|
||||
try {
|
||||
$results = $this->database->find($collection, $queries, $limit, cursor:$latestDocument);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
if (is_callable($this->errorHandler)) {
|
||||
call_user_func($this->errorHandler, $e, "fetch_documents_project_{$projectId}_collection_{$collection}");
|
||||
return;
|
||||
@@ -113,6 +125,7 @@ class UsageDB extends Usage
|
||||
* @param string $metric
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
private function sum(string $projectId, string $collection, string $attribute, string $metric): int
|
||||
{
|
||||
@@ -122,7 +135,7 @@ class UsageDB extends Usage
|
||||
$sum = (int) $this->database->sum($collection, $attribute);
|
||||
$this->createOrUpdateMetric($projectId, $metric, $sum);
|
||||
return $sum;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
if (is_callable($this->errorHandler)) {
|
||||
call_user_func($this->errorHandler, $e, "fetch_sum_project_{$projectId}_collection_{$collection}");
|
||||
} else {
|
||||
@@ -140,6 +153,7 @@ class UsageDB extends Usage
|
||||
* @param string $metric
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
private function count(string $projectId, string $collection, string $metric): int
|
||||
{
|
||||
@@ -149,7 +163,7 @@ class UsageDB extends Usage
|
||||
$count = $this->database->count($collection);
|
||||
$this->createOrUpdateMetric($projectId, $metric, $count);
|
||||
return $count;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
if (is_callable($this->errorHandler)) {
|
||||
call_user_func($this->errorHandler, $e, "fetch_count_project_{$projectId}_collection_{$collection}");
|
||||
} else {
|
||||
|
||||
@@ -20,6 +20,7 @@ use Appwrite\Utopia\Response\Model\AttributeEmail;
|
||||
use Appwrite\Utopia\Response\Model\AttributeEnum;
|
||||
use Appwrite\Utopia\Response\Model\AttributeIP;
|
||||
use Appwrite\Utopia\Response\Model\AttributeURL;
|
||||
use Appwrite\Utopia\Response\Model\AttributeDatetime;
|
||||
use Appwrite\Utopia\Response\Model\BaseList;
|
||||
use Appwrite\Utopia\Response\Model\Collection;
|
||||
use Appwrite\Utopia\Response\Model\Database;
|
||||
@@ -116,6 +117,7 @@ class Response extends SwooleResponse
|
||||
public const MODEL_ATTRIBUTE_ENUM = 'attributeEnum';
|
||||
public const MODEL_ATTRIBUTE_IP = 'attributeIp';
|
||||
public const MODEL_ATTRIBUTE_URL = 'attributeUrl';
|
||||
public const MODEL_ATTRIBUTE_DATETIME = 'attributeDatetime';
|
||||
|
||||
// Users
|
||||
public const MODEL_USER = 'user';
|
||||
@@ -255,6 +257,7 @@ class Response extends SwooleResponse
|
||||
->setModel(new AttributeEnum())
|
||||
->setModel(new AttributeIP())
|
||||
->setModel(new AttributeURL())
|
||||
->setModel(new AttributeDatetime())
|
||||
->setModel(new Index())
|
||||
->setModel(new ModelDocument())
|
||||
->setModel(new Log())
|
||||
|
||||
@@ -11,6 +11,7 @@ abstract class Model
|
||||
public const TYPE_FLOAT = 'double';
|
||||
public const TYPE_BOOLEAN = 'boolean';
|
||||
public const TYPE_JSON = 'json';
|
||||
public const TYPE_DATETIME = 'datetime';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class AttributeDatetime extends Attribute
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this
|
||||
->addRule('key', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Attribute Key.',
|
||||
'default' => '',
|
||||
'example' => 'birthDay',
|
||||
])
|
||||
->addRule('type', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Attribute type.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('format', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Datetime format.',
|
||||
'default' => APP_DATABASE_ATTRIBUTE_DATETIME,
|
||||
'example' => APP_DATABASE_ATTRIBUTE_DATETIME,
|
||||
'array' => false,
|
||||
'require' => true,
|
||||
])
|
||||
->addRule('default', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Default value for attribute when not provided. Only null is optional',
|
||||
'default' => null,
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
'array' => false,
|
||||
'require' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public array $conditions = [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'format' => \APP_DATABASE_ATTRIBUTE_DATETIME
|
||||
];
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'AttributeDatetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_ATTRIBUTE_DATETIME;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ class AttributeList extends Model
|
||||
Response::MODEL_ATTRIBUTE_ENUM,
|
||||
Response::MODEL_ATTRIBUTE_URL,
|
||||
Response::MODEL_ATTRIBUTE_IP,
|
||||
Response::MODEL_ATTRIBUTE_DATETIME,
|
||||
Response::MODEL_ATTRIBUTE_STRING // needs to be last, since its condition would dominate any other string attribute
|
||||
],
|
||||
'description' => 'List of attributes.',
|
||||
|
||||
@@ -17,16 +17,16 @@ class Bucket extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Bucket creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Bucket creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Bucket update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Bucket update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$permissions', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -16,12 +16,6 @@ class Build extends Model
|
||||
'default' => '',
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('startTime', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'The deployment creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
])
|
||||
->addRule('deploymentId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The deployment that created this build.',
|
||||
@@ -51,11 +45,17 @@ class Build extends Model
|
||||
'default' => '',
|
||||
'example' => '',
|
||||
])
|
||||
->addRule('startTime', [
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'The deployment creation date in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('endTime', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'The time the build was finished in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 0,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'The time the build was finished in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('duration', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
|
||||
@@ -17,16 +17,16 @@ class Collection extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Collection creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Collection creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Collection update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Collection update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$permissions', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -68,6 +68,7 @@ class Collection extends Model
|
||||
Response::MODEL_ATTRIBUTE_ENUM,
|
||||
Response::MODEL_ATTRIBUTE_URL,
|
||||
Response::MODEL_ATTRIBUTE_IP,
|
||||
Response::MODEL_ATTRIBUTE_DATETIME,
|
||||
Response::MODEL_ATTRIBUTE_STRING, // needs to be last, since its condition would dominate any other string attribute
|
||||
],
|
||||
'description' => 'Collection attributes.',
|
||||
|
||||
@@ -17,16 +17,16 @@ class Deployment extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Deployment creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Deployment creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Deployment update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Deployment update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('resourceId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -43,16 +43,16 @@ class Document extends Any
|
||||
'example' => '5e5ea5c15117e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Document creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Document creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Document update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Document update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$permissions', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -22,16 +22,16 @@ class Domain extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Domain creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Domain creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Domain update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Domain update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('domain', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -17,16 +17,16 @@ class Execution extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Execution creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Execution creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Execution update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Execution upate date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$roles', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -23,16 +23,16 @@ class File extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'File creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'File creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'File update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'File update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$permissions', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -19,16 +19,16 @@ class Func extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Function creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Function creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Function update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Function update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('execute', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -81,16 +81,16 @@ class Func extends Model
|
||||
'example' => '5 4 * * *',
|
||||
])
|
||||
->addRule('scheduleNext', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Function next scheduled execution date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981292,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Function next scheduled execution date in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('schedulePrevious', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Function next scheduled execution date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981237,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Function Previous scheduled execution date in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('timeout', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
|
||||
@@ -22,16 +22,16 @@ class Key extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Key creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Key creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Key update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Key update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -40,10 +40,10 @@ class Key extends Model
|
||||
'example' => 'My API Key',
|
||||
])
|
||||
->addRule('expire', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Key expiration in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => '1653990687',
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Key expiration date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('scopes', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -47,10 +47,10 @@ class Log extends Model
|
||||
'example' => '127.0.0.1',
|
||||
])
|
||||
->addRule('time', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Log creation time in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Log creation date in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('osCode', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -17,16 +17,16 @@ class Membership extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Membership creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Membership creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Membership update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Membership update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -59,16 +59,16 @@ class Membership extends Model
|
||||
'example' => 'VIP',
|
||||
])
|
||||
->addRule('invited', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Date, the user has been invited to join the team in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Date, the user has been invited to join the team in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('joined', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Date, the user has accepted the invitation to join the team in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Date, the user has accepted the invitation to join the team in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('confirm', [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
|
||||
@@ -22,16 +22,16 @@ class Platform extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Project creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Platform creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Project update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Platform update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -24,16 +24,16 @@ class Project extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Project creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Project creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Project update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Project update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -17,10 +17,10 @@ class Session extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Session creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Session creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -29,10 +29,10 @@ class Session extends Model
|
||||
'example' => '5e5bb8c16897e',
|
||||
])
|
||||
->addRule('expire', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Session expiration date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Session expiration date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('provider', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -53,10 +53,10 @@ class Session extends Model
|
||||
'example' => 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3',
|
||||
])
|
||||
->addRule('providerAccessTokenExpiry', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Date, the Unix timestamp of when the access token expires.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'The date of when the access token expires in datetime format.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('providerRefreshToken', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -17,16 +17,16 @@ class Team extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Team creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Team creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Team update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Team update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -17,10 +17,10 @@ class Token extends Model
|
||||
'example' => 'bb8ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Token creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Token creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('userId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -35,10 +35,10 @@ class Token extends Model
|
||||
'example' => '',
|
||||
])
|
||||
->addRule('expire', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Token expiration date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@ class User extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'User creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'User creation date in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'User update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'User update date in Datetime.',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -36,10 +36,10 @@ class User extends Model
|
||||
'example' => 'John Doe',
|
||||
])
|
||||
->addRule('registration', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'User registration date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'User registration date in Datetime.',
|
||||
'default' => null,
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
@@ -48,10 +48,10 @@ class User extends Model
|
||||
'example' => true,
|
||||
])
|
||||
->addRule('passwordUpdate', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Unix timestamp of the most recent password update',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Datetime of the most recent password update',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('email', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -22,16 +22,16 @@ class Webhook extends Model
|
||||
'example' => '5e5ea5c16897e',
|
||||
])
|
||||
->addRule('$createdAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Webhook creation date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Webhook creation date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('$updatedAt', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Webhook update date in Unix timestamp.',
|
||||
'default' => 0,
|
||||
'example' => 1592981250,
|
||||
'type' => self::TYPE_DATETIME,
|
||||
'description' => 'Webhook update date in Datetime',
|
||||
'default' => '',
|
||||
'example' => '1975-12-06 13:30:59',
|
||||
])
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Account;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\DateTime;
|
||||
|
||||
trait AccountBase
|
||||
{
|
||||
@@ -32,7 +33,7 @@ trait AccountBase
|
||||
$this->assertEquals($response['headers']['status-code'], 201);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
$this->assertEquals($response['body']['name'], $name);
|
||||
|
||||
@@ -196,7 +197,7 @@ trait AccountBase
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
$this->assertEquals($response['body']['name'], $name);
|
||||
|
||||
@@ -341,7 +342,7 @@ trait AccountBase
|
||||
$this->assertIsNumeric($response['body']['total']);
|
||||
$this->assertContains($response['body']['logs'][1]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]);
|
||||
$this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP));
|
||||
$this->assertIsString($response['body']['logs'][1]['time']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['logs'][1]['time']));
|
||||
|
||||
$this->assertEquals('Windows', $response['body']['logs'][1]['osName']);
|
||||
$this->assertEquals('WIN', $response['body']['logs'][1]['osCode']);
|
||||
@@ -363,7 +364,7 @@ trait AccountBase
|
||||
|
||||
$this->assertContains($response['body']['logs'][2]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]);
|
||||
$this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP));
|
||||
$this->assertIsString($response['body']['logs'][2]['time']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['logs'][2]['time']));
|
||||
|
||||
$this->assertEquals('Windows', $response['body']['logs'][2]['osName']);
|
||||
$this->assertEquals('WIN', $response['body']['logs'][2]['osCode']);
|
||||
@@ -475,7 +476,7 @@ trait AccountBase
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
$this->assertEquals($response['body']['name'], $newName);
|
||||
|
||||
@@ -541,7 +542,7 @@ trait AccountBase
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
||||
@@ -631,7 +632,7 @@ trait AccountBase
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $newEmail);
|
||||
|
||||
/**
|
||||
@@ -673,7 +674,7 @@ trait AccountBase
|
||||
$this->assertEquals($response['headers']['status-code'], 201);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $data['email']);
|
||||
$this->assertEquals($response['body']['name'], $data['name']);
|
||||
|
||||
@@ -815,7 +816,7 @@ trait AccountBase
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEmpty($response['body']['secret']);
|
||||
$this->assertIsNumeric($response['body']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['expire']));
|
||||
|
||||
$lastEmail = $this->getLastEmail();
|
||||
|
||||
@@ -824,9 +825,7 @@ trait AccountBase
|
||||
$this->assertEquals('Account Verification', $lastEmail['subject']);
|
||||
|
||||
$verification = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
||||
|
||||
$expireTime = strpos($lastEmail['text'], 'expire=' . $response['body']['expire'], 0);
|
||||
|
||||
$expireTime = strpos($lastEmail['text'], 'expire=' . urlencode($response['body']['expire']), 0);
|
||||
$this->assertNotFalse($expireTime);
|
||||
|
||||
$secretTest = strpos($lastEmail['text'], 'secret=' . $response['body']['secret'], 0);
|
||||
@@ -1119,7 +1118,7 @@ trait AccountBase
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEmpty($response['body']['secret']);
|
||||
$this->assertIsNumeric($response['body']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['expire']));
|
||||
|
||||
$lastEmail = $this->getLastEmail();
|
||||
|
||||
@@ -1129,7 +1128,7 @@ trait AccountBase
|
||||
|
||||
$recovery = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
||||
|
||||
$expireTime = strpos($lastEmail['text'], 'expire=' . $response['body']['expire'], 0);
|
||||
$expireTime = strpos($lastEmail['text'], 'expire=' . urlencode($response['body']['expire']), 0);
|
||||
|
||||
$this->assertNotFalse($expireTime);
|
||||
|
||||
@@ -1272,7 +1271,7 @@ trait AccountBase
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEmpty($response['body']['secret']);
|
||||
$this->assertIsNumeric($response['body']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['expire']));
|
||||
|
||||
$userId = $response['body']['userId'];
|
||||
|
||||
@@ -1282,7 +1281,7 @@ trait AccountBase
|
||||
|
||||
$token = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256);
|
||||
|
||||
$expireTime = strpos($lastEmail['text'], 'expire=' . $response['body']['expire'], 0);
|
||||
$expireTime = strpos($lastEmail['text'], 'expire=' . urlencode($response['body']['expire']), 0);
|
||||
|
||||
$this->assertNotFalse($expireTime);
|
||||
|
||||
@@ -1378,7 +1377,7 @@ trait AccountBase
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
$this->assertTrue($response['body']['emailVerification']);
|
||||
|
||||
@@ -1438,7 +1437,7 @@ trait AccountBase
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
||||
|
||||
@@ -7,6 +7,7 @@ use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Utopia\Database\DateTime;
|
||||
|
||||
use Utopia\Database\ID;
|
||||
use function sleep;
|
||||
@@ -447,7 +448,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
||||
@@ -539,7 +540,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('123456', $response['body']['providerAccessToken']);
|
||||
$this->assertEquals('tuvwxyz', $response['body']['providerRefreshToken']);
|
||||
$this->assertGreaterThan(\time() + 14400 - 5, $response['body']['providerAccessTokenExpiry']); // 5 seconds allowed networking delay
|
||||
$this->assertGreaterThan(DateTime::addSeconds(new \DateTime(), 14400 - 5), $response['body']['providerAccessTokenExpiry']); // 5 seconds allowed networking delay
|
||||
|
||||
$initialExpiry = $response['body']['providerAccessTokenExpiry'];
|
||||
|
||||
@@ -697,7 +698,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEmpty($response['body']['secret']);
|
||||
$this->assertIsNumeric($response['body']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['expire']));
|
||||
|
||||
$userId = $response['body']['userId'];
|
||||
|
||||
@@ -785,7 +786,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertEquals($response['headers']['status-code'], 200);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['phone'], $number);
|
||||
$this->assertTrue($response['body']['phoneVerification']);
|
||||
|
||||
@@ -836,7 +837,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
||||
@@ -878,7 +879,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['phone'], $newPhone);
|
||||
|
||||
/**
|
||||
@@ -927,7 +928,7 @@ class AccountCustomClientTest extends Scope
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertEmpty($response['body']['secret']);
|
||||
$this->assertIsNumeric($response['body']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['expire']));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\E2E\Services\Databases;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Role;
|
||||
|
||||
@@ -175,6 +176,14 @@ trait DatabasesBase
|
||||
'array' => true,
|
||||
]);
|
||||
|
||||
$datetime = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/datetime', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'birthDay',
|
||||
'required' => false,
|
||||
]);
|
||||
$this->assertEquals(202, $title['headers']['status-code']);
|
||||
$this->assertEquals($title['body']['key'], 'title');
|
||||
$this->assertEquals($title['body']['type'], 'string');
|
||||
@@ -198,6 +207,11 @@ trait DatabasesBase
|
||||
$this->assertEquals($actors['body']['required'], false);
|
||||
$this->assertEquals($actors['body']['array'], true);
|
||||
|
||||
$this->assertEquals($datetime['headers']['status-code'], 201);
|
||||
$this->assertEquals($datetime['body']['key'], 'birthDay');
|
||||
$this->assertEquals($datetime['body']['type'], 'datetime');
|
||||
$this->assertEquals($datetime['body']['required'], false);
|
||||
|
||||
// wait for database worker to create attributes
|
||||
sleep(2);
|
||||
|
||||
@@ -208,11 +222,12 @@ trait DatabasesBase
|
||||
]), []);
|
||||
|
||||
$this->assertIsArray($movies['body']['attributes']);
|
||||
$this->assertCount(4, $movies['body']['attributes']);
|
||||
$this->assertCount(5, $movies['body']['attributes']);
|
||||
$this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][1]['key'], $releaseYear['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][2]['key'], $duration['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][3]['key'], $actors['body']['key']);
|
||||
$this->assertEquals($movies['body']['attributes'][4]['key'], $datetime['body']['key']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -327,6 +342,16 @@ trait DatabasesBase
|
||||
'default' => true,
|
||||
]);
|
||||
|
||||
$datetime = $this->client->call(Client::METHOD_POST, $attributesPath . '/datetime', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'datetime',
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $string['headers']['status-code']);
|
||||
$this->assertEquals('string', $string['body']['key']);
|
||||
$this->assertEquals('string', $string['body']['type']);
|
||||
@@ -394,6 +419,13 @@ trait DatabasesBase
|
||||
$this->assertEquals(false, $boolean['body']['array']);
|
||||
$this->assertEquals(true, $boolean['body']['default']);
|
||||
|
||||
$this->assertEquals(201, $datetime['headers']['status-code']);
|
||||
$this->assertEquals('datetime', $datetime['body']['key']);
|
||||
$this->assertEquals('datetime', $datetime['body']['type']);
|
||||
$this->assertEquals(false, $datetime['body']['required']);
|
||||
$this->assertEquals(false, $datetime['body']['array']);
|
||||
$this->assertEquals(null, $datetime['body']['default']);
|
||||
|
||||
// wait for database worker to create attributes
|
||||
sleep(30);
|
||||
|
||||
@@ -445,6 +477,12 @@ trait DatabasesBase
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$datetimeResponse = $this->client->call(Client::METHOD_GET, $attributesPath . '/' . $datetime['body']['key'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $stringResponse['headers']['status-code']);
|
||||
$this->assertEquals($string['body']['key'], $stringResponse['body']['key']);
|
||||
$this->assertEquals($string['body']['type'], $stringResponse['body']['type']);
|
||||
@@ -519,6 +557,14 @@ trait DatabasesBase
|
||||
$this->assertEquals($boolean['body']['array'], $booleanResponse['body']['array']);
|
||||
$this->assertEquals($boolean['body']['default'], $booleanResponse['body']['default']);
|
||||
|
||||
$this->assertEquals(200, $datetimeResponse['headers']['status-code']);
|
||||
$this->assertEquals($datetime['body']['key'], $datetimeResponse['body']['key']);
|
||||
$this->assertEquals($datetime['body']['type'], $datetimeResponse['body']['type']);
|
||||
$this->assertEquals('available', $datetimeResponse['body']['status']);
|
||||
$this->assertEquals($datetime['body']['required'], $datetimeResponse['body']['required']);
|
||||
$this->assertEquals($datetime['body']['array'], $datetimeResponse['body']['array']);
|
||||
$this->assertEquals($datetime['body']['default'], $datetimeResponse['body']['default']);
|
||||
|
||||
$attributes = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -526,12 +572,12 @@ trait DatabasesBase
|
||||
]));
|
||||
|
||||
$this->assertEquals(200, $attributes['headers']['status-code']);
|
||||
$this->assertEquals(8, $attributes['body']['total']);
|
||||
$this->assertEquals(9, $attributes['body']['total']);
|
||||
|
||||
$attributes = $attributes['body']['attributes'];
|
||||
|
||||
$this->assertIsArray($attributes);
|
||||
$this->assertCount(8, $attributes);
|
||||
$this->assertCount(9, $attributes);
|
||||
|
||||
$this->assertEquals($stringResponse['body']['key'], $attributes[0]['key']);
|
||||
$this->assertEquals($stringResponse['body']['type'], $attributes[0]['type']);
|
||||
@@ -599,6 +645,13 @@ trait DatabasesBase
|
||||
$this->assertEquals($booleanResponse['body']['array'], $attributes[7]['array']);
|
||||
$this->assertEquals($booleanResponse['body']['default'], $attributes[7]['default']);
|
||||
|
||||
$this->assertEquals($datetimeResponse['body']['key'], $attributes[8]['key']);
|
||||
$this->assertEquals($datetimeResponse['body']['type'], $attributes[8]['type']);
|
||||
$this->assertEquals($datetimeResponse['body']['status'], $attributes[8]['status']);
|
||||
$this->assertEquals($datetimeResponse['body']['required'], $attributes[8]['required']);
|
||||
$this->assertEquals($datetimeResponse['body']['array'], $attributes[8]['array']);
|
||||
$this->assertEquals($datetimeResponse['body']['default'], $attributes[8]['default']);
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
@@ -610,7 +663,7 @@ trait DatabasesBase
|
||||
$attributes = $collection['body']['attributes'];
|
||||
|
||||
$this->assertIsArray($attributes);
|
||||
$this->assertCount(8, $attributes);
|
||||
$this->assertCount(9, $attributes);
|
||||
|
||||
$this->assertEquals($stringResponse['body']['key'], $attributes[0]['key']);
|
||||
$this->assertEquals($stringResponse['body']['type'], $attributes[0]['type']);
|
||||
@@ -678,6 +731,13 @@ trait DatabasesBase
|
||||
$this->assertEquals($booleanResponse['body']['array'], $attributes[7]['array']);
|
||||
$this->assertEquals($booleanResponse['body']['default'], $attributes[7]['default']);
|
||||
|
||||
$this->assertEquals($datetimeResponse['body']['key'], $attributes[8]['key']);
|
||||
$this->assertEquals($datetimeResponse['body']['type'], $attributes[8]['type']);
|
||||
$this->assertEquals($datetimeResponse['body']['status'], $attributes[8]['status']);
|
||||
$this->assertEquals($datetimeResponse['body']['required'], $attributes[8]['required']);
|
||||
$this->assertEquals($datetimeResponse['body']['array'], $attributes[8]['array']);
|
||||
$this->assertEquals($datetimeResponse['body']['default'], $attributes[8]['default']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
@@ -772,6 +832,23 @@ trait DatabasesBase
|
||||
$this->assertEquals('available', $movies['body']['indexes'][1]['status']);
|
||||
$this->assertEquals('available', $movies['body']['indexes'][2]['status']);
|
||||
|
||||
|
||||
$releaseWithDate = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'birthDay',
|
||||
'type' => 'key',
|
||||
'attributes' => ['birthDay'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $releaseWithDate['headers']['status-code']);
|
||||
$this->assertEquals('birthDay', $releaseWithDate['body']['key']);
|
||||
$this->assertEquals('key', $releaseWithDate['body']['type']);
|
||||
$this->assertCount(1, $releaseWithDate['body']['attributes']);
|
||||
$this->assertEquals('birthDay', $releaseWithDate['body']['attributes'][0]);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -789,6 +866,7 @@ trait DatabasesBase
|
||||
'data' => [
|
||||
'title' => 'Captain America',
|
||||
'releaseYear' => 1944,
|
||||
'birthDay' => '1975-06-12 14:12:55+02:00',
|
||||
'actors' => [
|
||||
'Chris Evans',
|
||||
'Samuel Jackson',
|
||||
@@ -809,6 +887,7 @@ trait DatabasesBase
|
||||
'data' => [
|
||||
'title' => 'Spider-Man: Far From Home',
|
||||
'releaseYear' => 2019,
|
||||
'birthDay' => null,
|
||||
'actors' => [
|
||||
'Tom Holland',
|
||||
'Zendaya Maree Stoermer',
|
||||
@@ -830,6 +909,7 @@ trait DatabasesBase
|
||||
'data' => [
|
||||
'title' => 'Spider-Man: Homecoming',
|
||||
'releaseYear' => 2017,
|
||||
'birthDay' => '1975-06-12 14:12:55 America/New_York',
|
||||
'duration' => 0,
|
||||
'actors' => [
|
||||
'Tom Holland',
|
||||
@@ -866,6 +946,7 @@ trait DatabasesBase
|
||||
$this->assertCount(2, $document1['body']['actors']);
|
||||
$this->assertEquals($document1['body']['actors'][0], 'Chris Evans');
|
||||
$this->assertEquals($document1['body']['actors'][1], 'Samuel Jackson');
|
||||
$this->assertEquals($document1['body']['birthDay'], '1975-06-12 12:12:55.000');
|
||||
|
||||
$this->assertEquals(201, $document2['headers']['status-code']);
|
||||
$this->assertEquals($document2['body']['title'], 'Spider-Man: Far From Home');
|
||||
@@ -877,6 +958,7 @@ trait DatabasesBase
|
||||
$this->assertEquals($document2['body']['actors'][0], 'Tom Holland');
|
||||
$this->assertEquals($document2['body']['actors'][1], 'Zendaya Maree Stoermer');
|
||||
$this->assertEquals($document2['body']['actors'][2], 'Samuel Jackson');
|
||||
$this->assertEquals($document2['body']['birthDay'], null);
|
||||
|
||||
$this->assertEquals(201, $document3['headers']['status-code']);
|
||||
$this->assertEquals($document3['body']['title'], 'Spider-Man: Homecoming');
|
||||
@@ -887,6 +969,7 @@ trait DatabasesBase
|
||||
$this->assertCount(2, $document3['body']['actors']);
|
||||
$this->assertEquals($document3['body']['actors'][0], 'Tom Holland');
|
||||
$this->assertEquals($document3['body']['actors'][1], 'Zendaya Maree Stoermer');
|
||||
$this->assertEquals($document3['body']['birthDay'], '1975-06-12 18:12:55.000');// UTC for NY
|
||||
|
||||
$this->assertEquals(400, $document4['headers']['status-code']);
|
||||
|
||||
@@ -1011,6 +1094,7 @@ trait DatabasesBase
|
||||
$this->assertEquals($response['body']['title'], $document['title']);
|
||||
$this->assertEquals($response['body']['releaseYear'], $document['releaseYear']);
|
||||
$this->assertEquals($response['body']['$permissions'], $document['$permissions']);
|
||||
$this->assertEquals($response['body']['birthDay'], $document['birthDay']);
|
||||
$this->assertFalse(array_key_exists('$internalId', $response['body']));
|
||||
}
|
||||
}
|
||||
@@ -1354,7 +1438,7 @@ trait DatabasesBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['$createdAt.greater(132)'],
|
||||
'queries' => ['$createdAt.greater("1976-06-12")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(3, $documents['body']['documents']);
|
||||
@@ -1363,7 +1447,7 @@ trait DatabasesBase
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['$createdAt.lesser(132)'],
|
||||
'queries' => ['$createdAt.lesser("1976-06-12")'],
|
||||
]);
|
||||
|
||||
$this->assertCount(0, $documents['body']['documents']);
|
||||
@@ -1410,6 +1494,19 @@ trait DatabasesBase
|
||||
|
||||
$this->assertEquals(400, $documents['headers']['status-code']);
|
||||
|
||||
|
||||
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'queries' => ['birthDay.greater("1960-01-01 10:10:10+02:30")'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($documents['headers']['status-code'], 200);
|
||||
$this->assertEquals('1975-06-12 12:12:55.000', $documents['body']['documents'][0]['birthDay']);
|
||||
$this->assertEquals('1975-06-12 18:12:55.000', $documents['body']['documents'][1]['birthDay']);
|
||||
$this->assertCount(2, $documents['body']['documents']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -1427,6 +1524,7 @@ trait DatabasesBase
|
||||
'data' => [
|
||||
'title' => 'Thor: Ragnaroc',
|
||||
'releaseYear' => 2017,
|
||||
'birthDay' => '1976-06-12 14:12:55',
|
||||
'actors' => [],
|
||||
'$createdAt' => 5 // Should be ignored
|
||||
],
|
||||
@@ -1442,7 +1540,8 @@ trait DatabasesBase
|
||||
$this->assertEquals(201, $document['headers']['status-code']);
|
||||
$this->assertEquals($document['body']['title'], 'Thor: Ragnaroc');
|
||||
$this->assertEquals($document['body']['releaseYear'], 2017);
|
||||
$this->assertNotEquals($document['body']['$createdAt'], 5);
|
||||
$this->assertEquals(true, DateTime::isValid($document['body']['$createdAt']));
|
||||
$this->assertEquals(true, DateTime::isValid($document['body']['birthDay']));
|
||||
$this->assertContains('read(user:' . $this->getUser()['$id'] . ')', $document['body']['$permissions']);
|
||||
$this->assertContains('update(user:' . $this->getUser()['$id'] . ')', $document['body']['$permissions']);
|
||||
$this->assertContains('delete(user:' . $this->getUser()['$id'] . ')', $document['body']['$permissions']);
|
||||
@@ -1498,6 +1597,7 @@ trait DatabasesBase
|
||||
'data' => [
|
||||
'title' => 'Thor: Ragnarok',
|
||||
'releaseYear' => 2017,
|
||||
'birthDay' => '1975-06-12 14:12:55',
|
||||
'actors' => [],
|
||||
],
|
||||
'permissions' => [
|
||||
@@ -1715,6 +1815,26 @@ trait DatabasesBase
|
||||
'default' => 'NORTH'
|
||||
]);
|
||||
|
||||
$goodDatetime = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/datetime', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'birthDay',
|
||||
'required' => false,
|
||||
'default' => null
|
||||
]);
|
||||
|
||||
$datetimeDefault = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/datetime', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'badBirthDay',
|
||||
'required' => false,
|
||||
'default' => 'bad'
|
||||
]);
|
||||
|
||||
$this->assertEquals(202, $email['headers']['status-code']);
|
||||
$this->assertEquals(202, $ip['headers']['status-code']);
|
||||
$this->assertEquals(202, $url['headers']['status-code']);
|
||||
@@ -1724,6 +1844,7 @@ trait DatabasesBase
|
||||
$this->assertEquals(202, $upperBound['headers']['status-code']);
|
||||
$this->assertEquals(202, $lowerBound['headers']['status-code']);
|
||||
$this->assertEquals(202, $enum['headers']['status-code']);
|
||||
$this->assertEquals(202, $goodDatetime['headers']['status-code']);
|
||||
$this->assertEquals(400, $invalidRange['headers']['status-code']);
|
||||
$this->assertEquals(400, $defaultArray['headers']['status-code']);
|
||||
$this->assertEquals(400, $defaultRequired['headers']['status-code']);
|
||||
@@ -1731,7 +1852,7 @@ trait DatabasesBase
|
||||
$this->assertEquals(400, $enumDefaultStrict['headers']['status-code']);
|
||||
$this->assertEquals('Minimum value must be lesser than maximum value', $invalidRange['body']['message']);
|
||||
$this->assertEquals('Cannot set default value for array attributes', $defaultArray['body']['message']);
|
||||
|
||||
$this->assertEquals(400, $datetimeDefault['headers']['status-code']);
|
||||
// wait for worker to add attributes
|
||||
sleep(3);
|
||||
|
||||
@@ -1741,7 +1862,7 @@ trait DatabasesBase
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]), []);
|
||||
|
||||
$this->assertCount(9, $collection['body']['attributes']);
|
||||
$this->assertCount(10, $collection['body']['attributes']);
|
||||
|
||||
/**
|
||||
* Test for successful validation
|
||||
@@ -2031,6 +2152,18 @@ trait DatabasesBase
|
||||
]
|
||||
]);
|
||||
|
||||
$badTime = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'documentId' => 'unique()',
|
||||
'data' => [
|
||||
'birthDay' => '2020-10-10 27:30:10+01:00',
|
||||
],
|
||||
'read' => ['user:' . $this->getUser()['$id']],
|
||||
'write' => ['user:' . $this->getUser()['$id']],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $badEmail['headers']['status-code']);
|
||||
$this->assertEquals(400, $badEnum['headers']['status-code']);
|
||||
$this->assertEquals(400, $badIp['headers']['status-code']);
|
||||
@@ -2040,6 +2173,7 @@ trait DatabasesBase
|
||||
$this->assertEquals(400, $badProbability['headers']['status-code']);
|
||||
$this->assertEquals(400, $tooHigh['headers']['status-code']);
|
||||
$this->assertEquals(400, $tooLow['headers']['status-code']);
|
||||
$this->assertEquals(400, $badTime['headers']['status-code']);
|
||||
$this->assertEquals('Invalid document structure: Attribute "email" has invalid format. Value must be a valid email address', $badEmail['body']['message']);
|
||||
$this->assertEquals('Invalid document structure: Attribute "enum" has invalid format. Value must be one of (yes, no, maybe)', $badEnum['body']['message']);
|
||||
$this->assertEquals('Invalid document structure: Attribute "ip" has invalid format. Value must be a valid IP address', $badIp['body']['message']);
|
||||
@@ -2487,16 +2621,17 @@ trait DatabasesBase
|
||||
$document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $data['databaseId'] . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, $headers, [
|
||||
'data' => [
|
||||
'title' => 'Again Updated Date Test',
|
||||
'$createdAt' => 1657271810, // Try to update it, should not work
|
||||
'$updatedAt' => 1657271810 // Try to update it, should not work
|
||||
'$createdAt' => '2022-08-01 13:09:23.040', // $createdAt is not updatable
|
||||
'$updatedAt' => '2022-08-01 13:09:23.050' // system will update it not api
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['body']['title'], 'Again Updated Date Test');
|
||||
$this->assertEquals($document['body']['$createdAt'], $createdAt);
|
||||
$this->assertNotEquals($document['body']['$createdAt'], '2022-08-01 13:09:23.040');
|
||||
$this->assertNotEquals($document['body']['$updatedAt'], $updatedAt);
|
||||
$this->assertNotEquals($document['body']['$updatedAt'], $updatedAtSecond);
|
||||
$this->assertNotEquals($document['body']['$updatedAt'], 1657271810);
|
||||
$this->assertNotEquals($document['body']['$updatedAt'], '2022-08-01 13:09:23.050');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
|
||||
class FunctionsCustomServerTest extends Scope
|
||||
@@ -48,8 +49,8 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertNotEmpty($response1['body']['$id']);
|
||||
$this->assertEquals('Test', $response1['body']['name']);
|
||||
$this->assertEquals('php-8.0', $response1['body']['runtime']);
|
||||
$this->assertIsInt($response1['body']['$createdAt']);
|
||||
$this->assertIsInt($response1['body']['$updatedAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response1['body']['$createdAt']));
|
||||
$this->assertEquals(true, DateTime::isValid($response1['body']['$updatedAt']));
|
||||
$this->assertEquals('', $response1['body']['deployment']);
|
||||
$this->assertEquals([
|
||||
'funcKey1' => 'funcValue1',
|
||||
@@ -249,8 +250,8 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertEquals(200, $response1['headers']['status-code']);
|
||||
$this->assertNotEmpty($response1['body']['$id']);
|
||||
$this->assertEquals('Test1', $response1['body']['name']);
|
||||
$this->assertIsInt($response1['body']['$createdAt']);
|
||||
$this->assertIsInt($response1['body']['$updatedAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response1['body']['$createdAt']));
|
||||
$this->assertEquals(true, DateTime::isValid($response1['body']['$updatedAt']));
|
||||
$this->assertEquals('', $response1['body']['deployment']);
|
||||
$this->assertEquals([
|
||||
'key4' => 'value4',
|
||||
@@ -295,7 +296,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
|
||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||
$this->assertNotEmpty($deployment['body']['$id']);
|
||||
$this->assertIsInt($deployment['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($deployment['body']['$createdAt']));
|
||||
$this->assertEquals('index.php', $deployment['body']['entrypoint']);
|
||||
|
||||
// Wait for deployment to build.
|
||||
@@ -344,7 +345,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
|
||||
$this->assertEquals(202, $largeTag['headers']['status-code']);
|
||||
$this->assertNotEmpty($largeTag['body']['$id']);
|
||||
$this->assertIsInt($largeTag['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($largeTag['body']['$createdAt']));
|
||||
$this->assertEquals('index.php', $largeTag['body']['entrypoint']);
|
||||
$this->assertGreaterThan(10000, $largeTag['body']['size']);
|
||||
|
||||
@@ -366,8 +367,8 @@ class FunctionsCustomServerTest extends Scope
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertIsInt($response['body']['$updatedAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$updatedAt']));
|
||||
$this->assertEquals($data['deploymentId'], $response['body']['deployment']);
|
||||
|
||||
/**
|
||||
@@ -488,7 +489,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
||||
$this->assertNotEmpty($execution['body']['$id']);
|
||||
$this->assertNotEmpty($execution['body']['functionId']);
|
||||
$this->assertIsInt($execution['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($execution['body']['$createdAt']));
|
||||
$this->assertEquals($data['functionId'], $execution['body']['functionId']);
|
||||
$this->assertEquals('waiting', $execution['body']['status']);
|
||||
$this->assertEquals(0, $execution['body']['statusCode']);
|
||||
@@ -505,7 +506,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
|
||||
$this->assertNotEmpty($execution['body']['$id']);
|
||||
$this->assertNotEmpty($execution['body']['functionId']);
|
||||
$this->assertIsInt($execution['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($execution['body']['$createdAt']));
|
||||
$this->assertEquals($data['functionId'], $execution['body']['functionId']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
$this->assertEquals(200, $execution['body']['statusCode']);
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace Tests\E2E\Services\Projects;
|
||||
|
||||
use Appwrite\Auth\Auth;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectConsole;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Tests\E2E\Services\Projects\ProjectsBase;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
|
||||
class ProjectsConsoleClientTest extends Scope
|
||||
@@ -1280,7 +1282,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['health.read'],
|
||||
'expire' => time() + 3600,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), 3600),
|
||||
]);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
||||
@@ -1300,7 +1302,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['health.read'],
|
||||
'expire' => 0,
|
||||
'expire' => null,
|
||||
]);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
||||
@@ -1320,7 +1322,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test',
|
||||
'scopes' => ['health.read'],
|
||||
'expire' => time() - 3600,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -3600),
|
||||
]);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
||||
@@ -1347,7 +1349,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
], $this->getHeaders()), [
|
||||
'name' => 'Key Test Update',
|
||||
'scopes' => ['users.read', 'users.write', 'collections.read'],
|
||||
'expire' => time() + 360,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), 360),
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Storage;
|
||||
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Role;
|
||||
@@ -51,7 +52,7 @@ trait StorageBase
|
||||
]);
|
||||
$this->assertEquals(201, $file['headers']['status-code']);
|
||||
$this->assertNotEmpty($file['body']['$id']);
|
||||
$this->assertIsInt($file['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($file['body']['$createdAt']));
|
||||
$this->assertEquals('logo.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
@@ -119,7 +120,7 @@ trait StorageBase
|
||||
|
||||
$this->assertEquals(201, $largeFile['headers']['status-code']);
|
||||
$this->assertNotEmpty($largeFile['body']['$id']);
|
||||
$this->assertIsInt($largeFile['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($largeFile['body']['$createdAt']));
|
||||
$this->assertEquals('large-file.mp4', $largeFile['body']['name']);
|
||||
$this->assertEquals('video/mp4', $largeFile['body']['mimeType']);
|
||||
$this->assertEquals($totalSize, $largeFile['body']['sizeOriginal']);
|
||||
@@ -287,7 +288,7 @@ trait StorageBase
|
||||
|
||||
$this->assertEquals(200, $file1['headers']['status-code']);
|
||||
$this->assertNotEmpty($file1['body']['$id']);
|
||||
$this->assertIsInt($file1['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($file1['body']['$createdAt']));
|
||||
$this->assertEquals('logo.png', $file1['body']['name']);
|
||||
$this->assertEquals('image/png', $file1['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file1['body']['sizeOriginal']);
|
||||
@@ -582,7 +583,7 @@ trait StorageBase
|
||||
|
||||
$this->assertEquals(200, $file['headers']['status-code']);
|
||||
$this->assertNotEmpty($file['body']['$id']);
|
||||
$this->assertIsInt($file['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($file['body']['$createdAt']));
|
||||
$this->assertEquals('logo.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
|
||||
@@ -10,6 +10,7 @@ use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Role;
|
||||
@@ -55,7 +56,7 @@ class StorageCustomClientTest extends Scope
|
||||
$fileId = $file['body']['$id'];
|
||||
$this->assertEquals($file['headers']['status-code'], 201);
|
||||
$this->assertNotEmpty($fileId);
|
||||
$this->assertIsInt($file['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($file['body']['$createdAt']));
|
||||
$this->assertEquals('permissions.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
@@ -149,7 +150,7 @@ class StorageCustomClientTest extends Scope
|
||||
$this->assertContains('read(user:' . $this->getUser()['$id'] . ')', $file['body']['$permissions']);
|
||||
$this->assertContains('update(user:' . $this->getUser()['$id'] . ')', $file['body']['$permissions']);
|
||||
$this->assertContains('delete(user:' . $this->getUser()['$id'] . ')', $file['body']['$permissions']);
|
||||
$this->assertIsInt($file['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($file['body']['$createdAt']));
|
||||
$this->assertEquals('permissions.png', $file['body']['name']);
|
||||
$this->assertEquals('image/png', $file['body']['mimeType']);
|
||||
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
||||
|
||||
@@ -6,6 +6,7 @@ use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
|
||||
class StorageCustomServerTest extends Scope
|
||||
@@ -29,7 +30,7 @@ class StorageCustomServerTest extends Scope
|
||||
]);
|
||||
$this->assertEquals(201, $bucket['headers']['status-code']);
|
||||
$this->assertNotEmpty($bucket['body']['$id']);
|
||||
$this->assertIsInt($bucket['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($bucket['body']['$createdAt']));
|
||||
$this->assertIsArray($bucket['body']['$permissions']);
|
||||
$this->assertIsArray($bucket['body']['allowedFileExtensions']);
|
||||
$this->assertEquals('Test Bucket', $bucket['body']['name']);
|
||||
@@ -187,9 +188,8 @@ class StorageCustomServerTest extends Scope
|
||||
]);
|
||||
$this->assertEquals(200, $bucket['headers']['status-code']);
|
||||
$this->assertNotEmpty($bucket['body']['$id']);
|
||||
$this->assertIsInt($bucket['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($bucket['body']['$createdAt']));
|
||||
$this->assertIsArray($bucket['body']['$permissions']);
|
||||
|
||||
$this->assertIsArray($bucket['body']['allowedFileExtensions']);
|
||||
$this->assertEquals('Test Bucket Updated', $bucket['body']['name']);
|
||||
$this->assertEquals(false, $bucket['body']['enabled']);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
|
||||
trait TeamsBase
|
||||
@@ -26,7 +27,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Arsenal', $response1['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response1['body']['total']);
|
||||
$this->assertIsInt($response1['body']['total']);
|
||||
$this->assertIsInt($response1['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response1['body']['$createdAt']));
|
||||
|
||||
$teamUid = $response1['body']['$id'];
|
||||
$teamName = $response1['body']['name'];
|
||||
@@ -46,7 +47,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Manchester United', $response2['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response2['body']['total']);
|
||||
$this->assertIsInt($response2['body']['total']);
|
||||
$this->assertIsInt($response2['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response2['body']['$createdAt']));
|
||||
|
||||
$response3 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -61,8 +62,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Newcastle', $response3['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response3['body']['total']);
|
||||
$this->assertIsInt($response3['body']['total']);
|
||||
$this->assertIsInt($response3['body']['$createdAt']);
|
||||
|
||||
$this->assertEquals(true, DateTime::isValid($response3['body']['$createdAt']));
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
@@ -97,7 +97,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Arsenal', $response['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response['body']['total']);
|
||||
$this->assertIsInt($response['body']['total']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -261,7 +261,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Demo', $response['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response['body']['total']);
|
||||
$this->assertIsInt($response['body']['total']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PUT, '/teams/' . $response['body']['$id'], array_merge([
|
||||
'content-type' => 'application/json',
|
||||
@@ -276,7 +276,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Demo New', $response['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response['body']['total']);
|
||||
$this->assertIsInt($response['body']['total']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -312,7 +312,7 @@ trait TeamsBase
|
||||
$this->assertEquals('Demo', $response['body']['name']);
|
||||
$this->assertGreaterThan(-1, $response['body']['total']);
|
||||
$this->assertIsInt($response['body']['total']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\DateTime;
|
||||
|
||||
trait TeamsBaseClient
|
||||
{
|
||||
@@ -112,7 +113,7 @@ trait TeamsBaseClient
|
||||
$this->assertNotEmpty($response['body']['teamId']);
|
||||
$this->assertNotEmpty($response['body']['teamName']);
|
||||
$this->assertCount(2, $response['body']['roles']);
|
||||
$this->assertIsInt($response['body']['joined']);
|
||||
$this->assertEquals(false, DateTime::isValid($response['body']['joined'])); // is null in DB
|
||||
$this->assertEquals(false, $response['body']['confirm']);
|
||||
|
||||
$lastEmail = $this->getLastEmail();
|
||||
@@ -246,7 +247,7 @@ trait TeamsBaseClient
|
||||
$this->assertNotEmpty($response['body']['userId']);
|
||||
$this->assertNotEmpty($response['body']['teamId']);
|
||||
$this->assertCount(2, $response['body']['roles']);
|
||||
$this->assertIsInt($response['body']['joined']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['joined']));
|
||||
$this->assertEquals(true, $response['body']['confirm']);
|
||||
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']];
|
||||
$data['session'] = $session;
|
||||
@@ -269,7 +270,7 @@ trait TeamsBaseClient
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
$this->assertEquals($response['body']['name'], $name);
|
||||
|
||||
@@ -303,7 +304,7 @@ trait TeamsBaseClient
|
||||
$this->assertIsArray($response['body']);
|
||||
$this->assertNotEmpty($response['body']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertIsNumeric($response['body']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['registration']));
|
||||
$this->assertEquals($response['body']['email'], $email);
|
||||
$this->assertEquals($response['body']['name'], $name);
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Tests\E2E\Services\Teams;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
|
||||
trait TeamsBaseServer
|
||||
{
|
||||
@@ -61,8 +63,7 @@ trait TeamsBaseServer
|
||||
$this->assertEquals($email, $response['body']['userEmail']);
|
||||
$this->assertNotEmpty($response['body']['teamId']);
|
||||
$this->assertCount(2, $response['body']['roles']);
|
||||
$this->assertIsInt($response['body']['joined']);
|
||||
$this->assertGreaterThan(0, $response['body']['joined']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['joined']));
|
||||
$this->assertEquals(true, $response['body']['confirm']);
|
||||
|
||||
$userUid = $response['body']['userId'];
|
||||
@@ -206,8 +207,7 @@ trait TeamsBaseServer
|
||||
$this->assertEquals('Arsenal', $response['body']['name']);
|
||||
$this->assertEquals(1, $response['body']['total']);
|
||||
$this->assertIsInt($response['body']['total']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
|
||||
/** Delete User */
|
||||
$user = $this->client->call(Client::METHOD_DELETE, '/users/' . $userUid, array_merge([
|
||||
@@ -232,6 +232,6 @@ trait TeamsBaseServer
|
||||
$this->assertEquals('Arsenal', $response['body']['name']);
|
||||
$this->assertEquals(0, $response['body']['total']);
|
||||
$this->assertIsInt($response['body']['total']);
|
||||
$this->assertIsInt($response['body']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($response['body']['$createdAt']));
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ trait UsersBase
|
||||
$this->assertEquals($body['name'], 'Cristiano Ronaldo');
|
||||
$this->assertEquals($body['email'], 'cristiano.ronaldo@manchester-united.co.uk');
|
||||
$this->assertEquals($body['status'], true);
|
||||
$this->assertGreaterThan(0, $body['registration']);
|
||||
$this->assertGreaterThan('2000-01-01 00:00:00', $body['registration']);
|
||||
|
||||
/**
|
||||
* Test Create with Custom ID for SUCCESS
|
||||
@@ -54,7 +54,7 @@ trait UsersBase
|
||||
$this->assertEquals($res['body']['name'], 'Lionel Messi');
|
||||
$this->assertEquals($res['body']['email'], 'lionel.messi@psg.fr');
|
||||
$this->assertEquals(true, $res['body']['status']);
|
||||
$this->assertGreaterThan(0, $res['body']['registration']);
|
||||
$this->assertGreaterThan('2000-01-01 00:00:00', $res['body']['registration']);
|
||||
|
||||
return ['userId' => $body['$id']];
|
||||
}
|
||||
@@ -229,7 +229,7 @@ trait UsersBase
|
||||
$this->assertEquals($user['body']['name'], 'Cristiano Ronaldo');
|
||||
$this->assertEquals($user['body']['email'], 'cristiano.ronaldo@manchester-united.co.uk');
|
||||
$this->assertEquals($user['body']['status'], true);
|
||||
$this->assertGreaterThan(0, $user['body']['registration']);
|
||||
$this->assertGreaterThan('2000-01-01 00:00:00', $user['body']['registration']);
|
||||
|
||||
$sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\E2E\Services\Webhooks;
|
||||
|
||||
use CURLFile;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Role;
|
||||
@@ -526,7 +527,7 @@ trait WebhooksBase
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertIsArray($webhook['data']['$permissions']);
|
||||
$this->assertEquals($webhook['data']['name'], 'logo.png');
|
||||
$this->assertIsInt($webhook['data']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['$createdAt']));
|
||||
$this->assertNotEmpty($webhook['data']['signature']);
|
||||
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
|
||||
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
|
||||
@@ -585,7 +586,7 @@ trait WebhooksBase
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertIsArray($webhook['data']['$permissions']);
|
||||
$this->assertEquals($webhook['data']['name'], 'logo.png');
|
||||
$this->assertIsInt($webhook['data']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['$createdAt']));
|
||||
$this->assertNotEmpty($webhook['data']['signature']);
|
||||
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
|
||||
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
|
||||
@@ -635,7 +636,7 @@ trait WebhooksBase
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertIsArray($webhook['data']['$permissions']);
|
||||
$this->assertEquals($webhook['data']['name'], 'logo.png');
|
||||
$this->assertIsInt($webhook['data']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['$createdAt']));
|
||||
$this->assertNotEmpty($webhook['data']['signature']);
|
||||
$this->assertEquals($webhook['data']['mimeType'], 'image/png');
|
||||
$this->assertEquals($webhook['data']['sizeOriginal'], 47218);
|
||||
@@ -717,7 +718,7 @@ trait WebhooksBase
|
||||
$this->assertEquals('Arsenal', $webhook['data']['name']);
|
||||
$this->assertGreaterThan(-1, $webhook['data']['total']);
|
||||
$this->assertIsInt($webhook['data']['total']);
|
||||
$this->assertIsInt($webhook['data']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['$createdAt']));
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -762,7 +763,7 @@ trait WebhooksBase
|
||||
$this->assertEquals('Demo New', $webhook['data']['name']);
|
||||
$this->assertGreaterThan(-1, $webhook['data']['total']);
|
||||
$this->assertIsInt($webhook['data']['total']);
|
||||
$this->assertIsInt($webhook['data']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['$createdAt']));
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -811,7 +812,7 @@ trait WebhooksBase
|
||||
$this->assertEquals('Chelsea', $webhook['data']['name']);
|
||||
$this->assertGreaterThan(-1, $webhook['data']['total']);
|
||||
$this->assertIsInt($webhook['data']['total']);
|
||||
$this->assertIsInt($webhook['data']['$createdAt']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['$createdAt']));
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
@@ -872,7 +873,7 @@ trait WebhooksBase
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['teamId']);
|
||||
$this->assertCount(2, $webhook['data']['roles']);
|
||||
$this->assertIsInt($webhook['data']['joined']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['invited']));
|
||||
$this->assertEquals(('server' === $this->getSide()), $webhook['data']['confirm']);
|
||||
|
||||
/**
|
||||
@@ -944,7 +945,7 @@ trait WebhooksBase
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['teamId']);
|
||||
$this->assertCount(2, $webhook['data']['roles']);
|
||||
$this->assertIsInt($webhook['data']['joined']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['invited']));
|
||||
$this->assertEquals(('server' === $this->getSide()), $webhook['data']['confirm']);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\SideClient;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
|
||||
class WebhooksCustomClientTest extends Scope
|
||||
@@ -58,7 +59,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id']), true);
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['registration']));
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -134,7 +135,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['registration']));
|
||||
$this->assertEquals($webhook['data']['status'], false);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -194,7 +195,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id']), true);
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertIsInt($webhook['data']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['expire']));
|
||||
$this->assertEquals($webhook['data']['ip'], '127.0.0.1');
|
||||
$this->assertNotEmpty($webhook['data']['osCode']);
|
||||
$this->assertIsString($webhook['data']['osCode']);
|
||||
@@ -283,7 +284,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertIsInt($webhook['data']['expire']);
|
||||
$this->assertIsString($webhook['data']['expire']);
|
||||
$this->assertEquals($webhook['data']['ip'], '127.0.0.1');
|
||||
$this->assertNotEmpty($webhook['data']['osCode']);
|
||||
$this->assertIsString($webhook['data']['osCode']);
|
||||
@@ -369,7 +370,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertIsInt($webhook['data']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['expire']));
|
||||
$this->assertEquals($webhook['data']['ip'], '127.0.0.1');
|
||||
$this->assertNotEmpty($webhook['data']['osCode']);
|
||||
$this->assertIsString($webhook['data']['osCode']);
|
||||
@@ -456,7 +457,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $newName);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertIsString($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -509,7 +510,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], 'New Name');
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertIsString($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -564,7 +565,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], 'New Name');
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertIsString($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $newEmail);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -620,7 +621,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], 'New Name');
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertIsString($webhook['data']['registration']);
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -680,7 +681,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['secret']);
|
||||
$this->assertIsNumeric($webhook['data']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['expire']));
|
||||
|
||||
$data['secret'] = $webhook['data']['secret'];
|
||||
|
||||
@@ -740,7 +741,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['secret']);
|
||||
$this->assertIsNumeric($webhook['data']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['expire']));
|
||||
|
||||
$data['secret'] = $webhook['data']['secret'];
|
||||
|
||||
@@ -796,7 +797,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['secret']);
|
||||
$this->assertIsNumeric($webhook['data']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['expire']));
|
||||
|
||||
$data['secret'] = $webhook['data']['secret'];
|
||||
|
||||
@@ -854,7 +855,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['secret']);
|
||||
$this->assertIsNumeric($webhook['data']['expire']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['expire']));
|
||||
|
||||
$data['secret'] = $webhook['data']['secret'];
|
||||
|
||||
@@ -917,7 +918,7 @@ class WebhooksCustomClientTest extends Scope
|
||||
$this->assertNotEmpty($webhook['data']['userId']);
|
||||
$this->assertNotEmpty($webhook['data']['teamId']);
|
||||
$this->assertCount(2, $webhook['data']['roles']);
|
||||
$this->assertIsInt($webhook['data']['joined']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['joined']));
|
||||
$this->assertEquals(true, $webhook['data']['confirm']);
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Permission;
|
||||
use Utopia\Database\Role;
|
||||
@@ -244,7 +245,7 @@ class WebhooksCustomServerTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $name);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['registration']));
|
||||
$this->assertEquals($webhook['data']['status'], true);
|
||||
$this->assertEquals($webhook['data']['email'], $email);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -335,7 +336,7 @@ class WebhooksCustomServerTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $data['name']);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['registration']));
|
||||
$this->assertEquals($webhook['data']['status'], false);
|
||||
$this->assertEquals($webhook['data']['email'], $data['email']);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
@@ -377,7 +378,7 @@ class WebhooksCustomServerTest extends Scope
|
||||
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide()));
|
||||
$this->assertNotEmpty($webhook['data']['$id']);
|
||||
$this->assertEquals($webhook['data']['name'], $data['name']);
|
||||
$this->assertIsInt($webhook['data']['registration']);
|
||||
$this->assertEquals(true, DateTime::isValid($webhook['data']['registration']));
|
||||
$this->assertEquals($webhook['data']['status'], false);
|
||||
$this->assertEquals($webhook['data']['email'], $data['email']);
|
||||
$this->assertEquals($webhook['data']['emailVerification'], false);
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
namespace Tests\Unit\Auth;
|
||||
|
||||
use Appwrite\Auth\Auth;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\ID;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Database\Database;
|
||||
|
||||
class AuthTest extends TestCase
|
||||
{
|
||||
@@ -72,14 +74,14 @@ class AuthTest extends TestCase
|
||||
$tokens1 = [
|
||||
new Document([
|
||||
'$id' => ID::custom('token1'),
|
||||
'expire' => time() + 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24),
|
||||
'secret' => $hash,
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => 'test@example.com',
|
||||
]),
|
||||
new Document([
|
||||
'$id' => ID::custom('token2'),
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => 'secret2',
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => 'test@example.com',
|
||||
@@ -89,14 +91,14 @@ class AuthTest extends TestCase
|
||||
$tokens2 = [
|
||||
new Document([ // Correct secret and type time, wrong expire time
|
||||
'$id' => ID::custom('token1'),
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => $hash,
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => 'test@example.com',
|
||||
]),
|
||||
new Document([
|
||||
'$id' => ID::custom('token2'),
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => 'secret2',
|
||||
'provider' => Auth::SESSION_PROVIDER_EMAIL,
|
||||
'providerUid' => 'test@example.com',
|
||||
@@ -117,13 +119,13 @@ class AuthTest extends TestCase
|
||||
new Document([
|
||||
'$id' => ID::custom('token1'),
|
||||
'type' => Auth::TOKEN_TYPE_RECOVERY,
|
||||
'expire' => time() + 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24),
|
||||
'secret' => $hash,
|
||||
]),
|
||||
new Document([
|
||||
'$id' => ID::custom('token2'),
|
||||
'type' => Auth::TOKEN_TYPE_RECOVERY,
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => 'secret2',
|
||||
]),
|
||||
];
|
||||
@@ -132,13 +134,13 @@ class AuthTest extends TestCase
|
||||
new Document([ // Correct secret and type time, wrong expire time
|
||||
'$id' => ID::custom('token1'),
|
||||
'type' => Auth::TOKEN_TYPE_RECOVERY,
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => $hash,
|
||||
]),
|
||||
new Document([
|
||||
'$id' => ID::custom('token2'),
|
||||
'type' => Auth::TOKEN_TYPE_RECOVERY,
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => 'secret2',
|
||||
]),
|
||||
];
|
||||
@@ -147,13 +149,13 @@ class AuthTest extends TestCase
|
||||
new Document([
|
||||
'$id' => ID::custom('token1'),
|
||||
'type' => Auth::TOKEN_TYPE_INVITE,
|
||||
'expire' => time() + 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24),
|
||||
'secret' => $hash,
|
||||
]),
|
||||
new Document([
|
||||
'$id' => ID::custom('token2'),
|
||||
'type' => Auth::TOKEN_TYPE_RECOVERY,
|
||||
'expire' => time() - 60 * 60 * 24,
|
||||
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
|
||||
'secret' => 'secret2',
|
||||
]),
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user