mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch 'swoole-and-functions' of github.com:appwrite/appwrite into feat-add-webhook-events-to-the-users-service
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\Range;
|
||||
use Utopia\Validator\WhiteList;
|
||||
use Utopia\Validator\Text;
|
||||
@@ -20,11 +19,12 @@ use Appwrite\Database\Validator\Collection;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Database\Exception\Authorization as AuthorizationException;
|
||||
use Appwrite\Database\Exception\Structure as StructureException;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
App::post('/v1/database/collections')
|
||||
->desc('Create Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('webhook', 'database.collections.create')
|
||||
->label('event', 'database.collections.create')
|
||||
->label('scope', 'collections.write')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
@@ -35,7 +35,7 @@ App::post('/v1/database/collections')
|
||||
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
||||
->param('rules', [], function ($projectDB) { return new ArrayList(new Collection($projectDB, [Database::SYSTEM_COLLECTION_RULES], ['$collection' => Database::SYSTEM_COLLECTION_RULES, '$permissions' => ['read' => [], 'write' => []]])); }, 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', false, ['projectDB'])
|
||||
->action(function ($name, $read, $write, $rules, $response, $projectDB, $webhooks, $audits) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $webhooks */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
@@ -77,25 +77,14 @@ App::post('/v1/database/collections')
|
||||
throw new Exception('Failed saving collection to DB', 500);
|
||||
}
|
||||
|
||||
$data = $data->getArrayCopy();
|
||||
|
||||
$webhooks
|
||||
->setParam('payload', $data)
|
||||
;
|
||||
|
||||
$audits
|
||||
->setParam('event', 'database.collections.create')
|
||||
->setParam('resource', 'database/collection/'.$data['$id'])
|
||||
->setParam('data', $data)
|
||||
->setParam('resource', 'database/collection/'.$data->getId())
|
||||
->setParam('data', $data->getArrayCopy())
|
||||
;
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json($data)
|
||||
;
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
$response->dynamic($data, Response::MODEL_COLLECTION);
|
||||
}, ['response', 'projectDB', 'webhooks', 'audits']);
|
||||
|
||||
App::get('/v1/database/collections')
|
||||
@@ -111,7 +100,7 @@ App::get('/v1/database/collections')
|
||||
->param('offset', 0, function () { return new Range(0, 40000); }, 'Results offset. The default value is 0. Use this param to manage pagination.', true)
|
||||
->param('orderType', 'ASC', function () { return new WhiteList(['ASC', 'DESC'], true); }, 'Order result by ASC or DESC order.', true)
|
||||
->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
|
||||
$results = $projectDB->getCollection([
|
||||
@@ -126,7 +115,10 @@ App::get('/v1/database/collections')
|
||||
],
|
||||
]);
|
||||
|
||||
$response->json(['sum' => $projectDB->getSum(), 'collections' => $results]);
|
||||
$response->dynamic(new Document([
|
||||
'sum' => $projectDB->getSum(),
|
||||
'collections' => $results
|
||||
]), Response::MODEL_COLLECTION_LIST);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
App::get('/v1/database/collections/:collectionId')
|
||||
@@ -139,7 +131,7 @@ App::get('/v1/database/collections/:collectionId')
|
||||
->label('sdk.description', '/docs/references/database/get-collection.md')
|
||||
->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.')
|
||||
->action(function ($collectionId, $response, $projectDB) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
|
||||
$collection = $projectDB->getDocument($collectionId, false);
|
||||
@@ -148,79 +140,14 @@ App::get('/v1/database/collections/:collectionId')
|
||||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
$response->json($collection->getArrayCopy());
|
||||
$response->dynamic($collection, Response::MODEL_COLLECTION);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
// App::get('/v1/database/collections/:collectionId/logs')
|
||||
// ->desc('Get Collection Logs')
|
||||
// ->groups(['api', 'database'])
|
||||
// ->label('scope', 'collections.read')
|
||||
// ->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
// ->label('sdk.namespace', 'database')
|
||||
// ->label('sdk.method', 'getCollectionLogs')
|
||||
// ->label('sdk.description', '/docs/references/database/get-collection-logs.md')
|
||||
// ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.')
|
||||
// ->action(
|
||||
// function ($collectionId) use ($response, $register, $projectDB, $project) {
|
||||
// $collection = $projectDB->getDocument($collectionId, false);
|
||||
|
||||
// if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
// throw new Exception('Collection not found', 404);
|
||||
// }
|
||||
|
||||
// $adapter = new AuditAdapter($register->get('db'));
|
||||
// $adapter->setNamespace('app_'.$project->getId());
|
||||
|
||||
// $audit = new Audit($adapter);
|
||||
|
||||
// $countries = Locale::getText('countries');
|
||||
|
||||
// $logs = $audit->getLogsByResource('database/collection/'.$collection->getId());
|
||||
|
||||
// $reader = new Reader(__DIR__.'/../../db/DBIP/dbip-country-lite-2020-01.mmdb');
|
||||
// $output = [];
|
||||
|
||||
// foreach ($logs as $i => &$log) {
|
||||
// $log['userAgent'] = (!empty($log['userAgent'])) ? $log['userAgent'] : 'UNKNOWN';
|
||||
|
||||
// $dd = new DeviceDetector($log['userAgent']);
|
||||
|
||||
// $dd->skipBotDetection(); // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then)
|
||||
|
||||
// $dd->parse();
|
||||
|
||||
// $output[$i] = [
|
||||
// 'event' => $log['event'],
|
||||
// 'ip' => $log['ip'],
|
||||
// 'time' => strtotime($log['time']),
|
||||
// 'OS' => $dd->getOs(),
|
||||
// 'client' => $dd->getClient(),
|
||||
// 'device' => $dd->getDevice(),
|
||||
// 'brand' => $dd->getBrand(),
|
||||
// 'model' => $dd->getModel(),
|
||||
// 'geo' => [],
|
||||
// ];
|
||||
|
||||
// try {
|
||||
// $record = $reader->country($log['ip']);
|
||||
// $output[$i]['geo']['isoCode'] = strtolower($record->country->isoCode);
|
||||
// $output[$i]['geo']['country'] = $record->country->name;
|
||||
// $output[$i]['geo']['country'] = (isset($countries[$record->country->isoCode])) ? $countries[$record->country->isoCode] : Locale::getText('locale.country.unknown');
|
||||
// } catch (\Exception $e) {
|
||||
// $output[$i]['geo']['isoCode'] = '--';
|
||||
// $output[$i]['geo']['country'] = Locale::getText('locale.country.unknown');
|
||||
// }
|
||||
// }
|
||||
|
||||
// $response->json($output);
|
||||
// }
|
||||
// );
|
||||
|
||||
App::put('/v1/database/collections/:collectionId')
|
||||
->desc('Update Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.write')
|
||||
->label('webhook', 'database.collections.update')
|
||||
->label('event', 'database.collections.update')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
->label('sdk.method', 'updateCollection')
|
||||
@@ -231,7 +158,7 @@ App::put('/v1/database/collections/:collectionId')
|
||||
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
||||
->param('rules', [], function ($projectDB) { return new ArrayList(new Collection($projectDB, [Database::SYSTEM_COLLECTION_RULES], ['$collection' => Database::SYSTEM_COLLECTION_RULES, '$permissions' => ['read' => [], 'write' => []]])); }, 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', true, ['projectDB'])
|
||||
->action(function ($collectionId, $name, $read, $write, $rules, $response, $projectDB, $webhooks, $audits) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $webhooks */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
@@ -277,33 +204,27 @@ App::put('/v1/database/collections/:collectionId')
|
||||
throw new Exception('Failed saving collection to DB', 500);
|
||||
}
|
||||
|
||||
$data = $collection->getArrayCopy();
|
||||
|
||||
$webhooks
|
||||
->setParam('payload', $data)
|
||||
;
|
||||
|
||||
$audits
|
||||
->setParam('event', 'database.collections.update')
|
||||
->setParam('resource', 'database/collections/'.$data['$id'])
|
||||
->setParam('data', $data)
|
||||
->setParam('resource', 'database/collections/'.$collection->getId())
|
||||
->setParam('data', $collection->getArrayCopy())
|
||||
;
|
||||
|
||||
$response->json($collection->getArrayCopy());
|
||||
$response->dynamic($collection, Response::MODEL_COLLECTION);
|
||||
}, ['response', 'projectDB', 'webhooks', 'audits']);
|
||||
|
||||
App::delete('/v1/database/collections/:collectionId')
|
||||
->desc('Delete Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.write')
|
||||
->label('webhook', 'database.collections.delete')
|
||||
->label('event', 'database.collections.delete')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_SERVER])
|
||||
->label('sdk.method', 'deleteCollection')
|
||||
->label('sdk.description', '/docs/references/database/delete-collection.md')
|
||||
->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.')
|
||||
->action(function ($collectionId, $response, $projectDB, $webhooks, $audits) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $webhooks */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
@@ -318,16 +239,14 @@ App::delete('/v1/database/collections/:collectionId')
|
||||
throw new Exception('Failed to remove collection from DB', 500);
|
||||
}
|
||||
|
||||
$data = $collection->getArrayCopy();
|
||||
|
||||
$webhooks
|
||||
->setParam('payload', $data)
|
||||
->setParam('payload', $response->output($collection, Response::MODEL_COLLECTION))
|
||||
;
|
||||
|
||||
$audits
|
||||
->setParam('event', 'database.collections.delete')
|
||||
->setParam('resource', 'database/collections/'.$data['$id'])
|
||||
->setParam('data', $data)
|
||||
->setParam('resource', 'database/collections/'.$collection->getId())
|
||||
->setParam('data', $collection->getArrayCopy())
|
||||
;
|
||||
|
||||
$response->noContent();
|
||||
@@ -336,7 +255,7 @@ App::delete('/v1/database/collections/:collectionId')
|
||||
App::post('/v1/database/collections/:collectionId/documents')
|
||||
->desc('Create Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('webhook', 'database.documents.create')
|
||||
->label('event', 'database.documents.create')
|
||||
->label('scope', 'documents.write')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
|
||||
@@ -350,7 +269,7 @@ App::post('/v1/database/collections/:collectionId/documents')
|
||||
->param('parentProperty', '', function () { return new Key(); }, 'Parent document property name. Use when you want your new document to be a child of a parent document.', true)
|
||||
->param('parentPropertyType', Document::SET_TYPE_ASSIGN, function () { return new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND], true); }, 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document.', true)
|
||||
->action(function ($collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType, $response, $projectDB, $webhooks, $audits) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $webhooks */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
@@ -387,11 +306,11 @@ App::post('/v1/database/collections/:collectionId/documents')
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. Check child has valid structure,
|
||||
* 2. Check user have write permission for parent document
|
||||
* 3. Assign parent data (including child) to $data
|
||||
* 4. Validate the combined result has valid structure (inside $projectDB->createDocument method)
|
||||
*/
|
||||
* 1. Check child has valid structure,
|
||||
* 2. Check user have write permission for parent document
|
||||
* 3. Assign parent data (including child) to $data
|
||||
* 4. Validate the combined result has valid structure (inside $projectDB->createDocument method)
|
||||
*/
|
||||
|
||||
$new = new Document($data);
|
||||
|
||||
@@ -436,25 +355,17 @@ App::post('/v1/database/collections/:collectionId/documents')
|
||||
throw new Exception('Failed saving document to DB'.$exception->getMessage(), 500);
|
||||
}
|
||||
|
||||
$data = $data->getArrayCopy();
|
||||
|
||||
$webhooks
|
||||
->setParam('payload', $data)
|
||||
;
|
||||
|
||||
$audits
|
||||
->setParam('event', 'database.documents.create')
|
||||
->setParam('resource', 'database/document/'.$data['$id'])
|
||||
->setParam('data', $data)
|
||||
->setParam('data', $data->getArrayCopy())
|
||||
;
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->json($data)
|
||||
;
|
||||
|
||||
$response->dynamic($data, Response::MODEL_ANY);
|
||||
}, ['response', 'projectDB', 'webhooks', 'audits']);
|
||||
|
||||
App::get('/v1/database/collections/:collectionId/documents')
|
||||
@@ -474,7 +385,7 @@ App::get('/v1/database/collections/:collectionId/documents')
|
||||
->param('orderCast', 'string', function () { return new WhiteList(['int', 'string', 'date', 'time', 'datetime'], true); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true)
|
||||
->param('search', '', function () { return new Text(256); }, 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars.', true)
|
||||
->action(function ($collectionId, $filters, $limit, $offset, $orderField, $orderType, $orderCast, $search, $response, $projectDB) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
|
||||
$collection = $projectDB->getDocument($collectionId, false);
|
||||
@@ -512,9 +423,6 @@ App::get('/v1/database/collections/:collectionId/documents')
|
||||
->setAttribute('documents', $list)
|
||||
;
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
$response->json($collection->getArrayCopy(/*['$id', '$collection', 'name', 'documents']*/[], ['rules']));
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
@@ -529,8 +437,8 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
|
||||
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
|
||||
->action(function ($collectionId, $documentId, $request, $response, $projectDB) {
|
||||
/** @var Utopia\Request $request */
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Utopia\Swoole\Request $request */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
|
||||
$document = $projectDB->getDocument($documentId, false);
|
||||
@@ -540,36 +448,13 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
throw new Exception('No document found', 404);
|
||||
}
|
||||
|
||||
$output = $document->getArrayCopy();
|
||||
|
||||
$paths = \explode('/', $request->getParam('q', ''));
|
||||
$paths = \array_slice($paths, 7, \count($paths));
|
||||
|
||||
if (\count($paths) > 0) {
|
||||
if (\count($paths) % 2 == 1) {
|
||||
$output = $document->getAttribute(\implode('.', $paths));
|
||||
} else {
|
||||
$id = (int) \array_pop($paths);
|
||||
$output = $document->search('$id', $id, $document->getAttribute(\implode('.', $paths)));
|
||||
}
|
||||
|
||||
$output = ($output instanceof Document) ? $output->getArrayCopy() : $output;
|
||||
|
||||
if (!\is_array($output)) {
|
||||
throw new Exception('No document found', 404);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
$response->json($output);
|
||||
$response->dynamic($document, Response::MODEL_ANY);
|
||||
}, ['request', 'response', 'projectDB']);
|
||||
|
||||
App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->desc('Update Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('webhook', 'database.documents.update')
|
||||
->label('event', 'database.documents.update')
|
||||
->label('scope', 'documents.write')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
|
||||
@@ -581,7 +466,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->param('read', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
||||
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
||||
->action(function ($collectionId, $documentId, $data, $read, $write, $response, $projectDB, $webhooks, $audits) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $webhooks */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
@@ -592,7 +477,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array
|
||||
|
||||
if (!\is_array($data)) {
|
||||
throw new Exception('Data param should be a valid JSON', 400);
|
||||
throw new Exception('Data param should be a valid JSON object', 400);
|
||||
}
|
||||
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
@@ -621,6 +506,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
if (empty($data)) {
|
||||
throw new Exception('Missing payload', 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $projectDB->updateDocument($data);
|
||||
} catch (AuthorizationException $exception) {
|
||||
@@ -631,29 +517,20 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
throw new Exception('Failed saving document to DB', 500);
|
||||
}
|
||||
|
||||
$data = $data->getArrayCopy();
|
||||
|
||||
$webhooks
|
||||
->setParam('payload', $data)
|
||||
;
|
||||
|
||||
$audits
|
||||
->setParam('event', 'database.documents.update')
|
||||
->setParam('resource', 'database/document/'.$data['$id'])
|
||||
->setParam('data', $data)
|
||||
->setParam('resource', 'database/document/'.$data->getId())
|
||||
->setParam('data', $data->getArrayCopy())
|
||||
;
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
$response->json($data);
|
||||
$response->dynamic($data, Response::MODEL_ANY);
|
||||
}, ['response', 'projectDB', 'webhooks', 'audits']);
|
||||
|
||||
App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->desc('Delete Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.write')
|
||||
->label('webhook', 'database.documents.delete')
|
||||
->label('event', 'database.documents.delete')
|
||||
->label('sdk.namespace', 'database')
|
||||
->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER])
|
||||
->label('sdk.method', 'deleteDocument')
|
||||
@@ -661,7 +538,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
|
||||
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
|
||||
->action(function ($collectionId, $documentId, $response, $projectDB, $webhooks, $audits) {
|
||||
/** @var Utopia\Response $response */
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $webhooks */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
@@ -687,16 +564,14 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
throw new Exception('Failed to remove document from DB', 500);
|
||||
}
|
||||
|
||||
$data = $document->getArrayCopy();
|
||||
|
||||
$webhooks
|
||||
->setParam('payload', $data)
|
||||
->setParam('payload', $response->output($document, Response::MODEL_ANY))
|
||||
;
|
||||
|
||||
|
||||
$audits
|
||||
->setParam('event', 'database.documents.delete')
|
||||
->setParam('resource', 'database/document/'.$data['$id'])
|
||||
->setParam('data', $data) // Audit document in case of malicious or disastrous action
|
||||
->setParam('resource', 'database/document/'.$document->getId())
|
||||
->setParam('data', $document->getArrayCopy()) // Audit document in case of malicious or disastrous action
|
||||
;
|
||||
|
||||
$response->noContent();
|
||||
|
||||
Reference in New Issue
Block a user