From bdda9733687e9e63e838acfe46b5184a21ab8c8a Mon Sep 17 00:00:00 2001 From: Jan Oppolzer Date: Tue, 26 Nov 2024 16:23:22 +0100 Subject: [PATCH] Entities code cleaning --- .../Controllers/EntityCategoryController.php | 3 +- app/Http/Controllers/EntityController.php | 12 +- .../Controllers/EntityEduGainController.php | 2 +- .../EntityFederationController.php | 5 +- .../EntityManagementController.php | 242 ------------------ .../Controllers/EntityMetadataController.php | 2 + .../Controllers/EntityOperatorController.php | 5 +- app/Http/Controllers/EntityRsController.php | 9 +- .../Controllers/EntityStateController.php | 3 +- app/Jobs/Old_Jobs/Old_GitAddEntity.php | 67 ----- app/Jobs/Old_Jobs/Old_GitAddMember.php | 70 ----- app/Jobs/Old_Jobs/Old_GitAddMembers.php | 73 ------ app/Jobs/Old_Jobs/Old_GitAddMembership.php | 70 ----- app/Jobs/Old_Jobs/Old_GitAddToEdugain.php | 69 ----- app/Jobs/Old_Jobs/Old_GitAddToHfd.php | 71 ----- app/Jobs/Old_Jobs/Old_GitAddToRs.php | 71 ----- app/Jobs/Old_Jobs/Old_GitDeleteEntity.php | 76 ------ .../Old_Jobs/Old_GitDeleteFromEdugain.php | 71 ----- .../Old_Jobs/Old_GitDeleteFromFederation.php | 73 ------ app/Jobs/Old_Jobs/Old_GitDeleteFromHfd.php | 71 ----- app/Jobs/Old_Jobs/Old_GitDeleteFromRs.php | 73 ------ app/Jobs/Old_Jobs/Old_GitDeleteMembers.php | 74 ------ app/Jobs/Old_Jobs/Old_GitRestoreToEdugain.php | 73 ------ app/Jobs/Old_Jobs/Old_GitUpdateEntity.php | 67 ----- app/Jobs/RunMdaScript.php | 7 +- .../EntityDeletedFromFederation.php | 3 +- app/Notifications/EntityDestroyed.php | 3 +- app/Notifications/EntityOperatorsChanged.php | 3 +- app/Notifications/EntityRequested.php | 3 +- app/Notifications/IdpCategoryChanged.php | 3 +- app/Notifications/YourEntityRightsChanged.php | 3 +- app/Services/CategoryTagService.php | 7 +- app/Services/HfdTagService.php | 5 +- app/Services/RsTagService.php | 5 +- resources/views/entities/index.blade.php | 6 - routes/web.php | 69 +++-- 36 files changed, 68 insertions(+), 1401 deletions(-) delete mode 100644 app/Http/Controllers/EntityManagementController.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddEntity.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddMember.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddMembers.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddMembership.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddToEdugain.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddToHfd.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitAddToRs.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitDeleteEntity.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitDeleteFromEdugain.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitDeleteFromFederation.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitDeleteFromHfd.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitDeleteFromRs.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitDeleteMembers.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitRestoreToEdugain.php delete mode 100644 app/Jobs/Old_Jobs/Old_GitUpdateEntity.php diff --git a/app/Http/Controllers/EntityCategoryController.php b/app/Http/Controllers/EntityCategoryController.php index 9b19ab1..8a198eb 100644 --- a/app/Http/Controllers/EntityCategoryController.php +++ b/app/Http/Controllers/EntityCategoryController.php @@ -28,9 +28,11 @@ public function update(Entity $entity) if ($xml_file) { $entity->xml_file = $xml_file; } + $entity->category()->associate($category); $entity->xml_file = CategoryTag::create($entity); $entity->save(); + $admins = User::activeAdmins()->select('id', 'email')->get(); Notification::send($admins, new IdpCategoryChanged($entity, $category)); @@ -42,6 +44,5 @@ public function update(Entity $entity) return redirect() ->route('entities.show', $entity) ->with('status', __('entities.category_updated')); - } } diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 867fe95..8904a96 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -14,18 +14,15 @@ use App\Notifications\EntityRequested; use App\Traits\DumpFromGit\EntitiesHelp\DeleteFromEntity; use App\Traits\DumpFromGit\EntitiesHelp\UpdateEntity; -use App\Traits\GitTrait; use App\Traits\ValidatorTrait; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Notification; -use Illuminate\Support\Facades\Storage; class EntityController extends Controller { - use DeleteFromEntity,UpdateEntity; - use GitTrait, ValidatorTrait; + use DeleteFromEntity, UpdateEntity, ValidatorTrait; /** * Display a listing of the resource. @@ -171,9 +168,7 @@ public function edit(Entity $entity) { $this->authorize('update', $entity); - return view('entities.edit', [ - 'entity' => $entity, - ]); + return view('entities.edit', compact('entity')); } /** @@ -260,7 +255,6 @@ public function update(Request $request, Entity $entity) ->back() ->with('status', __('entities.unknown_error_while_registration')) ->with('color', 'red'); - } } @@ -288,7 +282,7 @@ public function destroy(Entity $entity) $entity->forceDelete(); $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::sendNow($admins, new EntityDestroyed($name)); + Notification::send($admins, new EntityDestroyed($name)); return redirect('entities') ->with('status', __('entities.destroyed', ['name' => $name])); diff --git a/app/Http/Controllers/EntityEduGainController.php b/app/Http/Controllers/EntityEduGainController.php index e720b65..95555bf 100644 --- a/app/Http/Controllers/EntityEduGainController.php +++ b/app/Http/Controllers/EntityEduGainController.php @@ -7,7 +7,7 @@ class EntityEduGainController extends Controller { - public function edugain(Entity $entity) + public function update(Entity $entity) { $this->authorize('update', $entity); diff --git a/app/Http/Controllers/EntityFederationController.php b/app/Http/Controllers/EntityFederationController.php index 8384876..b13b62f 100644 --- a/app/Http/Controllers/EntityFederationController.php +++ b/app/Http/Controllers/EntityFederationController.php @@ -8,15 +8,12 @@ use App\Models\Federation; use App\Models\User; use App\Notifications\EntityDeletedFromFederation; -use App\Traits\GitTrait; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Notification; class EntityFederationController extends Controller { - use GitTrait; - public function index(Entity $entity) { $this->authorize('view', $entity); @@ -77,7 +74,7 @@ public function destroy(Request $request, Entity $entity) $federation = Federation::find($f); FolderDeleteMembership::dispatch($entity, $federation); - //GitDeleteFromFederation::dispatch($entity, $federation, Auth::user()); + Notification::send($entity->operators, new EntityDeletedFromFederation($entity, $federation)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromFederation($entity, $federation)); } diff --git a/app/Http/Controllers/EntityManagementController.php b/app/Http/Controllers/EntityManagementController.php deleted file mode 100644 index 3f6b043..0000000 --- a/app/Http/Controllers/EntityManagementController.php +++ /dev/null @@ -1,242 +0,0 @@ -authorize('do-everything'); - - $this->initializeGit(); - - $xmlfiles = []; - $tagfiles = []; - foreach (Storage::files() as $file) { - if (preg_match('/\.xml$/', $file)) { - $xmlfiles[] = $file; - } - - if (preg_match('/\.tag$/', $file)) { - if (preg_match('/^'.config('git.edugain_tag').'$/', $file)) { - continue; - } - - $federation = Federation::whereTagfile($file)->first(); - if ($federation === null && Storage::exists(preg_replace('/\.tag/', '.cfg', $file))) { - return redirect() - ->route('entities.index') - ->with('status', __('entities.missing_federations')) - ->with('color', 'red'); - } else { - $tagfiles[] = $file; - } - } - } - - $tagfiles[] = config('git.edugain_tag'); - - $entities = Entity::select('file')->get()->pluck('file')->toArray(); - - $unknown = []; - foreach ($xmlfiles as $xmlfile) { - if (in_array($xmlfile, $entities)) { - continue; - } - - $metadata = Storage::get($xmlfile); - $metadata = $this->parseMetadata($metadata); - $entity = json_decode($metadata, true); - - $unknown[$xmlfile]['type'] = $entity['type']; - $unknown[$xmlfile]['entityid'] = $entity['entityid']; - $unknown[$xmlfile]['file'] = $xmlfile; - $unknown[$xmlfile]['name_en'] = $entity['name_en']; - $unknown[$xmlfile]['name_cs'] = $entity['name_cs']; - $unknown[$xmlfile]['description_en'] = $entity['description_en']; - $unknown[$xmlfile]['description_cs'] = $entity['description_cs']; - - foreach ($tagfiles as $tagfile) { - $content = Storage::get($tagfile); - $pattern = preg_quote($entity['entityid'], '/'); - $pattern = "/^$pattern\$/m"; - - if (preg_match_all($pattern, $content)) { - if (strcmp($tagfile, config('git.edugain_tag')) === 0) { - $unknown[$xmlfile]['federations'][] = 'eduGAIN'; - - continue; - } - - $federation = Federation::whereTagfile($tagfile)->first(); - $unknown[$xmlfile]['federations'][] = $federation->name ?? null; - } - } - } - - if (empty($unknown)) { - return redirect() - ->route('entities.index') - ->with('status', __('entities.nothing_to_import')); - } - - return view('entities.import', [ - 'entities' => $unknown, - ]); - } - - public function store(Request $request) - { - $this->authorize('do-everything'); - - if (empty(request('entities'))) { - return back() - ->with('status', __('entities.empty_import')) - ->with('color', 'red'); - } - - // ADD SELECTED ENTITIES FROM XML FILES TO DATABASE - $imported = 0; - foreach (request('entities') as $xmlfile) { - $xml_entity = $this->parseMetadata(Storage::get($xmlfile)); - $new_entity = json_decode($xml_entity, true); - - DB::transaction(function () use ($new_entity) { - $entity = Entity::create($new_entity); - - $entity->approved = true; - $entity->update(); - }); - - $imported++; - } - - // FIX FEDERATIONS MEMBERSHIP - foreach (request('entities') as $xmlfile) { - $entity = Entity::whereFile($xmlfile)->first(); - - foreach (Federation::select('id', 'tagfile')->get() as $federation) { - $members = Storage::get($federation->tagfile); - $pattern = preg_quote($entity->entityid, '/'); - $pattern = "/^$pattern\$/m"; - - if (! preg_match_all($pattern, $members)) { - continue; - } - - $entity->federations()->attach($federation, [ - 'requested_by' => Auth::id(), - 'approved_by' => Auth::id(), - 'approved' => true, - 'explanation' => 'Imported from Git repository.', - ]); - } - } - - // FIX HIDE FROM DISCOVERY MEMBERSHIP - $hfd = array_filter(preg_split("/\r\n|\r|\n/", Storage::get(config('git.hfd')))); - foreach ($hfd as $entityid) { - Entity::whereEntityid($entityid)->update(['hfd' => true]); - } - - // FIX EDUGAIN MEMBERSHIP - $edugain = array_filter(preg_split("/\r\n|\r|\n/", Storage::get(config('git.edugain_tag')))); - foreach ($edugain as $entityid) { - Entity::whereEntityid($entityid)->update(['edugain' => true]); - } - - // FIX RESEARCH AND EDUCATION MEMBERSHIP - $rs = array_filter(preg_split("/\r\n|\r|\n/", Storage::get(config('git.ec_rs')))); - foreach ($rs as $entityid) { - Entity::whereEntityid($entityid)->update(['rs' => true]); - } - - return redirect('entities') - ->with('status', trans_choice('entities.imported', $imported)); - } - - public function update() - { - $this->authorize('do-everything'); - - $this->initializeGit(); - - $xmlfiles = []; - foreach (Storage::files() as $file) { - if (preg_match('/\.xml/', $file)) { - $xmlfiles[] = $file; - } - } - - $entities = Entity::select('file')->get()->pluck('file')->toArray(); - - $refreshed = 0; - foreach ($xmlfiles as $xmlfile) { - if (! in_array($xmlfile, $entities)) { - continue; - } - - $metadata = Storage::get($xmlfile); - $refreshed_entity = json_decode($this->parseMetadata($metadata), true); - - if ($refreshed_entity['type'] === 'sp') { - unset($refreshed_entity['rs']); - } - - $entity = Entity::whereFile($xmlfile)->first(); - $entity->update($refreshed_entity); - - $edugain = Storage::get(config('git.edugain_tag')); - $pattern = preg_quote($refreshed_entity['entityid'], '/'); - $pattern = "/^$pattern\$/m"; - - if (preg_match_all($pattern, $edugain)) { - $entity->update(['edugain' => true]); - } else { - $entity->update(['edugain' => false]); - } - - if ($entity->type->value === 'idp') { - $hfd = Storage::get(config('git.hfd')); - $pattern = preg_quote($refreshed_entity['entityid'], '/'); - $pattern = "/^$pattern\$/m"; - - if (preg_match_all($pattern, $hfd)) { - $entity->update(['hfd' => true]); - } else { - $entity->update(['hfd' => false]); - } - } - - if ($entity->type->value === 'sp') { - $rs = Storage::get(config('git.ec_rs')); - $pattern = preg_quote($refreshed_entity['entityid'], '/'); - $pattern = "/^$pattern\$/m"; - - if (preg_match_all($pattern, $rs)) { - $entity->update(['rs' => true]); - } else { - $entity->update(['rs' => false]); - } - } - - if ($entity->wasChanged()) { - $refreshed++; - } - } - - return redirect('entities') - ->with('status', trans_choice('entities.refreshed', $refreshed)); - } -} diff --git a/app/Http/Controllers/EntityMetadataController.php b/app/Http/Controllers/EntityMetadataController.php index 4ad80c0..3d15771 100644 --- a/app/Http/Controllers/EntityMetadataController.php +++ b/app/Http/Controllers/EntityMetadataController.php @@ -15,6 +15,7 @@ public function store(Entity $entity) ->with('status', __('entities.not_yet_approved')) ->with('color', 'red'); } + $folderName = optional($entity->federations->first())->name; if (is_null($folderName)) { return to_route('entities.show', $entity) @@ -36,6 +37,7 @@ public function show(Entity $entity) ->with('status', __('entities.not_yet_approved')) ->with('color', 'red'); } + $folderName = optional($entity->federations->first())->name; if (is_null($folderName)) { return to_route('entities.show', $entity) diff --git a/app/Http/Controllers/EntityOperatorController.php b/app/Http/Controllers/EntityOperatorController.php index 3433cf4..4b6c2a0 100644 --- a/app/Http/Controllers/EntityOperatorController.php +++ b/app/Http/Controllers/EntityOperatorController.php @@ -46,7 +46,7 @@ public function store(Entity $entity) $new_operators = User::whereIn('id', request('operators'))->get(); $entity->operators()->attach(request('operators')); - Notification::sendNow($new_operators, new YourEntityRightsChanged($entity, 'added')); + Notification::send($new_operators, new YourEntityRightsChanged($entity, 'added')); NotificationService::sendOperatorNotification($old_operators, new EntityOperatorsChanged($entity, $new_operators, 'added')); return redirect() @@ -70,12 +70,11 @@ public function destroy(Entity $entity) $old_operators = User::whereIn('id', request('operators'))->get(); $entity->operators()->detach(request('operators')); - Notification::sendNow($old_operators, new YourEntityRightsChanged($entity, 'deleted')); + Notification::send($old_operators, new YourEntityRightsChanged($entity, 'deleted')); NotificationService::sendOperatorNotification($old_operators, new EntityOperatorsChanged($entity, $old_operators, 'deleted')); return redirect() ->route('entities.operators.index', $entity) ->with('status', __('entities.operators_deleted')); - } } diff --git a/app/Http/Controllers/EntityRsController.php b/app/Http/Controllers/EntityRsController.php index eb17125..747c537 100644 --- a/app/Http/Controllers/EntityRsController.php +++ b/app/Http/Controllers/EntityRsController.php @@ -14,7 +14,11 @@ public function store(Entity $entity) { $this->authorize('update', $entity); - abort_unless($entity->federations()->where('xml_name', config('git.rs_federation'))->count(), 403, __('entities.rs_only_for_eduidcz_members')); + abort_unless( + $entity->federations()->where('xml_name', config('git.rs_federation'))->count(), + 403, + __('entities.rs_only_for_eduidcz_members') + ); Mail::to(config('mail.admin.address')) ->send(new AskRs($entity)); @@ -24,7 +28,7 @@ public function store(Entity $entity) ->with('status', __('entities.rs_asked')); } - public function rsState(Entity $entity) + public function update(Entity $entity) { $this->authorize('do-everything'); @@ -37,6 +41,7 @@ public function rsState(Entity $entity) $entity = DB::transaction(function () use ($entity) { $entity->rs = ! $entity->rs; $xml_document = RsTag::update($entity); + if ($xml_document) { $entity->xml_file = $xml_document; $entity->update(); diff --git a/app/Http/Controllers/EntityStateController.php b/app/Http/Controllers/EntityStateController.php index b620957..2b11605 100644 --- a/app/Http/Controllers/EntityStateController.php +++ b/app/Http/Controllers/EntityStateController.php @@ -6,7 +6,7 @@ class EntityStateController extends Controller { - public function state(Entity $entity) + public function update(Entity $entity) { $this->authorize('delete', $entity); @@ -21,6 +21,5 @@ public function state(Entity $entity) ->route('entities.show', $entity) ->with('status', __("entities.$state", ['name' => $entity->{"name_$locale"} ?? $entity->entityid])) ->with('color', $color); - } } diff --git a/app/Jobs/Old_Jobs/Old_GitAddEntity.php b/app/Jobs/Old_Jobs/Old_GitAddEntity.php deleted file mode 100644 index 1f6099e..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddEntity.php +++ /dev/null @@ -1,67 +0,0 @@ -initializeGit(); - - Storage::put($this->entity->file, $this->entity->metadata); - - if ($git->hasChanges()) { - $git->addFile($this->entity->file); - - $git->commit( - $this->committer().": {$this->fqdn($this->entity->entityid)} (add)\n\n" - ."Added 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_GitAddMember.php b/app/Jobs/Old_Jobs/Old_GitAddMember.php deleted file mode 100644 index bf20080..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddMember.php +++ /dev/null @@ -1,70 +0,0 @@ -initializeGit(); - - Storage::append($this->federation->tagfile, $this->entity->entityid); - $this->trimWhiteSpaces($this->federation->tagfile); - - if ($git->hasChanges()) { - $git->addFile($this->federation->tagfile); - - $git->commit( - $this->committer().": {$this->federation->tagfile} (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/Jobs/Old_Jobs/Old_GitAddMembers.php b/app/Jobs/Old_Jobs/Old_GitAddMembers.php deleted file mode 100644 index 42ee0e0..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddMembers.php +++ /dev/null @@ -1,73 +0,0 @@ -initializeGit(); - - foreach ($this->entities as $entity) { - Storage::append($this->federation->tagfile, $entity->entityid); - } - - $this->trimWhiteSpaces($this->federation->tagfile); - - if ($git->hasChanges()) { - $git->addFile($this->federation->tagfile); - - $git->commit( - $this->committer().": {$this->federation->tagfile} (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/Jobs/Old_Jobs/Old_GitAddMembership.php b/app/Jobs/Old_Jobs/Old_GitAddMembership.php deleted file mode 100644 index 104e0e0..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddMembership.php +++ /dev/null @@ -1,70 +0,0 @@ -initializeGit(); - - Storage::append($this->membership->federation->tagfile, $this->membership->entity->entityid); - $this->trimWhiteSpaces($this->membership->federation->tagfile); - - if ($git->hasChanges()) { - $git->addFile($this->membership->federation->tagfile); - - $git->commit( - $this->committer().": {$this->membership->federation->tagfile} (update)\n\n" - ."Requested by: {$this->membership->requester->name} ({$this->membership->requester->uniqueid})\n" - .wordwrap("Explanation: {$this->membership->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_GitAddToEdugain.php b/app/Jobs/Old_Jobs/Old_GitAddToEdugain.php deleted file mode 100644 index b26299d..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddToEdugain.php +++ /dev/null @@ -1,69 +0,0 @@ -initializeGit(); - - $tagfile = config('git.edugain_tag'); - Storage::append($tagfile, $this->entity->entityid); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitAddToHfd.php b/app/Jobs/Old_Jobs/Old_GitAddToHfd.php deleted file mode 100644 index 84d140f..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddToHfd.php +++ /dev/null @@ -1,71 +0,0 @@ -entity->hfd) { - $git = $this->initializeGit(); - - $tagfile = config('git.hfd'); - Storage::append($tagfile, $this->entity->entityid); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitAddToRs.php b/app/Jobs/Old_Jobs/Old_GitAddToRs.php deleted file mode 100644 index 947894a..0000000 --- a/app/Jobs/Old_Jobs/Old_GitAddToRs.php +++ /dev/null @@ -1,71 +0,0 @@ -entity->rs) { - $git = $this->initializeGit(); - - $tagfile = config('git.ec_rs'); - Storage::append($tagfile, $this->entity->entityid); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitDeleteEntity.php b/app/Jobs/Old_Jobs/Old_GitDeleteEntity.php deleted file mode 100644 index 179a63c..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteEntity.php +++ /dev/null @@ -1,76 +0,0 @@ -initializeGit(); - - $git->removeFile($this->entity->file); - - foreach ($this->entity->federations as $federation) { - $tagfile = Storage::get($federation->tagfile); - $tagfile = preg_replace('#'.$this->entity->entityid.'#', '', $tagfile); - Storage::put($federation->tagfile, $tagfile); - $this->trimWhiteSpaces($federation->tagfile); - - if ($git->hasChanges()) { - $git->addFile($federation->tagfile); - } - } - - if ($git->hasChanges()) { - $git->commit( - $this->committer().": {$this->fqdn($this->entity->entityid)} (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_GitDeleteFromEdugain.php b/app/Jobs/Old_Jobs/Old_GitDeleteFromEdugain.php deleted file mode 100644 index efe56a0..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteFromEdugain.php +++ /dev/null @@ -1,71 +0,0 @@ -initializeGit(); - - $tagfile = config('git.edugain_tag'); - $content = Storage::get($tagfile); - $content = preg_replace('#'.$this->entity->entityid.'#', '', $content); - Storage::put($tagfile, $content); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitDeleteFromFederation.php b/app/Jobs/Old_Jobs/Old_GitDeleteFromFederation.php deleted file mode 100644 index 35ff666..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteFromFederation.php +++ /dev/null @@ -1,73 +0,0 @@ -initializeGit(); - - $tagfile = $this->federation->tagfile; - $content = Storage::get($tagfile); - $content = preg_replace('#'.$this->entity->entityid.'#', '', $content); - Storage::put($tagfile, $content); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitDeleteFromHfd.php b/app/Jobs/Old_Jobs/Old_GitDeleteFromHfd.php deleted file mode 100644 index cc37d77..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteFromHfd.php +++ /dev/null @@ -1,71 +0,0 @@ -initializeGit(); - - $tagfile = config('git.hfd'); - $content = Storage::get($tagfile); - $content = preg_replace('#'.$this->entity->entityid.'#', '', $content); - Storage::put($tagfile, $content); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitDeleteFromRs.php b/app/Jobs/Old_Jobs/Old_GitDeleteFromRs.php deleted file mode 100644 index 97e70f7..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteFromRs.php +++ /dev/null @@ -1,73 +0,0 @@ -entity->rs) { - $git = $this->initializeGit(); - - $tagfile = config('git.ec_rs'); - $content = Storage::get($tagfile); - $content = preg_replace('#'.$this->entity->entityid.'#', '', $content); - Storage::put($tagfile, $content); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitDeleteMembers.php b/app/Jobs/Old_Jobs/Old_GitDeleteMembers.php deleted file mode 100644 index faa851b..0000000 --- a/app/Jobs/Old_Jobs/Old_GitDeleteMembers.php +++ /dev/null @@ -1,74 +0,0 @@ -initializeGit(); - - $tagfile = Storage::get($this->federation->tagfile); - foreach ($this->entities as $entity) { - $tagfile = preg_replace('#'.$entity->entityid.'#', '', $tagfile); - } - Storage::put($this->federation->tagfile, $tagfile); - $this->trimWhiteSpaces($this->federation->tagfile); - - if ($git->hasChanges()) { - $git->addFile($this->federation->tagfile); - - $git->commit( - $this->committer().": {$this->federation->tagfile} (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/Jobs/Old_Jobs/Old_GitRestoreToEdugain.php b/app/Jobs/Old_Jobs/Old_GitRestoreToEdugain.php deleted file mode 100644 index 2088225..0000000 --- a/app/Jobs/Old_Jobs/Old_GitRestoreToEdugain.php +++ /dev/null @@ -1,73 +0,0 @@ -entity->edugain) { - return; - } - - $git = $this->initializeGit(); - - $tagfile = config('git.edugain_tag'); - Storage::append($tagfile, $this->entity->entityid); - $this->trimWhiteSpaces($tagfile); - - if ($git->hasChanges()) { - $git->addFile($tagfile); - - $git->commit( - $this->committer().": $tagfile (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/Jobs/Old_Jobs/Old_GitUpdateEntity.php b/app/Jobs/Old_Jobs/Old_GitUpdateEntity.php deleted file mode 100644 index cb700c9..0000000 --- a/app/Jobs/Old_Jobs/Old_GitUpdateEntity.php +++ /dev/null @@ -1,67 +0,0 @@ -initializeGit(); - - Storage::put($this->entity->file, $this->entity->metadata); - - if ($git->hasChanges()) { - $git->addFile($this->entity->file); - - $git->commit( - $this->committer().": {$this->fqdn($this->entity->entityid)} (update)\n\n" - ."Updated by: {$this->user->name} ({$this->user->uniqueid})" - ); - - $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/RunMdaScript.php b/app/Jobs/RunMdaScript.php index 0723972..985d529 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -18,8 +18,7 @@ class RunMdaScript implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - use HandlesJobsFailuresTrait; + use Dispatchable, HandlesJobsFailuresTrait, InteractsWithQueue, Queueable, SerializesModels; public int $federationId; @@ -73,14 +72,11 @@ public function handle(): void Log::error('Script execution error '.$command.' Message: '.$output); } } - } catch (Exception $e) { Log::error($e); } finally { Cache::restoreLock($lockKey, $this->owner)->release(); - } - } /** @@ -99,6 +95,5 @@ public function middleware(): array new RateLimited('mda-run-limit'), (new WithoutOverlapping($lockKey))->dontRelease(), ]; - } } diff --git a/app/Notifications/EntityDeletedFromFederation.php b/app/Notifications/EntityDeletedFromFederation.php index 0d348a5..6230033 100644 --- a/app/Notifications/EntityDeletedFromFederation.php +++ b/app/Notifications/EntityDeletedFromFederation.php @@ -5,10 +5,11 @@ use App\Models\Entity; use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class EntityDeletedFromFederation extends Notification +class EntityDeletedFromFederation extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/EntityDestroyed.php b/app/Notifications/EntityDestroyed.php index c78c868..d7124b9 100644 --- a/app/Notifications/EntityDestroyed.php +++ b/app/Notifications/EntityDestroyed.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 EntityDestroyed extends Notification +class EntityDestroyed extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/EntityOperatorsChanged.php b/app/Notifications/EntityOperatorsChanged.php index d9edbf6..cd019da 100644 --- a/app/Notifications/EntityOperatorsChanged.php +++ b/app/Notifications/EntityOperatorsChanged.php @@ -4,11 +4,12 @@ use App\Models\Entity; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Collection; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class EntityOperatorsChanged extends Notification +class EntityOperatorsChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/EntityRequested.php b/app/Notifications/EntityRequested.php index c9d1b97..fe9666c 100644 --- a/app/Notifications/EntityRequested.php +++ b/app/Notifications/EntityRequested.php @@ -5,10 +5,11 @@ use App\Models\Entity; use App\Models\Federation; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class EntityRequested extends Notification +class EntityRequested extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/IdpCategoryChanged.php b/app/Notifications/IdpCategoryChanged.php index aff5515..0acc056 100644 --- a/app/Notifications/IdpCategoryChanged.php +++ b/app/Notifications/IdpCategoryChanged.php @@ -5,10 +5,11 @@ use App\Models\Category; use App\Models\Entity; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class IdpCategoryChanged extends Notification +class IdpCategoryChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Notifications/YourEntityRightsChanged.php b/app/Notifications/YourEntityRightsChanged.php index 0382eda..8e1e39e 100644 --- a/app/Notifications/YourEntityRightsChanged.php +++ b/app/Notifications/YourEntityRightsChanged.php @@ -4,10 +4,11 @@ use App\Models\Entity; use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class YourEntityRightsChanged extends Notification +class YourEntityRightsChanged extends Notification implements ShouldQueue { use Queueable; diff --git a/app/Services/CategoryTagService.php b/app/Services/CategoryTagService.php index b91a16b..9af443e 100644 --- a/app/Services/CategoryTagService.php +++ b/app/Services/CategoryTagService.php @@ -12,8 +12,7 @@ class CategoryTagService extends TagService { - use HandlesJobsFailuresTrait; - use TagTrait,ValidatorTrait; + use HandlesJobsFailuresTrait, TagTrait, ValidatorTrait; public function create(Entity $entity): false|string { @@ -25,10 +24,12 @@ public function create(Entity $entity): false|string if (! $category) { return false; } + $attributeValue = $this->hasAtributeValueInConfig($category); if (! $attributeValue) { return false; } + $xml_document = $entity->xml_file; $dom = $this->createDOM($xml_document); @@ -52,6 +53,7 @@ public function delete(Entity $entity): false|string if (! $category) { return false; } + $attributeValue = $this->hasAtributeValueInConfig($category); if (! $attributeValue) { return false; @@ -64,7 +66,6 @@ public function delete(Entity $entity): false|string $dom->normalize(); return $dom->saveXML(); - } private static function hasCategoryInDatabase(Entity $entity): false|Category diff --git a/app/Services/HfdTagService.php b/app/Services/HfdTagService.php index e003ac1..5935095 100644 --- a/app/Services/HfdTagService.php +++ b/app/Services/HfdTagService.php @@ -9,7 +9,7 @@ class HfdTagService extends TagService { - use TagTrait,ValidatorTrait; + use TagTrait, ValidatorTrait; private string $value = 'http://refeds.org/category/hide-from-discovery'; @@ -48,7 +48,6 @@ public function delete(Entity $entity): false|string $dom->normalize(); return $dom->saveXML(); - } public function deleteByXpath(DOMXPath $xPath): void @@ -60,11 +59,9 @@ public function deleteByXpath(DOMXPath $xPath): void public function update(Entity $entity): false|string { if ($entity->hfd) { - if (! $this->hasTagInDocument($entity->xml_file, $this->value)) { return $this->create($entity); } - } else { if ($this->hasTagInDocument($entity->xml_file, $this->value)) { return $this->delete($entity); diff --git a/app/Services/RsTagService.php b/app/Services/RsTagService.php index 9cafedd..d4bbd3f 100644 --- a/app/Services/RsTagService.php +++ b/app/Services/RsTagService.php @@ -9,7 +9,7 @@ class RsTagService extends TagService { - use TagTrait,ValidatorTrait; + use TagTrait, ValidatorTrait; private string $value = 'http://refeds.org/category/research-and-scholarship'; @@ -58,11 +58,9 @@ public function deleteByXpath(DOMXPath $xPath): void public function update(Entity $entity): false|string { if ($entity->rs) { - if (! $this->hasTagInDocument($entity->xml_file, $this->value)) { return $this->create($entity); } - } else { if ($this->hasTagInDocument($entity->xml_file, $this->value)) { return $this->delete($entity); @@ -75,6 +73,7 @@ public function update(Entity $entity): false|string protected function getOrCreateAttribute(\DOMXPath $xPath, \DOMDocument $dom, \DOMNode $entityAttributes, string $samlURI, bool $isIdp): \DOMNode { $attribute = $xPath->query('//mdattr:EntityAttributes/saml:Attribute', $entityAttributes); + if ($attribute->length === 0) { $attribute = $dom->createElementNS($samlURI, 'saml:Attribute'); $attribute->setAttribute('NameFormat', 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'); diff --git a/resources/views/entities/index.blade.php b/resources/views/entities/index.blade.php index 747de8f..3c77018 100644 --- a/resources/views/entities/index.blade.php +++ b/resources/views/entities/index.blade.php @@ -1,12 +1,6 @@ @extends('layouts.index') @section('title', __('common.entities')) - -@section('adminOnly_action') - {{ __('common.import') }} - {{ __('common.refresh') }} -@endsection - @section('create') {{ __('common.add') }} @endsection diff --git a/routes/web.php b/routes/web.php index c1b9cce..3773cf7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,7 +7,6 @@ use App\Http\Controllers\EntityEduGainController; use App\Http\Controllers\EntityFederationController; use App\Http\Controllers\EntityHfdController; -use App\Http\Controllers\EntityManagementController; use App\Http\Controllers\EntityMetadataController; use App\Http\Controllers\EntityOperatorController; use App\Http\Controllers\EntityOrganizationController; @@ -55,45 +54,6 @@ Route::get('fakelogout', [FakeController::class, 'destroy'])->name('fakelogout'); } -// Entities groups -Route::group(['prefix' => 'entities', 'as' => 'entities.', 'middleware' => ['auth']], function () { - - Route::middleware('throttle:anti-ddos-limit')->group(function () { - Route::post('{entity}/join', [EntityFederationController::class, 'store'])->name('join'); - Route::post('{entity}/leave', [EntityFederationController::class, 'destroy'])->name('leave'); - Route::patch('{entity}/state', [EntityStateController::class, 'state'])->name('state')->withTrashed(); - Route::patch('{entity}/edugain', [EntityEduGainController::class, 'edugain'])->name('edugain')->withTrashed(); - Route::match(['put', 'patch'], '{entity}', [EntityController::class, 'update'])->name('update')->withTrashed(); - }); - - Route::get('import', [EntityManagementController::class, 'index'])->name('unknown'); - Route::post('import', [EntityManagementController::class, 'store'])->name('import'); - Route::get('refresh', [EntityManagementController::class, 'update'])->name('refresh'); - - Route::get('{entity}/federations', [EntityFederationController::class, 'index'])->name('federations')->withTrashed(); - - Route::resource('{entity}/operators', EntityOperatorController::class)->only(['index', 'store'])->withTrashed(); - Route::delete('{entity}/operators', [EntityOperatorController::class, 'destroy'])->name('operators.destroy')->withTrashed(); - - Route::post('{entity}/rs', [EntityRsController::class, 'store'])->name('rs.store'); - Route::patch('{entity}/rs', [EntityRsController::class, 'rsState'])->name('rs.state')->withTrashed(); - - Route::patch('{entity}/category', [EntityCategoryController::class, 'update'])->name('category.update'); - - Route::patch('{entity}/hfd', [EntityHfdController::class, 'update'])->name('hfd'); - - Route::get('{entity}/metadata', [EntityMetadataController::class, 'store'])->name('metadata'); - Route::get('{entity}/showmetadata', [EntityMetadataController::class, 'show'])->name('showmetadata'); - - Route::get('{entity}/previewmetadata', [EntityPreviewMetadataController::class, 'show'])->name('previewmetadata'); - - Route::post('{entity}/organization', [EntityOrganizationController::class, 'update'])->name('organization'); - - Route::resource('/', EntityController::class)->parameters(['' => 'entity'])->except('update'); - Route::get('{entity}', [EntityController::class, 'show'])->name('show')->withTrashed(); - Route::delete('{entity}', [EntityController::class, 'destroy'])->name('destroy')->withTrashed(); -}); - Route::middleware('auth')->group(function () { // Dashboard Route::view('dashboard', 'dashboard')->name('dashboard'); @@ -116,6 +76,35 @@ Route::resource('federations', FederationController::class)->withTrashed(['show', 'destroy']); + // Entities + Route::get('entities/{entity}/previewmetadata', [EntityPreviewMetadataController::class, 'show'])->name('entities.previewmetadata'); + + Route::patch('entities/{entity}/category', [EntityCategoryController::class, 'update'])->name('entities.category.update'); + Route::patch('entities/{entity}/hfd', [EntityHfdController::class, 'update'])->name('entities.hfd'); + Route::post('entities/{entity}/organization', [EntityOrganizationController::class, 'update'])->name('entities.organization'); + + Route::post('entities/{entity}/rs', [EntityRsController::class, 'store'])->name('entities.rs.store'); + Route::patch('entities/{entity}/rs', [EntityRsController::class, 'update'])->name('entities.rs.state'); + + Route::get('entities/{entity}/operators', [EntityOperatorController::class, 'index'])->name('entities.operators.index')->withTrashed(); + Route::post('entities/{entity}/operators', [EntityOperatorController::class, 'store'])->name('entities.operators.store')->withTrashed(); + Route::delete('entities/{entity}/operators', [EntityOperatorController::class, 'destroy'])->name('entities.operators.destroy')->withTrashed(); + + Route::get('entities/{entity}/metadata', [EntityMetadataController::class, 'store'])->name('entities.metadata'); + Route::get('entities/{entity}/showmetadata', [EntityMetadataController::class, 'show'])->name('entities.showmetadata'); + + Route::get('entities/{entity}/federations', [EntityFederationController::class, 'index'])->name('entities.federations')->withTrashed(); + + Route::middleware('throttle:anti-ddos-limit')->group(function () { + Route::post('entities/{entity}/join', [EntityFederationController::class, 'store'])->name('entities.join'); + Route::post('entities/{entity}/leave', [EntityFederationController::class, 'destroy'])->name('entities.leave'); + Route::patch('entities/{entity}/state', [EntityStateController::class, 'update'])->name('entities.state')->withTrashed(); + Route::patch('entities/{entity}/edugain', [EntityEduGainController::class, 'update'])->name('entities.edugain'); + Route::match(['put', 'patch'], 'entities/{entity}', [EntityController::class, 'update'])->name('entities.update')->withTrashed(); + }); + + Route::resource('entities', EntityController::class)->except('update')->withTrashed(['show', 'destroy']); + // Categories Route::resource('categories', CategoryController::class)->only('index', 'show');