Skip to content

Commit

Permalink
Merge pull request #586 from HZ-HBO-ICT/main
Browse files Browse the repository at this point in the history
Hotfix for permissions
  • Loading branch information
eliotolhoek authored Nov 5, 2024
2 parents 0eeb84c + 2385483 commit 06abd51
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 600 deletions.
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.
Binary file not shown.
Binary file added public/files/policies/privacy_policy_1-9-2024.pdf
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ class="bg-gradient-to-br from-gradient-light-blue via-gradient-light-pink to-gra
<h2 class="mb-6 text-sm font-semibold text-gray-900 uppercase dark:text-white">Legal</h2>
<ul class="text-gray-400 font-medium">
<li class="mb-4">
<a href="#" class="hover:underline">Privacy Policy</a>
<a href="{{ route('privacy-policy') }}" class="hover:underline">Privacy Policy</a>
</li>
<li class="mb-4">
<a href="#" class="hover:underline">Licensing</a>
<a href="{{ route('cookie-statement') }}" class="hover:underline">Cookie Statement</a>
</li>
<li class="mb-4">
<a href="#" class="hover:underline">Terms &amp; Conditions</a>
<a href="{{ route('terms-and-conditions') }}" class="hover:underline">Terms &amp; Conditions</a>
</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class="after:content-['*'] after:text-red-500"/>

<div class="ml-2">
{!! __('I agree to the :terms_of_service and :privacy_policy', [
'terms_of_service' => '<a target="_blank" href="'.route('terms.show').'" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">'.__('Terms of Service').'</a>',
'privacy_policy' => '<a target="_blank" href="'.route('policy.show').'" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">'.__('Privacy Policy').'</a>',
'terms_of_service' => '<a target="_blank" href="'.route('terms-and-conditions').'" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">'.__('Terms of Service').'</a>',
'privacy_policy' => '<a target="_blank" href="'.route('privacy-policy').'" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">'.__('Privacy Policy').'</a>',
]) !!}
</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use App\Http\Controllers\RegistrationController;
use App\Http\Controllers\SpeakerController;
use Illuminate\Auth\Middleware\RedirectIfAuthenticated;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Route;

/*Route::middleware([
Expand Down Expand Up @@ -122,6 +123,39 @@
Route::post('/moderator/editions/{edition}/activate', [EditionController::class, 'activateEdition'])
->name('moderator.editions.activate');
});

// Routes for policy files
Route::get('/files/policies/privacy-policy', function () {
$path = public_path('files/policies/privacy_policy_1-9-2024.pdf');

if (file_exists($path)) {
return Response::file($path);
}

abort(404, 'File not found');
})->name('privacy-policy');

Route::get('/files/policies/cookie-statement', function () {
$path = public_path('files/policies/cookie_statement_1-9-2024.pdf');

if (file_exists($path)) {
return Response::file($path);
}

abort(404, 'File not found');
})->name('cookie-statement');

Route::get('/files/policies/terms-and-conditions', function () {
$path = public_path('files/policies/terms_and_conditions_1-9-2024.pdf');

if (file_exists($path)) {
return Response::file($path);
}

abort(404, 'File not found');
})->name('terms-and-conditions');


//
// //route for my profile in personal hub
// Route::get('/my/profile', [HubController::class, 'getProfileInfo'])->name('my-profile');
Expand Down
Loading

0 comments on commit 06abd51

Please sign in to comment.