diff --git a/app/config/collections.php b/app/config/collections.php index 70ffe67157..d3ea600574 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -834,7 +834,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('domain'), @@ -972,7 +972,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], ], 'indexes' => [ @@ -1171,7 +1171,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('prefs'), @@ -1193,7 +1193,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('emailVerification'), @@ -1356,7 +1356,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('userAgent'), @@ -1461,7 +1461,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('providerRefreshToken'), @@ -1494,7 +1494,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('userAgent'), @@ -1799,7 +1799,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('joined'), @@ -1810,7 +1810,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('confirm'), @@ -1980,7 +1980,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('scheduleNext'), @@ -1991,7 +1991,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('timeout'), @@ -2193,7 +2193,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('endTime'), @@ -2204,7 +2204,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('duration'), @@ -2468,7 +2468,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('renewDate'), @@ -2479,7 +2479,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('attempts'), @@ -2512,7 +2512,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], ], 'indexes' => [ @@ -2667,7 +2667,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('period'), @@ -2742,7 +2742,7 @@ $collections = [ 'required' => false, 'default' => null, 'array' => false, - 'filters' => [], + 'filters' => ['datetime'], ], [ '$id' => ID::custom('value'), diff --git a/app/controllers/general.php b/app/controllers/general.php index f8842a1022..71002d9e7d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -294,8 +294,7 @@ App::init() $scopes = \array_merge($roles[$role]['scopes'], $key->getAttribute('scopes', [])); $expire = $key->getAttribute('expire'); - - if (!empty($expire) && $expire < DateTime::now()) { + if (!empty($expire) && $expire < DateTime::formatTz(DateTime::now())) { throw new AppwriteException(AppwriteException:: PROJECT_KEY_EXPIRED); } diff --git a/composer.json b/composer.json index 0d8a28e91b..fee2f93c96 100644 --- a/composer.json +++ b/composer.json @@ -45,13 +45,13 @@ "appwrite/php-runtimes": "0.10.*", "utopia-php/framework": "0.20.*", "utopia-php/logger": "0.3.*", - "utopia-php/abuse": "dev-refactor-permissions", + "utopia-php/abuse": "0.10.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "dev-refactor-permissions", + "utopia-php/audit": "0.11.*", "utopia-php/cache": "0.6.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-refactor-permissions", + "utopia-php/database": "0.22.*", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", @@ -74,18 +74,6 @@ { "url": "https://github.com/appwrite/runtimes.git", "type": "git" - }, - { - "url": "https://github.com/utopia-php/database.git", - "type": "git" - }, - { - "url": "https://github.com/utopia-php/abuse.git", - "type": "git" - }, - { - "url": "https://github.com/utopia-php/audit.git", - "type": "git" } ], "require-dev": { diff --git a/composer.lock b/composer.lock index b975783f35..2ce4203494 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d49d34cbdc70504ea61c5548bd60278a", + "content-hash": "175fe4abafd8bde4053b91eea905c328", "packages": [ { "name": "adhocore/jwt", @@ -1733,17 +1733,23 @@ }, { "name": "utopia-php/abuse", - "version": "dev-refactor-permissions", + "version": "0.10.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "496cba1f2e7f50a6faebdb77b9178a99d755b49a" + "reference": "b5beadce6581291e4385b0cc86f1be2a79bb2ef0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/b5beadce6581291e4385b0cc86f1be2a79bb2ef0", + "reference": "b5beadce6581291e4385b0cc86f1be2a79bb2ef0", + "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "dev-refactor-permissions" + "utopia-php/database": "0.22.0" }, "require-dev": { "phpunit/phpunit": "^9.4", @@ -1755,6 +1761,7 @@ "Utopia\\Abuse\\": "src/Abuse" } }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1766,13 +1773,17 @@ ], "description": "A simple abuse library to manage application usage limits", "keywords": [ - "abuse", + "Abuse", "framework", "php", "upf", "utopia" ], - "time": "2022-08-16T05:16:56+00:00" + "support": { + "issues": "https://github.com/utopia-php/abuse/issues", + "source": "https://github.com/utopia-php/abuse/tree/0.10.0" + }, + "time": "2022-08-17T14:31:54+00:00" }, { "name": "utopia-php/analytics", @@ -1831,16 +1842,22 @@ }, { "name": "utopia-php/audit", - "version": "dev-refactor-permissions", + "version": "0.11.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "cd3f0f2fd4716e32333397fedd8e7f07932361ec" + "reference": "a06f784f8e8b69bcae4f1a5bca58d41bda76c250" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/a06f784f8e8b69bcae4f1a5bca58d41bda76c250", + "reference": "a06f784f8e8b69bcae4f1a5bca58d41bda76c250", + "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "dev-refactor-permissions" + "utopia-php/database": "0.22.0" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -1852,6 +1869,7 @@ "Utopia\\Audit\\": "src/Audit" } }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1863,13 +1881,17 @@ ], "description": "A simple audit library to manage application users logs", "keywords": [ - "audit", + "Audit", "framework", "php", "upf", "utopia" ], - "time": "2022-08-16T05:16:47+00:00" + "support": { + "issues": "https://github.com/utopia-php/audit/issues", + "source": "https://github.com/utopia-php/audit/tree/0.11.0" + }, + "time": "2022-08-17T15:08:58+00:00" }, { "name": "utopia-php/cache", @@ -2030,11 +2052,17 @@ }, { "name": "utopia-php/database", - "version": "dev-refactor-permissions", + "version": "0.22.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "3bce574ea6915d8cbf2a9e2e725a90784cf6b07e" + "reference": "22c45ae83612e907203b7571cd8e3115ae3ae4c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/database/zipball/22c45ae83612e907203b7571cd8e3115ae3ae4c5", + "reference": "22c45ae83612e907203b7571cd8e3115ae3ae4c5", + "shasum": "" }, "require": { "ext-mongodb": "*", @@ -2058,11 +2086,7 @@ "Utopia\\Database\\": "src/Database" } }, - "autoload-dev": { - "psr-4": { - "Utopia\\Tests\\": "tests/Database" - } - }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2084,7 +2108,11 @@ "upf", "utopia" ], - "time": "2022-08-16T09:05:39+00:00" + "support": { + "issues": "https://github.com/utopia-php/database/issues", + "source": "https://github.com/utopia-php/database/tree/0.22.0" + }, + "time": "2022-08-17T12:55:37+00:00" }, { "name": "utopia-php/domains", @@ -2805,12 +2833,12 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "807e7890aed597ef47e01be8ad11c3b561b7c1e8" + "reference": "987f2933b97bd04f702ea08685f2be28a08a841c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/807e7890aed597ef47e01be8ad11c3b561b7c1e8", - "reference": "807e7890aed597ef47e01be8ad11c3b561b7c1e8", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/987f2933b97bd04f702ea08685f2be28a08a841c", + "reference": "987f2933b97bd04f702ea08685f2be28a08a841c", "shasum": "" }, "require": { @@ -2848,7 +2876,7 @@ "issues": "https://github.com/appwrite/sdk-generator/issues", "source": "https://github.com/appwrite/sdk-generator/tree/master" }, - "time": "2022-08-15T22:33:25+00:00" + "time": "2022-08-17T12:50:44+00:00" }, { "name": "doctrine/instantiator", @@ -2922,16 +2950,16 @@ }, { "name": "matthiasmullie/minify", - "version": "1.3.68", + "version": "1.3.69", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "c00fb02f71b2ef0a5f53fe18c5a8b9aa30f48297" + "reference": "a61c949cccd086808063611ef9698eabe42ef22f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/c00fb02f71b2ef0a5f53fe18c5a8b9aa30f48297", - "reference": "c00fb02f71b2ef0a5f53fe18c5a8b9aa30f48297", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/a61c949cccd086808063611ef9698eabe42ef22f", + "reference": "a61c949cccd086808063611ef9698eabe42ef22f", "shasum": "" }, "require": { @@ -2980,7 +3008,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.68" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.69" }, "funding": [ { @@ -2988,7 +3016,7 @@ "type": "github" } ], - "time": "2022-04-19T08:28:56+00:00" + "time": "2022-08-01T09:00:18+00:00" }, { "name": "matthiasmullie/path-converter", @@ -5330,9 +5358,6 @@ ], "minimum-stability": "stable", "stability-flags": { - "utopia-php/abuse": 20, - "utopia-php/audit": 20, - "utopia-php/database": 20, "appwrite/sdk-generator": 20 }, "prefer-stable": false, @@ -5358,5 +5383,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index 7b1c1c0f01..30cbf54453 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -207,7 +207,7 @@ class Auth $token->isSet('expire') && $token->getAttribute('type') == $type && $token->getAttribute('secret') === self::hash($secret) && - $token->getAttribute('expire') >= DateTime::now() + DateTime::formatTz($token->getAttribute('expire')) >= DateTime::formatTz(DateTime::now()) ) { return (string)$token->getId(); } @@ -226,7 +226,7 @@ class Auth $token->isSet('expire') && $token->getAttribute('type') == Auth::TOKEN_TYPE_PHONE && $token->getAttribute('secret') === $secret && - $token->getAttribute('expire') >= DateTime::now() + DateTime::formatTz($token->getAttribute('expire')) >= DateTime::formatTz(DateTime::now()) ) { return (string) $token->getId(); } @@ -252,7 +252,7 @@ class Auth $session->isSet('expire') && $session->isSet('provider') && $session->getAttribute('secret') === self::hash($secret) && - $session->getAttribute('expire') >= DateTime::now() + DateTime::formatTz($session->getAttribute('expire')) >= DateTime::formatTz(DateTime::now()) ) { return $session->getId(); } diff --git a/src/Appwrite/Utopia/Response/Model.php b/src/Appwrite/Utopia/Response/Model.php index b4b8bde3db..48e29ec962 100644 --- a/src/Appwrite/Utopia/Response/Model.php +++ b/src/Appwrite/Utopia/Response/Model.php @@ -12,7 +12,7 @@ abstract class Model public const TYPE_BOOLEAN = 'boolean'; public const TYPE_JSON = 'json'; public const TYPE_DATETIME = 'datetime'; - public const TYPE_DATETIME_EXAMPLE = '2020-10-15T06:38:00.000Z'; + public const TYPE_DATETIME_EXAMPLE = '2020-10-15T06:38:00.000+00:00'; /** * @var bool diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index c87c5ae10c..1b287357b8 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -825,7 +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=' . urlencode($response['body']['expire']), 0); + $expireTime = strpos($lastEmail['text'], 'expire=' . urlencode(DateTime::format(new \DateTime($response['body']['expire']))), 0); $this->assertNotFalse($expireTime); $secretTest = strpos($lastEmail['text'], 'secret=' . $response['body']['secret'], 0); @@ -1128,7 +1128,7 @@ trait AccountBase $recovery = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $expireTime = strpos($lastEmail['text'], 'expire=' . urlencode($response['body']['expire']), 0); + $expireTime = strpos($lastEmail['text'], 'expire=' . urlencode(DateTime::format(new \DateTime($response['body']['expire']))), 0); $this->assertNotFalse($expireTime); @@ -1281,7 +1281,7 @@ trait AccountBase $token = substr($lastEmail['text'], strpos($lastEmail['text'], '&secret=', 0) + 8, 256); - $expireTime = strpos($lastEmail['text'], 'expire=' . urlencode($response['body']['expire']), 0); + $expireTime = strpos($lastEmail['text'], 'expire=' . urlencode(DateTime::format(new \DateTime($response['body']['expire']))), 0); $this->assertNotFalse($expireTime); diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 9bbd589ea8..4df1c71760 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -946,7 +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($document1['body']['birthDay'], '1975-06-12T12:12:55.000+00:00'); $this->assertEquals(201, $document2['headers']['status-code']); $this->assertEquals($document2['body']['title'], 'Spider-Man: Far From Home'); @@ -969,7 +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($document3['body']['birthDay'], '1975-06-12T18:12:55.000+00:00');// UTC for NY $this->assertEquals(400, $document4['headers']['status-code']); @@ -1503,8 +1503,8 @@ trait DatabasesBase ]); $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->assertEquals('1975-06-12T12:12:55.000+00:00', $documents['body']['documents'][0]['birthDay']); + $this->assertEquals('1975-06-12T18:12:55.000+00:00', $documents['body']['documents'][1]['birthDay']); $this->assertCount(2, $documents['body']['documents']); return []; diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index be445e62aa..8255af15ff 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -74,14 +74,14 @@ class AuthTest extends TestCase $tokens1 = [ new Document([ '$id' => ID::custom('token1'), - 'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24), + 'expire' => DateTime::formatTz(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' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)), 'secret' => 'secret2', 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', @@ -91,14 +91,14 @@ class AuthTest extends TestCase $tokens2 = [ new Document([ // Correct secret and type time, wrong expire time '$id' => ID::custom('token1'), - 'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(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' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)), 'secret' => 'secret2', 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => 'test@example.com', @@ -119,13 +119,13 @@ class AuthTest extends TestCase new Document([ '$id' => ID::custom('token1'), 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), 60 * 60 * 24)), 'secret' => $hash, ]), new Document([ '$id' => ID::custom('token2'), 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)), 'secret' => 'secret2', ]), ]; @@ -134,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' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)), 'secret' => $hash, ]), new Document([ '$id' => ID::custom('token2'), 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)), 'secret' => 'secret2', ]), ]; @@ -149,13 +149,13 @@ class AuthTest extends TestCase new Document([ '$id' => ID::custom('token1'), 'type' => Auth::TOKEN_TYPE_INVITE, - 'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), 60 * 60 * 24)), 'secret' => $hash, ]), new Document([ '$id' => ID::custom('token2'), 'type' => Auth::TOKEN_TYPE_RECOVERY, - 'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24), + 'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)), 'secret' => 'secret2', ]), ];