fix: throw correct exception when project custom ID already exists
This commit is contained in:
parent
0368cdb669
commit
f0df316b4f
4 changed files with 80 additions and 66 deletions
|
@ -484,6 +484,11 @@ return [
|
||||||
'description' => 'Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.',
|
'description' => 'Project with the requested ID could not be found. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.',
|
||||||
'code' => 404,
|
'code' => 404,
|
||||||
],
|
],
|
||||||
|
Exception::PROJECT_ALREADY_EXISTS => [
|
||||||
|
'name' => Exception::PROJECT_ALREADY_EXISTS,
|
||||||
|
'description' => 'Project with the requested ID already exists.',
|
||||||
|
'code' => 403,
|
||||||
|
],
|
||||||
Exception::PROJECT_UNKNOWN => [
|
Exception::PROJECT_UNKNOWN => [
|
||||||
'name' => Exception::PROJECT_UNKNOWN,
|
'name' => Exception::PROJECT_UNKNOWN,
|
||||||
'description' => 'The project ID is either missing or not valid. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.',
|
'description' => 'The project ID is either missing or not valid. Please check the value of the X-Appwrite-Project header to ensure the correct project ID is being used.',
|
||||||
|
|
|
@ -29,6 +29,7 @@ use Appwrite\Extend\Exception;
|
||||||
use Appwrite\Utopia\Database\Validator\Queries\Projects;
|
use Appwrite\Utopia\Database\Validator\Queries\Projects;
|
||||||
use Utopia\Cache\Cache;
|
use Utopia\Cache\Cache;
|
||||||
use Utopia\Pools\Group;
|
use Utopia\Pools\Group;
|
||||||
|
use Utopia\Database\Exception\Duplicate;
|
||||||
use Utopia\Validator\ArrayList;
|
use Utopia\Validator\ArrayList;
|
||||||
use Utopia\Validator\Boolean;
|
use Utopia\Validator\Boolean;
|
||||||
use Utopia\Validator\Hostname;
|
use Utopia\Validator\Hostname;
|
||||||
|
@ -96,6 +97,7 @@ App::post('/v1/projects')
|
||||||
throw new Exception(Exception::PROJECT_RESERVED_PROJECT, "'console' is a reserved project.");
|
throw new Exception(Exception::PROJECT_RESERVED_PROJECT, "'console' is a reserved project.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$project = $dbForConsole->createDocument('projects', new Document([
|
$project = $dbForConsole->createDocument('projects', new Document([
|
||||||
'$id' => $projectId,
|
'$id' => $projectId,
|
||||||
'$permissions' => [
|
'$permissions' => [
|
||||||
|
@ -127,8 +129,13 @@ App::post('/v1/projects')
|
||||||
'domains' => null,
|
'domains' => null,
|
||||||
'auths' => $auths,
|
'auths' => $auths,
|
||||||
'search' => implode(' ', [$projectId, $name]),
|
'search' => implode(' ', [$projectId, $name]),
|
||||||
'database' => $database,
|
|
||||||
]));
|
]));
|
||||||
|
} catch (Duplicate $th) {
|
||||||
|
throw new Exception(Exception::PROJECT_ALREADY_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var array $collections */
|
||||||
|
$collections = Config::getParam('collections', []);
|
||||||
|
|
||||||
$dbForProject = new Database($pools->get($database)->pop()->getResource(), $cache);
|
$dbForProject = new Database($pools->get($database)->pop()->getResource(), $cache);
|
||||||
$dbForProject->setNamespace("_{$project->getInternalId()}");
|
$dbForProject->setNamespace("_{$project->getInternalId()}");
|
||||||
|
|
67
composer.lock
generated
67
composer.lock
generated
|
@ -408,21 +408,21 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzlehttp/guzzle",
|
"name": "guzzlehttp/guzzle",
|
||||||
"version": "7.6.1",
|
"version": "7.7.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/guzzle.git",
|
"url": "https://github.com/guzzle/guzzle.git",
|
||||||
"reference": "8444a2bacf1960bc6a2b62ed86b8e72e11eebe51"
|
"reference": "fb7566caccf22d74d1ab270de3551f72a58399f5"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/8444a2bacf1960bc6a2b62ed86b8e72e11eebe51",
|
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/fb7566caccf22d74d1ab270de3551f72a58399f5",
|
||||||
"reference": "8444a2bacf1960bc6a2b62ed86b8e72e11eebe51",
|
"reference": "fb7566caccf22d74d1ab270de3551f72a58399f5",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"guzzlehttp/promises": "^1.5",
|
"guzzlehttp/promises": "^1.5.3 || ^2.0",
|
||||||
"guzzlehttp/psr7": "^1.9.1 || ^2.4.5",
|
"guzzlehttp/psr7": "^1.9.1 || ^2.4.5",
|
||||||
"php": "^7.2.5 || ^8.0",
|
"php": "^7.2.5 || ^8.0",
|
||||||
"psr/http-client": "^1.0",
|
"psr/http-client": "^1.0",
|
||||||
|
@ -434,7 +434,8 @@
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"bamarni/composer-bin-plugin": "^1.8.1",
|
"bamarni/composer-bin-plugin": "^1.8.1",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"php-http/client-integration-tests": "^3.0",
|
"php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999",
|
||||||
|
"php-http/message-factory": "^1.1",
|
||||||
"phpunit/phpunit": "^8.5.29 || ^9.5.23",
|
"phpunit/phpunit": "^8.5.29 || ^9.5.23",
|
||||||
"psr/log": "^1.1 || ^2.0 || ^3.0"
|
"psr/log": "^1.1 || ^2.0 || ^3.0"
|
||||||
},
|
},
|
||||||
|
@ -513,7 +514,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/guzzle/guzzle/issues",
|
"issues": "https://github.com/guzzle/guzzle/issues",
|
||||||
"source": "https://github.com/guzzle/guzzle/tree/7.6.1"
|
"source": "https://github.com/guzzle/guzzle/tree/7.7.0"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -529,38 +530,37 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2023-05-15T20:43:01+00:00"
|
"time": "2023-05-21T14:04:53+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzlehttp/promises",
|
"name": "guzzlehttp/promises",
|
||||||
"version": "1.5.2",
|
"version": "2.0.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/promises.git",
|
"url": "https://github.com/guzzle/promises.git",
|
||||||
"reference": "b94b2807d85443f9719887892882d0329d1e2598"
|
"reference": "3a494dc7dc1d7d12e511890177ae2d0e6c107da6"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/b94b2807d85443f9719887892882d0329d1e2598",
|
"url": "https://api.github.com/repos/guzzle/promises/zipball/3a494dc7dc1d7d12e511890177ae2d0e6c107da6",
|
||||||
"reference": "b94b2807d85443f9719887892882d0329d1e2598",
|
"reference": "3a494dc7dc1d7d12e511890177ae2d0e6c107da6",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5"
|
"php": "^7.2.5 || ^8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/phpunit-bridge": "^4.4 || ^5.1"
|
"bamarni/composer-bin-plugin": "^1.8.1",
|
||||||
|
"phpunit/phpunit": "^8.5.29 || ^9.5.23"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"bamarni-bin": {
|
||||||
"dev-master": "1.5-dev"
|
"bin-links": true,
|
||||||
|
"forward-command": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
|
||||||
"src/functions_include.php"
|
|
||||||
],
|
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"GuzzleHttp\\Promise\\": "src/"
|
"GuzzleHttp\\Promise\\": "src/"
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/guzzle/promises/issues",
|
"issues": "https://github.com/guzzle/promises/issues",
|
||||||
"source": "https://github.com/guzzle/promises/tree/1.5.2"
|
"source": "https://github.com/guzzle/promises/tree/2.0.0"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -613,7 +613,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2022-08-28T14:55:35+00:00"
|
"time": "2023-05-21T13:50:22+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzlehttp/psr7",
|
"name": "guzzlehttp/psr7",
|
||||||
|
@ -3165,16 +3165,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nikic/php-parser",
|
"name": "nikic/php-parser",
|
||||||
"version": "v4.15.4",
|
"version": "v4.15.5",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/nikic/PHP-Parser.git",
|
"url": "https://github.com/nikic/PHP-Parser.git",
|
||||||
"reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290"
|
"reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290",
|
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e",
|
||||||
"reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290",
|
"reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -3215,9 +3215,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
||||||
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.4"
|
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.5"
|
||||||
},
|
},
|
||||||
"time": "2023-03-05T19:49:14+00:00"
|
"time": "2023-05-19T20:20:00+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phar-io/manifest",
|
"name": "phar-io/manifest",
|
||||||
|
@ -3568,22 +3568,23 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpdoc-parser",
|
"name": "phpstan/phpdoc-parser",
|
||||||
"version": "1.20.4",
|
"version": "1.21.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
||||||
"reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd"
|
"reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd",
|
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6df62b08faef4f899772bc7c3bbabb93d2b7a21c",
|
||||||
"reference": "7d568c87a9df9c5f7e8b5f075fc469aa8cb0a4cd",
|
"reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2 || ^8.0"
|
"php": "^7.2 || ^8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"nikic/php-parser": "^4.15",
|
||||||
"php-parallel-lint/php-parallel-lint": "^1.2",
|
"php-parallel-lint/php-parallel-lint": "^1.2",
|
||||||
"phpstan/extension-installer": "^1.0",
|
"phpstan/extension-installer": "^1.0",
|
||||||
"phpstan/phpstan": "^1.5",
|
"phpstan/phpstan": "^1.5",
|
||||||
|
@ -3607,9 +3608,9 @@
|
||||||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
|
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
|
||||||
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.20.4"
|
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.0"
|
||||||
},
|
},
|
||||||
"time": "2023-05-02T09:19:37+00:00"
|
"time": "2023-05-17T13:13:44+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
|
|
|
@ -156,6 +156,7 @@ class Exception extends \Exception
|
||||||
public const PROJECT_UNKNOWN = 'project_unknown';
|
public const PROJECT_UNKNOWN = 'project_unknown';
|
||||||
public const PROJECT_PROVIDER_DISABLED = 'project_provider_disabled';
|
public const PROJECT_PROVIDER_DISABLED = 'project_provider_disabled';
|
||||||
public const PROJECT_PROVIDER_UNSUPPORTED = 'project_provider_unsupported';
|
public const PROJECT_PROVIDER_UNSUPPORTED = 'project_provider_unsupported';
|
||||||
|
public const PROJECT_ALREADY_EXISTS = 'project_already_exists';
|
||||||
public const PROJECT_INVALID_SUCCESS_URL = 'project_invalid_success_url';
|
public const PROJECT_INVALID_SUCCESS_URL = 'project_invalid_success_url';
|
||||||
public const PROJECT_INVALID_FAILURE_URL = 'project_invalid_failure_url';
|
public const PROJECT_INVALID_FAILURE_URL = 'project_invalid_failure_url';
|
||||||
public const PROJECT_RESERVED_PROJECT = 'project_reserved_project';
|
public const PROJECT_RESERVED_PROJECT = 'project_reserved_project';
|
||||||
|
|
Loading…
Reference in a new issue