Skip to content

Commit

Permalink
Reset teamId on octane (#2547)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 authored Nov 9, 2023
1 parent 62f22e1 commit 8e584d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
5 changes: 2 additions & 3 deletions config/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@
'register_permission_check_method' => true,

/*
* When set to true, the Spatie\Permission\Listeners\OctaneReloadPermissions listener will be registered
* on the Laravel\Octane\Events\OperationTerminated event, this will refresh permissions on every
* TickTerminated, TaskTerminated and RequestTerminated
* When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered
* this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated
* NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it.
*/
'register_octane_reset_listener' => false,
Expand Down
13 changes: 0 additions & 13 deletions src/Listeners/OctaneReloadPermissions.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/PermissionRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function getCacheStoreFromConfig(): Repository
/**
* Set the team id for teams/groups support, this id is used when querying permissions/roles
*
* @param int|string|\Illuminate\Database\Eloquent\Model $id
* @param int|string|\Illuminate\Database\Eloquent\Model|null $id
*/
public function setPermissionsTeamId($id): void
{
Expand Down
19 changes: 13 additions & 6 deletions src/PermissionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Illuminate\View\Compilers\BladeCompiler;
use Spatie\Permission\Contracts\Permission as PermissionContract;
use Spatie\Permission\Contracts\Role as RoleContract;
use Spatie\Permission\Listeners\OctaneReloadPermissions;

class PermissionServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -91,17 +90,25 @@ protected function registerCommands(): void

protected function registerOctaneListener(): void
{
if ($this->app->runningInConsole() || ! $this->app['config']->get('permission.register_octane_reset_listener')) {
if ($this->app->runningInConsole() || ! $this->app['config']->get('octane.listeners')) {
return;
}

if (! $this->app['config']->get('octane.listeners')) {
$dispatcher = $this->app[Dispatcher::class];
// @phpstan-ignore-next-line
$dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) {
// @phpstan-ignore-next-line
$event->sandbox->make(PermissionRegistrar::class)->setPermissionsTeamId(null);
});

if (! $this->app['config']->get('permission.register_octane_reset_listener')) {
return;
}

$dispatcher = $this->app[Dispatcher::class];
// @phpstan-ignore-next-line
$dispatcher->listen(\Laravel\Octane\Events\OperationTerminated::class, OctaneReloadPermissions::class);
$dispatcher->listen(function (\Laravel\Octane\Events\OperationTerminated $event) {
// @phpstan-ignore-next-line
$event->sandbox->make(PermissionRegistrar::class)->clearPermissionsCollection();
});
}

protected function registerModelBindings(): void
Expand Down

0 comments on commit 8e584d3

Please sign in to comment.