Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ public function updateCollection(string $id, array $permissions, bool $documentS

if (
$this->adapter->getSharedTables()
&& $collection->getAttribute('$tenant') != $this->adapter->getTenant()
&& $collection->getTenant() !== $this->adapter->getTenant()
) {
throw new NotFoundException('Collection not found');
}
Expand Down Expand Up @@ -1288,13 +1288,11 @@ public function getCollection(string $id): Document
{
$collection = $this->silent(fn () => $this->getDocument(self::METADATA, $id));

$tenant = $collection->getAttribute('$tenant');

if (
$id !== self::METADATA
&& $this->adapter->getSharedTables()
&& $tenant !== null
&& $tenant != $this->adapter->getTenant()
&& $collection->getTenant() !== null
&& $collection->getTenant() !== $this->adapter->getTenant()
) {
return new Document();
}
Expand Down Expand Up @@ -1341,7 +1339,7 @@ public function getSizeOfCollection(string $collection): int
throw new NotFoundException('Collection not found');
}

if ($this->adapter->getSharedTables() && $collection->getAttribute('$tenant') != $this->adapter->getTenant()) {
if ($this->adapter->getSharedTables() && $collection->getTenant() !== $this->adapter->getTenant()) {
throw new NotFoundException('Collection not found');
}

Expand All @@ -1367,7 +1365,7 @@ public function getSizeOfCollectionOnDisk(string $collection): int
throw new NotFoundException('Collection not found');
}

if ($this->adapter->getSharedTables() && $collection->getAttribute('$tenant') != $this->adapter->getTenant()) {
if ($this->adapter->getSharedTables() && $collection->getTenant() !== $this->adapter->getTenant()) {
throw new NotFoundException('Collection not found');
}

Expand All @@ -1390,7 +1388,7 @@ public function deleteCollection(string $id): bool
throw new NotFoundException('Collection not found');
}

if ($this->adapter->getSharedTables() && $collection->getAttribute('$tenant') != $this->adapter->getTenant()) {
if ($this->adapter->getSharedTables() && $collection->getTenant() !== $this->adapter->getTenant()) {
throw new NotFoundException('Collection not found');
}

Expand Down Expand Up @@ -3873,7 +3871,7 @@ public function updateDocument(string $collection, string $id, Document $documen
$document['$createdAt'] = $old->getCreatedAt(); // Make sure user doesn't switch createdAt

if ($this->adapter->getSharedTables()) {
$document['$tenant'] = $old->getAttribute('$tenant'); // Make sure user doesn't switch tenant
$document['$tenant'] = $old->getTenant(); // Make sure user doesn't switch tenant
}

$document = new Document($document);
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16302,7 +16302,7 @@ public function testSharedTables(): void

$doc = $database->getDocument('people', $docId);
$this->assertEquals('Spiderman', $doc['name']);
$this->assertEquals($tenant1, $doc->getAttribute('$tenant'));
$this->assertEquals($tenant1, $doc->getTenant());

/**
* Remove Permissions
Expand All @@ -16315,7 +16315,7 @@ public function testSharedTables(): void

$doc = $database->getDocument('people', $docId);
$this->assertEquals([Permission::read(Role::any())], $doc['$permissions']);
$this->assertEquals($tenant1, $doc->getAttribute('$tenant'));
$this->assertEquals($tenant1, $doc->getTenant());

/**
* Add Permissions
Expand Down Expand Up @@ -16512,7 +16512,7 @@ public function testSharedTablesTenantPerDocument(): void
->getDocument(__FUNCTION__, $doc2Id);

$this->assertEquals('Batman', $doc['name']);
$this->assertEquals(2, $doc->getAttribute('$tenant'));
$this->assertEquals(2, $doc->getTenant());

// Ensure no read cross-tenant
$docs = $database
Expand Down