fix: hide internal id from documents
This commit is contained in:
parent
2f5c958f22
commit
ba2790221c
|
@ -1832,7 +1832,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
$usage
|
||||
->setParam('database.documents.read', 1)
|
||||
->setParam('collectionId', $collectionId)
|
||||
;
|
||||
;
|
||||
|
||||
$response->dynamic($document, Response::MODEL_DOCUMENT);
|
||||
});
|
||||
|
|
|
@ -26,6 +26,7 @@ use Appwrite\Utopia\Response\Model\Continent;
|
|||
use Appwrite\Utopia\Response\Model\Country;
|
||||
use Appwrite\Utopia\Response\Model\Currency;
|
||||
use Appwrite\Utopia\Response\Model\Document as ModelDocument;
|
||||
use Appwrite\Utopia\Response\Model\DocumentList;
|
||||
use Appwrite\Utopia\Response\Model\Domain;
|
||||
use Appwrite\Utopia\Response\Model\Error;
|
||||
use Appwrite\Utopia\Response\Model\ErrorDev;
|
||||
|
@ -207,7 +208,6 @@ class Response extends SwooleResponse
|
|||
// Lists
|
||||
->setModel(new BaseList('Collections List', self::MODEL_COLLECTION_LIST, 'collections', self::MODEL_COLLECTION))
|
||||
->setModel(new BaseList('Indexes List', self::MODEL_INDEX_LIST, 'indexes', self::MODEL_INDEX))
|
||||
->setModel(new BaseList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_DOCUMENT))
|
||||
->setModel(new BaseList('Users List', self::MODEL_USER_LIST, 'users', self::MODEL_USER))
|
||||
->setModel(new BaseList('Sessions List', self::MODEL_SESSION_LIST, 'sessions', self::MODEL_SESSION))
|
||||
->setModel(new BaseList('Logs List', self::MODEL_LOG_LIST, 'logs', self::MODEL_LOG))
|
||||
|
@ -229,6 +229,7 @@ class Response extends SwooleResponse
|
|||
->setModel(new BaseList('Currencies List', self::MODEL_CURRENCY_LIST, 'currencies', self::MODEL_CURRENCY))
|
||||
->setModel(new BaseList('Phones List', self::MODEL_PHONE_LIST, 'phones', self::MODEL_PHONE))
|
||||
->setModel(new BaseList('Metric List', self::MODEL_METRIC_LIST, 'metrics', self::MODEL_METRIC, true, false))
|
||||
->setModel(new DocumentList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_DOCUMENT))
|
||||
// Entities
|
||||
->setModel(new Collection())
|
||||
->setModel(new Attribute())
|
||||
|
@ -370,13 +371,13 @@ class Response extends SwooleResponse
|
|||
$model = $this->getModel($model);
|
||||
$output = [];
|
||||
|
||||
$document = $model->filter($document);
|
||||
|
||||
if ($model->isAny()) {
|
||||
$this->payload = $document->getArrayCopy();
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
$document = $model->filter($document);
|
||||
|
||||
foreach ($model->getRules() as $key => $rule) {
|
||||
if (!$document->isSet($key) && $rule['require']) { // do not set attribute in response if not required
|
||||
if (!is_null($rule['default'])) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document as DatabaseDocument;
|
||||
|
||||
class Document extends Any
|
||||
{
|
||||
|
@ -57,4 +58,11 @@ class Document extends Any
|
|||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function filter(DatabaseDocument $document): DatabaseDocument
|
||||
{
|
||||
$document->removeAttribute('$internalId');
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
||||
|
|
17
src/Appwrite/Utopia/Response/Model/DocumentList.php
Normal file
17
src/Appwrite/Utopia/Response/Model/DocumentList.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Utopia\Database\Document;
|
||||
|
||||
class DocumentList extends BaseList
|
||||
{
|
||||
public function filter(Document $document): Document
|
||||
{
|
||||
foreach ($document->getAttribute('documents', []) as $node) {
|
||||
$node->removeAttribute('$internalId');
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
}
|
|
@ -825,6 +825,9 @@ trait DatabaseBase
|
|||
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
|
||||
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
|
||||
$this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']);
|
||||
$this->assertEmpty($documents['body']['documents'][0]['$internalId']);
|
||||
$this->assertEmpty($documents['body']['documents'][1]['$internalId']);
|
||||
$this->assertEmpty($documents['body']['documents'][2]['$internalId']);
|
||||
$this->assertCount(3, $documents['body']['documents']);
|
||||
|
||||
foreach ($documents['body']['documents'] as $document) {
|
||||
|
@ -866,6 +869,7 @@ trait DatabaseBase
|
|||
$this->assertEquals($response['body']['releaseYear'], $document['releaseYear']);
|
||||
$this->assertEquals($response['body']['$read'], $document['$read']);
|
||||
$this->assertEquals($response['body']['$write'], $document['$write']);
|
||||
$this->assertEmpty($response['body']['$internalId']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue