1
0
Fork 0
mirror of synced 2024-06-22 04:30:29 +12:00

Merge branch '0.7.x' of github.com:appwrite/appwrite into swoole-and-functions

This commit is contained in:
Eldad Fux 2020-12-06 21:44:20 +02:00
commit 2ab7e520b9
12 changed files with 209 additions and 14 deletions

View file

@ -3,98 +3,163 @@
/**
* List of publicly accessiable system events
*/
use Appwrite\Utopia\Response;
return [
'account.create' => [
'description' => 'This event triggers when the account is created.',
'model' => Response::MODEL_USER,
'note' => '',
],
'account.update.email' => [
'description' => 'This event triggers when the account email address is updated.',
'model' => Response::MODEL_USER,
'note' => '',
],
'account.update.name' => [
'description' => 'This event triggers when the account name is updated.',
'model' => Response::MODEL_USER,
'note' => '',
],
'account.update.password' => [
'description' => 'This event triggers when the account password is updated.',
'model' => Response::MODEL_USER,
'note' => '',
],
'account.update.prefs' => [
'description' => 'This event triggers when the account preferences are updated.',
'model' => Response::MODEL_USER,
'note' => '',
],
'account.recovery.create' => [
'description' => 'This event triggers when the account recovery token is created.',
'model' => Response::MODEL_TOKEN,
'note' => 'version >= 0.7',
],
'account.recovery.update' => [
'description' => 'This event triggers when the account recovery token is validated.',
'model' => Response::MODEL_TOKEN,
'note' => 'version >= 0.7',
],
'account.verification.create' => [
'description' => 'This event triggers when the account verification token is created.',
'model' => Response::MODEL_TOKEN,
'note' => 'version >= 0.7',
],
'account.verification.update' => [
'description' => 'This event triggers when the account verification token is validated.',
'model' => Response::MODEL_TOKEN,
'note' => 'version >= 0.7',
],
'account.delete' => [
'description' => 'This event triggers when the account is deleted.',
'model' => Response::MODEL_USER,
'note' => '',
],
'account.sessions.create' => [
'description' => 'This event triggers when the account session is created.',
'model' => Response::MODEL_SESSION,
'note' => '',
],
'account.sessions.delete' => [
'description' => 'This event triggers when the account session is deleted.',
'model' => Response::MODEL_SESSION,
'note' => '',
],
'database.collections.create' => [
'description' => 'This event triggers when a database collection is created.',
'model' => Response::MODEL_COLLECTION,
'note' => '',
],
'database.collections.update' => [
'description' => 'This event triggers when a database collection is updated.',
'model' => Response::MODEL_COLLECTION,
'note' => '',
],
'database.collections.delete' => [
'description' => 'This event triggers when a database collection is deleted.',
'model' => Response::MODEL_COLLECTION,
'note' => '',
],
'database.documents.create' => [
'description' => 'This event triggers when a database document is created.',
'model' => Response::MODEL_ANY,
'note' => '',
],
'database.documents.update' => [
'description' => 'This event triggers when a database document is updated.',
'model' => Response::MODEL_ANY,
'note' => '',
],
'database.documents.delete' => [
'description' => 'This event triggers when a database document is deleted.',
'model' => Response::MODEL_ANY,
'note' => '',
],
'storage.files.create' => [
'description' => 'This event triggers when a storage file is created.',
'model' => Response::MODEL_FILE,
'note' => '',
],
'storage.files.update' => [
'description' => 'This event triggers when a storage file is updated.',
'model' => Response::MODEL_FILE,
'note' => '',
],
'storage.files.delete' => [
'description' => 'This event triggers when a storage file is deleted.',
'model' => Response::MODEL_FILE,
'note' => '',
],
'users.create' => [
'description' => 'This event triggers when a user is created from the users API.',
'model' => Response::MODEL_USER,
'note' => 'version >= 0.7',
],
'users.update.status' => [
'description' => 'This event triggers when a user status is updated from the users API.',
'model' => Response::MODEL_USER,
'note' => 'version >= 0.7',
],
'users.delete' => [
'description' => 'This event triggers when a user is deleted from users API.',
'model' => Response::MODEL_USER,
'note' => 'version >= 0.7',
],
'users.sessions.delete' => [
'description' => 'This event triggers when a user session is deleted from users API.',
'model' => Response::MODEL_SESSION,
'note' => 'version >= 0.7',
],
'teams.create' => [
'description' => 'This event triggers when a team is created.',
'model' => Response::MODEL_TEAM,
'note' => 'version >= 0.7',
],
'teams.update' => [
'description' => 'This event triggers when a team is updated.',
'model' => Response::MODEL_TEAM,
'note' => 'version >= 0.7',
],
'teams.delete' => [
'description' => 'This event triggers when a team is deleted.',
'model' => Response::MODEL_TEAM,
'note' => 'version >= 0.7',
],
'teams.memberships.create' => [
'description' => 'This event triggers when a team memberships is created.',
'model' => Response::MODEL_MEMBERSHIP,
'note' => 'version >= 0.7',
],
'teams.memberships.update.status' => [
'description' => 'This event triggers when a team memberships status is updated.',
'model' => Response::MODEL_MEMBERSHIP,
'note' => 'version >= 0.7',
],
'teams.memberships.delete' => [
'description' => 'This event triggers when a team memberships is deleted.',
'model' => Response::MODEL_MEMBERSHIP,
'note' => 'version >= 0.7',
],
];

