mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Merge pull request #10590 from appwrite/dat-753
Bug fix -> related data in realtime payload
This commit is contained in:
commit
60433ef22d
2 changed files with 152 additions and 0 deletions
|
|
@ -592,6 +592,7 @@ class Event
|
|||
$this->project = $event->getProject();
|
||||
$this->user = $event->getUser();
|
||||
$this->payload = $event->getPayload();
|
||||
$this->sensitive = $event->sensitive;
|
||||
$this->event = $event->getEvent();
|
||||
$this->params = $event->getParams();
|
||||
$this->context = $event->context;
|
||||
|
|
|
|||
|
|
@ -2507,4 +2507,155 @@ class RealtimeCustomClientTest extends Scope
|
|||
|
||||
$client->close();
|
||||
}
|
||||
|
||||
public function testRelationshipPayloadHidesRelatedDoc()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$session = $user['session'] ?? '';
|
||||
$projectId = $this->getProject()['$id'];
|
||||
|
||||
$client = $this->getWebsocket(['documents'], [
|
||||
'origin' => 'http://localhost',
|
||||
'cookie' => 'a_session_' . $projectId . '=' . $session
|
||||
]);
|
||||
|
||||
$response = json_decode($client->receive(), true);
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertEquals('connected', $response['type']);
|
||||
|
||||
// Create database
|
||||
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'db-rel'
|
||||
]);
|
||||
$databaseId = $database['body']['$id'];
|
||||
|
||||
$level1 = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'level1',
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::create(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
'documentSecurity' => true,
|
||||
]);
|
||||
$level1Id = $level1['body']['$id'];
|
||||
|
||||
$level2 = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'collectionId' => ID::unique(),
|
||||
'name' => 'level2',
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::create(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
'documentSecurity' => true,
|
||||
]);
|
||||
$level2Id = $level2['body']['$id'];
|
||||
|
||||
$this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$level1Id}/attributes/string", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'name',
|
||||
'size' => 256,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$level2Id}/attributes/string", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'key' => 'name',
|
||||
'size' => 256,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
sleep(2);
|
||||
|
||||
// two-way one-to-one relationship from level1 to level2
|
||||
$this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$level1Id}/attributes/relationship", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'relatedCollectionId' => $level2Id,
|
||||
'type' => 'oneToOne',
|
||||
'twoWay' => true,
|
||||
'key' => 'level2Ref',
|
||||
'onDelete' => 'cascade',
|
||||
]);
|
||||
|
||||
sleep(2);
|
||||
|
||||
$doc2 = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$level2Id}/documents", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $this->getHeaders()), [
|
||||
'documentId' => ID::unique(),
|
||||
'data' => [ 'name' => 'L2' ],
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
]);
|
||||
$doc2Id = $doc2['body']['$id'];
|
||||
|
||||
$doc1 = $this->client->call(Client::METHOD_POST, "/databases/{$databaseId}/collections/{$level1Id}/documents", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $this->getHeaders()), [
|
||||
'documentId' => ID::unique(),
|
||||
'data' => [ 'name' => 'L1' ],
|
||||
'permissions' => [
|
||||
Permission::read(Role::any()),
|
||||
Permission::update(Role::any()),
|
||||
Permission::delete(Role::any()),
|
||||
],
|
||||
]);
|
||||
$doc1Id = $doc1['body']['$id'];
|
||||
|
||||
json_decode($client->receive(), true);
|
||||
|
||||
$this->client->call(Client::METHOD_PATCH, "/databases/{$databaseId}/collections/{$level1Id}/documents/{$doc1Id}", array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]), [
|
||||
'data' => [
|
||||
'level2Ref' => $doc2Id,
|
||||
],
|
||||
]);
|
||||
|
||||
// payload should not contain the relationship attribute 'level2Ref'
|
||||
$event = json_decode($client->receive(), true);
|
||||
$this->assertArrayHasKey('type', $event);
|
||||
$this->assertEquals('event', $event['type']);
|
||||
$this->assertArrayHasKey('data', $event);
|
||||
$this->assertNotEmpty($event['data']);
|
||||
$this->assertArrayHasKey('payload', $event['data']);
|
||||
$this->assertArrayHasKey('$id', $event['data']['payload']);
|
||||
$this->assertEquals($doc1Id, $event['data']['payload']['$id']);
|
||||
$this->assertArrayNotHasKey('level2Ref', $event['data']['payload']);
|
||||
|
||||
$client->close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue