1
0
Fork 0
mirror of synced 2024-07-10 17:06:17 +12:00

Merge pull request #5572 from appwrite/feat-update-project-creation

Feat update project creation
This commit is contained in:
Christy Jacob 2023-05-25 22:50:24 +05:30 committed by GitHub
commit 075ed65a2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 35 deletions

View file

@ -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' => 409,
],
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.',

View file

@ -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,39 +97,43 @@ 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.");
} }
$project = $dbForConsole->createDocument('projects', new Document([ try {
'$id' => $projectId, $project = $dbForConsole->createDocument('projects', new Document([
'$permissions' => [ '$id' => $projectId,
Permission::read(Role::team(ID::custom($teamId))), '$permissions' => [
Permission::update(Role::team(ID::custom($teamId), 'owner')), Permission::read(Role::team(ID::custom($teamId))),
Permission::update(Role::team(ID::custom($teamId), 'developer')), Permission::update(Role::team(ID::custom($teamId), 'owner')),
Permission::delete(Role::team(ID::custom($teamId), 'owner')), Permission::update(Role::team(ID::custom($teamId), 'developer')),
Permission::delete(Role::team(ID::custom($teamId), 'developer')), Permission::delete(Role::team(ID::custom($teamId), 'owner')),
], Permission::delete(Role::team(ID::custom($teamId), 'developer')),
'name' => $name, ],
'teamInternalId' => $team->getInternalId(), 'name' => $name,
'teamId' => $team->getId(), 'teamInternalId' => $team->getInternalId(),
'region' => $region, 'teamId' => $team->getId(),
'description' => $description, 'region' => $region,
'logo' => $logo, 'description' => $description,
'url' => $url, 'logo' => $logo,
'version' => APP_VERSION_STABLE, 'url' => $url,
'legalName' => $legalName, 'version' => APP_VERSION_STABLE,
'legalCountry' => $legalCountry, 'legalName' => $legalName,
'legalState' => $legalState, 'legalCountry' => $legalCountry,
'legalCity' => $legalCity, 'legalState' => $legalState,
'legalAddress' => $legalAddress, 'legalCity' => $legalCity,
'legalTaxId' => ID::custom($legalTaxId), 'legalAddress' => $legalAddress,
'services' => new stdClass(), 'legalTaxId' => ID::custom($legalTaxId),
'platforms' => null, 'services' => new stdClass(),
'authProviders' => [], 'platforms' => null,
'webhooks' => null, 'authProviders' => [],
'keys' => null, 'webhooks' => null,
'domains' => null, 'keys' => null,
'auths' => $auths, 'domains' => null,
'search' => implode(' ', [$projectId, $name]), 'auths' => $auths,
'database' => $database, 'search' => implode(' ', [$projectId, $name]),
])); 'database' => $database
]));
} catch (Duplicate $th) {
throw new Exception(Exception::PROJECT_ALREADY_EXISTS);
}
$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()}");

View file

@ -7,7 +7,7 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
> >
<extensions> <extensions>
<extension class="Appwrite\Tests\TestHook" /> <extension class="Appwrite\Tests\TestHook" />
</extensions> </extensions>

View file

@ -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';

View file

@ -3,6 +3,7 @@
namespace Tests\E2E\Services\Projects; namespace Tests\E2E\Services\Projects;
use Appwrite\Auth\Auth; use Appwrite\Auth\Auth;
use Appwrite\Extend\Exception;
use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectConsole; use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\SideClient; use Tests\E2E\Scopes\SideClient;
@ -98,7 +99,37 @@ class ProjectsConsoleClientTest extends Scope
$this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals(400, $response['headers']['status-code']);
return ['projectId' => $projectId]; return [
'projectId' => $projectId,
'teamId' => $team['body']['$id']
];
}
/**
* @depends testCreateProject
*/
public function testCreateDuplicateProject($data)
{
$teamId = $data['teamId'] ?? '';
$projectId = $data['projectId'] ?? '';
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'projectId' => $projectId,
'name' => 'Project Duplicate',
'teamId' => $teamId,
'region' => 'default'
]);
$this->assertEquals(409, $response['headers']['status-code']);
$this->assertEquals(409, $response['body']['code']);
$this->assertEquals(Exception::PROJECT_ALREADY_EXISTS, $response['body']['type']);
$this->assertEquals('Project with the requested ID already exists.', $response['body']['message']);
} }
/** /**