mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #2599 from appwrite/fix-create-existing-collection
Fix: 409 for createCollection
This commit is contained in:
commit
23df3a10ab
2 changed files with 19 additions and 2 deletions
|
|
@ -166,8 +166,6 @@ App::post('/v1/database/collections')
|
||||||
$collectionId = $collectionId == 'unique()' ? $dbForProject->getId() : $collectionId;
|
$collectionId = $collectionId == 'unique()' ? $dbForProject->getId() : $collectionId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dbForProject->createCollection('collection_' . $collectionId);
|
|
||||||
|
|
||||||
$collection = $dbForProject->createDocument('collections', new Document([
|
$collection = $dbForProject->createDocument('collections', new Document([
|
||||||
'$id' => $collectionId,
|
'$id' => $collectionId,
|
||||||
'$read' => $read ?? [], // Collection permissions for collection documents (based on permission model)
|
'$read' => $read ?? [], // Collection permissions for collection documents (based on permission model)
|
||||||
|
|
@ -179,8 +177,12 @@ App::post('/v1/database/collections')
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'search' => implode(' ', [$collectionId, $name]),
|
'search' => implode(' ', [$collectionId, $name]),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
$dbForProject->createCollection('collection_' . $collectionId);
|
||||||
} catch (DuplicateException $th) {
|
} catch (DuplicateException $th) {
|
||||||
throw new Exception('Collection already exists', 409);
|
throw new Exception('Collection already exists', 409);
|
||||||
|
} catch (LimitException $th) {
|
||||||
|
throw new Exception('Collection limit exceeded', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$audits
|
$audits
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,21 @@ class DatabaseCustomServerTest extends Scope
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals($response['headers']['status-code'], 400);
|
$this->assertEquals($response['headers']['status-code'], 400);
|
||||||
|
|
||||||
|
// This collection already exists
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||||
|
]), [
|
||||||
|
'name' => 'Test 1',
|
||||||
|
'collectionId' => 'first',
|
||||||
|
'read' => ['role:all'],
|
||||||
|
'write' => ['role:all'],
|
||||||
|
'permission' => 'document'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals($response['headers']['status-code'], 409);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteAttribute(): array
|
public function testDeleteAttribute(): array
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue