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

Development #585

Merged
merged 10 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
7 changes: 1 addition & 6 deletions app/Actions/Permissions/ReadPermissionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ class ReadPermissionConfig
*/
public function execute(string $path): array|null
{
$content = Storage::get($path);
if (!$content) {
throw new Exception("Error: file storage/app/$path is not found!");
}

$config = Yaml::parse($content);
$config = Yaml::parseFile($path);
// Validate if roles and permissions sections are present
if (!isset($config['roles'])) {
throw new Exception('Error: there are no roles specified!');
Expand Down
28 changes: 27 additions & 1 deletion 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,20 +29,31 @@ class SyncPermissions extends Command
protected $description = 'Synchronizes the permissions';
protected ReadPermissionConfig $readPermissionConfig;

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

/**
* Execute the console command.
*/
public function handle()
{
$this->readPermissionConfig = new ReadPermissionConfig();
$config = $this->readPermissionConfig->execute('config/permissions.yml');
$config = $this->readPermissionConfig->execute('config/permissions/permissions.yml');
if (!$config) {
$this->error("Aborting...");
return 1;
}

$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/Livewire/Crew/RolePermissionsInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function mount($role)
{
$this->role = Role::find($role);
$this->readPermissionConfig = new ReadPermissionConfig();
$permissionsData = $this->readPermissionConfig->execute('config/permissions.yml');
$permissionsData = $this->readPermissionConfig->execute('config/permissions/permissions.yml');

foreach ($permissionsData['permissions'] as $entity => $actions) {
foreach ($actions as $action => $rolesWithPermission) {
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
File renamed without changes.
Loading
Loading