Skip to content

Commit

Permalink
Federation code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
JanOppolzer committed Nov 26, 2024
1 parent 535008b commit 6922218
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 255 deletions.
15 changes: 3 additions & 12 deletions app/Http/Controllers/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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';
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Controllers/FederationEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function store(Federation $federation)
return redirect()
->route('federations.entities.index', $federation)
->with('status', __('federations.entities_added'));

}

/**
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions app/Http/Controllers/FederationOperatorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

}

/**
Expand All @@ -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'));

}
}
3 changes: 1 addition & 2 deletions app/Http/Controllers/FederationStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class FederationStateController extends Controller
{
public function state(Federation $federation)
public function update(Federation $federation)
{
$this->authorize('delete', $federation);

Expand All @@ -23,6 +23,5 @@ public function state(Federation $federation)
->route('federations.show', $federation)
->with('status', __("federations.$state", ['name' => $federation->name]))
->with('color', $color);

}
}
20 changes: 7 additions & 13 deletions app/Jobs/FolderDeleteMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)) {
Expand All @@ -84,6 +78,7 @@ public function handle(): void

return;
}

RunMdaScript::dispatch($federation->id, $lock->owner());
} catch (Exception $e) {
$this->fail($e);
Expand All @@ -94,6 +89,5 @@ public function handle(): void
Log::warning("Lock not owned by current process or lock lost for key: $lockKey");
}
}

}
}
76 changes: 0 additions & 76 deletions app/Jobs/Old_Jobs/Old_GitAddFederation.php

This file was deleted.

65 changes: 0 additions & 65 deletions app/Jobs/Old_Jobs/Old_GitDeleteFederation.php

This file was deleted.

71 changes: 0 additions & 71 deletions app/Jobs/Old_Jobs/Old_GitUpdateFederation.php

This file was deleted.

Loading

0 comments on commit 6922218

Please sign in to comment.