Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show info on added roles #584

Merged
merged 2 commits into from
Oct 31, 2024
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
26 changes: 26 additions & 0 deletions app/Console/Commands/SyncPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +29,9 @@ class SyncPermissions extends Command
protected $description = 'Synchronizes the permissions';
protected ReadPermissionConfig $readPermissionConfig;

private $newRoles = [];
private $newPermissions = [];

/**
* Execute the console command.
*/
Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/NotifyCompanyRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/NotifyPresentationRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading