From bb01a6d817536ba63b220b23a396c3be96393bf0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 24 Nov 2022 11:23:59 +1300 Subject: [PATCH 1/5] Get default region param from env --- app/controllers/api/projects.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 1e70a99fc..26c1e31df 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -59,7 +59,7 @@ App::post('/v1/projects') ->param('projectId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `ID.unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('teamId', '', new UID(), 'Team unique ID.') - ->param('region', 'default', new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.', true) + ->param('region', '', new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.', true) ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) ->param('logo', '', new Text(1024), 'Project logo.', true) ->param('url', '', new URL(), 'Project URL.', true) @@ -92,6 +92,10 @@ App::post('/v1/projects') throw new Exception(Exception::PROJECT_RESERVED_PROJECT, "'console' is a reserved project."); } + if (\empty($region)) { + $region = App::getEnv('_APP_REGION', 'default'); + } + $project = $dbForConsole->createDocument('projects', new Document([ '$id' => $projectId, '$permissions' => [ From de38fed306a2352546c386549861fb5f5bc53f73 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 25 Nov 2022 10:29:22 +1300 Subject: [PATCH 2/5] Fix empty check --- app/controllers/api/projects.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 26c1e31df..e56b6c5cd 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -92,7 +92,7 @@ App::post('/v1/projects') throw new Exception(Exception::PROJECT_RESERVED_PROJECT, "'console' is a reserved project."); } - if (\empty($region)) { + if (empty($region)) { $region = App::getEnv('_APP_REGION', 'default'); } From 6070e1de54df6519ef67637b846fa00b058a40b1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 25 Nov 2022 10:37:11 +1300 Subject: [PATCH 3/5] Add defaulted region test --- .../Projects/ProjectsConsoleClientTest.php | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index cd9f032d6..413b66589 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -55,6 +55,23 @@ class ProjectsConsoleClientTest extends Scope $projectId = $response['body']['$id']; + $response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'projectId' => ID::unique(), + 'name' => 'Project Test', + 'teamId' => $team['body']['$id'], + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals('Project Test', $response['body']['name']); + $this->assertEquals($team['body']['$id'], $response['body']['teamId']); + $this->assertArrayHasKey('platforms', $response['body']); + $this->assertArrayHasKey('webhooks', $response['body']); + $this->assertArrayHasKey('keys', $response['body']); + /** * Test for FAILURE */ @@ -116,9 +133,9 @@ class ProjectsConsoleClientTest extends Scope ])); $this->assertEquals($response['headers']['status-code'], 200); - $this->assertEquals($response['body']['total'], 1); + $this->assertEquals($response['body']['total'], 2); $this->assertIsArray($response['body']['projects']); - $this->assertCount(1, $response['body']['projects']); + $this->assertCount(2, $response['body']['projects']); $this->assertEquals($response['body']['projects'][0]['name'], 'Project Test'); $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ @@ -129,9 +146,9 @@ class ProjectsConsoleClientTest extends Scope ])); $this->assertEquals($response['headers']['status-code'], 200); - $this->assertEquals($response['body']['total'], 1); + $this->assertEquals($response['body']['total'], 2); $this->assertIsArray($response['body']['projects']); - $this->assertCount(1, $response['body']['projects']); + $this->assertCount(2, $response['body']['projects']); $this->assertEquals($response['body']['projects'][0]['$id'], $data['projectId']); /** @@ -195,7 +212,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [ 'offset(1)' ], + 'queries' => [ 'offset(2)' ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -224,7 +241,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']); - $this->assertCount(2, $response['body']['projects']); + $this->assertCount(3, $response['body']['projects']); $this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']); $this->assertEquals('Project Test', $response['body']['projects'][1]['name']); @@ -235,9 +252,9 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']); - $this->assertCount(2, $response['body']['projects']); + $this->assertCount(3, $response['body']['projects']); $this->assertEquals('Project Test', $response['body']['projects'][0]['name']); - $this->assertEquals('Project Test 2', $response['body']['projects'][1]['name']); + $this->assertEquals('Project Test 2', $response['body']['projects'][2]['name']); $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ 'content-type' => 'application/json', @@ -248,8 +265,8 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']); - $this->assertCount(1, $response['body']['projects']); - $this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']); + $this->assertCount(2, $response['body']['projects']); + $this->assertEquals('Project Test 2', $response['body']['projects'][1]['name']); $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ 'content-type' => 'application/json', From 9d0cbd3b6817864616c187c56c01e965596fbf9b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 25 Nov 2022 10:39:53 +1300 Subject: [PATCH 4/5] Update changelog --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e1655b069..1668f1c04 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# Version 1.2.0 +## Changes +- Get default region from environment on project create [#4780](https://github.com/appwrite/appwrite/pull/4780) + # Version 1.1.2 ## Changes - Make `region` parameter optional with default for project create [#4763](https://github.com/appwrite/appwrite/pull/4763) From f44a6429981d0d3e49de75eeb2d7e944cbd64072 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 25 Nov 2022 17:27:19 +1300 Subject: [PATCH 5/5] Get from env in param call --- app/controllers/api/projects.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index e56b6c5cd..1fc60c372 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -59,7 +59,7 @@ App::post('/v1/projects') ->param('projectId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `ID.unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('teamId', '', new UID(), 'Team unique ID.') - ->param('region', '', new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.', true) + ->param('region', App::getEnv('_APP_REGION', 'default'), new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.', true) ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) ->param('logo', '', new Text(1024), 'Project logo.', true) ->param('url', '', new URL(), 'Project URL.', true) @@ -92,10 +92,6 @@ App::post('/v1/projects') throw new Exception(Exception::PROJECT_RESERVED_PROJECT, "'console' is a reserved project."); } - if (empty($region)) { - $region = App::getEnv('_APP_REGION', 'default'); - } - $project = $dbForConsole->createDocument('projects', new Document([ '$id' => $projectId, '$permissions' => [