View file

@ -235,7 +235,7 @@ App::delete('/v1/database/collections/:collectionId')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_NONE)
->param('collectionId', '', new UID(), 'Collection unique ID.')
->action(function ($collectionId, $response, $projectDB, $webhooks, $audits) {
->action(function ($collectionId, $response, $projectDB, $webhooks, $audits, $deletes) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */
/** @var Appwrite\Event\Event $webhooks */
@ -250,7 +250,11 @@ App::delete('/v1/database/collections/:collectionId')
if (!$projectDB->deleteDocument($collectionId)) {
throw new Exception('Failed to remove collection from DB', 500);
}
$deletes
->setParam('document', $collection)
;
$webhooks
->setParam('payload', $response->output($collection, Response::MODEL_COLLECTION))
;
@ -262,7 +266,7 @@ App::delete('/v1/database/collections/:collectionId')
;
$response->noContent();
}, ['response', 'projectDB', 'webhooks', 'audits']);
}, ['response', 'projectDB', 'webhooks', 'audits', 'deletes']);
App::post('/v1/database/collections/:collectionId/documents')
->desc('Create Document')

View file

@ -37,7 +37,7 @@ const APP_USERAGENT = APP_NAME.'-Server v%s. Please report abuse at %s';
const APP_MODE_DEFAULT = 'default';
const APP_MODE_ADMIN = 'admin';
const APP_PAGING_LIMIT = 12;
const APP_CACHE_BUSTER = 140;
const APP_CACHE_BUSTER = 141;
const APP_VERSION_STABLE = '0.7.0';
const APP_STORAGE_UPLOADS = '/storage/uploads';
const APP_STORAGE_FUNCTIONS = '/storage/functions';

View file

