Skip to content

Commit 9074dfa

Browse files
committed
(fix): remove auto-registration of hooks, let callers register explicitly
1 parent 26f0c82 commit 9074dfa

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Database/Adapter/Mongo.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,17 @@ protected function syncReadHooks(): void
169169
{
170170
$this->readHooks = [];
171171

172-
$this->readHooks[] = new MongoTenantFilter(
173-
$this->tenant,
174-
$this->sharedTables,
175-
fn (string $collection, array $tenants = []) => $this->getTenantFilters($collection, $tenants),
176-
);
172+
if ($this->sharedTables && $this->tenant !== null) {
173+
$this->readHooks[] = new MongoTenantFilter(
174+
$this->tenant,
175+
$this->sharedTables,
176+
fn (string $collection, array $tenants = []) => $this->getTenantFilters($collection, $tenants),
177+
);
178+
}
177179

178-
$this->readHooks[] = new MongoPermissionFilter($this->authorization);
180+
if ($this->hasPermissionHook()) {
181+
$this->readHooks[] = new MongoPermissionFilter($this->authorization);
182+
}
179183
}
180184

181185
/**

src/Database/Adapter/SQL.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,10 +2887,6 @@ protected function newPermissionHook(string $collection, array $roles, string $t
28872887
*/
28882888
protected function syncWriteHooks(): void
28892889
{
2890-
if (empty(array_filter($this->writeHooks, fn ($h) => $h instanceof Permissions))) {
2891-
$this->addWriteHook(new Permissions());
2892-
}
2893-
28942890
$this->removeWriteHook(Tenancy::class);
28952891
if ($this->sharedTables && $this->tenant !== null) {
28962892
$this->addWriteHook(new Tenancy($this->tenant));

0 commit comments

Comments
 (0)