diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 5278abae3..19264454e 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1574,7 +1574,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') Query::equal('databaseInternalId', [$db->getInternalId()]) ], 61); - $limit = 64 - MariaDB::getNumberOfDefaultIndexes(); + $limit = 64 - MariaDB::getCountOfDefaultIndexes(); if ($count >= $limit) { throw new Exception(Exception::INDEX_LIMIT_EXCEEDED, 'Index limit exceeded'); diff --git a/app/http.php b/app/http.php index afda7053b..fe0778bb1 100644 --- a/app/http.php +++ b/app/http.php @@ -91,18 +91,11 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { /** @var array $collections */ $collections = Config::getParam('collections', []); - if (!$dbForConsole->exists(App::getEnv('_APP_DB_SCHEMA', 'appwrite'))) { - $redis->flushAll(); - - Console::success('[Setup] - Creating database: appwrite...'); - - $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); - } - try { - Console::success('[Setup] - Creating metadata table: appwrite...'); - $dbForConsole->createMetadata(); - } catch (\Throwable $th) { + $redis->flushAll(); + Console::success('[Setup] - Creating database: appwrite...'); + $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); + } catch (\Exception $e) { Console::success('[Setup] - Skip: metadata table already exists'); } diff --git a/app/init.php b/app/init.php index a19492394..054721d43 100644 --- a/app/init.php +++ b/app/init.php @@ -282,7 +282,7 @@ Database::addFilter( ->find('attributes', [ Query::equal('collectionInternalId', [$document->getInternalId()]), Query::equal('databaseInternalId', [$document->getAttribute('databaseInternalId')]), - Query::limit($database->getAttributeLimit()), + Query::limit($database->getLimitForAttributes()), ]); } ); diff --git a/composer.json b/composer.json index 973aec853..47317ed5e 100644 --- a/composer.json +++ b/composer.json @@ -45,13 +45,13 @@ "appwrite/php-runtimes": "0.11.*", "utopia-php/framework": "0.21.*", "utopia-php/logger": "0.3.*", - "utopia-php/abuse": "0.13.*", + "utopia-php/abuse": "0.14.*", "utopia-php/analytics": "0.2.*", - "utopia-php/audit": "0.14.*", + "utopia-php/audit": "0.15.*", "utopia-php/cache": "0.6.*", "utopia-php/cli": "0.13.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.25.*", + "utopia-php/database": "0.26.*", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", diff --git a/composer.lock b/composer.lock index cd2040eb1..b4bbda3ce 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": "568151395a8877f87d9bdce048adc2dc", + "content-hash": "08fdd139ad1285b02c4b4e555679e7de", "packages": [ { "name": "adhocore/jwt", @@ -1741,23 +1741,23 @@ }, { "name": "utopia-php/abuse", - "version": "0.13.1", + "version": "0.14.0", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "4c1b8fe742f17158c59550cdfd9074a94bf474ac" + "reference": "1a5da248e74c1bfc39bc440fa949de6935acceeb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/4c1b8fe742f17158c59550cdfd9074a94bf474ac", - "reference": "4c1b8fe742f17158c59550cdfd9074a94bf474ac", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/1a5da248e74c1bfc39bc440fa949de6935acceeb", + "reference": "1a5da248e74c1bfc39bc440fa949de6935acceeb", "shasum": "" }, "require": { "ext-curl": "*", "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.25.*" + "utopia-php/database": "0.26.*" }, "require-dev": { "phpunit/phpunit": "^9.4", @@ -1789,9 +1789,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/0.13.1" + "source": "https://github.com/utopia-php/abuse/tree/0.14.0" }, - "time": "2022-09-07T16:02:58+00:00" + "time": "2022-10-14T11:26:39+00:00" }, { "name": "utopia-php/analytics", @@ -1850,22 +1850,22 @@ }, { "name": "utopia-php/audit", - "version": "0.14.1", + "version": "0.15.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "b011224ed9bfef7e5c849938e65619af28f7cf41" + "reference": "937ffd13e7a5ac9ad220b329247569ef2a4881d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/b011224ed9bfef7e5c849938e65619af28f7cf41", - "reference": "b011224ed9bfef7e5c849938e65619af28f7cf41", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/937ffd13e7a5ac9ad220b329247569ef2a4881d9", + "reference": "937ffd13e7a5ac9ad220b329247569ef2a4881d9", "shasum": "" }, "require": { "ext-pdo": "*", "php": ">=8.0", - "utopia-php/database": "0.25.*" + "utopia-php/database": "0.26.*" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -1881,12 +1881,6 @@ "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - } - ], "description": "A simple audit library to manage application users logs", "keywords": [ "Audit", @@ -1897,9 +1891,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/0.14.1" + "source": "https://github.com/utopia-php/audit/tree/0.15.0" }, - "time": "2022-09-07T16:03:16+00:00" + "time": "2022-10-14T11:39:18+00:00" }, { "name": "utopia-php/cache", @@ -2060,16 +2054,16 @@ }, { "name": "utopia-php/database", - "version": "0.25.5", + "version": "0.26.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "6d1c1d46d66553154975a3e8e72d30b5bd2413d9" + "reference": "d172af2541137c83a86d066f82f48914b5a3a610" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/6d1c1d46d66553154975a3e8e72d30b5bd2413d9", - "reference": "6d1c1d46d66553154975a3e8e72d30b5bd2413d9", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d172af2541137c83a86d066f82f48914b5a3a610", + "reference": "d172af2541137c83a86d066f82f48914b5a3a610", "shasum": "" }, "require": { @@ -2118,9 +2112,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.25.5" + "source": "https://github.com/utopia-php/database/tree/0.26.0" }, - "time": "2022-09-30T15:01:32+00:00" + "time": "2022-10-03T17:12:01+00:00" }, { "name": "utopia-php/domains", @@ -5384,5 +5378,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 dbe74af0d..adde25a7a 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -14,6 +14,7 @@ use Utopia\Database\Document; use Utopia\Database\DateTime; use Utopia\Database\Role; use Utopia\Database\Validator\Authorization; +use Utopia\Database\Validator\Roles; class Auth { @@ -427,11 +428,11 @@ class Auth $phoneVerified = $user->getAttribute('phoneVerification', false); if ($emailVerified || $phoneVerified) { - $roles[] = Role::user($user->getId(), Database::DIMENSION_VERIFIED)->toString(); - $roles[] = Role::users(Database::DIMENSION_VERIFIED)->toString(); + $roles[] = Role::user($user->getId(), Roles::DIMENSION_VERIFIED)->toString(); + $roles[] = Role::users(Roles::DIMENSION_VERIFIED)->toString(); } else { - $roles[] = Role::user($user->getId(), Database::DIMENSION_UNVERIFIED)->toString(); - $roles[] = Role::users(Database::DIMENSION_UNVERIFIED)->toString(); + $roles[] = Role::user($user->getId(), Roles::DIMENSION_UNVERIFIED)->toString(); + $roles[] = Role::users(Roles::DIMENSION_UNVERIFIED)->toString(); } } else { return [Role::guests()->toString()]; diff --git a/src/Appwrite/Resque/Worker.php b/src/Appwrite/Resque/Worker.php index 40adc3e52..dd7cebd08 100644 --- a/src/Appwrite/Resque/Worker.php +++ b/src/Appwrite/Resque/Worker.php @@ -229,7 +229,7 @@ abstract class Worker throw new \Exception("Project does not exist: {$projectId}"); } - if ($type === self::DATABASE_CONSOLE && !$database->exists($database->getDefaultDatabase(), '_metadata')) { + if ($type === self::DATABASE_CONSOLE && !$database->exists($database->getDefaultDatabase(), Database::METADATA)) { throw new \Exception('Console project not ready'); } diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index 43a2bef8e..822b612db 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -10,6 +10,7 @@ use Utopia\Database\Role; use Utopia\Database\Validator\Authorization; use PHPUnit\Framework\TestCase; use Utopia\Database\Database; +use Utopia\Database\Validator\Roles; class AuthTest extends TestCase { @@ -379,8 +380,8 @@ class AuthTest extends TestCase $this->assertCount(11, $roles); $this->assertContains(Role::users()->toString(), $roles); $this->assertContains(Role::user(ID::custom('123'))->toString(), $roles); - $this->assertContains(Role::users(Database::DIMENSION_VERIFIED)->toString(), $roles); - $this->assertContains(Role::user(ID::custom('123'), Database::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::user(ID::custom('123'), Roles::DIMENSION_VERIFIED)->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles); @@ -394,15 +395,15 @@ class AuthTest extends TestCase $user['phoneVerification'] = false; $roles = Auth::getRoles($user); - $this->assertContains(Role::users(Database::DIMENSION_UNVERIFIED)->toString(), $roles); - $this->assertContains(Role::user(ID::custom('123'), Database::DIMENSION_UNVERIFIED)->toString(), $roles); + $this->assertContains(Role::users(Roles::DIMENSION_UNVERIFIED)->toString(), $roles); + $this->assertContains(Role::user(ID::custom('123'), Roles::DIMENSION_UNVERIFIED)->toString(), $roles); // Enable single verification type $user['emailVerification'] = true; $roles = Auth::getRoles($user); - $this->assertContains(Role::users(Database::DIMENSION_VERIFIED)->toString(), $roles); - $this->assertContains(Role::user(ID::custom('123'), Database::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertContains(Role::user(ID::custom('123'), Roles::DIMENSION_VERIFIED)->toString(), $roles); } public function testPrivilegedUserRoles(): void @@ -438,8 +439,8 @@ class AuthTest extends TestCase $this->assertCount(7, $roles); $this->assertNotContains(Role::users()->toString(), $roles); $this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles); - $this->assertNotContains(Role::users(Database::DIMENSION_VERIFIED)->toString(), $roles); - $this->assertNotContains(Role::user(ID::custom('123'), Database::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertNotContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); + $this->assertNotContains(Role::user(ID::custom('123'), Roles::DIMENSION_VERIFIED)->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles); $this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);