diff --git a/app/Console/Commands/SyncPermissions.php b/app/Console/Commands/SyncPermissions.php index 1529a909..a8ed3010 100644 --- a/app/Console/Commands/SyncPermissions.php +++ b/app/Console/Commands/SyncPermissions.php @@ -5,6 +5,8 @@ use App\Actions\Permissions\ReadPermissionConfig; use Illuminate\Console\Command; use Illuminate\Support\Facades\Storage; +use Mockery\Exception; +use Spatie\Permission\Exceptions\PermissionDoesNotExist; use Spatie\Permission\Exceptions\RoleDoesNotExist; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; @@ -27,6 +29,9 @@ class SyncPermissions extends Command protected $description = 'Synchronizes the permissions'; protected ReadPermissionConfig $readPermissionConfig; + private $newRoles = []; + private $newPermissions = []; + /** * Execute the console command. */ @@ -41,6 +46,14 @@ public function handle() $this->syncRoles($config['roles']); $this->syncPermissions($config['permissions']); + + if (count($this->newRoles) > 0) { + $this->info('The added roles: ' . implode(', ', $this->newRoles)); + } + if (count($this->newPermissions) > 0) { + $this->info('The added permissions: ' . implode(', ', $this->newPermissions)); + } + return 0; } @@ -61,6 +74,12 @@ private function syncRoles(array|string $input) ]; } foreach ($role_data as $role) { + try { + Role::findByName($role['name']); + } catch (RoleDoesNotExist) { + $this->newRoles[] = $role['name']; + } + Role::updateOrCreate( ['name' => $role['name']], $role @@ -103,6 +122,13 @@ private function syncPermissions(array $permissions) foreach ($permissions as $item) { $roles = $item['roles']; unset($item['roles']); + + try { + Permission::findByName($item['name']); + } catch (PermissionDoesNotExist) { + $this->newPermissions[] = $item['name']; + } + $permission = Permission::updateOrCreate( ['name' => $item['name']], $item diff --git a/app/Jobs/NotifyCompanyRoles.php b/app/Jobs/NotifyCompanyRoles.php index 58493462..0f450e51 100644 --- a/app/Jobs/NotifyCompanyRoles.php +++ b/app/Jobs/NotifyCompanyRoles.php @@ -37,7 +37,7 @@ public function handle(): void $users = collect(); if ($this->receiver == 'crew') { $users = User::role(['event organizer', 'assistant organizer'])->get(); - } else if ($this->receiver == 'company representative') { + } elseif ($this->receiver == 'company representative') { if ($representative = $this->company->representative) { $users->push($representative); } diff --git a/app/Jobs/NotifyPresentationRoles.php b/app/Jobs/NotifyPresentationRoles.php index 5d2ac072..c3267ec3 100644 --- a/app/Jobs/NotifyPresentationRoles.php +++ b/app/Jobs/NotifyPresentationRoles.php @@ -37,7 +37,7 @@ public function handle(): void $users = collect(); if ($this->receiver == 'crew') { $users = User::role(['event organizer', 'speakers supervisor', 'assistant organizer'])->get(); - } else if ($this->receiver == 'speaker') { + } elseif ($this->receiver == 'speaker') { $users = $this->presentation->speakers; } diff --git a/app/Models/User.php b/app/Models/User.php index 4ec7b233..87f2b52a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -400,7 +400,7 @@ public function ticketStatus(): Attribute 'color' => 'green', 'icon' => 'M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z', ]; - } else if (optional(Edition::current())->is_final_programme_released) { + } elseif (optional(Edition::current())->is_final_programme_released) { return [ 'status' => 'Ticket sent', 'color' => 'yellow',