Skip to content

Commit 8e584d3

Browse files
authored
Reset teamId on octane (#2547)
1 parent 62f22e1 commit 8e584d3

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

config/permission.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@
104104
'register_permission_check_method' => true,
105105

106106
/*
107-
* When set to true, the Spatie\Permission\Listeners\OctaneReloadPermissions listener will be registered
108-
* on the Laravel\Octane\Events\OperationTerminated event, this will refresh permissions on every
109-
* TickTerminated, TaskTerminated and RequestTerminated
107+
* When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered
108+
* this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated
110109
* NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it.
111110
*/
112111
'register_octane_reset_listener' => false,

src/Listeners/OctaneReloadPermissions.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/PermissionRegistrar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function getCacheStoreFromConfig(): Repository
9898
/**
9999
* Set the team id for teams/groups support, this id is used when querying permissions/roles
100100
*
101-
* @param int|string|\Illuminate\Database\Eloquent\Model $id
101+
* @param int|string|\Illuminate\Database\Eloquent\Model|null $id
102102
*/
103103
public function setPermissionsTeamId($id): void
104104
{

src/PermissionServiceProvider.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Illuminate\View\Compilers\BladeCompiler;
1414
use Spatie\Permission\Contracts\Permission as PermissionContract;
1515
use Spatie\Permission\Contracts\Role as RoleContract;
16-
use Spatie\Permission\Listeners\OctaneReloadPermissions;
1716

1817
class PermissionServiceProvider extends ServiceProvider
1918
{
@@ -91,17 +90,25 @@ protected function registerCommands(): void
9190

9291
protected function registerOctaneListener(): void
9392
{
94-
if ($this->app->runningInConsole() || ! $this->app['config']->get('permission.register_octane_reset_listener')) {
93+
if ($this->app->runningInConsole() || ! $this->app['config']->get('octane.listeners')) {
9594
return;
9695
}
9796

98-
if (! $this->app['config']->get('octane.listeners')) {
97+
$dispatcher = $this->app[Dispatcher::class];
98+
// @phpstan-ignore-next-line
99+
$dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) {
100+
// @phpstan-ignore-next-line
101+
$event->sandbox->make(PermissionRegistrar::class)->setPermissionsTeamId(null);
102+
});
103+
104+
if (! $this->app['config']->get('permission.register_octane_reset_listener')) {
99105
return;
100106
}
101-
102-
$dispatcher = $this->app[Dispatcher::class];
103107
// @phpstan-ignore-next-line
104-
$dispatcher->listen(\Laravel\Octane\Events\OperationTerminated::class, OctaneReloadPermissions::class);
108+
$dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) {
109+
// @phpstan-ignore-next-line
110+
$event->sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection();
111+
});
105112
}
106113

107114
protected function registerModelBindings(): void

0 commit comments

Comments
 (0)