diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index f1ccf32..18990ec 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -10,16 +10,12 @@ use App\Notifications\FederationRequested; use App\Notifications\FederationUpdated; use App\Services\NotificationService; -use App\Traits\GitTrait; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Notification; -use Illuminate\Support\Facades\Storage; class FederationController extends Controller { - use GitTrait; - /** * Display a listing of the resource. * @@ -85,9 +81,7 @@ public function show(Federation $federation) { $this->authorize('view', $federation); - return view('federations.show', [ - 'federation' => $federation, - ]); + return view('federations.show', compact('federation')); } /** @@ -99,9 +93,7 @@ public function edit(Federation $federation) { $this->authorize('update', $federation); - return view('federations.edit', [ - 'federation' => $federation, - ]); + return view('federations.edit', compact('federation')); } /** @@ -120,9 +112,9 @@ public function update(UpdateFederation $request, Federation $federation) if (isset($validated['name'])) { $id = generateFederationID($validated['name']); } - $additionalFilters = $request->input('sp_and_ip_feed', 0); $filters = $id; + $additionalFilters = $request->input('sp_and_ip_feed', 0); if ($additionalFilters) { $filters .= ', '.$id.'+idp'; $filters .= ', '.$id.'+sp'; @@ -137,7 +129,6 @@ public function update(UpdateFederation $request, Federation $federation) ->route('federations.show', $federation); } NotificationService::sendModelNotification($federation, new FederationUpdated($federation)); - // GitUpdateFederation::dispatch($federation, Auth::user()); return redirect() ->route('federations.show', $federation) diff --git a/app/Http/Controllers/FederationEntityController.php b/app/Http/Controllers/FederationEntityController.php index dd814d8..9a62329 100644 --- a/app/Http/Controllers/FederationEntityController.php +++ b/app/Http/Controllers/FederationEntityController.php @@ -58,7 +58,6 @@ public function store(Federation $federation) return redirect() ->route('federations.entities.index', $federation) ->with('status', __('federations.entities_added')); - } /** @@ -77,8 +76,7 @@ public function destroy(Federation $federation) $federation->entities()->detach(request('entities')); foreach (request('entities') as $id) { - $entity = Entity::find($id); - FolderDeleteMembership::dispatch($entity, $federation); + FolderDeleteMembership::dispatch(Entity::find($id), $federation); } $old_entities = Entity::whereIn('id', request('entities'))->get(); diff --git a/app/Http/Controllers/FederationOperatorController.php b/app/Http/Controllers/FederationOperatorController.php index 987b7f8..1ce0b6a 100644 --- a/app/Http/Controllers/FederationOperatorController.php +++ b/app/Http/Controllers/FederationOperatorController.php @@ -46,13 +46,12 @@ public function store(Federation $federation) $new_operators = User::whereIn('id', request('operators'))->get(); $federation->operators()->attach(request('operators')); - Notification::sendNow($new_operators, new YourFederationRightsChanged($federation, 'added')); + Notification::send($new_operators, new YourFederationRightsChanged($federation, 'added')); NotificationService::sendOperatorNotification($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); return redirect() ->route('federations.operators.index', $federation) ->with('status', __('federations.operators_added')); - } /** @@ -73,12 +72,11 @@ public function destroy(Federation $federation) $federation->operators()->toggle(request('operators')); $new_operators = $federation->operators; - Notification::sendNow($old_operators, new YourFederationRightsChanged($federation, 'deleted')); + Notification::send($old_operators, new YourFederationRightsChanged($federation, 'deleted')); NotificationService::sendOperatorNotification($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'added')); return redirect() ->route('federations.operators.index', $federation) ->with('status', __('federations.operators_deleted')); - } } diff --git a/app/Http/Controllers/FederationStateController.php b/app/Http/Controllers/FederationStateController.php index 94a346d..c7bdbcb 100644 --- a/app/Http/Controllers/FederationStateController.php +++ b/app/Http/Controllers/FederationStateController.php @@ -8,7 +8,7 @@ class FederationStateController extends Controller { - public function state(Federation $federation) + public function update(Federation $federation) { $this->authorize('delete', $federation); @@ -23,6 +23,5 @@ public function state(Federation $federation) ->route('federations.show', $federation) ->with('status', __("federations.$state", ['name' => $federation->name])) ->with('color', $color); - } } diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 66da80f..3abd377 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -21,21 +21,15 @@ class FolderDeleteMembership implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - use HandlesJobsFailuresTrait; - - private Federation $federation; - - private Entity $entity; + use Dispatchable, HandlesJobsFailuresTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. */ - public function __construct(Entity $entity, Federation $federation) - { - $this->federation = $federation; - $this->entity = $entity; - } + public function __construct( + private Entity $entity, + private Federation $federation + ) {} public function getFederation(): Federation { @@ -58,12 +52,12 @@ public function handle(): void try { $pathToDirectory = FederationService::getFederationFolder($federation); - } catch (\Exception $e) { $this->fail($e); return; } + $pathToFile = $federation->xml_id.'/'.$entity->file; if (! Storage::disk($diskName)->exists($pathToFile)) { @@ -84,6 +78,7 @@ public function handle(): void return; } + RunMdaScript::dispatch($federation->id, $lock->owner()); } catch (Exception $e) { $this->fail($e); @@ -94,6 +89,5 @@ public function handle(): void Log::warning("Lock not owned by current process or lock lost for key: $lockKey"); } } - } } diff --git a/app/Jobs/Old_Jobs/Old_GitAddFederation.php b/app/Jobs/Old_Jobs/Old_GitAddFederation.php deleted file mode 100644 index 0ef7f2e..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddFederation.php +++ /dev/null @@ -1,76 +0,0 @@ -federation->xml_id}]\n"; - $content .= "filters = {$this->federation->filters}\n"; - $content .= "name = {$this->federation->xml_name}"; - - $git = $this->initializeGit(); - - Storage::put($this->federation->cfgfile, $content); - Storage::put($this->federation->tagfile, ''); - - if ($git->hasChanges()) { - $git->addFile($this->federation->cfgfile); - $git->addFile($this->federation->tagfile); - - $git->commit( - $this->committer().": {$this->federation->xml_id} (add)\n\n" - ."Requested by: {$this->federation->operators[0]->name} ({$this->federation->operators[0]->uniqueid})\n" - .wordwrap("Explanation: {$this->federation->explanation}", 72)."\n\n" - ."Approved by: {$this->user->name} ({$this->user->uniqueid})\n" - ); - - $git->push(); - } - } - - public function failed(Throwable $exception) - { - Log::critical("Exception occured in {$exception->getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); - Log::channel('slack')->critical("Exception occured in {$exception->getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); - - Mail::to(config('mail.admin.address'))->send(new ExceptionOccured([ - 'message' => $exception->getMessage(), - 'file' => $exception->getFile(), - 'line' => $exception->getLine(), - ])); - } -} diff --git a/app/Jobs/Old_Jobs/Old_GitDeleteFederation.php b/app/Jobs/Old_Jobs/Old_GitDeleteFederation.php deleted file mode 100644 index 87b5810..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteFederation.php +++ /dev/null @@ -1,65 +0,0 @@ -initializeGit(); - - $git->removeFile($this->federation->cfgfile); - $git->removeFile($this->federation->tagfile); - - if ($git->hasChanges()) { - $git->commit( - $this->committer().": {$this->federation->xml_id} (delete)\n\n" - ."Deleted by: {$this->user->name} ({$this->user->uniqueid})\n" - ); - - $git->push(); - } - } - - public function failed(Throwable $exception) - { - Log::critical("Exception occured in {$exception->getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); - Log::channel('slack')->critical("Exception occured in {$exception->getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); - - Mail::to(config('mail.admin.address'))->send(new ExceptionOccured([ - 'message' => $exception->getMessage(), - 'file' => $exception->getFile(), - 'line' => $exception->getLine(), - ])); - } -} diff --git a/app/Jobs/Old_Jobs/Old_GitUpdateFederation.php b/app/Jobs/Old_Jobs/Old_GitUpdateFederation.php deleted file mode 100644 index 477ea57..0000000 --- a/app/Jobs/Old_Jobs/Old_GitUpdateFederation.php +++ /dev/null @@ -1,71 +0,0 @@ -federation->xml_id}]\n"; - $content .= "filters = {$this->federation->filters}\n"; - $content .= "name = {$this->federation->xml_name}"; - - $git = $this->initializeGit(); - - Storage::put($this->federation->cfgfile, $content); - - if ($git->hasChanges()) { - $git->addFile($this->federation->cfgfile); - - $git->commit( - $this->committer().": {$this->federation->cfgfile} (update)\n\n" - ."Updated by: {$this->user->name} ({$this->user->uniqueid})\n" - ); - - $git->push(); - } - } - - public function failed(Throwable $exception) - { - Log::critical("Exception occured in {$exception->getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); - Log::channel('slack')->critical("Exception occured in {$exception->getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); - - Mail::to(config('mail.admin.address'))->send(new ExceptionOccured([ - 'message' => $exception->getMessage(), - 'file' => $exception->getFile(), - 'line' => $exception->getLine(), - ])); - } -} diff --git a/app/Notifications/FederationMembersChanged.php b/app/Notifications/FederationMembersChanged.php index 15d85d1..aee6c75 100644 --- a/app/Notifications/FederationMembersChanged.php +++ b/app/Notifications/FederationMembersChanged.php @@ -4,11 +4,12 @@ use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Collection; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class FederationMembersChanged extends Notification +class FederationMembersChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/FederationOperatorsChanged.php b/app/Notifications/FederationOperatorsChanged.php index c9e8f1f..78cd134 100644 --- a/app/Notifications/FederationOperatorsChanged.php +++ b/app/Notifications/FederationOperatorsChanged.php @@ -4,11 +4,12 @@ use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Collection; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class FederationOperatorsChanged extends Notification +class FederationOperatorsChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/FederationStateChanged.php b/app/Notifications/FederationStateChanged.php index b39ee0c..8615d6a 100644 --- a/app/Notifications/FederationStateChanged.php +++ b/app/Notifications/FederationStateChanged.php @@ -4,10 +4,11 @@ use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class FederationStateChanged extends Notification +class FederationStateChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/FederationUpdated.php b/app/Notifications/FederationUpdated.php index a1e6011..d1dc9d5 100644 --- a/app/Notifications/FederationUpdated.php +++ b/app/Notifications/FederationUpdated.php @@ -4,10 +4,11 @@ use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class FederationUpdated extends Notification +class FederationUpdated extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/MembershipRejected.php b/app/Notifications/MembershipRejected.php index 4f962cc..471e2cc 100644 --- a/app/Notifications/MembershipRejected.php +++ b/app/Notifications/MembershipRejected.php @@ -3,10 +3,11 @@ namespace App\Notifications; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class MembershipRejected extends Notification +class MembershipRejected extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/YourFederationRightsChanged.php b/app/Notifications/YourFederationRightsChanged.php index dd84dd2..5079798 100644 --- a/app/Notifications/YourFederationRightsChanged.php +++ b/app/Notifications/YourFederationRightsChanged.php @@ -4,10 +4,11 @@ use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class YourFederationRightsChanged extends Notification +class YourFederationRightsChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 5a956ae..fce681b 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -75,7 +75,6 @@ private static function sendHfDNotification(Entity $entity): bool public static function sendUpdateNotification(Entity $entity): void { - if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) { self::sendModelNotification($entity, new EntityUpdated($entity)); } diff --git a/routes/web.php b/routes/web.php index 50f13b1..c1b9cce 100644 --- a/routes/web.php +++ b/routes/web.php @@ -102,9 +102,9 @@ Route::post('federations/{federation}/approve', [FederationApprovalController::class, 'store'])->name('federations.approve'); Route::delete('federations/{federation}/reject', [FederationApprovalController::class, 'destroy'])->name('federations.reject'); - Route::patch('federations/{federation}/state', [FederationStateController::class, 'state'])->name('federations.state')->withTrashed(); + Route::patch('federations/{federation}/state', [FederationStateController::class, 'update'])->name('federations.state')->withTrashed(); - Route::get('federations/{federation}/requests', [FederationJoinController::class, 'index'])->name('federations.requests')->withTrashed(); + Route::get('federations/{federation}/requests', [FederationJoinController::class, 'index'])->name('federations.requests'); Route::get('federations/{federation}/operators', [FederationOperatorController::class, 'index'])->name('federations.operators.index')->withTrashed(); Route::post('federations/{federation}/operators', [FederationOperatorController::class, 'store'])->name('federations.operators.store')->withTrashed();