@ -32,7 +32,7 @@ class DeletesV1
$document = new Document($document);
switch ($document->getCollection()) {
switch (strval($document->getCollection())) {
case Database::SYSTEM_COLLECTION_PROJECTS:
$this->deleteProject($document);
break;
@ -42,7 +42,9 @@ class DeletesV1
case Database::SYSTEM_COLLECTION_USERS:
$this->deleteUser($document, $projectId);
break;
case Database::SYSTEM_COLLECTION_COLLECTIONS:
$this->deleteDocuments($document, $projectId);
break;
default:
Console::error('No lazy delete operation available for document of type: '.$document->getCollection());
break;
@ -53,6 +55,16 @@ class DeletesV1
{
// ... Remove environment for this job
}
protected function deleteDocuments(Document $document, $projectId)
{
$collectionId = $document->getId();
// Delete Documents in the deleted collection
$this->deleteByGroup([
'$collection='.$collectionId
], $this->getProjectDB($projectId));
}
protected function deleteProject(Document $document)
{
@ -202,4 +214,4 @@ class DeletesV1
return $projectDB;
}
}
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View file

@ -1 +1 @@
<svg version="1" xmlns="http://www.w3.org/2000/svg" width="512" height="342" viewBox="0 0 5120 3420"><g fill="#788c99"><path d="M1460 3413c-166-27-376-95-523-170-475-241-815-693-916-1216-30-155-30-479 0-634 59-307 214-616 422-840 243-264 510-420 887-520 86-23 118-26 340-30 220-4 255-3 346 16 149 31 336 94 447 151l97 50 98-50c110-57 297-120 446-151 91-19 126-20 346-16 222 4 254 7 340 30 310 82 529 194 740 377 293 255 496 605 569 983 30 155 30 479 0 634-59 307-215 617-424 842-241 261-509 418-885 518-86 23-118 26-340 30-220 4-255 3-346-16-149-31-336-94-446-151l-98-50-97 50c-110 57-298 120-444 150-81 17-133 20-316 19-120-1-229-4-243-6zm514-377c183-35 467-179 611-308 154-138 235-244 322-420 111-225 137-336 137-598s-26-373-137-598c-87-176-168-282-322-420-144-129-428-273-611-308-101-19-420-19-529 0-119 21-302 95-434 174-255 154-456 403-569 704-63 169-76 243-76 448s13 279 76 448c113 301 314 550 569 704 126 76 314 153 424 173 100 18 443 19 539 1z"/><path d="M1500 2128c0-7 26-123 59-258 135-553 179-740 180-767 1-9 25-13 86-13 47 0 85 3 85 8 0 15-109 485-197 850l-47 192h-83c-60 0-83-4-83-12zM1257 1806c-21-22-62-68-92-100-33-36-51-64-47-72 4-6 47-55 96-108l88-96h104c83 0 104 3 104 14 0 8-3 16-7 18-5 2-45 43-91 91l-82 89 26 31c14 18 55 62 90 98 35 37 64 70 64 73s-48 5-107 5l-108-1-38-42zM1900 1842c0-4 40-50 89-103l89-95-89-94c-48-52-88-101-89-107 0-10 27-13 103-13h103l85 93c46 50 89 99 96 108 10 13-3 31-84 117l-96 102h-103c-57 0-104-3-104-8z"/></g></svg>
<svg viewBox="0 0 272 182" xmlns="http://www.w3.org/2000/svg" xmlns:bx="https://boxy-svg.com"><path d="M271.058 91.03c0 49.722-40.306 90.028-90.028 90.028-23.096 0-44.159-8.697-60.096-22.993 25.531-11.493 43.305-37.157 43.305-66.971 0-29.852-17.818-55.542-43.4-67.014 15.949-14.346 37.05-23.078 60.191-23.078 49.722 0 90.028 40.306 90.028 90.028z" fill="#788c99"/><path d="M145.043 19.167a90.028 90.028 0 10-108.46 143.725 90.028 90.028 0 10108.46-143.725zM135.03 32.434a73.407 73.407 0 01-88.435 117.19 73.407 73.407 0 0188.435-117.19z" bx:shape="ring 186.727 313.243 73.407 73.407 90.028 90.028 1@7a525c32" bx:origin="0.499777 0.499705" fill="#788c99"/><path d="M93.225 59.882c-.108.266-1.485 5.672-2.967 12.084-1.538 6.413-3.976 16.535-5.351 22.524-2.653 10.969-4.243 18.177-4.243 19.132 0 .263 1.644.477 3.657.477h3.658l1.641-7.315c.956-3.974 3.076-13.09 4.771-20.244 1.697-7.155 3.762-15.847 4.559-19.345.793-3.499 1.588-6.676 1.749-7.047.159-.477-.744-.635-3.499-.635-2.068 0-3.871.158-3.975.369zM64.764 82.829l-4.875 5.301 1.432 1.695c.792.953 2.968 3.339 4.822 5.301l3.392 3.602h9.646l-4.557-4.929c-2.493-2.647-4.56-5.193-4.56-5.51 0-.371 1.909-2.755 4.241-5.299 2.331-2.596 4.24-4.824 4.24-5.089 0-.212-2.014-.371-4.451-.371h-4.399l-4.931 5.299zm37.098-4.982c0 .161.902 1.166 2.013 2.28 4.137 4.133 7.051 7.633 6.892 8.32-.106.373-2.121 2.861-4.557 5.458l-4.398 4.823h4.927l4.929-.052 4.503-4.928c2.493-2.754 4.506-5.196 4.506-5.513 0-.263-2.119-2.755-4.77-5.562l-4.768-5.143h-4.613c-2.597 0-4.664.159-4.664.317z" fill="#788c99"/></svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -1 +1 @@
<svg version="1" xmlns="http://www.w3.org/2000/svg" width="512" height="342" viewBox="0 0 5120 3420"><g fill="#f02e65"><path d="M1460 3413c-166-27-376-95-523-170-475-241-815-693-916-1216-30-155-30-479 0-634 59-307 214-616 422-840 243-264 510-420 887-520 86-23 118-26 340-30 220-4 255-3 346 16 149 31 336 94 447 151l97 50 98-50c110-57 297-120 446-151 91-19 126-20 346-16 222 4 254 7 340 30 310 82 529 194 740 377 293 255 496 605 569 983 30 155 30 479 0 634-59 307-215 617-424 842-241 261-509 418-885 518-86 23-118 26-340 30-220 4-255 3-346-16-149-31-336-94-446-151l-98-50-97 50c-110 57-298 120-444 150-81 17-133 20-316 19-120-1-229-4-243-6zm514-377c183-35 467-179 611-308 154-138 235-244 322-420 111-225 137-336 137-598s-26-373-137-598c-87-176-168-282-322-420-144-129-428-273-611-308-101-19-420-19-529 0-119 21-302 95-434 174-255 154-456 403-569 704-63 169-76 243-76 448s13 279 76 448c113 301 314 550 569 704 126 76 314 153 424 173 100 18 443 19 539 1z"/><path d="M1500 2128c0-7 26-123 59-258 135-553 179-740 180-767 1-9 25-13 86-13 47 0 85 3 85 8 0 15-109 485-197 850l-47 192h-83c-60 0-83-4-83-12zM1257 1806c-21-22-62-68-92-100-33-36-51-64-47-72 4-6 47-55 96-108l88-96h104c83 0 104 3 104 14 0 8-3 16-7 18-5 2-45 43-91 91l-82 89 26 31c14 18 55 62 90 98 35 37 64 70 64 73s-48 5-107 5l-108-1-38-42zM1900 1842c0-4 40-50 89-103l89-95-89-94c-48-52-88-101-89-107 0-10 27-13 103-13h103l85 93c46 50 89 99 96 108 10 13-3 31-84 117l-96 102h-103c-57 0-104-3-104-8z"/></g></svg>
<svg viewBox="0 0 272 182" xmlns="http://www.w3.org/2000/svg" xmlns:bx="https://boxy-svg.com"><path d="M271.058 91.03c0 49.722-40.306 90.028-90.028 90.028-23.096 0-44.159-8.697-60.096-22.993 25.531-11.493 43.305-37.157 43.305-66.971 0-29.852-17.818-55.542-43.4-67.014 15.949-14.346 37.05-23.078 60.191-23.078 49.722 0 90.028 40.306 90.028 90.028z" fill="#f02e65"/><path d="M145.043 19.167a90.028 90.028 0 10-108.46 143.725 90.028 90.028 0 10108.46-143.725zM135.03 32.434a73.407 73.407 0 01-88.435 117.19 73.407 73.407 0 0188.435-117.19z" bx:shape="ring 186.727 313.243 73.407 73.407 90.028 90.028 1@7a525c32" bx:origin="0.499777 0.499705" fill="#f02e65"/><path d="M93.225 59.882c-.108.266-1.485 5.672-2.967 12.084-1.538 6.413-3.976 16.535-5.351 22.524-2.653 10.969-4.243 18.177-4.243 19.132 0 .263 1.644.477 3.657.477h3.658l1.641-7.315c.956-3.974 3.076-13.09 4.771-20.244 1.697-7.155 3.762-15.847 4.559-19.345.793-3.499 1.588-6.676 1.749-7.047.159-.477-.744-.635-3.499-.635-2.068 0-3.871.158-3.975.369zM64.764 82.829l-4.875 5.301 1.432 1.695c.792.953 2.968 3.339 4.822 5.301l3.392 3.602h9.646l-4.557-4.929c-2.493-2.647-4.56-5.193-4.56-5.51 0-.371 1.909-2.755 4.241-5.299 2.331-2.596 4.24-4.824 4.24-5.089 0-.212-2.014-.371-4.451-.371h-4.399l-4.931 5.299zm37.098-4.982c0 .161.902 1.166 2.013 2.28 4.137 4.133 7.051 7.633 6.892 8.32-.106.373-2.121 2.861-4.557 5.458l-4.398 4.823h4.927l4.929-.052 4.503-4.928c2.493-2.754 4.506-5.196 4.506-5.513 0-.263-2.119-2.755-4.77-5.562l-4.768-5.143h-4.613c-2.597 0-4.664.159-4.664.317z" fill="#f02e65"/></svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -5,10 +5,119 @@ namespace Tests\E2E\Services\Database;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
use Tests\E2E\Client;
class DatabaseCustomServerTest extends Scope
{
use DatabaseBase;
use ProjectCustom;
use SideServer;
public function testDeleteCollection()
{
/**
* Test for SUCCESS
*/
// Create collection
$actors = $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' => 'Actors',
'read' => ['*'],
'write' => ['role:1', 'role:2'],
'rules' => [
[
'label' => 'First Name',
'key' => 'firstName',
'type' => 'text',
'default' => '',
'required' => true,
'array' => false
],
[
'label' => 'Last Name',
'key' => 'lastName',
'type' => 'text',
'default' => '',
'required' => true,
'array' => false
],
],
]);
$this->assertEquals($actors['headers']['status-code'], 201);
$this->assertEquals($actors['body']['$collection'], 0);
$this->assertEquals($actors['body']['name'], 'Actors');
$this->assertIsArray($actors['body']['$permissions']);
$this->assertIsArray($actors['body']['$permissions']['read']);
$this->assertIsArray($actors['body']['$permissions']['write']);
$this->assertCount(1, $actors['body']['$permissions']['read']);
$this->assertCount(2, $actors['body']['$permissions']['write']);
// Add Documents to the collection
$document1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'firstName' => 'Tom',
'lastName' => 'Holland',
],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$document2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $actors['body']['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'firstName' => 'Samuel',
'lastName' => 'Jackson',
],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$this->assertEquals($document1['headers']['status-code'], 201);
$this->assertEquals($document1['body']['$collection'], $actors['body']['$id']);
$this->assertIsArray($document1['body']['$permissions']);
$this->assertIsArray($document1['body']['$permissions']['read']);
$this->assertIsArray($document1['body']['$permissions']['write']);
$this->assertCount(1, $document1['body']['$permissions']['read']);
$this->assertCount(1, $document1['body']['$permissions']['write']);
$this->assertEquals($document1['body']['firstName'], 'Tom');
$this->assertEquals($document1['body']['lastName'], 'Holland');
$this->assertEquals($document2['headers']['status-code'], 201);
$this->assertEquals($document2['body']['$collection'], $actors['body']['$id']);
$this->assertIsArray($document2['body']['$permissions']);
$this->assertIsArray($document2['body']['$permissions']['read']);
$this->assertIsArray($document2['body']['$permissions']['write']);
$this->assertCount(1, $document2['body']['$permissions']['read']);
$this->assertCount(1, $document2['body']['$permissions']['write']);
$this->assertEquals($document2['body']['firstName'], 'Samuel');
$this->assertEquals($document2['body']['lastName'], 'Jackson');
// Delete the actors collection
$response = $this->client->call(Client::METHOD_DELETE, '/database/collections/'.$actors['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
], $this->getHeaders()));
$this->assertEquals($response['headers']['status-code'], 204);
$this->assertEquals($response['body'],"");
// Try to get the collection and check if it has been deleted
$response = $this->client->call(Client::METHOD_GET, '/database/collections/'.$actors['body']['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id']
], $this->getHeaders()));
$this->assertEquals($response['headers']['status-code'], 404);
}
}