From 95c9ca605b8f2bf9d526cff7d3b5da774f076269 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 2 Jul 2024 14:54:37 +0200 Subject: [PATCH 01/53] add xml_file field to update case in store --- app/Http/Controllers/EntityController.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 1a08c1d..17e28a5 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -157,7 +157,6 @@ public function store(StoreEntity $request) ->back() ->with('status', "{$result['error']} {$result['message']}") ->with('color', 'red'); - break; default: @@ -256,6 +255,7 @@ public function update(Request $request, Entity $entity) switch ($result['code']) { case '0': + $xml_file = $this->deleteTags($updated_entity['metadata']); $entity->update([ 'name_en' => $updated_entity['name_en'], 'name_cs' => $updated_entity['name_cs'], @@ -264,6 +264,7 @@ public function update(Request $request, Entity $entity) 'cocov1' => $updated_entity['cocov1'], 'sirtfi' => $updated_entity['sirtfi'], 'metadata' => $updated_entity['metadata'], + 'xml_file' => $xml_file, ]); if ($entity->type->value === 'idp') { @@ -276,14 +277,14 @@ public function update(Request $request, Entity $entity) ->with('status', __('entities.not_changed')); } - Bus::chain([ +/* Bus::chain([ new GitUpdateEntity($entity, Auth::user()), function () use ($entity) { $admins = User::activeAdmins()->select('id', 'email')->get(); Notification::send($entity->operators, new EntityUpdated($entity)); Notification::send($admins, new EntityUpdated($entity)); }, - ])->dispatch(); + ])->dispatch();*/ return redirect() ->route('entities.show', $entity) @@ -313,10 +314,11 @@ function () use ($entity) { case 'state': $this->authorize('delete', $entity); + // TODO restore if ($entity->trashed()) { $entity->restore(); - Bus::chain([ +/* Bus::chain([ new GitAddEntity($entity, Auth::user()), new GitAddToHfd($entity, Auth::user()), new GitRestoreToEdugain($entity, Auth::user()), @@ -330,22 +332,24 @@ function () use ($entity) { Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); } }, - ])->dispatch(); + ])->dispatch();*/ + // TODO here M:N connection wit federation foreach ($entity->federations as $federation) { - Bus::chain([ +/* Bus::chain([ new GitAddMember($federation, $entity, Auth::user()), function () use ($federation, $entity) { $admins = User::activeAdmins()->select('id', 'email')->get(); Notification::send($federation->operators, new FederationMemberChanged($federation, $entity, 'added')); Notification::send($admins, new FederationMemberChanged($federation, $entity, 'added')); }, - ])->dispatch(); + ])->dispatch();*/ } } else { $entity->delete(); - Bus::chain([ + //TODO delete chain +/* Bus::chain([ new GitDeleteEntity($entity, Auth::user()), new GitDeleteFromHfd($entity, Auth::user()), new GitDeleteFromEdugain($entity, Auth::user()), @@ -359,7 +363,7 @@ function () use ($entity) { Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); } }, - ])->dispatch(); + ])->dispatch();*/ } $state = $entity->trashed() ? 'deleted' : 'restored'; From c8a44b7e333ac7a712f2e4d845daa92155c518f4 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 2 Jul 2024 15:19:05 +0200 Subject: [PATCH 02/53] fix test and commit Bus:chain --- app/Http/Controllers/EntityController.php | 18 +-- .../Http/Controllers/EntityControllerTest.php | 104 +++++++++--------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 17e28a5..f4ef207 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -335,16 +335,16 @@ function () use ($entity) { ])->dispatch();*/ // TODO here M:N connection wit federation - foreach ($entity->federations as $federation) { -/* Bus::chain([ +/* foreach ($entity->federations as $federation) { + Bus::chain([ new GitAddMember($federation, $entity, Auth::user()), function () use ($federation, $entity) { $admins = User::activeAdmins()->select('id', 'email')->get(); Notification::send($federation->operators, new FederationMemberChanged($federation, $entity, 'added')); Notification::send($admins, new FederationMemberChanged($federation, $entity, 'added')); }, - ])->dispatch();*/ - } + ])->dispatch(); + }*/ } else { $entity->delete(); @@ -435,7 +435,8 @@ function () use ($entity) { $status = $entity->edugain ? 'edugain' : 'no_edugain'; $color = $entity->edugain ? 'green' : 'red'; - if ($entity->edugain) { + // TODO add and delete from EDUGAIN +/* if ($entity->edugain) { Bus::chain([ new GitAddToEdugain($entity, Auth::user()), function () use ($entity) { @@ -453,7 +454,7 @@ function () use ($entity) { Notification::send($admins, new EntityEdugainStatusChanged($entity)); }, ])->dispatch(); - } + }*/ return redirect() ->back() @@ -509,14 +510,15 @@ function () use ($entity) { $entity->category()->associate($category); $entity->save(); - Bus::chain([ + // TODO work with category +/* Bus::chain([ new GitDeleteFromCategory($old_category, $entity, Auth::user()), new GitAddToCategory($category, $entity, Auth::user()), function () use ($entity, $category) { $admins = User::activeAdmins()->select('id', 'email')->get(); Notification::send($admins, new IdpCategoryChanged($entity, $category)); }, - ])->dispatch(); + ])->dispatch();*/ if (! $entity->wasChanged()) { return redirect() diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index 3e5eb87..9be8195 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -292,9 +292,9 @@ public function a_user_can_add_a_new_entity() $whoami = ' - + - + @@ -309,7 +309,7 @@ public function a_user_can_add_a_new_entity() - + cesnet.cz @@ -323,7 +323,7 @@ public function a_user_can_add_a_new_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -382,19 +382,19 @@ public function a_user_can_add_a_new_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -403,7 +403,7 @@ public function a_user_can_add_a_new_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -423,7 +423,7 @@ public function a_user_can_add_a_new_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; // add an entity using wrong metadata content @@ -496,9 +496,9 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() $whoami = ' - + - + @@ -513,7 +513,7 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() - + cesnet.cz @@ -527,7 +527,7 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -586,19 +586,19 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -607,7 +607,7 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -627,7 +627,7 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; $this @@ -641,9 +641,9 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() $this->assertEquals(route('entities.show', $entity), url()->current()); - Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { +/* Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { return $job->entity->is($entity); - }); + });*/ } /** @test */ @@ -664,9 +664,9 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ ->patch(route('entities.update', $entity), ['action' => 'state']) ->assertSeeText(__('entities.deleted', ['name' => $entity->name_en])); - Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { +/* Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { return $job->entity->is($entity); - }); + });*/ $entity->refresh(); $this->assertTrue($entity->trashed()); @@ -682,9 +682,9 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ $this->assertFalse($entity->trashed()); $this->assertEquals(route('entities.show', $entity), url()->current()); - Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { +/* Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { return $job->entity->is($entity); - }); + });*/ } /** @test */ @@ -949,9 +949,9 @@ public function an_admin_can_add_a_new_entity() $whoami = ' - + - + @@ -966,7 +966,7 @@ public function an_admin_can_add_a_new_entity() - + cesnet.cz @@ -980,7 +980,7 @@ public function an_admin_can_add_a_new_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -1039,19 +1039,19 @@ public function an_admin_can_add_a_new_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -1060,7 +1060,7 @@ public function an_admin_can_add_a_new_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -1080,7 +1080,7 @@ public function an_admin_can_add_a_new_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; // add an entity using wrong metadata content @@ -1140,9 +1140,9 @@ public function an_admin_can_edit_an_existing_entity() $whoami = ' - + - + @@ -1157,7 +1157,7 @@ public function an_admin_can_edit_an_existing_entity() - + cesnet.cz @@ -1171,7 +1171,7 @@ public function an_admin_can_edit_an_existing_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -1230,19 +1230,19 @@ public function an_admin_can_edit_an_existing_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -1251,7 +1251,7 @@ public function an_admin_can_edit_an_existing_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -1271,7 +1271,7 @@ public function an_admin_can_edit_an_existing_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; $this @@ -1284,9 +1284,9 @@ public function an_admin_can_edit_an_existing_entity() ->assertSeeText(__('entities.entity_updated')); $this->assertEquals(route('entities.show', $entity), url()->current()); - Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { +/* Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { return $job->entity->is($entity); - }); + });*/ } /** @test */ @@ -1306,9 +1306,9 @@ public function an_admin_can_change_an_existing_entities_state() ->patch(route('entities.update', $entity), ['action' => 'state']) ->assertSeeText(__('entities.deleted', ['name' => $entity->name_en])); - Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { +/* Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { return $job->entity->is($entity); - }); + });*/ $entity->refresh(); $this->assertTrue($entity->trashed()); @@ -1324,9 +1324,9 @@ public function an_admin_can_change_an_existing_entities_state() $this->assertFalse($entity->trashed()); $this->assertEquals(route('entities.show', $entity), url()->current()); - Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { +/* Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { return $job->entity->is($entity); - }); + });*/ } /** @test */ From f1d9d759bc7cad428dd362dd1a782416722802bd Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 3 Jul 2024 10:18:08 +0200 Subject: [PATCH 03/53] start with job --- app/Events/CreateEntity.php | 27 ++++++++++++++++ app/Http/Controllers/EntityController.php | 1 - app/Jobs/FolderAddEntity.php | 33 ++++++++++++++++++++ app/Listeners/SendCreatedEntityToSaveJob.php | 30 ++++++++++++++++++ app/Models/Entity.php | 6 ++++ app/Providers/EventServiceProvider.php | 12 +++++-- 6 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 app/Events/CreateEntity.php create mode 100644 app/Jobs/FolderAddEntity.php create mode 100644 app/Listeners/SendCreatedEntityToSaveJob.php diff --git a/app/Events/CreateEntity.php b/app/Events/CreateEntity.php new file mode 100644 index 0000000..aa2c9bd --- /dev/null +++ b/app/Events/CreateEntity.php @@ -0,0 +1,27 @@ +entity = $entity; + } +} diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index f4ef207..4679702 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -139,7 +139,6 @@ public function store(StoreEntity $request) 'requested_by' => Auth::id(), ]); - $this->updateEntityXml(Entity::where('id', $entity['id'])->first()); return $entity; }); diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php new file mode 100644 index 0000000..1b80b62 --- /dev/null +++ b/app/Jobs/FolderAddEntity.php @@ -0,0 +1,33 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + public function handle(): void + { + dump("hello word"); + } +} diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php new file mode 100644 index 0000000..07410cf --- /dev/null +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -0,0 +1,30 @@ + $event->entity->id]); + + FolderAddEntity::dispatch($event->entity); + } +} diff --git a/app/Models/Entity.php b/app/Models/Entity.php index eb914f3..16e9701 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Enums\EntityType; +use App\Events\CreateEntity; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -90,4 +91,9 @@ public function scopeSearch($query, string $search = null) ->orWhere('description_en', 'like', "%$search%") ->orWhere('description_cs', 'like', "%$search%"); } + + protected $dispatchesEvents = [ + 'created' => CreateEntity::class, + ]; + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index c9661ca..1a0002d 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,8 +2,10 @@ namespace App\Providers; +use App\Events\CreateEntity; use App\Events\FederationApprove; use App\Listeners\CreateFederationFolder; +use App\Listeners\SendCreatedEntityToSaveJob; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -20,10 +22,14 @@ class EventServiceProvider extends ServiceProvider Registered::class => [ SendEmailVerificationNotification::class, ], - FederationApprove::class => - [ + FederationApprove::class => [ CreateFederationFolder::class, - ] + ], + CreateEntity::class =>[ + SendCreatedEntityToSaveJob::class, + ], + + ]; /** From 004d0992d2bdb0028ef987abfecbf12a4769172a Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 3 Jul 2024 10:52:04 +0200 Subject: [PATCH 04/53] rewrite update to transaction --- app/Http/Controllers/EntityController.php | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 4679702..b17b406 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -255,20 +255,23 @@ public function update(Request $request, Entity $entity) case '0': $xml_file = $this->deleteTags($updated_entity['metadata']); - $entity->update([ - 'name_en' => $updated_entity['name_en'], - 'name_cs' => $updated_entity['name_cs'], - 'description_en' => $updated_entity['description_en'], - 'description_cs' => $updated_entity['description_cs'], - 'cocov1' => $updated_entity['cocov1'], - 'sirtfi' => $updated_entity['sirtfi'], - 'metadata' => $updated_entity['metadata'], - 'xml_file' => $xml_file, - ]); - - if ($entity->type->value === 'idp') { - $entity->update(['rs' => $updated_entity['rs']]); - } + + DB::transaction(function () use ($entity, $updated_entity, $xml_file) { + $entity->update([ + 'name_en' => $updated_entity['name_en'], + 'name_cs' => $updated_entity['name_cs'], + 'description_en' => $updated_entity['description_en'], + 'description_cs' => $updated_entity['description_cs'], + 'cocov1' => $updated_entity['cocov1'], + 'sirtfi' => $updated_entity['sirtfi'], + 'metadata' => $updated_entity['metadata'], + 'xml_file' => $xml_file, + ]); + + if ($entity->type->value === 'idp') { + $entity->update(['rs' => $updated_entity['rs']]); + } + }); if (! $entity->wasChanged()) { return redirect() @@ -276,6 +279,7 @@ public function update(Request $request, Entity $entity) ->with('status', __('entities.not_changed')); } + //TODO updateChain /* Bus::chain([ new GitUpdateEntity($entity, Auth::user()), function () use ($entity) { From 9eb036fd7457eb195fdcb50a3cd063b1cf839aac Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 3 Jul 2024 13:30:53 +0200 Subject: [PATCH 05/53] use pint for code style --- app/Console/Commands/DumpFromGit.php | 19 +- app/Console/Commands/ValidateMetaConsole.php | 38 +- app/Console/Kernel.php | 1 - app/Events/CreateEntity.php | 4 - app/Events/FederationApprove.php | 7 +- app/Http/Controllers/CategoryController.php | 4 - app/Http/Controllers/EntityController.php | 161 +++-- .../EntityManagementController.php | 2 +- app/Http/Controllers/FederationController.php | 26 +- app/Http/Controllers/GroupController.php | 4 - app/Http/Controllers/MembershipController.php | 2 - app/Http/Controllers/UserController.php | 1 - app/Http/Middleware/Localization.php | 2 - .../Middleware/RedirectIfAuthenticated.php | 2 - app/Jobs/FolderAddEntity.php | 11 + app/Jobs/GitAddCategory.php | 2 +- app/Jobs/GitAddEntity.php | 2 +- app/Jobs/GitAddGroup.php | 2 +- app/Jobs/GitAddMember.php | 2 +- app/Jobs/GitAddMembers.php | 2 +- app/Jobs/GitAddMembership.php | 2 +- app/Jobs/GitAddToCategory.php | 2 +- app/Jobs/GitAddToEdugain.php | 2 +- app/Jobs/GitAddToHfd.php | 2 +- app/Jobs/GitAddToRs.php | 2 +- app/Jobs/GitDeleteCategory.php | 2 +- app/Jobs/GitDeleteEntity.php | 2 +- app/Jobs/GitDeleteFromCategory.php | 2 +- app/Jobs/GitDeleteFromEdugain.php | 2 +- app/Jobs/GitDeleteFromFederation.php | 2 +- app/Jobs/GitDeleteFromHfd.php | 2 +- app/Jobs/GitDeleteFromRs.php | 2 +- app/Jobs/GitDeleteGroup.php | 2 +- app/Jobs/GitDeleteMembers.php | 2 +- app/Jobs/GitRestoreToCategory.php | 2 +- app/Jobs/GitRestoreToEdugain.php | 2 +- app/Jobs/GitUpdateCategory.php | 2 +- app/Jobs/GitUpdateEntity.php | 2 +- app/Jobs/GitUpdateGroup.php | 2 +- app/Jobs/Old_GitAddFederation.php | 2 +- app/Jobs/Old_GitDeleteFederation.php | 2 +- app/Jobs/Old_GitUpdateFederation.php | 2 +- app/Listeners/CreateFederationFolder.php | 7 +- app/Listeners/SendCreatedEntityToSaveJob.php | 2 - app/Models/Category.php | 4 +- app/Models/Entity.php | 3 +- app/Models/Federation.php | 3 +- app/Models/Group.php | 2 +- app/Models/User.php | 2 +- app/Policies/EntityPolicy.php | 12 - app/Policies/FederationPolicy.php | 8 - app/Policies/MembershipPolicy.php | 4 - app/Policies/UserPolicy.php | 6 - app/Providers/AppServiceProvider.php | 1 - app/Providers/EventServiceProvider.php | 3 +- app/Services/EntityService.php | 24 +- .../CreateCategoriesAndGroupsTrait.php | 16 +- .../DumpFromGit/CreateEntitiesTrait.php | 23 +- .../DumpFromGit/CreateFederationTrait.php | 18 +- .../EntitiesHelp/DeleteFromEntity.php | 48 +- .../EntitiesHelp/FixEntityTrait.php | 54 +- .../DumpFromGit/EntitiesHelp/UpdateEntity.php | 96 ++- app/Traits/EdugainTrait.php | 16 +- app/Traits/FederationTrait.php | 12 +- app/Traits/ValidatorTrait.php | 64 +- app/View/Components/Buttons/Back.php | 1 - app/View/Components/Buttons/Edit.php | 4 +- app/View/Components/Buttons/Subhead.php | 2 +- app/View/Components/FormTable/HeadCell.php | 2 - .../Components/Forms/Element/Textarea.php | 11 +- app/View/Components/Forms/Element/input.php | 3 +- .../Forms/Section/FormBodySection.php | 14 +- config/app.php | 2 +- config/registrationInfo.php | 1 + config/xmlNameSpace.php | 3 +- database/factories/CategoryFactory.php | 2 +- ...020_12_23_133143_create_entities_table.php | 2 +- ...1_01_04_132833_create_categories_table.php | 2 +- database/seeders/DatabaseSeeder.php | 8 +- tests/Browser/Pages/HomePage.php | 1 - .../Http/Controllers/EntityControllerTest.php | 616 +++++++++--------- .../Controllers/FederationControllerTest.php | 41 +- 82 files changed, 667 insertions(+), 814 deletions(-) diff --git a/app/Console/Commands/DumpFromGit.php b/app/Console/Commands/DumpFromGit.php index 4113418..804201b 100644 --- a/app/Console/Commands/DumpFromGit.php +++ b/app/Console/Commands/DumpFromGit.php @@ -2,7 +2,6 @@ namespace App\Console\Commands; - use App\Facades\EntityFacade; use App\Models\Membership; use App\Models\User; @@ -14,17 +13,16 @@ use App\Traits\EdugainTrait; use App\Traits\FederationTrait; use App\Traits\GitTrait; +use App\Traits\ValidatorTrait; use Exception; use Illuminate\Console\Command; -use App\Traits\ValidatorTrait; - class DumpFromGit extends Command { - use GitTrait, ValidatorTrait; - use CreateFederationTrait,CreateEntitiesTrait,CreateCategoriesAndGroupsTrait; - use UpdateEntity,FederationTrait,FixEntityTrait; + use CreateCategoriesAndGroupsTrait,CreateEntitiesTrait,CreateFederationTrait; use EdugainTrait; + use FederationTrait,FixEntityTrait,UpdateEntity; + use GitTrait, ValidatorTrait; /** * The name and signature of the console command. @@ -43,23 +41,23 @@ class DumpFromGit extends Command private function createMetadataFiles(): void { $this->updateFederationFolders(); - $membership = Membership::select('entity_id','federation_id')->whereApproved(1)->get(); + $membership = Membership::select('entity_id', 'federation_id')->whereApproved(1)->get(); foreach ($membership as $member) { EntityFacade::saveMetadataToFederationFolder($member->entity_id, $member->federation_id); } } - /** * Execute the console command. + * * @throws Exception no amin */ public function handle() { $firstAdminId = User::where('admin', 1)->first()->id; - if(empty($firstAdminId)) + if (empty($firstAdminId)) { throw new Exception('firstAdminId is null'); - + } $this->initializeGit(); $this->createFederations(); @@ -72,6 +70,5 @@ public function handle() $this->createMetadataFiles(); $this->makeEdu2Edugain(); - } } diff --git a/app/Console/Commands/ValidateMetaConsole.php b/app/Console/Commands/ValidateMetaConsole.php index 55cab09..22bf500 100644 --- a/app/Console/Commands/ValidateMetaConsole.php +++ b/app/Console/Commands/ValidateMetaConsole.php @@ -23,32 +23,24 @@ class ValidateMetaConsole extends Command */ protected $description = 'Command description'; - - use ValidatorTrait,FixEntityTrait; + use FixEntityTrait,ValidatorTrait; /** * Execute the console command. */ - private function doc() { - foreach (Entity::select()->get() as $entity) - { + foreach (Entity::select()->get() as $entity) { $ent = Entity::where('id', $entity->id)->select()->first(); - // $res = json_decode($this->validateMetadata($ent->metadata),true); - $res = json_decode($this->validateMetadata($ent->xml_file,true),true); + $res = json_decode($this->validateMetadata($ent->xml_file, true), true); $res['ent_id'] = $ent->id; $errorArray = $res['errorArray']; - - if($res['code']==1) - { + if ($res['code'] == 1) { dump($res); - } - else - { + } else { dump($res['ent_id']); } } @@ -56,38 +48,34 @@ private function doc() private function meta() { - foreach (Entity::select()->get() as $entity) - { + foreach (Entity::select()->get() as $entity) { $ent = Entity::where('id', $entity->id)->select()->first(); $curr = 345; - if($ent->id < $curr) + if ($ent->id < $curr) { continue; - if($ent->id > $curr) + } + if ($ent->id > $curr) { break; + } - - $res = json_decode($this->validateMetadata($ent->metadata),true); + $res = json_decode($this->validateMetadata($ent->metadata), true); $res['ent_id'] = $ent->id; - dump($res); - if( $res['code']==1) - { + if ($res['code'] == 1) { } } } - public function handle() { - // $this->fixEntities(); + // $this->fixEntities(); $this->doc(); - } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 69914e9..35e9ccd 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) diff --git a/app/Events/CreateEntity.php b/app/Events/CreateEntity.php index aa2c9bd..ff1fb9d 100644 --- a/app/Events/CreateEntity.php +++ b/app/Events/CreateEntity.php @@ -3,11 +3,7 @@ namespace App\Events; use App\Models\Entity; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/FederationApprove.php b/app/Events/FederationApprove.php index ed58ab2..967b5b6 100644 --- a/app/Events/FederationApprove.php +++ b/app/Events/FederationApprove.php @@ -3,11 +3,7 @@ namespace App\Events; use App\Models\Federation; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; @@ -20,9 +16,8 @@ class FederationApprove /** * Create a new event instance. */ - public function __construct(Federation $federation) + public function __construct(Federation $federation) { $this->federation = $federation; } - } diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 4caab85..a8c1cb4 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -77,7 +77,6 @@ public function store(StoreCategory $request) /** * Display the specified resource. * - * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function show(Category $category) @@ -92,7 +91,6 @@ public function show(Category $category) /** * Show the form for editing the specified resource. * - * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function edit(Category $category) @@ -108,7 +106,6 @@ public function edit(Category $category) * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function update(UpdateCategory $request, Category $category) @@ -134,7 +131,6 @@ public function update(UpdateCategory $request, Category $category) /** * Remove the specified resource from storage. * - * @param \App\Models\Category $category * @return \Illuminate\Http\Response */ public function destroy(Category $category) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index b17b406..53d4dd1 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -51,8 +51,8 @@ class EntityController extends Controller { - use ValidatorTrait, GitTrait; use DeleteFromEntity,UpdateEntity; + use GitTrait, ValidatorTrait; public function __construct() { @@ -130,7 +130,7 @@ public function store(StoreEntity $request) if ($new_entity['type'] === 'idp') { $new_entity = array_merge($new_entity, ['hfd' => true]); } - $new_entity= array_merge($new_entity, ['xml_file' => $this->deleteTags($new_entity['metadata']) ]); + $new_entity = array_merge($new_entity, ['xml_file' => $this->deleteTags($new_entity['metadata'])]); $entity = Entity::create($new_entity); $entity->operators()->attach(Auth::id()); @@ -169,7 +169,6 @@ public function store(StoreEntity $request) /** * Display the specified resource. * - * @param \App\Models\Entity $entity * @return \Illuminate\Http\Response */ public function show(Entity $entity) @@ -196,7 +195,6 @@ public function show(Entity $entity) /** * Show the form for editing the specified resource. * - * @param \App\Models\Entity $entity * @return \Illuminate\Http\Response */ public function edit(Entity $entity) @@ -211,8 +209,6 @@ public function edit(Entity $entity) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param \App\Models\Entity $entity * @return \Illuminate\Http\Response */ public function update(Request $request, Entity $entity) @@ -280,14 +276,14 @@ public function update(Request $request, Entity $entity) } //TODO updateChain -/* Bus::chain([ - new GitUpdateEntity($entity, Auth::user()), - function () use ($entity) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($entity->operators, new EntityUpdated($entity)); - Notification::send($admins, new EntityUpdated($entity)); - }, - ])->dispatch();*/ + /* Bus::chain([ + new GitUpdateEntity($entity, Auth::user()), + function () use ($entity) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($entity->operators, new EntityUpdated($entity)); + Notification::send($admins, new EntityUpdated($entity)); + }, + ])->dispatch();*/ return redirect() ->route('entities.show', $entity) @@ -321,52 +317,52 @@ function () use ($entity) { if ($entity->trashed()) { $entity->restore(); -/* Bus::chain([ - new GitAddEntity($entity, Auth::user()), - new GitAddToHfd($entity, Auth::user()), - new GitRestoreToEdugain($entity, Auth::user()), - new GitRestoreToCategory($entity, Auth::user()), - function () use ($entity) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($entity->operators, new EntityStateChanged($entity)); - Notification::send($admins, new EntityStateChanged($entity)); - if ($entity->hfd) { - Notification::send($entity->operators, new EntityAddedToHfd($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); - } - }, - ])->dispatch();*/ + /* Bus::chain([ + new GitAddEntity($entity, Auth::user()), + new GitAddToHfd($entity, Auth::user()), + new GitRestoreToEdugain($entity, Auth::user()), + new GitRestoreToCategory($entity, Auth::user()), + function () use ($entity) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($entity->operators, new EntityStateChanged($entity)); + Notification::send($admins, new EntityStateChanged($entity)); + if ($entity->hfd) { + Notification::send($entity->operators, new EntityAddedToHfd($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); + } + }, + ])->dispatch();*/ // TODO here M:N connection wit federation -/* foreach ($entity->federations as $federation) { - Bus::chain([ - new GitAddMember($federation, $entity, Auth::user()), - function () use ($federation, $entity) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($federation->operators, new FederationMemberChanged($federation, $entity, 'added')); - Notification::send($admins, new FederationMemberChanged($federation, $entity, 'added')); - }, - ])->dispatch(); - }*/ + /* foreach ($entity->federations as $federation) { + Bus::chain([ + new GitAddMember($federation, $entity, Auth::user()), + function () use ($federation, $entity) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($federation->operators, new FederationMemberChanged($federation, $entity, 'added')); + Notification::send($admins, new FederationMemberChanged($federation, $entity, 'added')); + }, + ])->dispatch(); + }*/ } else { $entity->delete(); //TODO delete chain -/* Bus::chain([ - new GitDeleteEntity($entity, Auth::user()), - new GitDeleteFromHfd($entity, Auth::user()), - new GitDeleteFromEdugain($entity, Auth::user()), - new GitDeleteFromCategory($entity->category ?? null, $entity, Auth::user()), - function () use ($entity) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($entity->operators, new EntityStateChanged($entity)); - Notification::send($admins, new EntityStateChanged($entity)); - if ($entity->hfd) { - Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); - } - }, - ])->dispatch();*/ + /* Bus::chain([ + new GitDeleteEntity($entity, Auth::user()), + new GitDeleteFromHfd($entity, Auth::user()), + new GitDeleteFromEdugain($entity, Auth::user()), + new GitDeleteFromCategory($entity->category ?? null, $entity, Auth::user()), + function () use ($entity) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($entity->operators, new EntityStateChanged($entity)); + Notification::send($admins, new EntityStateChanged($entity)); + if ($entity->hfd) { + Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); + } + }, + ])->dispatch();*/ } $state = $entity->trashed() ? 'deleted' : 'restored'; @@ -439,25 +435,25 @@ function () use ($entity) { $color = $entity->edugain ? 'green' : 'red'; // TODO add and delete from EDUGAIN -/* if ($entity->edugain) { - Bus::chain([ - new GitAddToEdugain($entity, Auth::user()), - function () use ($entity) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($entity->operators, new EntityEdugainStatusChanged($entity)); - Notification::send($admins, new EntityEdugainStatusChanged($entity)); - }, - ])->dispatch(); - } else { - Bus::chain([ - new GitDeleteFromEdugain($entity, Auth::user()), - function () use ($entity) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($entity->operators, new EntityEdugainStatusChanged($entity)); - Notification::send($admins, new EntityEdugainStatusChanged($entity)); - }, - ])->dispatch(); - }*/ + /* if ($entity->edugain) { + Bus::chain([ + new GitAddToEdugain($entity, Auth::user()), + function () use ($entity) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($entity->operators, new EntityEdugainStatusChanged($entity)); + Notification::send($admins, new EntityEdugainStatusChanged($entity)); + }, + ])->dispatch(); + } else { + Bus::chain([ + new GitDeleteFromEdugain($entity, Auth::user()), + function () use ($entity) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($entity->operators, new EntityEdugainStatusChanged($entity)); + Notification::send($admins, new EntityEdugainStatusChanged($entity)); + }, + ])->dispatch(); + }*/ return redirect() ->back() @@ -514,14 +510,14 @@ function () use ($entity) { $entity->save(); // TODO work with category -/* Bus::chain([ - new GitDeleteFromCategory($old_category, $entity, Auth::user()), - new GitAddToCategory($category, $entity, Auth::user()), - function () use ($entity, $category) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($admins, new IdpCategoryChanged($entity, $category)); - }, - ])->dispatch();*/ + /* Bus::chain([ + new GitDeleteFromCategory($old_category, $entity, Auth::user()), + new GitAddToCategory($category, $entity, Auth::user()), + function () use ($entity, $category) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($admins, new IdpCategoryChanged($entity, $category)); + }, + ])->dispatch();*/ if (! $entity->wasChanged()) { return redirect() @@ -575,7 +571,6 @@ function () use ($entity, $category) { /** * Remove the specified resource from storage. * - * @param \App\Models\Entity $entity * @return \Illuminate\Http\Response */ public function destroy(Entity $entity) @@ -588,7 +583,7 @@ public function destroy(Entity $entity) if (! app()->environment('testing')) { if ($entity->type->value === 'idp' && ! $entity->hfd) { $eduidczOrganization = EduidczOrganization::whereEntityIDofIdP($entity->entityid)->first(); - if (!is_null($eduidczOrganization)) { + if (! is_null($eduidczOrganization)) { $eduidczOrganization->delete(); } } diff --git a/app/Http/Controllers/EntityManagementController.php b/app/Http/Controllers/EntityManagementController.php index 9ec4a7f..d8d69c0 100644 --- a/app/Http/Controllers/EntityManagementController.php +++ b/app/Http/Controllers/EntityManagementController.php @@ -13,7 +13,7 @@ class EntityManagementController extends Controller { - use ValidatorTrait, GitTrait; + use GitTrait, ValidatorTrait; public function __construct() { diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 38e3221..67aa975 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -67,12 +67,9 @@ public function store(StoreFederation $request) { $this->authorize('create', Federation::class); - $validated = $request->validated(); $id = generateFederationID($validated['name']); - - $federation = DB::transaction(function () use ($validated, $id) { $federation = Federation::create(array_merge($validated, [ 'xml_id' => $id, @@ -95,7 +92,6 @@ public function store(StoreFederation $request) /** * Display the specified resource. * - * @param \App\Models\Federation $federation * @return \Illuminate\Http\Response */ public function show(Federation $federation) @@ -110,7 +106,6 @@ public function show(Federation $federation) /** * Show the form for editing the specified resource. * - * @param \App\Models\Federation $federation * @return \Illuminate\Http\Response */ public function edit(Federation $federation) @@ -126,7 +121,6 @@ public function edit(Federation $federation) * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Models\Federation $federation * @return \Illuminate\Http\Response */ public function update(UpdateFederation $request, Federation $federation) @@ -164,20 +158,18 @@ public function update(UpdateFederation $request, Federation $federation) case 'update': - $this->authorize('update', $federation); $validated = $request->validated(); $id = $federation->name; - if(isset($validated['name'])) - { + if (isset($validated['name'])) { $id = generateFederationID($validated['name']); } $additionalFilters = $request->input('sp_and_ip_feed', 0); $filters = $id; - if($additionalFilters){ + if ($additionalFilters) { $filters .= ', '.$id.'+idp'; $filters .= ', '.$id.'+sp'; } @@ -191,7 +183,7 @@ public function update(UpdateFederation $request, Federation $federation) ->route('federations.show', $federation); } - // GitUpdateFederation::dispatch($federation, Auth::user()); + // GitUpdateFederation::dispatch($federation, Auth::user()); Notification::send($federation->operators, new FederationUpdated($federation)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationUpdated($federation)); @@ -209,13 +201,12 @@ public function update(UpdateFederation $request, Federation $federation) $state = $federation->trashed() ? 'deleted' : 'restored'; $color = $federation->trashed() ? 'red' : 'green'; + /* if ($federation->trashed()) { + GitDeleteFederation::dispatch($federation, Auth::user()); + } else { -/* if ($federation->trashed()) { - GitDeleteFederation::dispatch($federation, Auth::user()); - } else { - - GitAddFederation::dispatch($federation, 'state', Auth::user()); - }*/ + GitAddFederation::dispatch($federation, 'state', Auth::user()); + }*/ Notification::send($federation->operators, new FederationStateChanged($federation)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationStateChanged($federation)); @@ -333,7 +324,6 @@ public function update(UpdateFederation $request, Federation $federation) /** * Remove the specified resource from storage. * - * @param \App\Models\Federation $federation * @return \Illuminate\Http\Response */ public function destroy(Federation $federation) diff --git a/app/Http/Controllers/GroupController.php b/app/Http/Controllers/GroupController.php index 999d821..03c8b71 100644 --- a/app/Http/Controllers/GroupController.php +++ b/app/Http/Controllers/GroupController.php @@ -76,7 +76,6 @@ public function store(StoreGroup $request) /** * Display the specified resource. * - * @param \App\Models\Group $group * @return \Illuminate\Http\Response */ public function show(Group $group) @@ -91,7 +90,6 @@ public function show(Group $group) /** * Show the form for editing the specified resource. * - * @param \App\Models\Group $group * @return \Illuminate\Http\Response */ public function edit(Group $group) @@ -107,7 +105,6 @@ public function edit(Group $group) * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Models\Group $group * @return \Illuminate\Http\Response */ public function update(UpdateGroup $request, Group $group) @@ -133,7 +130,6 @@ public function update(UpdateGroup $request, Group $group) /** * Remove the specified resource from storage. * - * @param \App\Models\Group $group * @return \Illuminate\Http\Response */ public function destroy(Group $group) diff --git a/app/Http/Controllers/MembershipController.php b/app/Http/Controllers/MembershipController.php index 49fccc5..5a9ad23 100644 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -26,7 +26,6 @@ public function __construct() * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Models\Membership $membership * @return \Illuminate\Http\Response */ public function update(Membership $membership) @@ -65,7 +64,6 @@ function () use ($membership) { /** * Remove the specified resource from storage. * - * @param \App\Models\Membership $membership * @return \Illuminate\Http\Response */ public function destroy(Membership $membership) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 2e16dbc..de2ecda 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -81,7 +81,6 @@ public function show(User $user) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ diff --git a/app/Http/Middleware/Localization.php b/app/Http/Middleware/Localization.php index 2c675f2..64e14b6 100644 --- a/app/Http/Middleware/Localization.php +++ b/app/Http/Middleware/Localization.php @@ -12,8 +12,6 @@ class Localization /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 362b48b..fe886b0 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -12,8 +12,6 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure $next * @param string|null ...$guards * @return mixed */ diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 1b80b62..f44fa8d 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; class FolderAddEntity implements ShouldQueue @@ -30,4 +31,14 @@ public function handle(): void { dump("hello word"); } + + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array + { + return [(new WithoutOverlapping($this->entity->id))->dontRelease()]; + } } diff --git a/app/Jobs/GitAddCategory.php b/app/Jobs/GitAddCategory.php index f887d12..743fc93 100644 --- a/app/Jobs/GitAddCategory.php +++ b/app/Jobs/GitAddCategory.php @@ -18,7 +18,7 @@ class GitAddCategory implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddEntity.php b/app/Jobs/GitAddEntity.php index d90ad2f..d8f6aab 100644 --- a/app/Jobs/GitAddEntity.php +++ b/app/Jobs/GitAddEntity.php @@ -18,7 +18,7 @@ class GitAddEntity implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddGroup.php b/app/Jobs/GitAddGroup.php index 75f063d..d1a05f0 100644 --- a/app/Jobs/GitAddGroup.php +++ b/app/Jobs/GitAddGroup.php @@ -18,7 +18,7 @@ class GitAddGroup implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddMember.php b/app/Jobs/GitAddMember.php index 593543a..9809447 100644 --- a/app/Jobs/GitAddMember.php +++ b/app/Jobs/GitAddMember.php @@ -19,7 +19,7 @@ class GitAddMember implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddMembers.php b/app/Jobs/GitAddMembers.php index 7ccab14..7fcd22b 100644 --- a/app/Jobs/GitAddMembers.php +++ b/app/Jobs/GitAddMembers.php @@ -19,7 +19,7 @@ class GitAddMembers implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddMembership.php b/app/Jobs/GitAddMembership.php index ac30523..20de888 100644 --- a/app/Jobs/GitAddMembership.php +++ b/app/Jobs/GitAddMembership.php @@ -18,7 +18,7 @@ class GitAddMembership implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddToCategory.php b/app/Jobs/GitAddToCategory.php index ff5003a..2cf65b7 100644 --- a/app/Jobs/GitAddToCategory.php +++ b/app/Jobs/GitAddToCategory.php @@ -19,7 +19,7 @@ class GitAddToCategory implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddToEdugain.php b/app/Jobs/GitAddToEdugain.php index 3d5d69d..4a3f774 100644 --- a/app/Jobs/GitAddToEdugain.php +++ b/app/Jobs/GitAddToEdugain.php @@ -18,7 +18,7 @@ class GitAddToEdugain implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddToHfd.php b/app/Jobs/GitAddToHfd.php index 0de5cb8..32d44ec 100644 --- a/app/Jobs/GitAddToHfd.php +++ b/app/Jobs/GitAddToHfd.php @@ -18,7 +18,7 @@ class GitAddToHfd implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitAddToRs.php b/app/Jobs/GitAddToRs.php index bba57d3..cb6cdfd 100644 --- a/app/Jobs/GitAddToRs.php +++ b/app/Jobs/GitAddToRs.php @@ -18,7 +18,7 @@ class GitAddToRs implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteCategory.php b/app/Jobs/GitDeleteCategory.php index 502d586..6ae71cd 100644 --- a/app/Jobs/GitDeleteCategory.php +++ b/app/Jobs/GitDeleteCategory.php @@ -16,7 +16,7 @@ class GitDeleteCategory implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteEntity.php b/app/Jobs/GitDeleteEntity.php index 9657845..f136fdb 100644 --- a/app/Jobs/GitDeleteEntity.php +++ b/app/Jobs/GitDeleteEntity.php @@ -18,7 +18,7 @@ class GitDeleteEntity implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteFromCategory.php b/app/Jobs/GitDeleteFromCategory.php index 4ef7683..656cd7a 100644 --- a/app/Jobs/GitDeleteFromCategory.php +++ b/app/Jobs/GitDeleteFromCategory.php @@ -19,7 +19,7 @@ class GitDeleteFromCategory implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteFromEdugain.php b/app/Jobs/GitDeleteFromEdugain.php index 6aae9b5..69378f3 100644 --- a/app/Jobs/GitDeleteFromEdugain.php +++ b/app/Jobs/GitDeleteFromEdugain.php @@ -18,7 +18,7 @@ class GitDeleteFromEdugain implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteFromFederation.php b/app/Jobs/GitDeleteFromFederation.php index d6e69ed..b7dc670 100644 --- a/app/Jobs/GitDeleteFromFederation.php +++ b/app/Jobs/GitDeleteFromFederation.php @@ -19,7 +19,7 @@ class GitDeleteFromFederation implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteFromHfd.php b/app/Jobs/GitDeleteFromHfd.php index b35983d..1576adc 100644 --- a/app/Jobs/GitDeleteFromHfd.php +++ b/app/Jobs/GitDeleteFromHfd.php @@ -18,7 +18,7 @@ class GitDeleteFromHfd implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteFromRs.php b/app/Jobs/GitDeleteFromRs.php index d9c1236..a0b55e7 100644 --- a/app/Jobs/GitDeleteFromRs.php +++ b/app/Jobs/GitDeleteFromRs.php @@ -18,7 +18,7 @@ class GitDeleteFromRs implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteGroup.php b/app/Jobs/GitDeleteGroup.php index 3e59f59..5acda40 100644 --- a/app/Jobs/GitDeleteGroup.php +++ b/app/Jobs/GitDeleteGroup.php @@ -16,7 +16,7 @@ class GitDeleteGroup implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitDeleteMembers.php b/app/Jobs/GitDeleteMembers.php index 9c71ae9..c236363 100644 --- a/app/Jobs/GitDeleteMembers.php +++ b/app/Jobs/GitDeleteMembers.php @@ -19,7 +19,7 @@ class GitDeleteMembers implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitRestoreToCategory.php b/app/Jobs/GitRestoreToCategory.php index a14347c..6622c00 100644 --- a/app/Jobs/GitRestoreToCategory.php +++ b/app/Jobs/GitRestoreToCategory.php @@ -18,7 +18,7 @@ class GitRestoreToCategory implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitRestoreToEdugain.php b/app/Jobs/GitRestoreToEdugain.php index 0e3455f..59553e1 100644 --- a/app/Jobs/GitRestoreToEdugain.php +++ b/app/Jobs/GitRestoreToEdugain.php @@ -18,7 +18,7 @@ class GitRestoreToEdugain implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitUpdateCategory.php b/app/Jobs/GitUpdateCategory.php index d72c4a3..4f630ac 100644 --- a/app/Jobs/GitUpdateCategory.php +++ b/app/Jobs/GitUpdateCategory.php @@ -17,7 +17,7 @@ class GitUpdateCategory implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitUpdateEntity.php b/app/Jobs/GitUpdateEntity.php index aeca68b..92d8754 100644 --- a/app/Jobs/GitUpdateEntity.php +++ b/app/Jobs/GitUpdateEntity.php @@ -18,7 +18,7 @@ class GitUpdateEntity implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/GitUpdateGroup.php b/app/Jobs/GitUpdateGroup.php index 3952ac7..95d5aee 100644 --- a/app/Jobs/GitUpdateGroup.php +++ b/app/Jobs/GitUpdateGroup.php @@ -17,7 +17,7 @@ class GitUpdateGroup implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/Old_GitAddFederation.php b/app/Jobs/Old_GitAddFederation.php index 8d593cb..9626a83 100644 --- a/app/Jobs/Old_GitAddFederation.php +++ b/app/Jobs/Old_GitAddFederation.php @@ -18,7 +18,7 @@ class Old_GitAddFederation implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/Old_GitDeleteFederation.php b/app/Jobs/Old_GitDeleteFederation.php index 67bf2ed..9fa0499 100644 --- a/app/Jobs/Old_GitDeleteFederation.php +++ b/app/Jobs/Old_GitDeleteFederation.php @@ -17,7 +17,7 @@ class Old_GitDeleteFederation implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Jobs/Old_GitUpdateFederation.php b/app/Jobs/Old_GitUpdateFederation.php index 84ad3df..1f647d3 100644 --- a/app/Jobs/Old_GitUpdateFederation.php +++ b/app/Jobs/Old_GitUpdateFederation.php @@ -18,7 +18,7 @@ class Old_GitUpdateFederation implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, GitTrait; + use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. diff --git a/app/Listeners/CreateFederationFolder.php b/app/Listeners/CreateFederationFolder.php index deaf14b..571b0c7 100644 --- a/app/Listeners/CreateFederationFolder.php +++ b/app/Listeners/CreateFederationFolder.php @@ -4,8 +4,6 @@ use App\Events\FederationApprove; use App\Traits\FederationTrait; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Storage; class CreateFederationFolder @@ -27,9 +25,8 @@ public function handle(FederationApprove $event): void { $federation = $event->federation; - if($federation->approved) - { - if(!Storage::disk('metadata')->exists($federation->name)){ + if ($federation->approved) { + if (! Storage::disk('metadata')->exists($federation->name)) { $this->createFederationFolder($federation->name); } } diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index 07410cf..be8d99e 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -4,8 +4,6 @@ use App\Events\CreateEntity; use App\Jobs\FolderAddEntity; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Log; class SendCreatedEntityToSaveJob diff --git a/app/Models/Category.php b/app/Models/Category.php index ce51c9d..dd8aef6 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -13,7 +13,7 @@ class Category extends Model 'name', 'description', 'tagfile', - 'xml_value' + 'xml_value', ]; public function entities() @@ -21,7 +21,7 @@ public function entities() return $this->hasMany('App\Models\Entity'); } - public function scopeSearch($query, string $search = null) + public function scopeSearch($query, ?string $search = null) { $query ->where('name', 'like', "%$search%") diff --git a/app/Models/Entity.php b/app/Models/Entity.php index 16e9701..9a7e0d1 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -82,7 +82,7 @@ public function scopeVisibleTo($query, User $user) } } - public function scopeSearch($query, string $search = null) + public function scopeSearch($query, ?string $search = null) { $query ->where('entityid', 'like', "%$search%") @@ -95,5 +95,4 @@ public function scopeSearch($query, string $search = null) protected $dispatchesEvents = [ 'created' => CreateEntity::class, ]; - } diff --git a/app/Models/Federation.php b/app/Models/Federation.php index 0a5ab66..3e4f3bc 100644 --- a/app/Models/Federation.php +++ b/app/Models/Federation.php @@ -53,7 +53,7 @@ public function scopeVisibleTo($query, User $user) // FIXME: add federations if the user is its operator! } - public function scopeSearch($query, string $search = null) + public function scopeSearch($query, ?string $search = null) { $query ->where('name', 'like', "%$search%") @@ -65,5 +65,4 @@ public function scopeSearch($query, string $search = null) protected $dispatchesEvents = [ 'updated' => FederationApprove::class, ]; - } diff --git a/app/Models/Group.php b/app/Models/Group.php index dbac33f..b9087a7 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -20,7 +20,7 @@ public function entities() return $this->belongsToMany('App\Models\Entity'); } - public function scopeSearch($query, string $search = null) + public function scopeSearch($query, ?string $search = null) { $query ->where('name', 'like', "%$search%") diff --git a/app/Models/User.php b/app/Models/User.php index 940dc66..37829c8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -62,7 +62,7 @@ public function scopeActiveAdmins($query) ->where('active', true); } - public function scopeSearch($query, string $search = null) + public function scopeSearch($query, ?string $search = null) { $query ->where('name', 'like', "%$search%") diff --git a/app/Policies/EntityPolicy.php b/app/Policies/EntityPolicy.php index 1154b7a..9a07225 100644 --- a/app/Policies/EntityPolicy.php +++ b/app/Policies/EntityPolicy.php @@ -14,7 +14,6 @@ class EntityPolicy /** * Determine whether the user can view any models. * - * @param \App\Models\User $user * @return mixed */ public function viewAny(User $user) @@ -25,8 +24,6 @@ public function viewAny(User $user) /** * Determine whether the user can view the model. * - * @param \App\Models\User $user - * @param \App\Models\Entity $entity * @return mixed */ public function view(User $user, Entity $entity) @@ -37,7 +34,6 @@ public function view(User $user, Entity $entity) /** * Determine whether the user can create models. * - * @param \App\Models\User $user * @return mixed */ public function create(User $user) @@ -48,8 +44,6 @@ public function create(User $user) /** * Determine whether the user can update the model. * - * @param \App\Models\User $user - * @param \App\Models\Entity $entity * @return mixed */ public function update(User $user, Entity $entity) @@ -66,8 +60,6 @@ public function update(User $user, Entity $entity) /** * Determine whether the user can delete the model. * - * @param \App\Models\User $user - * @param \App\Models\Entity $entity * @return mixed */ public function delete(User $user, Entity $entity) @@ -84,8 +76,6 @@ public function delete(User $user, Entity $entity) /** * Determine whether the user can restore the model. * - * @param \App\Models\User $user - * @param \App\Models\Entity $entity * @return mixed */ public function restore(User $user, Entity $entity) @@ -103,8 +93,6 @@ public function restore(User $user, Entity $entity) /** * Determine whether the user can permanently delete the model. * - * @param \App\Models\User $user - * @param \App\Models\Entity $entity * @return mixed */ public function forceDelete(User $user, Entity $entity) diff --git a/app/Policies/FederationPolicy.php b/app/Policies/FederationPolicy.php index c04b8ac..1f85b08 100644 --- a/app/Policies/FederationPolicy.php +++ b/app/Policies/FederationPolicy.php @@ -14,7 +14,6 @@ class FederationPolicy /** * Determine whether the user can view any models. * - * @param \App\Models\User $user * @return mixed */ public function viewAny(User $user) @@ -25,8 +24,6 @@ public function viewAny(User $user) /** * Determine whether the user can view the model. * - * @param \App\Models\User $user - * @param \App\Models\Federation $federation * @return mixed */ public function view(User $user, Federation $federation) @@ -37,7 +34,6 @@ public function view(User $user, Federation $federation) /** * Determine whether the user can create models. * - * @param \App\Models\User $user * @return mixed */ public function create(User $user) @@ -48,8 +44,6 @@ public function create(User $user) /** * Determine whether the user can update the model. * - * @param \App\Models\User $user - * @param \App\Models\Federation $federation * @return mixed */ public function update(User $user, Federation $federation) @@ -66,8 +60,6 @@ public function update(User $user, Federation $federation) /** * Determine whether the user can delete the model. * - * @param \App\Models\User $user - * @param \App\Models\Federation $federation * @return mixed */ public function delete(User $user, Federation $federation) diff --git a/app/Policies/MembershipPolicy.php b/app/Policies/MembershipPolicy.php index 220c3f3..f69ff32 100644 --- a/app/Policies/MembershipPolicy.php +++ b/app/Policies/MembershipPolicy.php @@ -14,8 +14,6 @@ class MembershipPolicy /** * Determine whether the user can update the model. * - * @param \App\Models\User $user - * @param \App\Models\Membership $membership * @return mixed */ public function update(User $user, Membership $membership) @@ -32,8 +30,6 @@ public function update(User $user, Membership $membership) /** * Determine whether the user can delete the model. * - * @param \App\Models\User $user - * @param \App\Models\Membership $membership * @return mixed */ public function delete(User $user, Membership $membership) diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php index accc1af..be84fee 100644 --- a/app/Policies/UserPolicy.php +++ b/app/Policies/UserPolicy.php @@ -12,7 +12,6 @@ class UserPolicy /** * Determine whether the user can view any models. * - * @param \App\Models\User $user * @return mixed */ public function viewAny(User $user) @@ -23,8 +22,6 @@ public function viewAny(User $user) /** * Determine whether the user can view the model. * - * @param \App\Models\User $user - * @param \App\Models\User $model * @return mixed */ public function view(User $user, User $model) @@ -35,7 +32,6 @@ public function view(User $user, User $model) /** * Determine whether the user can create models. * - * @param \App\Models\User $user * @return mixed */ public function create(User $user) @@ -46,8 +42,6 @@ public function create(User $user) /** * Determine whether the user can update the model. * - * @param \App\Models\User $user - * @param \App\Models\User $model * @return mixed */ public function update(User $user, User $model) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3ed473e..f326216 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,6 @@ namespace App\Providers; -use App\Services\EntityService; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Mail; use Illuminate\Support\ServiceProvider; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 1a0002d..3cc685e 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -25,11 +25,10 @@ class EventServiceProvider extends ServiceProvider FederationApprove::class => [ CreateFederationFolder::class, ], - CreateEntity::class =>[ + CreateEntity::class => [ SendCreatedEntityToSaveJob::class, ], - ]; /** diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index a58ed2e..87db935 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -1,5 +1,7 @@ saveEntityMetadataToFolder($entity_id,$federation->name); + $this->saveEntityMetadataToFolder($entity_id, $federation->name); } /** * save entity if we know folder name + * * @throws Exception if entity doesnt exist in database */ - public function saveEntityMetadataToFolder($entity_id,$folderName): void + public function saveEntityMetadataToFolder($entity_id, $folderName): void { $entity = Entity::find($entity_id); - if(!$entity){ + if (! $entity) { throw new Exception("Entity not found with id $entity_id"); } $fileName = $entity->file; - if(!Storage::disk('metadata')->exists($folderName)) - { + if (! Storage::disk('metadata')->exists($folderName)) { Storage::disk('metadata')->makeDirectory($folderName); } - $filePath = $folderName . '/' . $fileName; + $filePath = $folderName.'/'.$fileName; $content = $entity->xml_file; Storage::disk('metadata')->put($filePath, $content); - } - - } diff --git a/app/Traits/DumpFromGit/CreateCategoriesAndGroupsTrait.php b/app/Traits/DumpFromGit/CreateCategoriesAndGroupsTrait.php index ad92707..fe6344b 100644 --- a/app/Traits/DumpFromGit/CreateCategoriesAndGroupsTrait.php +++ b/app/Traits/DumpFromGit/CreateCategoriesAndGroupsTrait.php @@ -1,5 +1,7 @@ $names[$item], 'description' => $descriptions[$item], 'tagfile' => $item, - 'xml_value'=> $categories_conf[$names[$item]] + 'xml_value' => $categories_conf[$names[$item]], ]); }); - } - else - { + } else { DB::transaction(function () use ($item, $names, $descriptions) { Group::create([ 'name' => $names[$item], @@ -72,7 +71,6 @@ public function createCategoriesAndGroups(): void } } - private function updateCategories(): void { foreach (Category::select('id', 'tagfile')->get() as $category) { @@ -105,7 +103,7 @@ private function updateGroups(): void } } - public function updateGroupsAndCategories(): void + public function updateGroupsAndCategories(): void { $this->updateGroups(); $this->updateCategories(); diff --git a/app/Traits/DumpFromGit/CreateEntitiesTrait.php b/app/Traits/DumpFromGit/CreateEntitiesTrait.php index 13b21d7..f52480a 100644 --- a/app/Traits/DumpFromGit/CreateEntitiesTrait.php +++ b/app/Traits/DumpFromGit/CreateEntitiesTrait.php @@ -1,26 +1,18 @@ first(); - if (!($federation === null && Storage::exists(preg_replace('/\.tag/', '.cfg', $file)))) { + if (! ($federation === null && Storage::exists(preg_replace('/\.tag/', '.cfg', $file)))) { $tagfiles[] = $file; } } @@ -77,6 +69,7 @@ public function createEntities(int $adminId): void if (preg_match_all($pattern, $content)) { if (strcmp($tagfile, config('git.edugain_tag')) === 0) { $unknown[$xmlfile]['edugain'] = 1; + continue; } @@ -92,7 +85,7 @@ public function createEntities(int $adminId): void $entity->approved = true; $entity->update(); foreach ($ent['federations'] as $fed) { - if (!empty($fed)) { + if (! empty($fed)) { $entity->federations()->attach($fed, [ 'requested_by' => $adminId, 'approved_by' => $adminId, diff --git a/app/Traits/DumpFromGit/CreateFederationTrait.php b/app/Traits/DumpFromGit/CreateFederationTrait.php index ffae34a..9ea1b37 100644 --- a/app/Traits/DumpFromGit/CreateFederationTrait.php +++ b/app/Traits/DumpFromGit/CreateFederationTrait.php @@ -1,4 +1,5 @@ 1; - + $additionalFilters = count($filtersArray) > 1; DB::transaction(function () use ($additionalFilters, $fed) { $federation = Federation::create([ 'name' => $fed['xml_id'], 'description' => $fed['xml_id'], - 'tagfile' => preg_replace('/\.cfg$/', '.tag', $fed["cfgfile"]), - 'cfgfile' => $fed["cfgfile"], - 'xml_id' => $fed["xml_id"], - 'xml_name' => $fed["xml_name"], - 'filters' => $fed["filters"], + 'tagfile' => preg_replace('/\.cfg$/', '.tag', $fed['cfgfile']), + 'cfgfile' => $fed['cfgfile'], + 'xml_id' => $fed['xml_id'], + 'xml_name' => $fed['xml_name'], + 'filters' => $fed['filters'], 'additional_filters' => $additionalFilters, 'explanation' => 'Imported from Git repository.', ]); @@ -63,5 +62,4 @@ public function createFederations(): void }); } } - } diff --git a/app/Traits/DumpFromGit/EntitiesHelp/DeleteFromEntity.php b/app/Traits/DumpFromGit/EntitiesHelp/DeleteFromEntity.php index d7085a9..13b7d74 100644 --- a/app/Traits/DumpFromGit/EntitiesHelp/DeleteFromEntity.php +++ b/app/Traits/DumpFromGit/EntitiesHelp/DeleteFromEntity.php @@ -1,12 +1,13 @@ childNodes as $child) { @@ -27,12 +28,12 @@ private function deleteTag(object $tag): void private function deleteNoChilledTag(object $tag): void { - if (!$this->hasChildElements($tag)) { + if (! $this->hasChildElements($tag)) { $this->deleteTag($tag); } } - private function DeleteAllTags(string $xpathQuery, \DOMXPath $xPath ) : void + private function DeleteAllTags(string $xpathQuery, \DOMXPath $xPath): void { $tags = $xPath->query($xpathQuery); @@ -46,32 +47,31 @@ private function DeleteAllTags(string $xpathQuery, \DOMXPath $xPath ) : void } } - - private function deleteCategories(\DOMXPath $xPath) :void + private function deleteCategories(\DOMXPath $xPath): void { $values = config('categories'); $xpathQueryParts = array_map(function ($value) { return "text()='$value'"; }, $values); - $xpathQuery = '//saml:AttributeValue[' . implode(' or ', $xpathQueryParts) . ']'; - $this->DeleteAllTags($xpathQuery,$xPath); + $xpathQuery = '//saml:AttributeValue['.implode(' or ', $xpathQueryParts).']'; + $this->DeleteAllTags($xpathQuery, $xPath); } - private function deleteResearchAndScholarship(\DOMXPath $xPath) : void + private function deleteResearchAndScholarship(\DOMXPath $xPath): void { - $value = "http://refeds.org/category/research-and-scholarship" ; + $value = 'http://refeds.org/category/research-and-scholarship'; $xpathQueryParts = "text()='$value'"; - $xpathQuery = '//saml:AttributeValue[' . $xpathQueryParts . ']'; - $this->DeleteAllTags($xpathQuery,$xPath); + $xpathQuery = '//saml:AttributeValue['.$xpathQueryParts.']'; + $this->DeleteAllTags($xpathQuery, $xPath); } - private function deleteRegistrationInfo(\DOMXPath $xPath) : void + + private function deleteRegistrationInfo(\DOMXPath $xPath): void { $xpathQuery = '//mdrpi:RegistrationInfo'; $tags = $xPath->query($xpathQuery); - if(!empty($tags)) - { + if (! empty($tags)) { foreach ($tags as $tag) { $this->deleteTag($tag); } @@ -79,19 +79,18 @@ private function deleteRegistrationInfo(\DOMXPath $xPath) : void } - - private function deleteFromIdp( \DOMXPath $xPath ) : void + private function deleteFromIdp(\DOMXPath $xPath): void { $this->deleteCategories($xPath); } - private function deleteFromSP( \DOMXPath $xpath ) : void + private function deleteFromSP(\DOMXPath $xpath): void { $this->deleteResearchAndScholarship($xpath); } - private function deleteRepublishRequest(\DOMXPath $xPath) : void + private function deleteRepublishRequest(\DOMXPath $xPath): void { $xpathQuery = '//eduidmd:RepublishRequest'; @@ -104,33 +103,26 @@ private function deleteRepublishRequest(\DOMXPath $xPath) : void } - private function deleteTags(string $metadata): string { $dom = $this->createDOM($metadata); $xPath = $this->createXPath($dom); // Make action for IDP - if($this->isIDP($xPath)) - { + if ($this->isIDP($xPath)) { $this->deleteFromIdp($xPath); } // Make action for SP - else - { + else { $this->deleteFromSP($xPath); } - // Make action for Sp and Idp $this->deleteRepublishRequest($xPath); $this->deleteRegistrationInfo($xPath); - $dom->normalize(); + return $dom->saveXML(); } - - - } diff --git a/app/Traits/DumpFromGit/EntitiesHelp/FixEntityTrait.php b/app/Traits/DumpFromGit/EntitiesHelp/FixEntityTrait.php index 13ef78c..4dedea2 100644 --- a/app/Traits/DumpFromGit/EntitiesHelp/FixEntityTrait.php +++ b/app/Traits/DumpFromGit/EntitiesHelp/FixEntityTrait.php @@ -1,25 +1,30 @@ get() as $entity) - { + foreach (Entity::select()->get() as $entity) { $this->mdURI = config('xmlNameSpace.md'); $this->mdattrURI = config('xmlNameSpace.mdattr'); @@ -29,46 +34,41 @@ public function fixEntities(): void $xml_document = $entity->xml_file; - //$xml_document = $entity->metadata; - $res = json_decode($this->validateMetadata($xml_document,true),true); + $res = json_decode($this->validateMetadata($xml_document, true), true); $res['ent_id'] = $entity->id; $errorArray = $res['errorArray']; $dom = $this->createDOM($xml_document); $xPath = $this->createXPath($dom); - $UIInfo = $this->CreateUIInfo($dom,$xPath); + $UIInfo = $this->CreateUIInfo($dom, $xPath); - - if(array_key_exists('Logo',$errorArray)) - { - $this->fixLogo($UIInfo,$dom,$xPath); + if (array_key_exists('Logo', $errorArray)) { + $this->fixLogo($UIInfo, $dom, $xPath); } - $xml_document = $dom->saveXML(); Entity::whereId($entity->id)->update(['xml_file' => $xml_document]); dump($entity->id); - // dump($res); + // dump($res); } } - private function CreateUIInfo(DOMDocument $dom, DOMXPath $xPath ): DOMNode|null + private function CreateUIInfo(DOMDocument $dom, DOMXPath $xPath): ?DOMNode { $rootTag = $xPath->query('//md:Extensions')->item(0); $UIInfo = $xPath->query('//mdui:UIInfo'); - if($UIInfo->length === 0) - { - $UIInfo = $dom->createElementNS($this->mdui,'mdui:UIInfo'); + if ($UIInfo->length === 0) { + $UIInfo = $dom->createElementNS($this->mdui, 'mdui:UIInfo'); $rootTag->appendChild($UIInfo); - } else - { + } else { $UIInfo = $UIInfo->item(0); } - return $UIInfo ; + + return $UIInfo; } private function deleteLogo(object $tag): void @@ -77,25 +77,23 @@ private function deleteLogo(object $tag): void $tag->parentNode->removeChild($tag); } } - private function ClearOldLogo(object $logos):void + + private function ClearOldLogo(object $logos): void { foreach ($logos as $logo) { $this->deleteLogo($logo); } } - - private function fixLogo(DOMNode $UIInfo,DOMDocument $dom, DOMXPath $xPath): void + private function fixLogo(DOMNode $UIInfo, DOMDocument $dom, DOMXPath $xPath): void { $logo = $xPath->query('//mdui:Logo'); $this->ClearOldLogo($logo); - $logo = $dom->createElementNS($this->mdui,'mdui:Logo','https://www.eduid.cz/images/no_logo_100x100.png'); - $logo->setAttribute('width',100); - $logo->setAttribute('height',100); + $logo = $dom->createElementNS($this->mdui, 'mdui:Logo', 'https://www.eduid.cz/images/no_logo_100x100.png'); + $logo->setAttribute('width', 100); + $logo->setAttribute('height', 100); $UIInfo->appendChild($logo); } - - } diff --git a/app/Traits/DumpFromGit/EntitiesHelp/UpdateEntity.php b/app/Traits/DumpFromGit/EntitiesHelp/UpdateEntity.php index 76e0aa1..6abbf53 100644 --- a/app/Traits/DumpFromGit/EntitiesHelp/UpdateEntity.php +++ b/app/Traits/DumpFromGit/EntitiesHelp/UpdateEntity.php @@ -1,5 +1,7 @@ createDOM($xml_document); $xPath = $this->createXPath($dom); $rootTag = $xPath->query("//*[local-name()='EntityDescriptor']")->item(0); $entityExtensions = $xPath->query('//md:Extensions'); - if($entityExtensions->length === 0) - { + if ($entityExtensions->length === 0) { $namespaceURI = $dom->documentElement->lookupNamespaceURI('md'); $entityExtensions = $dom->createElementNS($this->mdURI, 'md:Extensions'); - $rootTag->insertBefore($entityExtensions,$rootTag->firstChild); - }else { + $rootTag->insertBefore($entityExtensions, $rootTag->firstChild); + } else { $entityExtensions = $entityExtensions->item(0); } $entityAttributes = $xPath->query('//mdattr:EntityAttributes'); @@ -59,7 +62,7 @@ private function updateXmlCategories(string $xml_document, int $category_id ) : return $dom->saveXML(); } - private function updateResearchAndScholarship( string $xml_document,bool $isIdp) : string + private function updateResearchAndScholarship(string $xml_document, bool $isIdp): string { $dom = $this->createDOM($xml_document); $xPath = $this->createXPath($dom); @@ -67,34 +70,31 @@ private function updateResearchAndScholarship( string $xml_document,bool $isIdp) $rootTag = $xPath->query("//*[local-name()='EntityDescriptor']")->item(0); $extensions = $xPath->query('//md:Extensions'); - if($extensions->length === 0) - { + if ($extensions->length === 0) { $extensions = $dom->createElementNS($this->mdURI, 'md:Extensions'); $rootTag->appendChild($extensions); - } - else - { + } else { $extensions = $extensions->item(0); } $entityAttributes = $xPath->query('//mdattr:EntityAttributes'); if ($entityAttributes->length === 0) { - $entityAttributes = $dom->createElementNS( $this->mdattrURI,'mdattr:EntityAttributes'); + $entityAttributes = $dom->createElementNS($this->mdattrURI, 'mdattr:EntityAttributes'); $extensions->appendChild($entityAttributes); } else { $entityAttributes = $entityAttributes->item(0); } - $attribute = $xPath->query('//mdattr:EntityAttributes/saml:Attribute', $entityAttributes); if ($attribute->length === 0) { $attribute = $dom->createElementNS($this->samlURI, 'saml:Attribute'); $attribute->setAttribute('NameFormat', 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'); - if($isIdp) + if ($isIdp) { $attribute->setAttribute('Name', 'http://macedir.org/entity-category-support'); - else + } else { $attribute->setAttribute('Name', 'http://macedir.org/entity-category'); + } $entityAttributes->appendChild($attribute); } else { @@ -104,8 +104,8 @@ private function updateResearchAndScholarship( string $xml_document,bool $isIdp) $attributeValue = $dom->createElementNS($this->samlURI, 'saml:AttributeValue', 'http://refeds.org/category/research-and-scholarship'); $attribute->appendChild($attributeValue); - $dom->normalize(); + return $dom->saveXML(); } @@ -113,28 +113,28 @@ private function updateResearchAndScholarship( string $xml_document,bool $isIdp) /** * @throws Exception if exist more or less then 2 part something gone wrong */ - private function splitDocument():array + private function splitDocument(): array { $document = Storage::get(config('git.reginfo')); $lines = explode("\n", $document); $splitDocument = []; foreach ($lines as $line) { - if(empty(ltrim($line))) { + if (empty(ltrim($line))) { continue; } $parts = preg_split('/\s+/', $line, 2); - if(count($parts) != 2) { + if (count($parts) != 2) { throw new Exception('no 2 part'); - } else - { + } else { $splitDocument[$parts[0]] = $parts[1]; } } + return $splitDocument; } - private function updateRegistrationInfo(string $xml_document, string $entityId,array $timestampDocumentArray ) : string + private function updateRegistrationInfo(string $xml_document, string $entityId, array $timestampDocumentArray): string { $dom = $this->createDOM($xml_document); $xPath = $this->createXPath($dom); @@ -142,8 +142,8 @@ private function updateRegistrationInfo(string $xml_document, string $entityId,a $entityExtensions = $xPath->query('//md:Extensions'); if ($entityExtensions->length === 0) { - $entityExtensions = $dom->createElementNS( $this->mdURI,'md:Extensions'); - $rootTag->insertBefore($entityExtensions,$rootTag->firstChild); + $entityExtensions = $dom->createElementNS($this->mdURI, 'md:Extensions'); + $rootTag->insertBefore($entityExtensions, $rootTag->firstChild); } else { $entityExtensions = $entityExtensions->item(0); } @@ -154,65 +154,61 @@ private function updateRegistrationInfo(string $xml_document, string $entityId,a $info->setAttribute('registrationAuthority', config('registrationInfo.registrationAuthority')); - - if(empty($timestampDocumentArray[$entityId])) { + if (empty($timestampDocumentArray[$entityId])) { $info->setAttribute('registrationInstant', gmdate('Y-m-d\TH:i:s\Z')); } else { - $info->setAttribute('registrationInstant',$timestampDocumentArray[$entityId]); + $info->setAttribute('registrationInstant', $timestampDocumentArray[$entityId]); } - $entityExtensions->appendChild($info); } else { $info = $info->item(0); } //For English - $registrationPolicyEN = $dom->createElementNS($this->samlURI, 'saml:AttributeValue',config('registrationInfo.en')); + $registrationPolicyEN = $dom->createElementNS($this->samlURI, 'saml:AttributeValue', config('registrationInfo.en')); $registrationPolicyEN->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en'); $info->appendChild($registrationPolicyEN); // For Czech - $registrationPolicyCZ = $dom->createElementNS($this->samlURI, 'saml:AttributeValue',config('registrationInfo.cs')); + $registrationPolicyCZ = $dom->createElementNS($this->samlURI, 'saml:AttributeValue', config('registrationInfo.cs')); $registrationPolicyCZ->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'cs'); $info->appendChild($registrationPolicyCZ); $dom->normalize(); + return $dom->saveXML(); } /** - * @param array $timestampDocumentArray for add registration time from git file + * @param array $timestampDocumentArray for add registration time from git file * @return void update entity in db and return */ - public function updateEntityXml($entity,array $timestampDocumentArray = []): void + public function updateEntityXml($entity, array $timestampDocumentArray = []): void { - if(empty($entity->xml_file)) + if (empty($entity->xml_file)) { return; + } $xml_document = $entity->xml_file; $isIdp = false; - if($entity->type == "idp") + if ($entity->type == 'idp') { $isIdp = true; + } - - if($entity->rs) - { - $xml_document = $this->updateResearchAndScholarship($xml_document,$isIdp); + if ($entity->rs) { + $xml_document = $this->updateResearchAndScholarship($xml_document, $isIdp); } - if(!empty($entity->category_id)) - { - $xml_document = $this->updateXmlCategories($xml_document,$entity->category_id); + if (! empty($entity->category_id)) { + $xml_document = $this->updateXmlCategories($xml_document, $entity->category_id); } - $xml_document = $this->updateRegistrationInfo($xml_document,$entity->entityid,$timestampDocumentArray); - + $xml_document = $this->updateRegistrationInfo($xml_document, $entity->entityid, $timestampDocumentArray); Entity::whereId($entity->id)->update(['xml_file' => $xml_document]); } - - public function updateEntitiesXml() : void + public function updateEntitiesXml(): void { $this->mdURI = config('xmlNameSpace.md'); $this->mdattrURI = config('xmlNameSpace.mdattr'); @@ -222,12 +218,8 @@ public function updateEntitiesXml() : void $timestampDocumentArray = $this->splitDocument(); // dump($timestampDocumentArray); - - foreach (Entity::select()->get() as $entity) - { - $this->updateEntityXml($entity,$timestampDocumentArray); + foreach (Entity::select()->get() as $entity) { + $this->updateEntityXml($entity, $timestampDocumentArray); } } - - } diff --git a/app/Traits/EdugainTrait.php b/app/Traits/EdugainTrait.php index f5ce618..fd146c3 100644 --- a/app/Traits/EdugainTrait.php +++ b/app/Traits/EdugainTrait.php @@ -1,27 +1,23 @@ get(); + $eduFed = Entity::where('edugain', 1)->get(); foreach ($eduFed as $edu) { EntityFacade::saveEntityMetadataToFolder($edu->id, $folderName); } - - } - - - - } diff --git a/app/Traits/FederationTrait.php b/app/Traits/FederationTrait.php index a189501..34c2d2b 100644 --- a/app/Traits/FederationTrait.php +++ b/app/Traits/FederationTrait.php @@ -1,25 +1,25 @@ makeDirectory($name); } + public function updateFederationFolders(): void { $federations = Federation::select('name')->get(); foreach ($federations as $fed) { - if(!Storage::disk('metadata')->exists($fed['name'])){ - $this->createFederationFolder($fed['name']); + if (! Storage::disk('metadata')->exists($fed['name'])) { + $this->createFederationFolder($fed['name']); } } } - - } diff --git a/app/Traits/ValidatorTrait.php b/app/Traits/ValidatorTrait.php index 3165932..8c2cc63 100644 --- a/app/Traits/ValidatorTrait.php +++ b/app/Traits/ValidatorTrait.php @@ -14,24 +14,20 @@ trait ValidatorTrait public array $errorsArray = []; - private $context; - - + private $context; // ////////////////////////////////////////////////// // Helper functions // ////////////////////////////////////////////////// - private function initContext() + private function initContext() { - $this->context = stream_context_create(array( - 'http' => array( - 'timeout' => 5 // Timeout in seconds - ) - )); + $this->context = stream_context_create([ + 'http' => [ + 'timeout' => 5, // Timeout in seconds + ], + ]); } - - public function getMetadata(Request $request): string { if ($request->hasFile('file')) { @@ -64,7 +60,6 @@ public function createDOM(string $metadata): object { libxml_use_internal_errors(true); - $dom = new \DOMDocument(); $dom->formatOutput = true; $dom->preserveWhiteSpace = false; @@ -103,7 +98,7 @@ public function createXPath(object $dom): object $xpath->registerNameSpace('mdattr', 'urn:oasis:names:tc:SAML:metadata:attribute'); $xpath->registerNameSpace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion'); $xpath->registerNameSpace('remd', 'http://refeds.org/metadata'); - $xpath->registerNamespace('mdrpi','urn:oasis:names:tc:SAML:metadata:rpi'); + $xpath->registerNamespace('mdrpi', 'urn:oasis:names:tc:SAML:metadata:rpi'); return $xpath; } @@ -368,13 +363,12 @@ public function checkRepublishRequest(object $xpath): void } } - public function checkURLaddress(object $element): string { $this->initContext(); foreach ($element as $e) { - @$file = file_get_contents(trim($e->nodeValue),0,$this->context); + @$file = file_get_contents(trim($e->nodeValue), 0, $this->context); if (@$http_response_header === null) { return $e->nodeValue.' from '.$e->parentNode->nodeName.'/'.$e->nodeName.'[@xml:lang="'.$e->getAttribute('xml:lang').'"] could not be read, check www.ssllabs.com for possible SSL errors. '; } elseif (preg_match('/403|404|500/', $http_response_header[0])) { @@ -387,10 +381,6 @@ public function checkURLaddress(object $element): string } } - - - - public function checkUIInfo(object $xpath): void { if ($this->isIDP($xpath)) { @@ -439,8 +429,6 @@ public function checkUIInfo(object $xpath): void $this->errorsArray['InformationURLEN'] = 'InformationURL[@xml:lang="en"] missing'; } - - if ($this->isIDP($xpath)) { if ($Logo->length < 1) { $this->error .= $SSODescriptor.'/UIInfo/Logo missing. '; @@ -448,14 +436,14 @@ public function checkUIInfo(object $xpath): void } else { $this->initContext(); foreach ($Logo as $logo) { - @$file = file_get_contents($logo->nodeValue,0,$this->context); - if (!$file) { + @$file = file_get_contents($logo->nodeValue, 0, $this->context); + if (! $file) { $this->error .= $SSODescriptor.'/UIInfo/Logo '.$logo->nodeValue.' could not be read. '; $this->errorsArray['Logo'] = 'Logo '.$logo->nodeValue.' could not be read'; } else { $headers = get_headers($logo->nodeValue, true); - if(! 'image/svg+xml'===$headers['Content-Type']) { + if (! 'image/svg+xml' === $headers['Content-Type']) { if (exif_imagetype($logo->nodeValue)) { @@ -475,17 +463,12 @@ public function checkUIInfo(object $xpath): void $this->errorsArray['Logo'] = 'Logo '.$logo->nodeValue.' could not be read'; } - } - else - { + } else { $this->errorsArray['Logo'] = 'Logo '.$logo->nodeValue.' is not an image.'; } } - - - } } } @@ -767,7 +750,7 @@ public function checkEC(object $xpath): void if ($PrivacyStatementURL_EN->length === 0) { $this->error .= 'UIInfo/PrivacyStatementURL[@xml:lang="en"] missing. '; - $this->errorsArray['PrivacyStatementURLEN']= 'UIInfo/PrivacyStatementURL[@xml:lang="en"]'; + $this->errorsArray['PrivacyStatementURLEN'] = 'UIInfo/PrivacyStatementURL[@xml:lang="en"]'; } } } @@ -838,15 +821,15 @@ public function generateResult(): void } } - private function setValueToDefault() : void + private function setValueToDefault(): void { $this->errorsArray = []; - $this->message=''; - $this->error=''; - $this->code=0; + $this->message = ''; + $this->error = ''; + $this->code = 0; } - public function validateMetadata(string $metadata,bool $withRestore = false): string + public function validateMetadata(string $metadata, bool $withRestore = false): string { $this->setValueToDefault(); @@ -871,16 +854,13 @@ public function validateMetadata(string $metadata,bool $withRestore = false): st $this->generateResult(); } - if(!$withRestore) - { + if (! $withRestore) { return json_encode([ 'code' => $this->code, 'message' => $this->message, 'error' => $this->error, ], JSON_FORCE_OBJECT); - } - else - { + } else { return json_encode([ 'code' => $this->code, 'message' => $this->message, @@ -889,7 +869,5 @@ public function validateMetadata(string $metadata,bool $withRestore = false): st ], JSON_FORCE_OBJECT); } - - } } diff --git a/app/View/Components/Buttons/Back.php b/app/View/Components/Buttons/Back.php index b35d3e6..0ee5022 100644 --- a/app/View/Components/Buttons/Back.php +++ b/app/View/Components/Buttons/Back.php @@ -11,7 +11,6 @@ class Back extends Component * * @return void */ - public function __construct() { } diff --git a/app/View/Components/Buttons/Edit.php b/app/View/Components/Buttons/Edit.php index 89f56e7..a3e5d72 100644 --- a/app/View/Components/Buttons/Edit.php +++ b/app/View/Components/Buttons/Edit.php @@ -11,9 +11,9 @@ class Edit extends Component /** * Create a new component instance. */ + public $href; - public $href; - public function __construct($href = "/") + public function __construct($href = '/') { $this->href = $href; } diff --git a/app/View/Components/Buttons/Subhead.php b/app/View/Components/Buttons/Subhead.php index 662a5a8..dc5347f 100644 --- a/app/View/Components/Buttons/Subhead.php +++ b/app/View/Components/Buttons/Subhead.php @@ -11,8 +11,8 @@ class Subhead extends Component /** * Create a new component instance. */ + public $href; - public $href; public function __construct($href) { $this->href = $href; diff --git a/app/View/Components/FormTable/HeadCell.php b/app/View/Components/FormTable/HeadCell.php index f94cf93..1d9b90b 100644 --- a/app/View/Components/FormTable/HeadCell.php +++ b/app/View/Components/FormTable/HeadCell.php @@ -11,8 +11,6 @@ class HeadCell extends Component /** * Create a new component instance. */ - - public function __construct() { diff --git a/app/View/Components/Forms/Element/Textarea.php b/app/View/Components/Forms/Element/Textarea.php index 90c702e..3ce3402 100644 --- a/app/View/Components/Forms/Element/Textarea.php +++ b/app/View/Components/Forms/Element/Textarea.php @@ -12,15 +12,14 @@ class Textarea extends Component * Create a new component instance. */ public $content; + public $err; - public function __construct($err,$content = null) + + public function __construct($err, $content = null) { - if(is_null($content)) - { + if (is_null($content)) { $this->content = $err; - } - else - { + } else { $this->content = $content; } $this->err = $err; diff --git a/app/View/Components/Forms/Element/input.php b/app/View/Components/Forms/Element/input.php index e27027c..0e78cac 100644 --- a/app/View/Components/Forms/Element/input.php +++ b/app/View/Components/Forms/Element/input.php @@ -11,12 +11,13 @@ class input extends Component /** * Create a new component instance. */ - public $err; + public function __construct($err) { $this->err = $err; } + /** * Get the view / contents that represent the component. */ diff --git a/app/View/Components/Forms/Section/FormBodySection.php b/app/View/Components/Forms/Section/FormBodySection.php index 1e12629..2982647 100644 --- a/app/View/Components/Forms/Section/FormBodySection.php +++ b/app/View/Components/Forms/Section/FormBodySection.php @@ -12,24 +12,22 @@ class FormBodySection extends Component * Create a new component instance. */ public $name; + public $label; + public $err; - public function __construct($name,$label,$err = null) + + public function __construct($name, $label, $err = null) { - if(is_null($err)) - { + if (is_null($err)) { $this->err = $label; - } - else - { + } else { $this->err = $err; } $this->name = $name; $this->label = $label; - - } /** diff --git a/config/app.php b/config/app.php index f09651e..9d4cbfd 100644 --- a/config/app.php +++ b/config/app.php @@ -229,7 +229,7 @@ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, - 'EntityFacade' => App\Facades\EntityFacade::class + 'EntityFacade' => App\Facades\EntityFacade::class, ], ]; diff --git a/config/registrationInfo.php b/config/registrationInfo.php index aece5e9..c112b62 100644 --- a/config/registrationInfo.php +++ b/config/registrationInfo.php @@ -1,4 +1,5 @@ 'http://www.eduid.cz/', 'en' => 'http://www.eduid.cz/wiki/_media/en/eduid/policy/policy_eduid_en-1_1.pdf', diff --git a/config/xmlNameSpace.php b/config/xmlNameSpace.php index 0e8f2e0..4a724e6 100644 --- a/config/xmlNameSpace.php +++ b/config/xmlNameSpace.php @@ -1,6 +1,5 @@ 'urn:oasis:names:tc:SAML:2.0:metadata', 'ds' => 'http://www.w3.org/2000/09/xmldsig#', @@ -12,6 +11,6 @@ 'mdattr' => 'urn:oasis:names:tc:SAML:metadata:attribute', 'saml' => 'urn:oasis:names:tc:SAML:2.0:assertion', 'remd' => 'http://refeds.org/metadata', - 'mdrpi'=> 'urn:oasis:names:tc:SAML:metadata:rpi', + 'mdrpi' => 'urn:oasis:names:tc:SAML:metadata:rpi', ]; diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index 8b0c45b..0944f77 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -27,7 +27,7 @@ public function definition() 'name' => $name, 'description' => $this->faker->catchPhrase(), 'tagfile' => generateFederationID($name).'.tag', - 'xml_value' => $this->faker->unique()->url() + 'xml_value' => $this->faker->unique()->url(), ]; } } diff --git a/database/migrations/2020_12_23_133143_create_entities_table.php b/database/migrations/2020_12_23_133143_create_entities_table.php index 6f0ef50..186e28d 100644 --- a/database/migrations/2020_12_23_133143_create_entities_table.php +++ b/database/migrations/2020_12_23_133143_create_entities_table.php @@ -18,7 +18,7 @@ public function up() $table->enum('type', ['idp', 'sp']); $table->string('entityid')->unique(); $table->string('file')->unique(); - $table->longText("xml_file")->nullable(); + $table->longText('xml_file')->nullable(); $table->string('name_en', 128)->nullable(); $table->string('name_cs', 128)->nullable(); $table->string('description_en')->nullable(); diff --git a/database/migrations/2021_01_04_132833_create_categories_table.php b/database/migrations/2021_01_04_132833_create_categories_table.php index e361179..2c0d68c 100644 --- a/database/migrations/2021_01_04_132833_create_categories_table.php +++ b/database/migrations/2021_01_04_132833_create_categories_table.php @@ -18,7 +18,7 @@ public function up() $table->string('name', 32)->unique(); $table->string('description'); $table->string('tagfile', 36)->unique(); - $table->string('xml_value',255)->unique()->nullable(); + $table->string('xml_value', 255)->unique()->nullable(); $table->timestamps(); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index b3abf73..f6d7ff9 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -23,9 +23,9 @@ public function run() User::factory()->create(['active' => false, 'admin' => true]); User::factory()->create(['active' => true]); User::factory(96)->create(); -/* Federation::factory(20)->create(); - Entity::factory(100)->create();*/ -/* Category::factory(20)->create(); - Group::factory(20)->create();*/ + /* Federation::factory(20)->create(); + Entity::factory(100)->create();*/ + /* Category::factory(20)->create(); + Group::factory(20)->create();*/ } } diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php index 26bf174..c04a7f0 100644 --- a/tests/Browser/Pages/HomePage.php +++ b/tests/Browser/Pages/HomePage.php @@ -19,7 +19,6 @@ public function url() /** * Assert that the browser is on the page. * - * @param \Laravel\Dusk\Browser $browser * @return void */ public function assert(Browser $browser) diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index 9be8195..eb675c3 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -22,9 +22,9 @@ class EntityControllerTest extends TestCase public function an_anonymouse_user_isnt_shown_an_entities_list() { $this - ->followingRedirects() - ->get(route('federations.index')) - ->assertSeeText('login'); + ->followingRedirects() + ->get(route('federations.index')) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); } @@ -35,9 +35,9 @@ public function an_anonymouse_user_isnt_shown_an_entities_details() $entity = Entity::factory()->create(); $this - ->followingRedirects() - ->get(route('entities.show', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->get(route('entities.show', $entity)) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); } @@ -46,9 +46,9 @@ public function an_anonymouse_user_isnt_shown_an_entities_details() public function an_anonymouse_user_isnt_shown_a_form_to_add_a_new_entity() { $this - ->followingRedirects() - ->get(route('entities.create')) - ->assertSeeText('login'); + ->followingRedirects() + ->get(route('entities.create')) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); } @@ -58,13 +58,13 @@ public function an_anonymouse_user_cannot_add_a_new_entity() { // metadata URL $this - ->followingRedirects() - ->post(route('entities.store'), [ - 'url' => "https://{$this->faker->domainName()}/{$this->faker->unique()->slug(3)}", - 'federation' => Federation::factory()->create()->id, - 'explanation' => $this->faker->catchPhrase(), - ]) - ->assertSeeText('login'); + ->followingRedirects() + ->post(route('entities.store'), [ + 'url' => "https://{$this->faker->domainName()}/{$this->faker->unique()->slug(3)}", + 'federation' => Federation::factory()->create()->id, + 'explanation' => $this->faker->catchPhrase(), + ]) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); @@ -77,9 +77,9 @@ public function an_anonymouse_user_cannot_see_entities_edit_page() $entity = Entity::factory()->create(); $this - ->followingRedirects() - ->get(route('entities.edit', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->get(route('entities.edit', $entity)) + ->assertSeeText('login'); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('login'), url()->current()); @@ -91,9 +91,9 @@ public function an_anonymouse_user_cannot_edit_an_existing_entity() $entity = Entity::factory()->create(); $this - ->followingRedirects() - ->patch(route('entities.update', $entity), ['action' => 'update']) - ->assertSeeText('login'); + ->followingRedirects() + ->patch(route('entities.update', $entity), ['action' => 'update']) + ->assertSeeText('login'); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('login'), url()->current()); @@ -107,9 +107,9 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_state() $this->assertFalse($entity->trashed()); $this - ->followingRedirects() - ->patch(route('entities.update', $entity), ['action' => 'state']) - ->assertSeeText('login'); + ->followingRedirects() + ->patch(route('entities.update', $entity), ['action' => 'state']) + ->assertSeeText('login'); $this->assertFalse($entity->trashed()); $this->assertEquals(route('login'), url()->current()); @@ -125,23 +125,23 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_operators( $user = User::factory()->create(); $this - ->followingRedirects() - ->patch(route('entities.update', $entity), [ - 'action' => 'add_operators', - 'operators' => [$user->id], - ]) - ->assertSeeText('login'); + ->followingRedirects() + ->patch(route('entities.update', $entity), [ + 'action' => 'add_operators', + 'operators' => [$user->id], + ]) + ->assertSeeText('login'); $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('login'), url()->current()); $this - ->followingRedirects() - ->patch(route('entities.update', $entity), [ - 'action' => 'delete_operators', - 'operators' => [User::find(1)->id], - ]) - ->assertSeeText('login'); + ->followingRedirects() + ->patch(route('entities.update', $entity), [ + 'action' => 'delete_operators', + 'operators' => [User::find(1)->id], + ]) + ->assertSeeText('login'); $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('login'), url()->current()); @@ -153,14 +153,14 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_federation $entity = Entity::factory()->create(); $this - ->followingRedirects() - ->post(route('entities.join', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->post(route('entities.join', $entity)) + ->assertSeeText('login'); $this - ->followingRedirects() - ->post(route('entities.leave', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->post(route('entities.leave', $entity)) + ->assertSeeText('login'); } /** @test */ @@ -171,9 +171,9 @@ public function an_anonymouse_user_cannot_purge_an_existing_entity() ]); $this - ->followingRedirects() - ->delete(route('entities.destroy', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->delete(route('entities.destroy', $entity)) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); } @@ -191,9 +191,9 @@ public function an_anonymouse_user_cannot_reject_a_new_entity_request() $membership = Membership::find(1); $this - ->followingRedirects() - ->delete(route('memberships.destroy', $membership)) - ->assertSeeText('login'); + ->followingRedirects() + ->delete(route('memberships.destroy', $membership)) + ->assertSeeText('login'); } /** @test */ @@ -209,9 +209,9 @@ public function an_anonymouse_user_cannot_approve_a_new_entity_request() $membership = Membership::find(1); $this - ->followingRedirects() - ->patch(route('memberships.update', $membership)) - ->assertSeeText('login'); + ->followingRedirects() + ->patch(route('memberships.update', $membership)) + ->assertSeeText('login'); } /** @test */ @@ -223,11 +223,11 @@ public function a_user_is_shown_a_entities_list() $entity = Entity::factory()->create(); $this - ->actingAs($user) - ->get(route('entities.index')) - ->assertSeeText($entity->name) - ->assertSeeText($entity->description) - ->assertSeeText(__('common.active')); + ->actingAs($user) + ->get(route('entities.index')) + ->assertSeeText($entity->name) + ->assertSeeText($entity->description) + ->assertSeeText(__('common.active')); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); @@ -242,12 +242,12 @@ public function a_user_is_shown_a_entities_details() $entity = Entity::factory()->create(); $this - ->actingAs($user) - ->get(route('entities.show', $entity)) - ->assertSeeText($entity->name) - ->assertSeeText($entity->description) - ->assertSeeText($entity->entityid) - ->assertSeeText($entity->type->name); + ->actingAs($user) + ->get(route('entities.show', $entity)) + ->assertSeeText($entity->name) + ->assertSeeText($entity->description) + ->assertSeeText($entity->entityid) + ->assertSeeText($entity->type->name); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', $entity), url()->current()); @@ -259,9 +259,9 @@ public function a_user_is_shown_a_form_to_add_a_new_entity() $user = User::factory()->create(); $this - ->actingAs($user) - ->get(route('entities.create')) - ->assertSeeText(__('entities.add')); + ->actingAs($user) + ->get(route('entities.create')) + ->assertSeeText(__('entities.add')); $this->assertEquals(route('entities.create'), url()->current()); } @@ -273,14 +273,14 @@ public function a_user_cannot_add_metadata_using_invalid_url() $federation = Federation::factory()->create(); $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.store', [ - 'metadata' => 'http://example.com', - 'federation' => $federation->id, - 'explanation' => $this->faker()->catchPhrase(), - ])) - ->assertSeeText(__('entities.no_metadata')); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.store', [ + 'metadata' => 'http://example.com', + 'federation' => $federation->id, + 'explanation' => $this->faker()->catchPhrase(), + ])) + ->assertSeeText(__('entities.no_metadata')); } /** @test */ @@ -428,41 +428,41 @@ public function a_user_can_add_a_new_entity() // add an entity using wrong metadata content // $this - // ->followingRedirects() - // ->actingAs($user) - // ->post(route('entities.store', [ - // 'metadata' => '', - // 'federation' => $federation->id, - // 'explanation' => $this->faker->catchPhrase(), - // ])) - // ->assertSeeText(__('entities.no_metadata')); + // ->followingRedirects() + // ->actingAs($user) + // ->post(route('entities.store', [ + // 'metadata' => '', + // 'federation' => $federation->id, + // 'explanation' => $this->faker->catchPhrase(), + // ])) + // ->assertSeeText(__('entities.no_metadata')); $this->assertEquals(0, Entity::count()); // add an entity using corrent metadata content $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.store', [ - 'metadata' => $whoami, - 'federation' => $federation->id, - 'explanation' => $this->faker->catchPhrase(), - ])) - ->assertSeeText(__('entities.entity_requested', ['name' => 'https://whoami.cesnet.cz/idp/shibboleth'])); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.store', [ + 'metadata' => $whoami, + 'federation' => $federation->id, + 'explanation' => $this->faker->catchPhrase(), + ])) + ->assertSeeText(__('entities.entity_requested', ['name' => 'https://whoami.cesnet.cz/idp/shibboleth'])); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); // add already existing entity $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.store', [ - 'metadata' => $whoami, - 'federation' => $federation->id, - 'explanation' => $this->faker->catchPhrase(), - ])) - ->assertSeeText(__('entities.existing_already')); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.store', [ + 'metadata' => $whoami, + 'federation' => $federation->id, + 'explanation' => $this->faker->catchPhrase(), + ])) + ->assertSeeText(__('entities.existing_already')); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', Entity::find(1)), url()->current()); @@ -476,10 +476,10 @@ public function a_user_with_operator_permission_can_see_entities_edit_page() $user->entities()->attach($entity); $this - ->actingAs($user) - ->get(route('entities.edit', $entity)) - ->assertSeeText(__('entities.edit', ['name' => $entity->name_en])) - ->assertSeeText(__('entities.profile')); + ->actingAs($user) + ->get(route('entities.edit', $entity)) + ->assertSeeText(__('entities.edit', ['name' => $entity->name_en])) + ->assertSeeText(__('entities.profile')); $this->assertEquals(route('entities.edit', $entity), url()->current()); } @@ -631,19 +631,19 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() '; $this - ->followingRedirects() - ->actingAs($user) - ->patch(route('entities.update', $entity), [ - 'action' => 'update', - 'metadata' => $whoami, - ]) - ->assertSeeText(__('entities.entity_updated')); + ->followingRedirects() + ->actingAs($user) + ->patch(route('entities.update', $entity), [ + 'action' => 'update', + 'metadata' => $whoami, + ]) + ->assertSeeText(__('entities.entity_updated')); $this->assertEquals(route('entities.show', $entity), url()->current()); -/* Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { - return $job->entity->is($entity); - });*/ + /* Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { + return $job->entity->is($entity); + });*/ } /** @test */ @@ -659,32 +659,32 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ $this->assertFalse($entity->trashed()); $this - ->followingRedirects() - ->actingAs($user) - ->patch(route('entities.update', $entity), ['action' => 'state']) - ->assertSeeText(__('entities.deleted', ['name' => $entity->name_en])); + ->followingRedirects() + ->actingAs($user) + ->patch(route('entities.update', $entity), ['action' => 'state']) + ->assertSeeText(__('entities.deleted', ['name' => $entity->name_en])); -/* Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { - return $job->entity->is($entity); - });*/ + /* Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { + return $job->entity->is($entity); + });*/ $entity->refresh(); $this->assertTrue($entity->trashed()); $this->assertEquals(route('entities.show', $entity), url()->current()); $this - ->followingRedirects() - ->actingAs($user) - ->patch(route('entities.update', $entity), ['action' => 'state']) - ->assertSeeText(__('entities.restored', ['name' => $entity->name_en])); + ->followingRedirects() + ->actingAs($user) + ->patch(route('entities.update', $entity), ['action' => 'state']) + ->assertSeeText(__('entities.restored', ['name' => $entity->name_en])); $entity->refresh(); $this->assertFalse($entity->trashed()); $this->assertEquals(route('entities.show', $entity), url()->current()); -/* Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { - return $job->entity->is($entity); - });*/ + /* Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { + return $job->entity->is($entity); + });*/ } /** @test */ @@ -698,26 +698,26 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ $this->assertEquals(1, $entity->operators()->count()); $this - ->followingRedirects() - ->actingAs($user) - ->patch(route('entities.update', $entity), [ - 'action' => 'add_operators', - 'operators' => [$new_operator->id], - ]) - ->assertSeeText(__('entities.operators_added')); + ->followingRedirects() + ->actingAs($user) + ->patch(route('entities.update', $entity), [ + 'action' => 'add_operators', + 'operators' => [$new_operator->id], + ]) + ->assertSeeText(__('entities.operators_added')); $entity->refresh(); $this->assertEquals(2, $entity->operators()->count()); $this->assertEquals(route('entities.show', $entity), url()->current()); $this - ->followingRedirects() - ->actingAs($user) - ->patch(route('entities.update', $entity), [ - 'action' => 'delete_operators', - 'operators' => [$new_operator->id], - ]) - ->assertSeeText(__('entities.operators_deleted')); + ->followingRedirects() + ->actingAs($user) + ->patch(route('entities.update', $entity), [ + 'action' => 'delete_operators', + 'operators' => [$new_operator->id], + ]) + ->assertSeeText(__('entities.operators_deleted')); $entity->refresh(); $this->assertEquals(1, $entity->operators()->count()); @@ -736,13 +736,13 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ $this->assertEquals(0, Membership::whereApproved(false)->count()); $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.join', $entity), [ - 'federation' => $federation->id, - 'explanation' => $this->faker->sentence(), - ]) - ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.join', $entity), [ + 'federation' => $federation->id, + 'explanation' => $this->faker->sentence(), + ]) + ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); $this->assertEquals(1, Membership::whereApproved(false)->count()); } @@ -754,9 +754,9 @@ public function a_user_without_operator_permission_cannot_see_entities_edit_page $entity = Entity::factory()->create(); $this - ->actingAs($user) - ->get(route('entities.edit', $entity)) - ->assertForbidden(); + ->actingAs($user) + ->get(route('entities.edit', $entity)) + ->assertForbidden(); } /** @test */ @@ -765,12 +765,12 @@ public function a_user_without_operator_permission_cannot_edit_an_existing_entit $entity = Entity::factory()->create(['entityid' => 'https://whoami.cesnet.cz/idp/shibboleth']); $this - ->followingRedirects() - ->patch(route('entities.update', $entity), [ - 'action' => 'update', - 'url' => 'https://whoami.cesnet.cz/idp/shibboleth', - ]) - ->assertSeeText('login'); + ->followingRedirects() + ->patch(route('entities.update', $entity), [ + 'action' => 'update', + 'url' => 'https://whoami.cesnet.cz/idp/shibboleth', + ]) + ->assertSeeText('login'); } /** @test */ @@ -782,9 +782,9 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent $this->assertEquals(1, Entity::count()); $this - ->actingAs($user) - ->patch(route('entities.update', $entity), ['action' => 'state']) - ->assertForbidden(); + ->actingAs($user) + ->patch(route('entities.update', $entity), ['action' => 'state']) + ->assertForbidden(); } /** @test */ @@ -795,23 +795,23 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent $new_operator = User::factory()->create(); $this - ->actingAs($user) - ->patch(route('entities.update', $entity), [ - 'action' => 'add_operators', - 'operators' => [$new_operator->id], - ]) - ->assertForbidden(); + ->actingAs($user) + ->patch(route('entities.update', $entity), [ + 'action' => 'add_operators', + 'operators' => [$new_operator->id], + ]) + ->assertForbidden(); $entity->refresh(); $this->assertEquals(0, $entity->operators()->count()); $this - ->actingAs($user) - ->patch(route('entities.update', $entity), [ - 'action' => 'delete_operators', - 'operators' => [$new_operator->id], - ]) - ->assertForbidden(); + ->actingAs($user) + ->patch(route('entities.update', $entity), [ + 'action' => 'delete_operators', + 'operators' => [$new_operator->id], + ]) + ->assertForbidden(); } /** @test */ @@ -825,13 +825,13 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent $this->assertEquals(0, Membership::whereApproved(false)->count()); $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.join', $entity), [ - 'federation' => $federation->id, - 'explanation' => $this->faker->sentence(), - ]) - ->assertForbidden(); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.join', $entity), [ + 'federation' => $federation->id, + 'explanation' => $this->faker->sentence(), + ]) + ->assertForbidden(); $this->assertEquals(0, Membership::whereApproved(false)->count()); } @@ -845,10 +845,10 @@ public function a_user_cannot_purge_an_existing_entity() ]); $this - ->followingRedirects() - ->actingAs($user) - ->delete(route('entities.destroy', $entity)) - ->assertForbidden(); + ->followingRedirects() + ->actingAs($user) + ->delete(route('entities.destroy', $entity)) + ->assertForbidden(); } /** @test */ @@ -865,10 +865,10 @@ public function a_user_cannot_reject_a_new_entity_request() $membership = Membership::find(1); $this - ->followingRedirects() - ->actingAs($user) - ->delete(route('memberships.destroy', $membership)) - ->assertForbidden(); + ->followingRedirects() + ->actingAs($user) + ->delete(route('memberships.destroy', $membership)) + ->assertForbidden(); } /** @test */ @@ -886,10 +886,10 @@ public function a_user_cannot_approve_a_new_entity_request() $membership = Membership::find(1); $this - ->followingRedirects() - ->actingAs($user) - ->patch(route('memberships.update', $membership)) - ->assertForbidden(); + ->followingRedirects() + ->actingAs($user) + ->patch(route('memberships.update', $membership)) + ->assertForbidden(); } /** @test */ @@ -899,11 +899,11 @@ public function an_admin_is_shown_a_entities_list() $entity = Entity::factory()->create(); $this - ->actingAs($admin) - ->get(route('entities.index')) - ->assertSeeText($entity->name) - ->assertSeeText($entity->description) - ->assertSeeText(__('common.active')); + ->actingAs($admin) + ->get(route('entities.index')) + ->assertSeeText($entity->name) + ->assertSeeText($entity->description) + ->assertSeeText(__('common.active')); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); @@ -916,12 +916,12 @@ public function an_admin_is_shown_a_entities_details() $entity = Entity::factory()->create(); $this - ->actingAs($admin) - ->get(route('entities.show', $entity)) - ->assertSeeText($entity->name) - ->assertSeeText($entity->description) - ->assertSeeText($entity->entityid) - ->assertSeeText($entity->type->name); + ->actingAs($admin) + ->get(route('entities.show', $entity)) + ->assertSeeText($entity->name) + ->assertSeeText($entity->description) + ->assertSeeText($entity->entityid) + ->assertSeeText($entity->type->name); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', $entity), url()->current()); @@ -933,9 +933,9 @@ public function an_admin_is_shown_a_form_to_add_a_new_entity() $admin = User::factory()->create(['admin' => true]); $this - ->actingAs($admin) - ->get(route('entities.create')) - ->assertSeeText(__('entities.add')); + ->actingAs($admin) + ->get(route('entities.create')) + ->assertSeeText(__('entities.add')); $this->assertEquals(route('entities.create'), url()->current()); } @@ -1086,28 +1086,28 @@ public function an_admin_can_add_a_new_entity() // add an entity using wrong metadata content // add an entity using correct metadata content $this - ->followingRedirects() - ->actingAs($admin) - ->post(route('entities.store', [ - 'metadata' => $whoami, - 'federation' => $federation->id, - 'explanation' => $this->faker->catchPhrase(), - ])) - ->assertSeeText(__('entities.entity_requested', ['name' => 'https://whoami.cesnet.cz/idp/shibboleth'])); + ->followingRedirects() + ->actingAs($admin) + ->post(route('entities.store', [ + 'metadata' => $whoami, + 'federation' => $federation->id, + 'explanation' => $this->faker->catchPhrase(), + ])) + ->assertSeeText(__('entities.entity_requested', ['name' => 'https://whoami.cesnet.cz/idp/shibboleth'])); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); // add already existing entity $this - ->followingRedirects() - ->actingAs($admin) - ->post(route('entities.store', [ - 'metadata' => $whoami, - 'federation' => $federation->id, - 'explanation' => $this->faker->catchPhrase(), - ])) - ->assertSeeText(__('entities.existing_already')); + ->followingRedirects() + ->actingAs($admin) + ->post(route('entities.store', [ + 'metadata' => $whoami, + 'federation' => $federation->id, + 'explanation' => $this->faker->catchPhrase(), + ])) + ->assertSeeText(__('entities.existing_already')); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', Entity::find(1)), url()->current()); @@ -1120,10 +1120,10 @@ public function an_admin_can_see_entities_edit_page() $entity = Entity::factory()->create(); $this - ->actingAs($admin) - ->get(route('entities.edit', $entity)) - ->assertSeeText(__('entities.edit', ['name' => $entity->name_en])) - ->assertSeeText(__('entities.profile')); + ->actingAs($admin) + ->get(route('entities.edit', $entity)) + ->assertSeeText(__('entities.edit', ['name' => $entity->name_en])) + ->assertSeeText(__('entities.profile')); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.edit', $entity), url()->current()); @@ -1275,18 +1275,18 @@ public function an_admin_can_edit_an_existing_entity() '; $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), [ - 'action' => 'update', - 'metadata' => $whoami, - ]) - ->assertSeeText(__('entities.entity_updated')); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), [ + 'action' => 'update', + 'metadata' => $whoami, + ]) + ->assertSeeText(__('entities.entity_updated')); $this->assertEquals(route('entities.show', $entity), url()->current()); -/* Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { - return $job->entity->is($entity); - });*/ + /* Bus::assertDispatched(GitUpdateEntity::class, function ($job) use ($entity) { + return $job->entity->is($entity); + });*/ } /** @test */ @@ -1301,32 +1301,32 @@ public function an_admin_can_change_an_existing_entities_state() $this->assertFalse($entity->trashed()); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), ['action' => 'state']) - ->assertSeeText(__('entities.deleted', ['name' => $entity->name_en])); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), ['action' => 'state']) + ->assertSeeText(__('entities.deleted', ['name' => $entity->name_en])); -/* Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { - return $job->entity->is($entity); - });*/ + /* Bus::assertDispatched(GitDeleteEntity::class, function ($job) use ($entity) { + return $job->entity->is($entity); + });*/ $entity->refresh(); $this->assertTrue($entity->trashed()); $this->assertEquals(route('entities.show', $entity), url()->current()); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), ['action' => 'state']) - ->assertSeeText(__('entities.restored', ['name' => $entity->name_en])); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), ['action' => 'state']) + ->assertSeeText(__('entities.restored', ['name' => $entity->name_en])); $entity->refresh(); $this->assertFalse($entity->trashed()); $this->assertEquals(route('entities.show', $entity), url()->current()); -/* Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { - return $job->entity->is($entity); - });*/ + /* Bus::assertDispatched(GitAddEntity::class, function ($job) use ($entity) { + return $job->entity->is($entity); + });*/ } /** @test */ @@ -1341,46 +1341,46 @@ public function an_admin_can_change_an_existing_entities_operators() $this->assertEquals(0, $entity->operators()->count()); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), ['action' => 'add_operators']) - ->assertSeeText(__('entities.add_empty_operators')); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), ['action' => 'add_operators']) + ->assertSeeText(__('entities.add_empty_operators')); $entity->refresh(); $this->assertEquals(0, $entity->operators()->count()); $this->assertEquals(route('entities.operators', $entity), url()->current()); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), [ - 'action' => 'add_operators', - 'operators' => [$new_operator->id], - ]) - ->assertSeeText(__('entities.operators_added')); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), [ + 'action' => 'add_operators', + 'operators' => [$new_operator->id], + ]) + ->assertSeeText(__('entities.operators_added')); $entity->refresh(); $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('entities.show', $entity), url()->current()); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), ['action' => 'delete_operators']) - ->assertSeeText(__('entities.delete_empty_operators')); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), ['action' => 'delete_operators']) + ->assertSeeText(__('entities.delete_empty_operators')); $entity->refresh(); $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('entities.operators', $entity), url()->current()); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('entities.update', $entity), [ - 'action' => 'delete_operators', - 'operators' => [$new_operator->id], - ]) - ->assertSeeText(__('entities.operators_deleted')); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('entities.update', $entity), [ + 'action' => 'delete_operators', + 'operators' => [$new_operator->id], + ]) + ->assertSeeText(__('entities.operators_deleted')); $entity->refresh(); $this->assertEquals(0, $entity->operators()->count()); @@ -1399,13 +1399,13 @@ public function an_admin_can_change_an_existing_entities_federation_membership() $this->assertEquals(0, Membership::whereApproved(false)->count()); $this - ->followingRedirects() - ->actingAs($admin) - ->post(route('entities.join', $entity), [ - 'federation' => $federation->id, - 'explanation' => $this->faker->sentence(), - ]) - ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); + ->followingRedirects() + ->actingAs($admin) + ->post(route('entities.join', $entity), [ + 'federation' => $federation->id, + 'explanation' => $this->faker->sentence(), + ]) + ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); $this->assertEquals(1, Membership::whereApproved(false)->count()); } @@ -1420,10 +1420,10 @@ public function an_admin_can_purge_an_existing_entity() $name = $entity->name_en; $this - ->followingRedirects() - ->actingAs($admin) - ->delete(route('entities.destroy', $entity)) - ->assertSeeText(__('entities.destroyed', ['name' => $name])); + ->followingRedirects() + ->actingAs($admin) + ->delete(route('entities.destroy', $entity)) + ->assertSeeText(__('entities.destroyed', ['name' => $name])); } /** @test */ @@ -1439,10 +1439,10 @@ public function an_admin_can_reject_a_new_entity_request() $membership = Membership::find(1); $this - ->followingRedirects() - ->actingAs($admin) - ->delete(route('memberships.destroy', $membership)) - ->assertSeeText(__('federations.membership_rejected', ['entity' => $entity->name_en])); + ->followingRedirects() + ->actingAs($admin) + ->delete(route('memberships.destroy', $membership)) + ->assertSeeText(__('federations.membership_rejected', ['entity' => $entity->name_en])); } /** @test */ @@ -1460,10 +1460,10 @@ public function an_admin_can_approve_a_new_entity_request() $membership = Membership::find(1); $this - ->followingRedirects() - ->actingAs($admin) - ->patch(route('memberships.update', $membership)) - ->assertSeeText(__('federations.membership_accepted', ['entity' => $entity->entityid])); + ->followingRedirects() + ->actingAs($admin) + ->patch(route('memberships.update', $membership)) + ->assertSeeText(__('federations.membership_accepted', ['entity' => $entity->entityid])); } /** @test */ @@ -1473,9 +1473,9 @@ public function not_even_an_admin_can_run_update_function_without_definig_action $entity = Entity::factory()->create(); $this - ->followingRedirects() - ->actingAs($admin) - ->put(route('entities.update', $entity)); + ->followingRedirects() + ->actingAs($admin) + ->put(route('entities.update', $entity)); $this->assertEquals(route('home'), url()->current()); } @@ -1488,16 +1488,16 @@ public function ask_rs_isnt_shown_for_sp_entities_not_in_rs_federation() $user->entities()->attach($entity); $this - ->actingAs($user) - ->get(route('entities.show', $entity)) - ->assertDontSeeText(__('entities.ask_rs')); + ->actingAs($user) + ->get(route('entities.show', $entity)) + ->assertDontSeeText(__('entities.ask_rs')); $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.rs', $entity)) - ->assertStatus(403) - ->assertSeeText(__('entities.rs_only_for_eduidcz_members')); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.rs', $entity)) + ->assertStatus(403) + ->assertSeeText(__('entities.rs_only_for_eduidcz_members')); } /** @test */ @@ -1515,15 +1515,15 @@ public function ask_rs_is_shown_for_sp_entities_in_rs_federation() ]); $this - ->actingAs($user) - ->get(route('entities.show', $entity)) - ->assertSeeText(__('entities.ask_rs')); + ->actingAs($user) + ->get(route('entities.show', $entity)) + ->assertSeeText(__('entities.ask_rs')); $this - ->followingRedirects() - ->actingAs($user) - ->post(route('entities.rs', $entity)) - ->assertStatus(200) - ->assertSeeText(__('entities.rs_asked')); + ->followingRedirects() + ->actingAs($user) + ->post(route('entities.rs', $entity)) + ->assertStatus(200) + ->assertSeeText(__('entities.rs_asked')); } } diff --git a/tests/Feature/Http/Controllers/FederationControllerTest.php b/tests/Feature/Http/Controllers/FederationControllerTest.php index bec4c36..168eabd 100644 --- a/tests/Feature/Http/Controllers/FederationControllerTest.php +++ b/tests/Feature/Http/Controllers/FederationControllerTest.php @@ -2,11 +2,10 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\Old_GitAddFederation; use App\Jobs\GitAddMembers; -use App\Jobs\Old_GitDeleteFederation; use App\Jobs\GitDeleteMembers; use App\Jobs\GitUpdateFederation; +use App\Jobs\Old_GitAddFederation; use App\Models\Entity; use App\Models\Federation; use App\Models\User; @@ -392,9 +391,9 @@ public function a_user_with_operator_permission_can_edit_an_existing_federation( $federation->refresh(); $this->assertEquals($federationName, $federation->name); -/* Bus::assertDispatched(GitUpdateFederation::class, function ($job) use ($federation) { - return $job->federation->is($federation); - });*/ + /* Bus::assertDispatched(GitUpdateFederation::class, function ($job) use ($federation) { + return $job->federation->is($federation); + });*/ } /** @test */ @@ -421,9 +420,9 @@ public function a_user_with_operator_permission_can_change_an_existing_federatio $this->assertTrue($federation->trashed()); $this->assertEquals(route('federations.show', $federation), url()->current()); -/* Bus::assertDispatched(GitDeleteFederation::class, function ($job) use ($federation) { - return $job->federation->is($federation); - });*/ + /* Bus::assertDispatched(GitDeleteFederation::class, function ($job) use ($federation) { + return $job->federation->is($federation); + });*/ $this ->followingRedirects() @@ -439,9 +438,9 @@ public function a_user_with_operator_permission_can_change_an_existing_federatio // TODO ask about this because no job no test -/* Bus::assertDispatched(Old_GitAddFederation::class, function ($job) use ($federation) { - return $job->federation->is($federation); - });*/ + /* Bus::assertDispatched(Old_GitAddFederation::class, function ($job) use ($federation) { + return $job->federation->is($federation); + });*/ } /** @test */ @@ -606,7 +605,7 @@ public function a_user_without_operator_permission_cannot_edit_an_existing_feder $this->assertEquals(route('federations.show', $federation), url()->current()); -// Bus::assertNotDispatched(GitUpdateFederation::class); + // Bus::assertNotDispatched(GitUpdateFederation::class); } /** @test */ @@ -960,9 +959,9 @@ public function an_admin_can_change_an_existing_federations_state() $this->assertTrue($federation->trashed()); $this->assertEquals(route('federations.show', $federation), url()->current()); -/* Bus::assertDispatched(GitDeleteFederation::class, function ($job) use ($federation) { - return $job->federation->is($federation); - });*/ + /* Bus::assertDispatched(GitDeleteFederation::class, function ($job) use ($federation) { + return $job->federation->is($federation); + });*/ $this ->followingRedirects() @@ -976,9 +975,9 @@ public function an_admin_can_change_an_existing_federations_state() $this->assertFalse($federation->trashed()); $this->assertEquals(route('federations.show', $federation), url()->current()); -/* Bus::assertDispatched(Old_GitAddFederation::class, function ($job) use ($federation) { - return $job->federation->is($federation); - });*/ + /* Bus::assertDispatched(Old_GitAddFederation::class, function ($job) use ($federation) { + return $job->federation->is($federation); + });*/ } /** @test */ @@ -1210,9 +1209,9 @@ public function an_admin_can_approve_a_new_federation_request() $this->assertEquals(route('federations.show', $federation), url()->current()); -/* Bus::assertDispatched(Old_GitAddFederation::class, function ($job) use ($federation) { - return $job->federation->is($federation); - });*/ + /* Bus::assertDispatched(Old_GitAddFederation::class, function ($job) use ($federation) { + return $job->federation->is($federation); + });*/ } /** @test */ From 3043cb7bb195a4aaf18e83a18b3070fa2c85a311 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 3 Jul 2024 14:24:32 +0200 Subject: [PATCH 06/53] make save job --- app/Jobs/FolderAddEntity.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index f44fa8d..73e14a4 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -2,7 +2,9 @@ namespace App\Jobs; +use App\Facades\EntityFacade; use App\Models\Entity; +use App\Models\Membership; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -29,7 +31,15 @@ public function __construct(Entity $entity) */ public function handle(): void { - dump("hello word"); + // TODO add aproveChecker to this query + $federationMembershipId = Membership::select('federation_id') + ->where('entity_id',$this->entity->id) + ->get(); + + foreach ($federationMembershipId as $fedId ) + { + EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + } } /** From 61553cad5faddf8a1b13a88b619a898de245ce6c Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 3 Jul 2024 15:07:22 +0200 Subject: [PATCH 07/53] make update (no tested) --- app/Events/UpdateEntity.php | 23 +++++++++++++++ app/Jobs/FolderAddEntity.php | 5 ++-- app/Listeners/SendUpdatedEntityToSaveJob.php | 31 ++++++++++++++++++++ app/Models/Entity.php | 3 ++ app/Providers/EventServiceProvider.php | 5 ++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 app/Events/UpdateEntity.php create mode 100644 app/Listeners/SendUpdatedEntityToSaveJob.php diff --git a/app/Events/UpdateEntity.php b/app/Events/UpdateEntity.php new file mode 100644 index 0000000..7d1f123 --- /dev/null +++ b/app/Events/UpdateEntity.php @@ -0,0 +1,23 @@ +entity = $entity; + } +} diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 73e14a4..9e610a3 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -33,11 +33,10 @@ public function handle(): void { // TODO add aproveChecker to this query $federationMembershipId = Membership::select('federation_id') - ->where('entity_id',$this->entity->id) + ->where('entity_id', $this->entity->id) ->get(); - foreach ($federationMembershipId as $fedId ) - { + foreach ($federationMembershipId as $fedId) { EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php new file mode 100644 index 0000000..b3ad6f5 --- /dev/null +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -0,0 +1,31 @@ + $event->entity->id]); + $ent = $event->entity; + + if ($ent->wasChanged('xml_file')) { + FolderAddEntity::dispatch($event->entity); + } + } +} diff --git a/app/Models/Entity.php b/app/Models/Entity.php index 9a7e0d1..0ed5a2e 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -4,6 +4,7 @@ use App\Enums\EntityType; use App\Events\CreateEntity; +use App\Events\UpdateEntity; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -94,5 +95,7 @@ public function scopeSearch($query, ?string $search = null) protected $dispatchesEvents = [ 'created' => CreateEntity::class, + 'updated' => UpdateEntity::class, + ]; } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3cc685e..08fd1aa 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -4,8 +4,10 @@ use App\Events\CreateEntity; use App\Events\FederationApprove; +use App\Events\UpdateEntity; use App\Listeners\CreateFederationFolder; use App\Listeners\SendCreatedEntityToSaveJob; +use App\Listeners\SendUpdatedEntityToSaveJob; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -28,6 +30,9 @@ class EventServiceProvider extends ServiceProvider CreateEntity::class => [ SendCreatedEntityToSaveJob::class, ], + UpdateEntity::class => [ + SendUpdatedEntityToSaveJob::class, + ], ]; From fa6a79e661e4e59c314dc2ee9307c8145467d6e5 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 8 Jul 2024 13:15:33 +0200 Subject: [PATCH 08/53] rewrite metadata storage name to config file --- app/Listeners/CreateFederationFolder.php | 3 ++- app/Services/EntityService.php | 9 ++++++--- app/Traits/FederationTrait.php | 8 ++++++-- config/storageCfg.php | 4 ++++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 config/storageCfg.php diff --git a/app/Listeners/CreateFederationFolder.php b/app/Listeners/CreateFederationFolder.php index 571b0c7..dd69582 100644 --- a/app/Listeners/CreateFederationFolder.php +++ b/app/Listeners/CreateFederationFolder.php @@ -23,10 +23,11 @@ public function __construct() */ public function handle(FederationApprove $event): void { + $diskName = config('storageCfg.name'); $federation = $event->federation; if ($federation->approved) { - if (! Storage::disk('metadata')->exists($federation->name)) { + if (! Storage::disk($diskName)->exists($federation->name)) { $this->createFederationFolder($federation->name); } } diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index 87db935..18975e9 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -31,17 +31,20 @@ public function saveMetadataToFederationFolder($entity_id, $federation_id): void */ public function saveEntityMetadataToFolder($entity_id, $folderName): void { + $diskName = config('storageCfg.name'); + + $entity = Entity::find($entity_id); if (! $entity) { throw new Exception("Entity not found with id $entity_id"); } $fileName = $entity->file; - if (! Storage::disk('metadata')->exists($folderName)) { - Storage::disk('metadata')->makeDirectory($folderName); + if (! Storage::disk($diskName)->exists($folderName)) { + Storage::disk($diskName)->makeDirectory($folderName); } $filePath = $folderName.'/'.$fileName; $content = $entity->xml_file; - Storage::disk('metadata')->put($filePath, $content); + Storage::disk($diskName)->put($filePath, $content); } } diff --git a/app/Traits/FederationTrait.php b/app/Traits/FederationTrait.php index 34c2d2b..12b6f9f 100644 --- a/app/Traits/FederationTrait.php +++ b/app/Traits/FederationTrait.php @@ -7,9 +7,13 @@ trait FederationTrait { + + + public function createFederationFolder(string $name): void { - Storage::disk('metadata')->makeDirectory($name); + + Storage::disk(config('storageCfg.name'))->makeDirectory($name); } public function updateFederationFolders(): void @@ -17,7 +21,7 @@ public function updateFederationFolders(): void $federations = Federation::select('name')->get(); foreach ($federations as $fed) { - if (! Storage::disk('metadata')->exists($fed['name'])) { + if (! Storage::disk(config('storageCfg.name'))->exists($fed['name'])) { $this->createFederationFolder($fed['name']); } } diff --git a/config/storageCfg.php b/config/storageCfg.php new file mode 100644 index 0000000..3e2ed80 --- /dev/null +++ b/config/storageCfg.php @@ -0,0 +1,4 @@ + 'metadata', +]; From 753bfed0523afe0da26051217c1c0dbe36eb187f Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 8 Jul 2024 13:32:55 +0200 Subject: [PATCH 09/53] change saving attribute from name to xml_id --- app/Traits/FederationTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Traits/FederationTrait.php b/app/Traits/FederationTrait.php index 12b6f9f..a834978 100644 --- a/app/Traits/FederationTrait.php +++ b/app/Traits/FederationTrait.php @@ -21,8 +21,8 @@ public function updateFederationFolders(): void $federations = Federation::select('name')->get(); foreach ($federations as $fed) { - if (! Storage::disk(config('storageCfg.name'))->exists($fed['name'])) { - $this->createFederationFolder($fed['name']); + if (! Storage::disk(config('storageCfg.name'))->exists($fed['xml_id'])) { + $this->createFederationFolder($fed['xml_id']); } } } From aaaf675ee153380e94b3d27beb8f2d71f74969b1 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 8 Jul 2024 14:07:00 +0200 Subject: [PATCH 10/53] make Cache lock on job --- app/Jobs/FolderAddEntity.php | 30 +++++++++++++++++++- app/Listeners/SendCreatedEntityToSaveJob.php | 2 +- app/Listeners/SendUpdatedEntityToSaveJob.php | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 9e610a3..f6467cf 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -4,6 +4,7 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Models\Federation; use App\Models\Membership; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -11,6 +12,10 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Storage; +use Mockery\Exception; class FolderAddEntity implements ShouldQueue { @@ -36,8 +41,31 @@ public function handle(): void ->where('entity_id', $this->entity->id) ->get(); + $diskName = config('storageCfg.name'); + foreach ($federationMembershipId as $fedId) { - EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + + $federationFolderName = Federation::select('name') + ->where('id', $fedId->federation_id) + ->first(); + + + if (!Storage::disk($diskName)->exists($federationFolderName->name)) { + continue; + } + $pathToDirectory = Storage::disk($diskName)->path($federationFolderName->name); + $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; + $lock = Cache::lock($lockKey,120); + + try { + EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + } catch (Exception $e) + { + Log::error($e->getMessage()); + } finally { + $lock->release(); + } + } } diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index be8d99e..3fba8a6 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -21,7 +21,7 @@ public function __construct() */ public function handle(CreateEntity $event): void { - Log::info('Listener triggered for CreateEntity event', ['entity_id' => $event->entity->id]); + //Log::info('Listener triggered for CreateEntity event', ['entity_id' => $event->entity->id]); FolderAddEntity::dispatch($event->entity); } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index b3ad6f5..98e06f1 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -21,7 +21,7 @@ public function __construct() */ public function handle(UpdateEntity $event): void { - Log::info('Listener triggered for UpdateEntity event', ['entity_id' => $event->entity->id]); + // Log::info('Listener triggered for UpdateEntity event', ['entity_id' => $event->entity->id]); $ent = $event->entity; if ($ent->wasChanged('xml_file')) { From 78a2bd61821d794111426e59b8bbd92a1b1c6789 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 9 Jul 2024 12:38:55 +0200 Subject: [PATCH 11/53] make run script function --- app/Console/Commands/ValidateMetaConsole.php | 31 +++++++++++++++++- app/Jobs/FolderAddEntity.php | 34 +++++++++++++++++--- config/storageCfg.php | 3 ++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/ValidateMetaConsole.php b/app/Console/Commands/ValidateMetaConsole.php index 22bf500..d932106 100644 --- a/app/Console/Commands/ValidateMetaConsole.php +++ b/app/Console/Commands/ValidateMetaConsole.php @@ -2,9 +2,12 @@ namespace App\Console\Commands; +use App\Jobs\FolderAddEntity; use App\Models\Entity; +use App\Models\Federation; use App\Traits\DumpFromGit\EntitiesHelp\FixEntityTrait; use App\Traits\ValidatorTrait; +use Exception; use Illuminate\Console\Command; class ValidateMetaConsole extends Command @@ -71,11 +74,37 @@ private function meta() } } + private function runMDA(Federation $federation) + { + $filterArray = explode(", ", $federation->filters); + + $scriptPath = config('storageCfg.mdaScript'); + $command = "sh " . config('storageCfg.mdaScript'); + + $realScriptPath = realpath($scriptPath); + + if ($realScriptPath === false) { + throw new Exception("file not exist" . $scriptPath); + } + + foreach ($filterArray as $filter) { + $file = escapeshellarg($filter) . '.xml'; + $pipeline = 'main'; + $command = 'sh ' . escapeshellarg($realScriptPath) . ' ' . $file . ' ' . $pipeline ; + + $res = shell_exec($command); + dump($res); + } + } + public function handle() { + $federation = Federation::where('id',1)->first(); + $this->runMDA($federation); + // $this->fixEntities(); - $this->doc(); + // $this->doc(); } } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index f6467cf..d406d0b 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -31,6 +31,30 @@ public function __construct(Entity $entity) $this->entity = $entity; } + private function runMDA(Federation $federation) + { + $filterArray = explode(", ", $federation->filters); + + $scriptPath = config('storageCfg.mdaScript'); + $command = "sh " . config('storageCfg.mdaScript'); + + $realScriptPath = realpath($scriptPath); + + if ($realScriptPath === false) { + throw new Exception("file not exist" . $scriptPath); + } + + foreach ($filterArray as $filter) { + $file = escapeshellarg($filter) . '.xml'; + $pipeline = 'main'; + $command = 'sh ' . escapeshellarg($realScriptPath) . ' ' . $file . ' ' . $pipeline ; + + $res = shell_exec($command); + dump($res); + } + } + + /** * Execute the job. */ @@ -45,20 +69,20 @@ public function handle(): void foreach ($federationMembershipId as $fedId) { - $federationFolderName = Federation::select('name') - ->where('id', $fedId->federation_id) - ->first(); + + $federation = Federation::where('id', $fedId->federation_id)->first(); - if (!Storage::disk($diskName)->exists($federationFolderName->name)) { + if (!Storage::disk($diskName)->exists($federation->name)) { continue; } - $pathToDirectory = Storage::disk($diskName)->path($federationFolderName->name); + $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; $lock = Cache::lock($lockKey,120); try { EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + $this->runMDA($federation); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/config/storageCfg.php b/config/storageCfg.php index 3e2ed80..5188380 100644 --- a/config/storageCfg.php +++ b/config/storageCfg.php @@ -1,4 +1,7 @@ 'metadata', + 'mdaConfigFolder'=>'/home/artem/Desktop/cesnet/metadata/testdata/mda/config', + 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/hello.sh' + /* 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/mda.sh',*/ ]; From 25e453782d2dbc9a29ca1973e098f6c6504a854b Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 9 Jul 2024 14:29:54 +0200 Subject: [PATCH 12/53] rewrite to Locks Across Processes --- app/Console/Commands/ValidateMetaConsole.php | 18 +++--- app/Jobs/FolderAddEntity.php | 49 +++++--------- app/Jobs/RunMdaScript.php | 68 ++++++++++++++++++++ app/Listeners/SendUpdatedEntityToSaveJob.php | 2 +- app/Services/EntityService.php | 1 - app/Traits/FederationTrait.php | 3 - config/storageCfg.php | 7 +- 7 files changed, 97 insertions(+), 51 deletions(-) create mode 100644 app/Jobs/RunMdaScript.php diff --git a/app/Console/Commands/ValidateMetaConsole.php b/app/Console/Commands/ValidateMetaConsole.php index d932106..f60d0ef 100644 --- a/app/Console/Commands/ValidateMetaConsole.php +++ b/app/Console/Commands/ValidateMetaConsole.php @@ -2,7 +2,6 @@ namespace App\Console\Commands; -use App\Jobs\FolderAddEntity; use App\Models\Entity; use App\Models\Federation; use App\Traits\DumpFromGit\EntitiesHelp\FixEntityTrait; @@ -76,35 +75,34 @@ private function meta() private function runMDA(Federation $federation) { - $filterArray = explode(", ", $federation->filters); + $filterArray = explode(', ', $federation->filters); $scriptPath = config('storageCfg.mdaScript'); - $command = "sh " . config('storageCfg.mdaScript'); + $command = 'sh '.config('storageCfg.mdaScript'); $realScriptPath = realpath($scriptPath); if ($realScriptPath === false) { - throw new Exception("file not exist" . $scriptPath); + throw new Exception('file not exist'.$scriptPath); } foreach ($filterArray as $filter) { - $file = escapeshellarg($filter) . '.xml'; + $file = escapeshellarg($filter).'.xml'; $pipeline = 'main'; - $command = 'sh ' . escapeshellarg($realScriptPath) . ' ' . $file . ' ' . $pipeline ; + $command = 'sh '.escapeshellarg($realScriptPath).' '.$file.' '.$pipeline; - $res = shell_exec($command); + $res = shell_exec($command); dump($res); } } public function handle() { - $federation = Federation::where('id',1)->first(); + $federation = Federation::where('id', 1)->first(); $this->runMDA($federation); - // $this->fixEntities(); - // $this->doc(); + // $this->doc(); } } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index d406d0b..064c6b6 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -33,28 +33,9 @@ public function __construct(Entity $entity) private function runMDA(Federation $federation) { - $filterArray = explode(", ", $federation->filters); - $scriptPath = config('storageCfg.mdaScript'); - $command = "sh " . config('storageCfg.mdaScript'); - - $realScriptPath = realpath($scriptPath); - - if ($realScriptPath === false) { - throw new Exception("file not exist" . $scriptPath); - } - - foreach ($filterArray as $filter) { - $file = escapeshellarg($filter) . '.xml'; - $pipeline = 'main'; - $command = 'sh ' . escapeshellarg($realScriptPath) . ' ' . $file . ' ' . $pipeline ; - - $res = shell_exec($command); - dump($res); - } } - /** * Execute the job. */ @@ -69,25 +50,27 @@ public function handle(): void foreach ($federationMembershipId as $fedId) { - $federation = Federation::where('id', $fedId->federation_id)->first(); - - if (!Storage::disk($diskName)->exists($federation->name)) { + if (! Storage::disk($diskName)->exists($federation->name)) { continue; } $pathToDirectory = Storage::disk($diskName)->path($federation->name); - $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; - $lock = Cache::lock($lockKey,120); - - try { - EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); - $this->runMDA($federation); - } catch (Exception $e) - { - Log::error($e->getMessage()); - } finally { - $lock->release(); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 120); + + if ($lock->get()) { + + try { + EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + RunMdaScript::dispatch($federation, $lock->owner()); + $this->runMDA($federation); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + $lock->release(); + } + } } diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php new file mode 100644 index 0000000..b71a677 --- /dev/null +++ b/app/Jobs/RunMdaScript.php @@ -0,0 +1,68 @@ +federation = $federation; + $this->owner = $owner; + } + + /** + * Execute the job. + */ + public function handle(): void + { + + $diskName = config('storageCfg.name'); + $pathToDirectory = Storage::disk($diskName)->path($this->federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + + $filterArray = explode(', ', $this->federation->filters); + $scriptPath = config('storageCfg.mdaScript'); + $command = 'sh '.config('storageCfg.mdaScript'); + + $realScriptPath = realpath($scriptPath); + + try { + + foreach ($filterArray as $filter) { + $file = escapeshellarg($filter).'.xml'; + $pipeline = 'main'; + $command = 'sh '.escapeshellarg($realScriptPath).' '.$file.' '.$pipeline; + + $res = shell_exec($command); + dump($res); + } + + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + Cache::restoreLock($lockKey, $this->owner)->release(); + + } + + } +} diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 98e06f1..26624b1 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -21,7 +21,7 @@ public function __construct() */ public function handle(UpdateEntity $event): void { - // Log::info('Listener triggered for UpdateEntity event', ['entity_id' => $event->entity->id]); + // Log::info('Listener triggered for UpdateEntity event', ['entity_id' => $event->entity->id]); $ent = $event->entity; if ($ent->wasChanged('xml_file')) { diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index 18975e9..1d0876d 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -33,7 +33,6 @@ public function saveEntityMetadataToFolder($entity_id, $folderName): void { $diskName = config('storageCfg.name'); - $entity = Entity::find($entity_id); if (! $entity) { throw new Exception("Entity not found with id $entity_id"); diff --git a/app/Traits/FederationTrait.php b/app/Traits/FederationTrait.php index a834978..be760cc 100644 --- a/app/Traits/FederationTrait.php +++ b/app/Traits/FederationTrait.php @@ -7,9 +7,6 @@ trait FederationTrait { - - - public function createFederationFolder(string $name): void { diff --git a/config/storageCfg.php b/config/storageCfg.php index 5188380..518618f 100644 --- a/config/storageCfg.php +++ b/config/storageCfg.php @@ -1,7 +1,8 @@ 'metadata', - 'mdaConfigFolder'=>'/home/artem/Desktop/cesnet/metadata/testdata/mda/config', - 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/hello.sh' - /* 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/mda.sh',*/ + 'mdaConfigFolder' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/config', + 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/hello.sh', + /* 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/mda.sh',*/ ]; From 7e409d8b5b7045c6f63f5963479bd95fe8a4ebe3 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 9 Jul 2024 15:04:04 +0200 Subject: [PATCH 13/53] mke mda paths with env --- .env.example | 5 ++++- config/storageCfg.php | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 1070d8f..f22e66f 100644 --- a/.env.example +++ b/.env.example @@ -62,6 +62,9 @@ VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" +MDA_CONFIG_FOLDER=/opt/mda-distribution-0.10.0/config +MDA_SCRIPT=/opt/mda-distribution-0.10.0/mda.sh + GIT_REMOTE=user@git.example.org:repository GIT_REMOTE_BRANCH=main GIT_LOCAL=/home/user/metaman/storage/git @@ -86,4 +89,4 @@ LDAP_PORT=636 LDAP_BASE_DN="ou=Organizations,dc=example,dc=org" LDAP_BASE_DN_EDUIDCZORGANIZATIONS="ou=Organizations,o=saml,dc=example,dc=org" LDAP_SSL=true -LDAP_TLS=false \ No newline at end of file +LDAP_TLS=false diff --git a/config/storageCfg.php b/config/storageCfg.php index 518618f..fe6a17e 100644 --- a/config/storageCfg.php +++ b/config/storageCfg.php @@ -2,7 +2,6 @@ return [ 'name' => 'metadata', - 'mdaConfigFolder' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/config', - 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/hello.sh', - /* 'mdaScript' => '/home/artem/Desktop/cesnet/metadata/testdata/mda/mda.sh',*/ + 'mdaConfigFolder' => env('MDA_CONFIG_FOLDER'), + 'mdaScript' => env('MDA_SCRIPT'), ]; From ba44a8984e886741ee6ec75cc0e3f3aa0b0a9b36 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 9 Jul 2024 15:28:18 +0200 Subject: [PATCH 14/53] make RateLimited for RunMdaScript job --- app/Jobs/RunMdaScript.php | 11 +++++++++++ app/Providers/AppServiceProvider.php | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php index b71a677..4aae30e 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\Middleware\RateLimited; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; @@ -65,4 +66,14 @@ public function handle(): void } } + + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array + { + return [new RateLimited('mda-run-limit')]; + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index f326216..4960438 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,8 +2,12 @@ namespace App\Providers; +use App\Jobs\RunMdaScript; +use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\RateLimiter; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider @@ -29,5 +33,14 @@ public function boot() // Mail::alwaysTo('foo@example.org'); Model::preventLazyLoading(); } + + RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { + $diskName = config('storageCfg.name'); + $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + + return Limit::perMinute(1)->by($lockKey); + }); + } } From 39e13efc3070d13f0b079e05fb50e46b9c0e67ee Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 9 Jul 2024 16:27:33 +0200 Subject: [PATCH 15/53] fix dump from git --- app/Console/Commands/DumpFromGit.php | 27 +++++++++++++++++---------- app/Traits/FederationTrait.php | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/DumpFromGit.php b/app/Console/Commands/DumpFromGit.php index 804201b..e1a1aef 100644 --- a/app/Console/Commands/DumpFromGit.php +++ b/app/Console/Commands/DumpFromGit.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Facades\EntityFacade; +use App\Models\Entity; use App\Models\Membership; use App\Models\User; use App\Traits\DumpFromGit\CreateCategoriesAndGroupsTrait; @@ -16,6 +17,7 @@ use App\Traits\ValidatorTrait; use Exception; use Illuminate\Console\Command; +use Illuminate\Database\Eloquent\Model; class DumpFromGit extends Command { @@ -59,16 +61,21 @@ public function handle() throw new Exception('firstAdminId is null'); } - $this->initializeGit(); - $this->createFederations(); - $this->createEntities($firstAdminId); - $this->createCategoriesAndGroups(); - $this->updateGroupsAndCategories(); - $this->updateEntitiesXml(); - $this->updateFederationFolders(); - $this->fixEntities(); - $this->createMetadataFiles(); - $this->makeEdu2Edugain(); + Entity::withoutEvents( function () use ($firstAdminId) { + $this->initializeGit(); + $this->createFederations(); + $this->createEntities($firstAdminId); + $this->createCategoriesAndGroups(); + $this->updateGroupsAndCategories(); + $this->updateEntitiesXml(); + $this->updateFederationFolders(); + $this->fixEntities(); + $this->createMetadataFiles(); + $this->makeEdu2Edugain(); + + }); + + } } diff --git a/app/Traits/FederationTrait.php b/app/Traits/FederationTrait.php index be760cc..6aaf753 100644 --- a/app/Traits/FederationTrait.php +++ b/app/Traits/FederationTrait.php @@ -15,7 +15,7 @@ public function createFederationFolder(string $name): void public function updateFederationFolders(): void { - $federations = Federation::select('name')->get(); + $federations = Federation::all(); foreach ($federations as $fed) { if (! Storage::disk(config('storageCfg.name'))->exists($fed['xml_id'])) { From dcfba680edc7eaa3902912f01cdb95c9961d6b04 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 10 Jul 2024 10:39:18 +0200 Subject: [PATCH 16/53] only approved entity can start a job --- app/Http/Controllers/EntityController.php | 2 +- app/Listeners/SendCreatedEntityToSaveJob.php | 5 +++-- app/Listeners/SendUpdatedEntityToSaveJob.php | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 53d4dd1..42589f8 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -275,7 +275,7 @@ public function update(Request $request, Entity $entity) ->with('status', __('entities.not_changed')); } - //TODO updateChain + // Make update with job /* Bus::chain([ new GitUpdateEntity($entity, Auth::user()), function () use ($entity) { diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index 3fba8a6..c8abe18 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -21,8 +21,9 @@ public function __construct() */ public function handle(CreateEntity $event): void { - //Log::info('Listener triggered for CreateEntity event', ['entity_id' => $event->entity->id]); - FolderAddEntity::dispatch($event->entity); + if($event->entity->approved == 1){ + FolderAddEntity::dispatch($event->entity); + } } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 26624b1..6a5912f 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -21,10 +21,12 @@ public function __construct() */ public function handle(UpdateEntity $event): void { - // Log::info('Listener triggered for UpdateEntity event', ['entity_id' => $event->entity->id]); + $ent = $event->entity; - if ($ent->wasChanged('xml_file')) { + if ($ent->wasChanged('xml_file') || + ($ent->wasChanged('approved') && $ent->approved == 1) + ) { FolderAddEntity::dispatch($event->entity); } } From ec08f0b06215e415cac3ae9d0fa9508c6ef5122e Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 10 Jul 2024 12:43:22 +0200 Subject: [PATCH 17/53] fix lock and use pint --- app/Console/Commands/DumpFromGit.php | 27 +++++++++----------- app/Jobs/FolderAddEntity.php | 19 +++++++------- app/Listeners/SendCreatedEntityToSaveJob.php | 3 +-- app/Listeners/SendUpdatedEntityToSaveJob.php | 1 - 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/Console/Commands/DumpFromGit.php b/app/Console/Commands/DumpFromGit.php index e1a1aef..28db647 100644 --- a/app/Console/Commands/DumpFromGit.php +++ b/app/Console/Commands/DumpFromGit.php @@ -17,7 +17,6 @@ use App\Traits\ValidatorTrait; use Exception; use Illuminate\Console\Command; -use Illuminate\Database\Eloquent\Model; class DumpFromGit extends Command { @@ -61,21 +60,19 @@ public function handle() throw new Exception('firstAdminId is null'); } - Entity::withoutEvents( function () use ($firstAdminId) { - $this->initializeGit(); - $this->createFederations(); - $this->createEntities($firstAdminId); - $this->createCategoriesAndGroups(); - $this->updateGroupsAndCategories(); - $this->updateEntitiesXml(); - $this->updateFederationFolders(); - $this->fixEntities(); - $this->createMetadataFiles(); - $this->makeEdu2Edugain(); - - }); - + Entity::withoutEvents(function () use ($firstAdminId) { + $this->initializeGit(); + $this->createFederations(); + $this->createEntities($firstAdminId); + $this->createCategoriesAndGroups(); + $this->updateGroupsAndCategories(); + $this->updateEntitiesXml(); + $this->updateFederationFolders(); + $this->fixEntities(); + $this->createMetadataFiles(); + $this->makeEdu2Edugain(); + }); } } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 064c6b6..a2e9327 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -59,18 +59,17 @@ public function handle(): void $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; $lock = Cache::lock($lockKey, 120); - if ($lock->get()) { - - try { - EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); - RunMdaScript::dispatch($federation, $lock->owner()); - $this->runMDA($federation); - } catch (Exception $e) { - Log::error($e->getMessage()); - } finally { + try { + $lock->block(120); + EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + RunMdaScript::dispatch($federation, $lock->owner()); + $this->runMDA($federation); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { $lock->release(); } - } } diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index c8abe18..379842b 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -4,7 +4,6 @@ use App\Events\CreateEntity; use App\Jobs\FolderAddEntity; -use Illuminate\Support\Facades\Log; class SendCreatedEntityToSaveJob { @@ -22,7 +21,7 @@ public function __construct() public function handle(CreateEntity $event): void { - if($event->entity->approved == 1){ + if ($event->entity->approved == 1) { FolderAddEntity::dispatch($event->entity); } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 6a5912f..7024231 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -4,7 +4,6 @@ use App\Events\UpdateEntity; use App\Jobs\FolderAddEntity; -use Illuminate\Support\Facades\Log; class SendUpdatedEntityToSaveJob { From 87e1462c84a1954ea71e1528a860c0fe717dfa38 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 10 Jul 2024 14:43:37 +0200 Subject: [PATCH 18/53] make delete but without job --- app/Events/DeleteEntity.php | 27 ++++++++ app/Jobs/FolderAddEntity.php | 6 -- app/Jobs/FolderDeleteEntity.php | 66 +++++++++++++++++++ .../SendDeletedEntityToDeleteJob.php | 41 ++++++++++++ app/Models/Entity.php | 2 + app/Providers/EventServiceProvider.php | 5 ++ app/Services/EntityService.php | 22 +++++++ 7 files changed, 163 insertions(+), 6 deletions(-) create mode 100644 app/Events/DeleteEntity.php create mode 100644 app/Jobs/FolderDeleteEntity.php create mode 100644 app/Listeners/SendDeletedEntityToDeleteJob.php diff --git a/app/Events/DeleteEntity.php b/app/Events/DeleteEntity.php new file mode 100644 index 0000000..f24fd20 --- /dev/null +++ b/app/Events/DeleteEntity.php @@ -0,0 +1,27 @@ +entity = $entity; + } + +} diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index a2e9327..0cfad1c 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -31,17 +31,12 @@ public function __construct(Entity $entity) $this->entity = $entity; } - private function runMDA(Federation $federation) - { - - } /** * Execute the job. */ public function handle(): void { - // TODO add aproveChecker to this query $federationMembershipId = Membership::select('federation_id') ->where('entity_id', $this->entity->id) ->get(); @@ -63,7 +58,6 @@ public function handle(): void $lock->block(120); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); RunMdaScript::dispatch($federation, $lock->owner()); - $this->runMDA($federation); } catch (Exception $e) { Log::error($e->getMessage()); } finally { diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php new file mode 100644 index 0000000..defdaf5 --- /dev/null +++ b/app/Jobs/FolderDeleteEntity.php @@ -0,0 +1,66 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $entity = $this->entity; + $federations = $entity->federations; + $diskName = config('storageCfg.name'); + foreach ($federations as $federation) { + if (! Storage::disk($diskName)->exists($federation->name)) { + continue; + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 120); + try { + $lock->block(120); + EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); + RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + + + + } + + + } +} diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php new file mode 100644 index 0000000..8733e55 --- /dev/null +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -0,0 +1,41 @@ +entity; + $federations = $entity->federations; + $diskName = config('storageCfg.name'); + + foreach ($federations as $federation) { + Log::info("file -> $entity->file folder -> $federation->xml_id"); + EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); + } + + + + + // FolderDeleteEntity::dispatch($event->entity); + } +} diff --git a/app/Models/Entity.php b/app/Models/Entity.php index 0ed5a2e..78750d6 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -4,6 +4,7 @@ use App\Enums\EntityType; use App\Events\CreateEntity; +use App\Events\DeleteEntity; use App\Events\UpdateEntity; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -96,6 +97,7 @@ public function scopeSearch($query, ?string $search = null) protected $dispatchesEvents = [ 'created' => CreateEntity::class, 'updated' => UpdateEntity::class, + 'deleted' => DeleteEntity::class, ]; } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 08fd1aa..7a91ba2 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -3,10 +3,12 @@ namespace App\Providers; use App\Events\CreateEntity; +use App\Events\DeleteEntity; use App\Events\FederationApprove; use App\Events\UpdateEntity; use App\Listeners\CreateFederationFolder; use App\Listeners\SendCreatedEntityToSaveJob; +use App\Listeners\SendDeletedEntityToDeleteJob; use App\Listeners\SendUpdatedEntityToSaveJob; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; @@ -33,6 +35,9 @@ class EventServiceProvider extends ServiceProvider UpdateEntity::class => [ SendUpdatedEntityToSaveJob::class, ], + DeleteEntity::class => [ + SendDeletedEntityToDeleteJob::class, + ] ]; diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index 1d0876d..5c55a5f 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -5,6 +5,7 @@ use App\Models\Entity; use App\Models\Federation; use Exception; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; class EntityService @@ -46,4 +47,25 @@ public function saveEntityMetadataToFolder($entity_id, $folderName): void Storage::disk($diskName)->put($filePath, $content); } + + public function deleteEntityMetadataFromFolder($fileName, $folderName): void + { + $diskName = config('storageCfg.name'); + $pathToFile = $folderName . '/' . $fileName; + + if (Storage::disk($diskName)->exists($pathToFile)) { + try { + Storage::disk($diskName)->delete($pathToFile); + } catch (Exception $e) { + Log::error("Failed to delete file: {$pathToFile}. Error: " . $e->getMessage()); + } + } else { + Log::warning("File does not exist: {$pathToFile}"); + } + + + + } + + } From 073ece6c4500237c6f60666a1a0002b5832c12e1 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 10 Jul 2024 15:06:58 +0200 Subject: [PATCH 19/53] turn off most old git jobs --- app/Events/DeleteEntity.php | 8 ++--- app/Http/Controllers/EntityController.php | 4 --- app/Http/Controllers/FederationController.php | 5 +-- app/Http/Controllers/MembershipController.php | 31 +++++++++---------- app/Jobs/FolderAddEntity.php | 1 - app/Jobs/FolderDeleteEntity.php | 5 --- ...{GitAddEntity.php => Old_GitAddEntity.php} | 2 +- ...{GitAddMember.php => Old_GitAddMember.php} | 2 +- ...itAddMembers.php => Old_GitAddMembers.php} | 2 +- ...embership.php => Old_GitAddMembership.php} | 2 +- ...leteEntity.php => Old_GitDeleteEntity.php} | 2 +- ...dateEntity.php => Old_GitUpdateEntity.php} | 2 +- .../SendDeletedEntityToDeleteJob.php | 7 +---- app/Providers/EventServiceProvider.php | 2 +- app/Services/EntityService.php | 8 ++--- .../Http/Controllers/EntityControllerTest.php | 3 -- .../Controllers/FederationControllerTest.php | 17 +++++----- 17 files changed, 38 insertions(+), 65 deletions(-) rename app/Jobs/{GitAddEntity.php => Old_GitAddEntity.php} (97%) rename app/Jobs/{GitAddMember.php => Old_GitAddMember.php} (97%) rename app/Jobs/{GitAddMembers.php => Old_GitAddMembers.php} (97%) rename app/Jobs/{GitAddMembership.php => Old_GitAddMembership.php} (97%) rename app/Jobs/{GitDeleteEntity.php => Old_GitDeleteEntity.php} (97%) rename app/Jobs/{GitUpdateEntity.php => Old_GitUpdateEntity.php} (97%) diff --git a/app/Events/DeleteEntity.php b/app/Events/DeleteEntity.php index f24fd20..f296424 100644 --- a/app/Events/DeleteEntity.php +++ b/app/Events/DeleteEntity.php @@ -3,25 +3,21 @@ namespace App\Events; use App\Models\Entity; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class DeleteEntity { use Dispatchable, InteractsWithSockets, SerializesModels; + public Entity $entity; /** * Create a new event instance. */ - public function __construct(Entity $entity ) + public function __construct(Entity $entity) { $this->entity = $entity; } - } diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 42589f8..657f293 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -3,20 +3,16 @@ namespace App\Http\Controllers; use App\Http\Requests\StoreEntity; -use App\Jobs\GitAddEntity; -use App\Jobs\GitAddMember; use App\Jobs\GitAddToCategory; use App\Jobs\GitAddToEdugain; use App\Jobs\GitAddToHfd; use App\Jobs\GitAddToRs; -use App\Jobs\GitDeleteEntity; use App\Jobs\GitDeleteFromCategory; use App\Jobs\GitDeleteFromEdugain; use App\Jobs\GitDeleteFromHfd; use App\Jobs\GitDeleteFromRs; use App\Jobs\GitRestoreToCategory; use App\Jobs\GitRestoreToEdugain; -use App\Jobs\GitUpdateEntity; use App\Ldap\CesnetOrganization; use App\Ldap\EduidczOrganization; use App\Mail\NewIdentityProvider; diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 67aa975..870eb51 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -4,7 +4,6 @@ use App\Http\Requests\StoreFederation; use App\Http\Requests\UpdateFederation; -use App\Jobs\GitAddMembers; use App\Jobs\GitDeleteMembers; use App\Models\Entity; use App\Models\Federation; @@ -284,7 +283,9 @@ public function update(UpdateFederation $request, Federation $federation) ]); $new_entities = Entity::whereIn('id', request('entities'))->get(); - GitAddMembers::dispatch($federation, $new_entities, Auth::user()); + + //TODO add members to federation + // GitAddMembers::dispatch($federation, $new_entities, Auth::user()); Notification::send($federation->operators, new FederationMembersChanged($federation, $new_entities, 'added')); Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $new_entities, 'added')); diff --git a/app/Http/Controllers/MembershipController.php b/app/Http/Controllers/MembershipController.php index 5a9ad23..17e64cd 100644 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers; -use App\Jobs\GitAddEntity; -use App\Jobs\GitAddMembership; use App\Jobs\GitAddToHfd; use App\Models\Membership; use App\Models\User; @@ -41,20 +39,21 @@ public function update(Membership $membership) $membership->update(); }); - Bus::chain([ - new GitAddEntity($membership->entity, Auth::user()), - new GitAddToHfd($membership->entity, Auth::user()), - new GitAddMembership($membership, Auth::user()), - function () use ($membership) { - $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($membership->entity->operators, new MembershipAccepted($membership)); - Notification::send($admins, new MembershipAccepted($membership)); - if ($membership->entity->hfd) { - Notification::send($membership->entity->operators, new EntityAddedToHfd($membership->entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($membership->entity)); - } - }, - ])->dispatch(); + // TODO chain of update membership chain + /* Bus::chain([ + new Old_GitAddEntity($membership->entity, Auth::user()), + new GitAddToHfd($membership->entity, Auth::user()), + new GitAddMembership($membership, Auth::user()), + function () use ($membership) { + $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($membership->entity->operators, new MembershipAccepted($membership)); + Notification::send($admins, new MembershipAccepted($membership)); + if ($membership->entity->hfd) { + Notification::send($membership->entity->operators, new EntityAddedToHfd($membership->entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($membership->entity)); + } + }, + ])->dispatch();*/ return redirect() ->back() diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 0cfad1c..b9c4c35 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -31,7 +31,6 @@ public function __construct(Entity $entity) $this->entity = $entity; } - /** * Execute the job. */ diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index defdaf5..058de5c 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -4,7 +4,6 @@ use App\Facades\EntityFacade; use App\Models\Entity; -use App\Models\Federation; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -56,11 +55,7 @@ public function handle(): void } } - - - } - } } diff --git a/app/Jobs/GitAddEntity.php b/app/Jobs/Old_GitAddEntity.php similarity index 97% rename from app/Jobs/GitAddEntity.php rename to app/Jobs/Old_GitAddEntity.php index d8f6aab..2925379 100644 --- a/app/Jobs/GitAddEntity.php +++ b/app/Jobs/Old_GitAddEntity.php @@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddEntity implements ShouldQueue +class Old_GitAddEntity implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Jobs/GitAddMember.php b/app/Jobs/Old_GitAddMember.php similarity index 97% rename from app/Jobs/GitAddMember.php rename to app/Jobs/Old_GitAddMember.php index 9809447..8535026 100644 --- a/app/Jobs/GitAddMember.php +++ b/app/Jobs/Old_GitAddMember.php @@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddMember implements ShouldQueue +class Old_GitAddMember implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Jobs/GitAddMembers.php b/app/Jobs/Old_GitAddMembers.php similarity index 97% rename from app/Jobs/GitAddMembers.php rename to app/Jobs/Old_GitAddMembers.php index 7fcd22b..c2dcd9e 100644 --- a/app/Jobs/GitAddMembers.php +++ b/app/Jobs/Old_GitAddMembers.php @@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddMembers implements ShouldQueue +class Old_GitAddMembers implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Jobs/GitAddMembership.php b/app/Jobs/Old_GitAddMembership.php similarity index 97% rename from app/Jobs/GitAddMembership.php rename to app/Jobs/Old_GitAddMembership.php index 20de888..60dfe1c 100644 --- a/app/Jobs/GitAddMembership.php +++ b/app/Jobs/Old_GitAddMembership.php @@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddMembership implements ShouldQueue +class Old_GitAddMembership implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Jobs/GitDeleteEntity.php b/app/Jobs/Old_GitDeleteEntity.php similarity index 97% rename from app/Jobs/GitDeleteEntity.php rename to app/Jobs/Old_GitDeleteEntity.php index f136fdb..894af03 100644 --- a/app/Jobs/GitDeleteEntity.php +++ b/app/Jobs/Old_GitDeleteEntity.php @@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitDeleteEntity implements ShouldQueue +class Old_GitDeleteEntity implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Jobs/GitUpdateEntity.php b/app/Jobs/Old_GitUpdateEntity.php similarity index 97% rename from app/Jobs/GitUpdateEntity.php rename to app/Jobs/Old_GitUpdateEntity.php index 92d8754..8e34422 100644 --- a/app/Jobs/GitUpdateEntity.php +++ b/app/Jobs/Old_GitUpdateEntity.php @@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitUpdateEntity implements ShouldQueue +class Old_GitUpdateEntity implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index 8733e55..cebd908 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -5,8 +5,6 @@ use App\Events\DeleteEntity; use App\Facades\EntityFacade; use App\Jobs\FolderDeleteEntity; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Log; class SendDeletedEntityToDeleteJob @@ -33,9 +31,6 @@ public function handle(DeleteEntity $event): void EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); } - - - - // FolderDeleteEntity::dispatch($event->entity); + // FolderDeleteEntity::dispatch($event->entity); } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 7a91ba2..b07c157 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -37,7 +37,7 @@ class EventServiceProvider extends ServiceProvider ], DeleteEntity::class => [ SendDeletedEntityToDeleteJob::class, - ] + ], ]; diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index 5c55a5f..f07263e 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -51,21 +51,17 @@ public function saveEntityMetadataToFolder($entity_id, $folderName): void public function deleteEntityMetadataFromFolder($fileName, $folderName): void { $diskName = config('storageCfg.name'); - $pathToFile = $folderName . '/' . $fileName; + $pathToFile = $folderName.'/'.$fileName; if (Storage::disk($diskName)->exists($pathToFile)) { try { Storage::disk($diskName)->delete($pathToFile); } catch (Exception $e) { - Log::error("Failed to delete file: {$pathToFile}. Error: " . $e->getMessage()); + Log::error("Failed to delete file: {$pathToFile}. Error: ".$e->getMessage()); } } else { Log::warning("File does not exist: {$pathToFile}"); } - - } - - } diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index eb675c3..facd132 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -2,9 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\GitAddEntity; -use App\Jobs\GitDeleteEntity; -use App\Jobs\GitUpdateEntity; use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; diff --git a/tests/Feature/Http/Controllers/FederationControllerTest.php b/tests/Feature/Http/Controllers/FederationControllerTest.php index 168eabd..4865cca 100644 --- a/tests/Feature/Http/Controllers/FederationControllerTest.php +++ b/tests/Feature/Http/Controllers/FederationControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\GitAddMembers; use App\Jobs\GitDeleteMembers; use App\Jobs\GitUpdateFederation; use App\Jobs\Old_GitAddFederation; @@ -514,10 +513,10 @@ public function a_user_with_operator_permission_can_change_an_existing_federatio $this->assertEquals(2, $federation->entities()->count()); $this->assertEquals(route('federations.entities', $federation), url()->current()); - Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) { - return $job->federation->is($federation) && - $job->entities->contains($new_entity); - }); + /* Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) { + return $job->federation->is($federation) && + $job->entities->contains($new_entity); + });*/ $this ->followingRedirects() @@ -1086,10 +1085,10 @@ public function an_admin_can_change_an_existing_federations_entities() $this->assertEquals(2, $federation->entities()->count()); $this->assertEquals(route('federations.entities', $federation), url()->current()); - Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) { - return $job->federation->is($federation) && - $job->entities->contains($new_entity); - }); + /* Bus::assertDispatched(GitAddMembers::class, function ($job) use ($federation, $new_entity) { + return $job->federation->is($federation) && + $job->entities->contains($new_entity); + });*/ $this ->followingRedirects() From dc72ba08af64dab32384c26ec0c6b25a42f6baa8 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Thu, 11 Jul 2024 13:35:18 +0200 Subject: [PATCH 20/53] make delete with job and make Failure part of job --- app/Jobs/FolderAddEntity.php | 11 ++++++++++ app/Jobs/FolderDeleteEntity.php | 7 +++++++ .../SendDeletedEntityToDeleteJob.php | 11 +--------- app/Traits/HandlesJobsFailuresTrait.php | 21 +++++++++++++++++++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 app/Traits/HandlesJobsFailuresTrait.php diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index b9c4c35..3ed352e 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -3,9 +3,11 @@ namespace App\Jobs; use App\Facades\EntityFacade; +use App\Mail\ExceptionOccured; use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; +use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -14,13 +16,21 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; use Mockery\Exception; +use Throwable; class FolderAddEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * trait with failure function + */ + use HandlesJobsFailuresTrait; + + public Entity $entity; /** @@ -77,4 +87,5 @@ public function middleware(): array { return [(new WithoutOverlapping($this->entity->id))->dontRelease()]; } + } diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 058de5c..84fc7ee 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -4,6 +4,7 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -18,6 +19,11 @@ class FolderDeleteEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * trait with failure function + */ + use HandlesJobsFailuresTrait; + public Entity $entity; /** @@ -33,6 +39,7 @@ public function __construct(Entity $entity) */ public function handle(): void { + $entity = $this->entity; $federations = $entity->federations; $diskName = config('storageCfg.name'); diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index cebd908..8d2d9a2 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -22,15 +22,6 @@ public function __construct() */ public function handle(DeleteEntity $event): void { - $entity = $event->entity; - $federations = $entity->federations; - $diskName = config('storageCfg.name'); - - foreach ($federations as $federation) { - Log::info("file -> $entity->file folder -> $federation->xml_id"); - EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - } - - // FolderDeleteEntity::dispatch($event->entity); + FolderDeleteEntity::dispatch($event->entity); } } diff --git a/app/Traits/HandlesJobsFailuresTrait.php b/app/Traits/HandlesJobsFailuresTrait.php new file mode 100644 index 0000000..732823c --- /dev/null +++ b/app/Traits/HandlesJobsFailuresTrait.php @@ -0,0 +1,21 @@ +getFile()} on line {$exception->getLine()}: {$exception->getMessage()}"); + Log::channel('slack')->critical("Exception occurred 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(), + ])); + } +} From 6d8b4b3341d3691f41c2ae3a6c0f8dc4f86b05f5 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Thu, 11 Jul 2024 14:02:57 +0200 Subject: [PATCH 21/53] fix test now it's working with delete job --- .../Feature/Http/Controllers/EntityControllerTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index facd132..a3bc60a 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\FolderDeleteEntity; use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; @@ -9,6 +10,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Bus; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class EntityControllerTest extends TestCase @@ -1410,6 +1412,9 @@ public function an_admin_can_change_an_existing_entities_federation_membership() /** @test */ public function an_admin_can_purge_an_existing_entity() { + + Queue::fake(); + $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create([ 'deleted_at' => now(), @@ -1421,11 +1426,14 @@ public function an_admin_can_purge_an_existing_entity() ->actingAs($admin) ->delete(route('entities.destroy', $entity)) ->assertSeeText(__('entities.destroyed', ['name' => $name])); + + Queue::assertPushed(FolderDeleteEntity::class); } /** @test */ public function an_admin_can_reject_a_new_entity_request() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $federation = Federation::factory()->create(); $entity = Entity::factory()->create(['approved' => false]); @@ -1440,6 +1448,8 @@ public function an_admin_can_reject_a_new_entity_request() ->actingAs($admin) ->delete(route('memberships.destroy', $membership)) ->assertSeeText(__('federations.membership_rejected', ['entity' => $entity->name_en])); + + Queue::assertPushed(FolderDeleteEntity::class); } /** @test */ From 87250fee42a613e00d94ad1fdb9c5165be08d6fd Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Thu, 11 Jul 2024 14:20:37 +0200 Subject: [PATCH 22/53] make restore with job --- app/Http/Controllers/EntityController.php | 1 + app/Models/Entity.php | 1 + 2 files changed, 2 insertions(+) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 657f293..5e60005 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -313,6 +313,7 @@ function () use ($entity) { if ($entity->trashed()) { $entity->restore(); + //TODO restore chain /* Bus::chain([ new GitAddEntity($entity, Auth::user()), new GitAddToHfd($entity, Auth::user()), diff --git a/app/Models/Entity.php b/app/Models/Entity.php index 78750d6..c6b497c 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -98,6 +98,7 @@ public function scopeSearch($query, ?string $search = null) 'created' => CreateEntity::class, 'updated' => UpdateEntity::class, 'deleted' => DeleteEntity::class, + 'restored' => CreateEntity::class, ]; } From 7eac6efe03e6c85077b2dd6f71b66fe8f9bd90e3 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Fri, 12 Jul 2024 23:37:22 +0200 Subject: [PATCH 23/53] make new NotificationService (not tested) --- app/Http/Controllers/EntityController.php | 13 +++++++------ app/Jobs/FolderAddEntity.php | 12 ++++++++++++ app/Jobs/FolderDeleteEntity.php | 11 +++++++++++ .../{GitAddToRs.php => Old_GitAddToRs.php} | 2 +- app/Listeners/SendUpdatedEntityToSaveJob.php | 19 +++++++++++++++---- app/Providers/AppServiceProvider.php | 4 ++-- app/Services/NotificationService.php | 16 ++++++++++++++++ 7 files changed, 64 insertions(+), 13 deletions(-) rename app/Jobs/{GitAddToRs.php => Old_GitAddToRs.php} (97%) create mode 100644 app/Services/NotificationService.php diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 5e60005..6326591 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -6,7 +6,6 @@ use App\Jobs\GitAddToCategory; use App\Jobs\GitAddToEdugain; use App\Jobs\GitAddToHfd; -use App\Jobs\GitAddToRs; use App\Jobs\GitDeleteFromCategory; use App\Jobs\GitDeleteFromEdugain; use App\Jobs\GitDeleteFromHfd; @@ -271,7 +270,7 @@ public function update(Request $request, Entity $entity) ->with('status', __('entities.not_changed')); } - // Make update with job + // TODO notification /* Bus::chain([ new GitUpdateEntity($entity, Auth::user()), function () use ($entity) { @@ -474,7 +473,8 @@ function () use ($entity) { $status = $entity->rs ? 'rs' : 'no_rs'; $color = $entity->rs ? 'green' : 'red'; - if ($entity->rs) { + // TODO notification +/* if ($entity->rs) { GitAddToRs::dispatch($entity, Auth::user()); Notification::send($entity->operators, new EntityAddedToRs($entity)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity)); @@ -482,7 +482,7 @@ function () use ($entity) { GitDeleteFromRs::dispatch($entity, Auth::user()); Notification::send($entity->operators, new EntityDeletedFromRs($entity)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity)); - } + }*/ return redirect() ->back() @@ -542,7 +542,8 @@ function () use ($entity, $category) { $status = $entity->hfd ? 'hfd' : 'no_hfd'; $color = $entity->hfd ? 'red' : 'green'; - if ($entity->hfd) { + //TODO change HfD status +/* if ($entity->hfd) { GitAddToHfd::dispatch($entity, Auth::user()); Notification::send($entity->operators, new EntityAddedToHfd($entity)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); @@ -551,7 +552,7 @@ function () use ($entity, $category) { Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity)); Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); - } + }*/ return redirect() ->route('entities.show', $entity) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 3ed352e..f5b4c89 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -7,6 +7,10 @@ use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; +use App\Notifications\EntityStateChanged; +use App\Notifications\EntityUpdated; +use App\Services\EntityService; +use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -66,6 +70,14 @@ public function handle(): void try { $lock->block(120); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + + +/* if ($this->entity->wasRecentlyCreated) { + NotificationService::sendEntityNotification($this->entity,EntityUpdated::class); + } elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { + NotificationService::sendEntityNotification($this->entity,EntityStateChanged::class); + }*/ + RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 84fc7ee..34540cf 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -4,6 +4,10 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Notifications\EntityDeletedFromHfd; +use App\Notifications\EntityStateChanged; +use App\Services\EntityService; +use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -53,6 +57,13 @@ public function handle(): void try { $lock->block(120); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); + + NotificationService::sendEntityNotification($entity,EntityStateChanged::class); + if ($entity->hfd) { + NotificationService::sendEntityNotification($entity,EntityDeletedFromHfd::class); + } + + RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Jobs/GitAddToRs.php b/app/Jobs/Old_GitAddToRs.php similarity index 97% rename from app/Jobs/GitAddToRs.php rename to app/Jobs/Old_GitAddToRs.php index cb6cdfd..532c9ab 100644 --- a/app/Jobs/GitAddToRs.php +++ b/app/Jobs/Old_GitAddToRs.php @@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddToRs implements ShouldQueue +class Old_GitAddToRs implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 7024231..a330716 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -4,6 +4,10 @@ use App\Events\UpdateEntity; use App\Jobs\FolderAddEntity; +use App\Models\User; +use App\Notifications\EntityUpdated; +use App\Services\NotificationService; +use Illuminate\Support\Facades\Notification; class SendUpdatedEntityToSaveJob { @@ -21,12 +25,19 @@ public function __construct() public function handle(UpdateEntity $event): void { - $ent = $event->entity; + $entity = $event->entity; - if ($ent->wasChanged('xml_file') || - ($ent->wasChanged('approved') && $ent->approved == 1) - ) { + + + if ($entity->wasChanged('xml_file') || + ($entity->wasChanged('approved') && $entity->approved == 1) + ) + { FolderAddEntity::dispatch($event->entity); } + elseif ($entity->approved == 1) + { + NotificationService::sendEntityNotification($entity,EntityUpdated::class); + } } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 4960438..e7a30f4 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -34,13 +34,13 @@ public function boot() Model::preventLazyLoading(); } - RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { +/* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { $diskName = config('storageCfg.name'); $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; return Limit::perMinute(1)->by($lockKey); - }); + });*/ } } diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php new file mode 100644 index 0000000..b997f70 --- /dev/null +++ b/app/Services/NotificationService.php @@ -0,0 +1,16 @@ +select('id', 'email')->get(); + Notification::sendNow($entity->operators, new $notification($entity)); + Notification::sendNow($admins, new $notification($entity)); + } + +} From eb4e015af509daec5c281a4f5c4b61b5e380d1d2 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 00:03:04 +0200 Subject: [PATCH 24/53] make new NotificationService (not tested) --- app/Services/NotificationService.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index b997f70..cf82a1b 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -9,8 +9,15 @@ class NotificationService{ public static function sendEntityNotification(Entity $entity,$notification){ $admins = User::activeAdmins()->select('id', 'email')->get(); + + $operators = $entity->operators->pluck('id')->toArray(); + + $filteredAdmins = $admins->filter(function ($admin) use ($operators) { + return !in_array($admin->id, $operators); + }); + Notification::sendNow($entity->operators, new $notification($entity)); - Notification::sendNow($admins, new $notification($entity)); + Notification::sendNow($filteredAdmins, new $notification($entity)); } } From d099eb7a4c5c1096389f90365f6e9641f99e1c05 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 10:11:37 +0200 Subject: [PATCH 25/53] uncommented notification and make better RunMdaScript --- app/Jobs/FolderAddEntity.php | 6 +++--- app/Jobs/FolderDeleteEntity.php | 2 +- app/Jobs/RunMdaScript.php | 11 ++++++++++- app/Providers/AppServiceProvider.php | 3 +-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index f5b4c89..fee9f4f 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -65,18 +65,18 @@ public function handle(): void } $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - $lock = Cache::lock($lockKey, 120); + $lock = Cache::lock($lockKey, 61); try { $lock->block(120); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); -/* if ($this->entity->wasRecentlyCreated) { + if ($this->entity->wasRecentlyCreated) { NotificationService::sendEntityNotification($this->entity,EntityUpdated::class); } elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { NotificationService::sendEntityNotification($this->entity,EntityStateChanged::class); - }*/ + } RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 34540cf..e3c6731 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -53,7 +53,7 @@ public function handle(): void } $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - $lock = Cache::lock($lockKey, 120); + $lock = Cache::lock($lockKey, 61); try { $lock->block(120); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php index 4aae30e..96073f3 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -8,6 +8,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Middleware\RateLimited; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; @@ -74,6 +75,14 @@ public function handle(): void */ public function middleware(): array { - return [new RateLimited('mda-run-limit')]; + $diskName = config('storageCfg.name'); + $pathToDirectory = Storage::disk($diskName)->path($this->federation->name); + $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; + + return [ + new RateLimited('mda-run-limit'), + (new WithoutOverlapping($lockKey))->dontRelease() + ]; + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index e7a30f4..58e39d6 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -33,12 +33,11 @@ public function boot() // Mail::alwaysTo('foo@example.org'); Model::preventLazyLoading(); } - +//TODO comment this for testing part /* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { $diskName = config('storageCfg.name'); $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - return Limit::perMinute(1)->by($lockKey); });*/ From 0094a51f82acc593be16fe56e7c9d4c501e03a5b Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 11:33:12 +0200 Subject: [PATCH 26/53] rewrite edu2edugain to config --- .env.example | 1 + app/Traits/EdugainTrait.php | 2 +- config/storageCfg.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index f22e66f..d7863f2 100644 --- a/.env.example +++ b/.env.example @@ -64,6 +64,7 @@ VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" MDA_CONFIG_FOLDER=/opt/mda-distribution-0.10.0/config MDA_SCRIPT=/opt/mda-distribution-0.10.0/mda.sh +EDU_TO_EDUGAIN_FOLDER="eduid2edugain" GIT_REMOTE=user@git.example.org:repository GIT_REMOTE_BRANCH=main diff --git a/app/Traits/EdugainTrait.php b/app/Traits/EdugainTrait.php index fd146c3..0970a31 100644 --- a/app/Traits/EdugainTrait.php +++ b/app/Traits/EdugainTrait.php @@ -11,7 +11,7 @@ trait EdugainTrait public function makeEdu2Edugain() { - $folderName = 'eduid2edugain'; + $folderName = config('storageCfg.edu2edugain'); $eduFed = Entity::where('edugain', 1)->get(); foreach ($eduFed as $edu) { diff --git a/config/storageCfg.php b/config/storageCfg.php index fe6a17e..cb12053 100644 --- a/config/storageCfg.php +++ b/config/storageCfg.php @@ -4,4 +4,5 @@ 'name' => 'metadata', 'mdaConfigFolder' => env('MDA_CONFIG_FOLDER'), 'mdaScript' => env('MDA_SCRIPT'), + 'edu2edugain' =>env('EDU_TO_EDUGAIN_FOLDER'), ]; From 9e99685c7dfffb79a8ce6b2852b988959d53ca69 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 12:14:31 +0200 Subject: [PATCH 27/53] start write new job for EduGain (not ready script run part) --- app/Jobs/EduGainAddEntity.php | 70 +++++++++++++++++++++++++++++++++++ app/Jobs/FolderAddEntity.php | 2 +- app/Jobs/RunMdaScript.php | 2 +- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/EduGainAddEntity.php diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php new file mode 100644 index 0000000..fa23d27 --- /dev/null +++ b/app/Jobs/EduGainAddEntity.php @@ -0,0 +1,70 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $diskName = config('storageCfg.name'); + $folderName = config('storageCfg.edu2edugain'); + try { + if (! Storage::disk($diskName)->exists($folderName)) { + throw new Exception("No $folderName in $diskName"); + } + } catch (Exception $e) { + $this->fail($e); + } + $pathToDirectory = Storage::disk($diskName)->path($folderName); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + try { + $lock->block(61); + EntityFacade::saveMetadataToFederationFolder($this->entity->id,$folderName); + + //TODO write custom function to run special MDA script (ask about this) + + // RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + + + } +} diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index fee9f4f..d56af97 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -68,7 +68,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { - $lock->block(120); + $lock->block(61); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php index 96073f3..9e02d5c 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -44,7 +44,7 @@ public function handle(): void $filterArray = explode(', ', $this->federation->filters); $scriptPath = config('storageCfg.mdaScript'); - $command = 'sh '.config('storageCfg.mdaScript'); + $realScriptPath = realpath($scriptPath); From e6125379dda2d4290ea9d68d84c8dc6e42e4c234 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 15:52:50 +0200 Subject: [PATCH 28/53] write working EduToEdugain jobs but without mda script --- app/Jobs/EduGainAddEntity.php | 2 +- app/Jobs/EduGainDeleteEntity.php | 69 +++++++++++++++++++ app/Jobs/FolderDeleteEntity.php | 2 +- app/Listeners/SendCreatedEntityToSaveJob.php | 6 ++ .../SendDeletedEntityToDeleteJob.php | 12 +++- app/Listeners/SendUpdatedEntityToSaveJob.php | 17 ++++- 6 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 app/Jobs/EduGainDeleteEntity.php diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index fa23d27..cf29019 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -51,7 +51,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { $lock->block(61); - EntityFacade::saveMetadataToFederationFolder($this->entity->id,$folderName); + EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName); //TODO write custom function to run special MDA script (ask about this) diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php new file mode 100644 index 0000000..866148a --- /dev/null +++ b/app/Jobs/EduGainDeleteEntity.php @@ -0,0 +1,69 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $diskName = config('storageCfg.name'); + $folderName = config('storageCfg.edu2edugain'); + try { + if (! Storage::disk($diskName)->exists($folderName)) { + throw new Exception("No $folderName in $diskName"); + } + } catch (Exception $e) { + $this->fail($e); + } + $pathToDirectory = Storage::disk($diskName)->path($folderName); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + try { + $lock->block(61); + EntityFacade::deleteEntityMetadataFromFolder($this->entity->file,$folderName); + + //TODO write custom function to run special MDA script (ask about this) + + // RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + } +} diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index e3c6731..b7af833 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -55,7 +55,7 @@ public function handle(): void $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; $lock = Cache::lock($lockKey, 61); try { - $lock->block(120); + $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); NotificationService::sendEntityNotification($entity,EntityStateChanged::class); diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index 379842b..45043f1 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -3,6 +3,7 @@ namespace App\Listeners; use App\Events\CreateEntity; +use App\Jobs\EduGainAddEntity; use App\Jobs\FolderAddEntity; class SendCreatedEntityToSaveJob @@ -23,6 +24,11 @@ public function handle(CreateEntity $event): void if ($event->entity->approved == 1) { FolderAddEntity::dispatch($event->entity); + + if($event->entity->edugain == 1){ + EduGainAddEntity::dispatch($event->entity); + } + } } } diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index 8d2d9a2..10e4d53 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -3,9 +3,9 @@ namespace App\Listeners; use App\Events\DeleteEntity; -use App\Facades\EntityFacade; +use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderDeleteEntity; -use Illuminate\Support\Facades\Log; + class SendDeletedEntityToDeleteJob { @@ -22,6 +22,12 @@ public function __construct() */ public function handle(DeleteEntity $event): void { - FolderDeleteEntity::dispatch($event->entity); + FolderDeleteEntity::dispatch($event->entity); + + if($event->entity->edugain == 1){ + EduGainDeleteEntity::dispatch($event->entity); + } + + } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index a330716..1123e7c 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -3,6 +3,8 @@ namespace App\Listeners; use App\Events\UpdateEntity; +use App\Jobs\EduGainAddEntity; +use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; use App\Models\User; use App\Notifications\EntityUpdated; @@ -27,17 +29,26 @@ public function handle(UpdateEntity $event): void $entity = $event->entity; - - if ($entity->wasChanged('xml_file') || ($entity->wasChanged('approved') && $entity->approved == 1) ) { FolderAddEntity::dispatch($event->entity); } - elseif ($entity->approved == 1) + elseif ($entity->approved == 1 && !$entity->wasChanged('edugain')) { NotificationService::sendEntityNotification($entity,EntityUpdated::class); } + if($entity->wasChanged('edugain')) + { + if($entity->edugain == 1) { + EduGainAddEntity::dispatch($entity); + } else { + EduGainDeleteEntity::dispatch($entity); + } + } + + + } } From 1a79a55a3346e495356336d28960c0d35d5fd16a Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 16:08:00 +0200 Subject: [PATCH 29/53] add run script to EduGain jobs --- app/Jobs/EduGainAddEntity.php | 2 +- app/Jobs/EduGainDeleteEntity.php | 2 +- app/Jobs/EduGainRunMdaScript.php | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/EduGainRunMdaScript.php diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index cf29019..1818f65 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -54,8 +54,8 @@ public function handle(): void EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName); //TODO write custom function to run special MDA script (ask about this) + EduGainRunMdaScript::dispatch($lock->owner()); - // RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); } finally { diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 866148a..6152ea5 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -57,7 +57,7 @@ public function handle(): void //TODO write custom function to run special MDA script (ask about this) - // RunMdaScript::dispatch($federation, $lock->owner()); + EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); } finally { diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php new file mode 100644 index 0000000..b7e9514 --- /dev/null +++ b/app/Jobs/EduGainRunMdaScript.php @@ -0,0 +1,61 @@ +owner = $owner; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $diskName = config('storageCfg.name'); + $folderName = config('storageCfg.edu2edugain'); + + $pathToDirectory = Storage::disk($diskName)->path($folderName); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $scriptPath = config('storageCfg.mdaScript'); + $realScriptPath = realpath($scriptPath); + + try { + $file = escapeshellarg($folderName).'.xml'; + $pipeline = 'main'; + $command = 'sh '.escapeshellarg($realScriptPath).' '.$file.' '.$pipeline; + + $res = shell_exec($command); + dump($res); + + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + Cache::restoreLock($lockKey, $this->owner)->release(); + + } + + + + + } +} From dd1446fc135048e7438711706411d4a4fb0c4b22 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 16:08:53 +0200 Subject: [PATCH 30/53] run pint --- app/Http/Controllers/EntityController.php | 38 +++++++++---------- app/Jobs/EduGainAddEntity.php | 10 ++--- app/Jobs/EduGainDeleteEntity.php | 4 +- app/Jobs/EduGainRunMdaScript.php | 3 -- app/Jobs/FolderAddEntity.php | 11 +----- app/Jobs/FolderDeleteEntity.php | 6 +-- app/Jobs/RunMdaScript.php | 5 +-- app/Listeners/SendCreatedEntityToSaveJob.php | 2 +- .../SendDeletedEntityToDeleteJob.php | 4 +- app/Listeners/SendUpdatedEntityToSaveJob.php | 18 +++------ app/Providers/AppServiceProvider.php | 14 +++---- app/Services/NotificationService.php | 13 ++++--- app/Traits/HandlesJobsFailuresTrait.php | 4 +- config/storageCfg.php | 2 +- 14 files changed, 55 insertions(+), 79 deletions(-) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 6326591..60f23e4 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -474,15 +474,15 @@ function () use ($entity) { $color = $entity->rs ? 'green' : 'red'; // TODO notification -/* if ($entity->rs) { - GitAddToRs::dispatch($entity, Auth::user()); - Notification::send($entity->operators, new EntityAddedToRs($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity)); - } else { - GitDeleteFromRs::dispatch($entity, Auth::user()); - Notification::send($entity->operators, new EntityDeletedFromRs($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity)); - }*/ + /* if ($entity->rs) { + GitAddToRs::dispatch($entity, Auth::user()); + Notification::send($entity->operators, new EntityAddedToRs($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity)); + } else { + GitDeleteFromRs::dispatch($entity, Auth::user()); + Notification::send($entity->operators, new EntityDeletedFromRs($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity)); + }*/ return redirect() ->back() @@ -543,16 +543,16 @@ function () use ($entity, $category) { $color = $entity->hfd ? 'red' : 'green'; //TODO change HfD status -/* if ($entity->hfd) { - GitAddToHfd::dispatch($entity, Auth::user()); - Notification::send($entity->operators, new EntityAddedToHfd($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); - } else { - GitDeleteFromHfd::dispatch($entity, Auth::user()); - Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity)); - Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); - }*/ + /* if ($entity->hfd) { + GitAddToHfd::dispatch($entity, Auth::user()); + Notification::send($entity->operators, new EntityAddedToHfd($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity)); + } else { + GitDeleteFromHfd::dispatch($entity, Auth::user()); + Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity)); + Notification::send($entity->operators, new EntityDeletedFromHfd($entity)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity)); + }*/ return redirect() ->route('entities.show', $entity) diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index 1818f65..57b5c24 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -4,9 +4,6 @@ use App\Facades\EntityFacade; use App\Models\Entity; -use App\Notifications\EntityStateChanged; -use App\Notifications\EntityUpdated; -use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Exception; use Illuminate\Bus\Queueable; @@ -22,6 +19,7 @@ class EduGainAddEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use HandlesJobsFailuresTrait; + public Entity $entity; /** @@ -41,7 +39,7 @@ public function handle(): void $folderName = config('storageCfg.edu2edugain'); try { if (! Storage::disk($diskName)->exists($folderName)) { - throw new Exception("No $folderName in $diskName"); + throw new Exception("No $folderName in $diskName"); } } catch (Exception $e) { $this->fail($e); @@ -51,7 +49,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { $lock->block(61); - EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName); + EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName); //TODO write custom function to run special MDA script (ask about this) EduGainRunMdaScript::dispatch($lock->owner()); @@ -64,7 +62,5 @@ public function handle(): void } } - - } } diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 6152ea5..0b951b4 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -43,7 +43,7 @@ public function handle(): void $folderName = config('storageCfg.edu2edugain'); try { if (! Storage::disk($diskName)->exists($folderName)) { - throw new Exception("No $folderName in $diskName"); + throw new Exception("No $folderName in $diskName"); } } catch (Exception $e) { $this->fail($e); @@ -53,7 +53,7 @@ public function handle(): void $lock = Cache::lock($lockKey, 61); try { $lock->block(61); - EntityFacade::deleteEntityMetadataFromFolder($this->entity->file,$folderName); + EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); //TODO write custom function to run special MDA script (ask about this) diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php index b7e9514..c4f906e 100644 --- a/app/Jobs/EduGainRunMdaScript.php +++ b/app/Jobs/EduGainRunMdaScript.php @@ -54,8 +54,5 @@ public function handle(): void } - - - } } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index d56af97..beda436 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -3,13 +3,11 @@ namespace App\Jobs; use App\Facades\EntityFacade; -use App\Mail\ExceptionOccured; use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; use App\Notifications\EntityStateChanged; use App\Notifications\EntityUpdated; -use App\Services\EntityService; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; @@ -20,10 +18,8 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; use Mockery\Exception; -use Throwable; class FolderAddEntity implements ShouldQueue { @@ -34,7 +30,6 @@ class FolderAddEntity implements ShouldQueue */ use HandlesJobsFailuresTrait; - public Entity $entity; /** @@ -71,11 +66,10 @@ public function handle(): void $lock->block(61); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); - if ($this->entity->wasRecentlyCreated) { - NotificationService::sendEntityNotification($this->entity,EntityUpdated::class); + NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); } elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { - NotificationService::sendEntityNotification($this->entity,EntityStateChanged::class); + NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); } RunMdaScript::dispatch($federation, $lock->owner()); @@ -99,5 +93,4 @@ public function middleware(): array { return [(new WithoutOverlapping($this->entity->id))->dontRelease()]; } - } diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index b7af833..490faee 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -6,7 +6,6 @@ use App\Models\Entity; use App\Notifications\EntityDeletedFromHfd; use App\Notifications\EntityStateChanged; -use App\Services\EntityService; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; @@ -58,12 +57,11 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - NotificationService::sendEntityNotification($entity,EntityStateChanged::class); + NotificationService::sendEntityNotification($entity, EntityStateChanged::class); if ($entity->hfd) { - NotificationService::sendEntityNotification($entity,EntityDeletedFromHfd::class); + NotificationService::sendEntityNotification($entity, EntityDeletedFromHfd::class); } - RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php index 9e02d5c..43318e2 100644 --- a/app/Jobs/RunMdaScript.php +++ b/app/Jobs/RunMdaScript.php @@ -45,7 +45,6 @@ public function handle(): void $filterArray = explode(', ', $this->federation->filters); $scriptPath = config('storageCfg.mdaScript'); - $realScriptPath = realpath($scriptPath); try { @@ -77,11 +76,11 @@ public function middleware(): array { $diskName = config('storageCfg.name'); $pathToDirectory = Storage::disk($diskName)->path($this->federation->name); - $lockKey = 'directory-' . md5($pathToDirectory) . '-lock'; + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; return [ new RateLimited('mda-run-limit'), - (new WithoutOverlapping($lockKey))->dontRelease() + (new WithoutOverlapping($lockKey))->dontRelease(), ]; } diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php index 45043f1..be43a24 100644 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ b/app/Listeners/SendCreatedEntityToSaveJob.php @@ -25,7 +25,7 @@ public function handle(CreateEntity $event): void if ($event->entity->approved == 1) { FolderAddEntity::dispatch($event->entity); - if($event->entity->edugain == 1){ + if ($event->entity->edugain == 1) { EduGainAddEntity::dispatch($event->entity); } diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index 10e4d53..c8763ce 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -6,7 +6,6 @@ use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderDeleteEntity; - class SendDeletedEntityToDeleteJob { /** @@ -24,10 +23,9 @@ public function handle(DeleteEntity $event): void { FolderDeleteEntity::dispatch($event->entity); - if($event->entity->edugain == 1){ + if ($event->entity->edugain == 1) { EduGainDeleteEntity::dispatch($event->entity); } - } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 1123e7c..b6ef3cf 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -6,10 +6,8 @@ use App\Jobs\EduGainAddEntity; use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; -use App\Models\User; use App\Notifications\EntityUpdated; use App\Services\NotificationService; -use Illuminate\Support\Facades\Notification; class SendUpdatedEntityToSaveJob { @@ -31,24 +29,18 @@ public function handle(UpdateEntity $event): void if ($entity->wasChanged('xml_file') || ($entity->wasChanged('approved') && $entity->approved == 1) - ) - { + ) { FolderAddEntity::dispatch($event->entity); + } elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) { + NotificationService::sendEntityNotification($entity, EntityUpdated::class); } - elseif ($entity->approved == 1 && !$entity->wasChanged('edugain')) - { - NotificationService::sendEntityNotification($entity,EntityUpdated::class); - } - if($entity->wasChanged('edugain')) - { - if($entity->edugain == 1) { + if ($entity->wasChanged('edugain')) { + if ($entity->edugain == 1) { EduGainAddEntity::dispatch($entity); } else { EduGainDeleteEntity::dispatch($entity); } } - - } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 58e39d6..c206604 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -33,13 +33,13 @@ public function boot() // Mail::alwaysTo('foo@example.org'); Model::preventLazyLoading(); } -//TODO comment this for testing part -/* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { - $diskName = config('storageCfg.name'); - $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); - $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; - return Limit::perMinute(1)->by($lockKey); - });*/ + //TODO comment this for testing part + /* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) { + $diskName = config('storageCfg.name'); + $pathToDirectory = Storage::disk($diskName)->path($job->federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + return Limit::perMinute(1)->by($lockKey); + });*/ } } diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index cf82a1b..61097c0 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -1,23 +1,24 @@ select('id', 'email')->get(); $operators = $entity->operators->pluck('id')->toArray(); $filteredAdmins = $admins->filter(function ($admin) use ($operators) { - return !in_array($admin->id, $operators); + return ! in_array($admin->id, $operators); }); Notification::sendNow($entity->operators, new $notification($entity)); Notification::sendNow($filteredAdmins, new $notification($entity)); } - } diff --git a/app/Traits/HandlesJobsFailuresTrait.php b/app/Traits/HandlesJobsFailuresTrait.php index 732823c..7c10aa9 100644 --- a/app/Traits/HandlesJobsFailuresTrait.php +++ b/app/Traits/HandlesJobsFailuresTrait.php @@ -1,8 +1,10 @@ 'metadata', 'mdaConfigFolder' => env('MDA_CONFIG_FOLDER'), 'mdaScript' => env('MDA_SCRIPT'), - 'edu2edugain' =>env('EDU_TO_EDUGAIN_FOLDER'), + 'edu2edugain' => env('EDU_TO_EDUGAIN_FOLDER'), ]; From 7d13e99ea1c624774590f5ff371800b66266f304 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 15 Jul 2024 12:34:40 +0200 Subject: [PATCH 31/53] fix tests --- .../Controllers/CategoryControllerTest.php | 4 ++ .../Http/Controllers/EntityControllerTest.php | 57 +++++++++++++++++++ .../EntityMetadataControllerTest.php | 4 ++ .../Controllers/FederationControllerTest.php | 6 ++ .../Http/Controllers/GroupControllerTest.php | 4 ++ .../Controllers/StatisticControllerTest.php | 4 ++ tests/Feature/Mail/AskRsTest.php | 7 ++- 7 files changed, 85 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Http/Controllers/CategoryControllerTest.php b/tests/Feature/Http/Controllers/CategoryControllerTest.php index b5b6f24..5921773 100644 --- a/tests/Feature/Http/Controllers/CategoryControllerTest.php +++ b/tests/Feature/Http/Controllers/CategoryControllerTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\EduGainAddEntity; use App\Jobs\GitAddCategory; use App\Jobs\GitDeleteCategory; use App\Jobs\GitUpdateCategory; @@ -10,6 +11,7 @@ use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Bus; use Tests\TestCase; @@ -430,6 +432,7 @@ public function an_admin_can_delete_an_existing_category_without_members() /** @test */ public function an_admin_cannot_delete_an_existing_category_with_members() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $category = Category::factory()->create(); $category->entities()->save(Entity::factory()->create()); @@ -448,5 +451,6 @@ public function an_admin_cannot_delete_an_existing_category_with_members() $this->assertEquals(1, $category->entities()->count()); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('categories.show', $category), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } } diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index a3bc60a..aee1bcf 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -2,6 +2,8 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\EduGainAddEntity; +use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderDeleteEntity; use App\Models\Entity; use App\Models\Federation; @@ -31,6 +33,7 @@ public function an_anonymouse_user_isnt_shown_an_entities_list() /** @test */ public function an_anonymouse_user_isnt_shown_an_entities_details() { + Queue::fake(); $entity = Entity::factory()->create(); $this @@ -39,6 +42,7 @@ public function an_anonymouse_user_isnt_shown_an_entities_details() ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -73,6 +77,7 @@ public function an_anonymouse_user_cannot_add_a_new_entity() /** @test */ public function an_anonymouse_user_cannot_see_entities_edit_page() { + Queue::fake(); $entity = Entity::factory()->create(); $this @@ -82,11 +87,13 @@ public function an_anonymouse_user_cannot_see_entities_edit_page() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function an_anonymouse_user_cannot_edit_an_existing_entity() { + Queue::fake(); $entity = Entity::factory()->create(); $this @@ -96,11 +103,14 @@ public function an_anonymouse_user_cannot_edit_an_existing_entity() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function an_anonymouse_user_cannot_change_an_existing_entities_state() { + Queue::fake(); + $entity = Entity::factory()->create(); $this->assertFalse($entity->trashed()); @@ -112,11 +122,14 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_state() $this->assertFalse($entity->trashed()); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ public function an_anonymouse_user_cannot_change_an_existing_entities_operators() { + Queue::fake(); $entity = Entity::factory()->create(); $entity->operators()->attach(User::factory()->create()); $this->assertEquals(1, $entity->operators()->count()); @@ -144,11 +157,13 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_operators( $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function an_anonymouse_user_cannot_change_an_existing_entities_federation_membership() { + Queue::fake(); $entity = Entity::factory()->create(); $this @@ -160,11 +175,13 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_federation ->followingRedirects() ->post(route('entities.leave', $entity)) ->assertSeeText('login'); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function an_anonymouse_user_cannot_purge_an_existing_entity() { + Queue::fake(); $entity = Entity::factory()->create([ 'deleted_at' => now(), ]); @@ -175,6 +192,7 @@ public function an_anonymouse_user_cannot_purge_an_existing_entity() ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -218,6 +236,7 @@ public function a_user_is_shown_a_entities_list() { $this->assertEquals(0, Entity::count()); + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); @@ -230,6 +249,7 @@ public function a_user_is_shown_a_entities_list() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -237,6 +257,7 @@ public function a_user_is_shown_a_entities_details() { $this->assertEquals(0, Entity::count()); + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); @@ -250,6 +271,7 @@ public function a_user_is_shown_a_entities_details() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', $entity), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -470,6 +492,7 @@ public function a_user_can_add_a_new_entity() /** @test */ public function a_user_with_operator_permission_can_see_entities_edit_page() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $user->entities()->attach($entity); @@ -481,6 +504,7 @@ public function a_user_with_operator_permission_can_see_entities_edit_page() ->assertSeeText(__('entities.profile')); $this->assertEquals(route('entities.edit', $entity), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -689,6 +713,7 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ /** @test */ public function a_user_with_operator_permission_can_change_an_existing_entities_operators() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $user->entities()->attach($entity); @@ -721,11 +746,13 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ $entity->refresh(); $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('entities.show', $entity), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_with_operator_permission_can_change_an_existing_entities_federation_membership() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $user->entities()->attach($entity); @@ -744,11 +771,13 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); $this->assertEquals(1, Membership::whereApproved(false)->count()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_without_operator_permission_cannot_see_entities_edit_page() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); @@ -756,13 +785,16 @@ public function a_user_without_operator_permission_cannot_see_entities_edit_page ->actingAs($user) ->get(route('entities.edit', $entity)) ->assertForbidden(); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_without_operator_permission_cannot_edit_an_existing_entity() { + Queue::fake(); $entity = Entity::factory()->create(['entityid' => 'https://whoami.cesnet.cz/idp/shibboleth']); + $this ->followingRedirects() ->patch(route('entities.update', $entity), [ @@ -770,11 +802,13 @@ public function a_user_without_operator_permission_cannot_edit_an_existing_entit 'url' => 'https://whoami.cesnet.cz/idp/shibboleth', ]) ->assertSeeText('login'); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_without_operator_permission_cannot_change_an_existing_entities_state() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); @@ -784,11 +818,13 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent ->actingAs($user) ->patch(route('entities.update', $entity), ['action' => 'state']) ->assertForbidden(); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_without_operator_permission_cannot_change_an_existing_entities_operators() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $new_operator = User::factory()->create(); @@ -811,11 +847,13 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent 'operators' => [$new_operator->id], ]) ->assertForbidden(); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_without_operator_permission_cannot_change_an_existing_entities_federation_membership() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $federation = Federation::factory()->create(); @@ -833,11 +871,13 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent ->assertForbidden(); $this->assertEquals(0, Membership::whereApproved(false)->count()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function a_user_cannot_purge_an_existing_entity() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create([ 'deleted_at' => now(), @@ -848,6 +888,7 @@ public function a_user_cannot_purge_an_existing_entity() ->actingAs($user) ->delete(route('entities.destroy', $entity)) ->assertForbidden(); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -894,6 +935,7 @@ public function a_user_cannot_approve_a_new_entity_request() /** @test */ public function an_admin_is_shown_a_entities_list() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create(); @@ -906,11 +948,13 @@ public function an_admin_is_shown_a_entities_list() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function an_admin_is_shown_a_entities_details() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create(); @@ -924,6 +968,7 @@ public function an_admin_is_shown_a_entities_details() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', $entity), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -1115,6 +1160,7 @@ public function an_admin_can_add_a_new_entity() /** @test */ public function an_admin_can_see_entities_edit_page() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create(); @@ -1126,6 +1172,7 @@ public function an_admin_can_see_entities_edit_page() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.edit', $entity), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -1331,6 +1378,7 @@ public function an_admin_can_change_an_existing_entities_state() /** @test */ public function an_admin_can_change_an_existing_entities_operators() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create(); $new_operator = User::factory()->create(); @@ -1384,12 +1432,14 @@ public function an_admin_can_change_an_existing_entities_operators() $entity->refresh(); $this->assertEquals(0, $entity->operators()->count()); $this->assertEquals(route('entities.show', $entity), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function an_admin_can_change_an_existing_entities_federation_membership() { $this->withoutExceptionHandling(); + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create(); @@ -1407,6 +1457,7 @@ public function an_admin_can_change_an_existing_entities_federation_membership() ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); $this->assertEquals(1, Membership::whereApproved(false)->count()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -1476,6 +1527,7 @@ public function an_admin_can_approve_a_new_entity_request() /** @test */ public function not_even_an_admin_can_run_update_function_without_definig_action() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $entity = Entity::factory()->create(); @@ -1485,11 +1537,13 @@ public function not_even_an_admin_can_run_update_function_without_definig_action ->put(route('entities.update', $entity)); $this->assertEquals(route('home'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function ask_rs_isnt_shown_for_sp_entities_not_in_rs_federation() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(['type' => 'sp']); $user->entities()->attach($entity); @@ -1505,11 +1559,13 @@ public function ask_rs_isnt_shown_for_sp_entities_not_in_rs_federation() ->post(route('entities.rs', $entity)) ->assertStatus(403) ->assertSeeText(__('entities.rs_only_for_eduidcz_members')); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function ask_rs_is_shown_for_sp_entities_in_rs_federation() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(['type' => 'sp', 'rs' => false]); $user->entities()->attach($entity); @@ -1532,5 +1588,6 @@ public function ask_rs_is_shown_for_sp_entities_in_rs_federation() ->post(route('entities.rs', $entity)) ->assertStatus(200) ->assertSeeText(__('entities.rs_asked')); + Queue::assertPushed(EduGainAddEntity::class); } } diff --git a/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php b/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php index 711c2d9..eab166c 100644 --- a/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php @@ -2,9 +2,11 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\EduGainAddEntity; use App\Models\Entity; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class EntityMetadataControllerTest extends TestCase @@ -14,12 +16,14 @@ class EntityMetadataControllerTest extends TestCase /** @test */ public function anonymouse_user_is_redirected_to_login(): void { + Queue::fake(); $entity = Entity::factory()->create(); $this ->followingRedirects() ->get(route('entities.metadata', $entity)) ->assertSeeText('login'); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ diff --git a/tests/Feature/Http/Controllers/FederationControllerTest.php b/tests/Feature/Http/Controllers/FederationControllerTest.php index 4865cca..087297e 100644 --- a/tests/Feature/Http/Controllers/FederationControllerTest.php +++ b/tests/Feature/Http/Controllers/FederationControllerTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\EduGainAddEntity; use App\Jobs\GitDeleteMembers; use App\Jobs\GitUpdateFederation; use App\Jobs\Old_GitAddFederation; @@ -12,6 +13,7 @@ use App\Notifications\FederationRejected; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Notification; use Tests\TestCase; @@ -160,6 +162,7 @@ public function an_anonymouse_user_cannot_change_an_existing_federations_operato /** @test */ public function an_anonymouse_user_cannot_change_an_existing_federations_entities() { + Queue::fake(); $federation = Federation::factory()->create(); $user = User::factory()->create(); $entity = Entity::factory()->create(); @@ -194,6 +197,7 @@ public function an_anonymouse_user_cannot_change_an_existing_federations_entitie $this->assertEquals(1, $federation->entities()->count()); $this->assertEquals(route('login'), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ @@ -667,6 +671,7 @@ public function a_user_without_operator_permission_cannot_change_an_existing_fed /** @test */ public function a_user_without_operator_permission_cannot_change_an_existing_federations_entities() { + Queue::fake(); $federation = Federation::factory()->create(); $user = User::factory()->create(); $entity = Entity::factory()->create(); @@ -705,6 +710,7 @@ public function a_user_without_operator_permission_cannot_change_an_existing_fed $federation->refresh(); $this->assertEquals(1, $federation->entities()->count()); $this->assertEquals(route('federations.show', $federation), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ diff --git a/tests/Feature/Http/Controllers/GroupControllerTest.php b/tests/Feature/Http/Controllers/GroupControllerTest.php index 7726d77..e450207 100644 --- a/tests/Feature/Http/Controllers/GroupControllerTest.php +++ b/tests/Feature/Http/Controllers/GroupControllerTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\EduGainAddEntity; use App\Jobs\GitAddGroup; use App\Jobs\GitDeleteGroup; use App\Jobs\GitUpdateGroup; @@ -11,6 +12,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Bus; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class GroupControllerTest extends TestCase @@ -402,6 +404,7 @@ public function an_admin_can_delete_an_existing_group_without_members() /** @test */ public function an_admin_cannot_delete_an_existing_group_with_members() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $group = Group::factory()->create(); $group->entities()->save(Entity::factory()->create()); @@ -420,5 +423,6 @@ public function an_admin_cannot_delete_an_existing_group_with_members() $this->assertEquals(1, $group->entities()->count()); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('groups.show', $group), url()->current()); + Queue::assertPushed(EduGainAddEntity::class); } } diff --git a/tests/Feature/Http/Controllers/StatisticControllerTest.php b/tests/Feature/Http/Controllers/StatisticControllerTest.php index 536eec1..71951ad 100644 --- a/tests/Feature/Http/Controllers/StatisticControllerTest.php +++ b/tests/Feature/Http/Controllers/StatisticControllerTest.php @@ -2,11 +2,13 @@ namespace Tests\Feature\Http\Controllers; +use App\Jobs\EduGainAddEntity; use App\Models\Category; use App\Models\Entity; use App\Models\Federation; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class StatisticControllerTest extends TestCase @@ -16,6 +18,7 @@ class StatisticControllerTest extends TestCase /** @test */ public function it_produces_statistics(): void { + Queue::fake(); User::factory(2)->create(); Federation::factory(10)->hasAttached( Entity::factory()->count(10), @@ -81,5 +84,6 @@ public function it_produces_statistics(): void ], ], ]); + Queue::assertPushed(EduGainAddEntity::class); } } diff --git a/tests/Feature/Mail/AskRsTest.php b/tests/Feature/Mail/AskRsTest.php index 1a6aa85..5869a76 100644 --- a/tests/Feature/Mail/AskRsTest.php +++ b/tests/Feature/Mail/AskRsTest.php @@ -2,12 +2,14 @@ namespace Tests\Feature\Mail; +use App\Jobs\EduGainAddEntity; use App\Mail\AskRs; use App\Models\Entity; use App\Models\Federation; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class AskRsTest extends TestCase @@ -18,6 +20,7 @@ class AskRsTest extends TestCase public function email_is_queued_for_rs_federation_only() { Mail::fake(); + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(['type' => 'sp']); @@ -40,13 +43,14 @@ public function email_is_queued_for_rs_federation_only() return $email->hasTo(config('mail.admin.address')) && $email->entity->is($entity); }); + Queue::assertPushed(EduGainAddEntity::class); } /** @test */ public function email_isnt_queued_for_non_rs_federation() { Mail::fake(); - + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(['type' => 'sp']); $user->entities()->attach($entity); @@ -57,5 +61,6 @@ public function email_isnt_queued_for_non_rs_federation() ->assertStatus(403); Mail::assertNotQueued(AskRs::class); + Queue::assertPushed(EduGainAddEntity::class); } } From 3aa5ac3c3e7369e8b836ef5a493a09a3065a7817 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 15 Jul 2024 12:50:37 +0200 Subject: [PATCH 32/53] fix test and run pint --- .../Controllers/CategoryControllerTest.php | 4 +- .../Http/Controllers/EntityControllerTest.php | 54 +++++++++---------- .../EntityMetadataControllerTest.php | 3 +- .../Controllers/FederationControllerTest.php | 7 ++- .../Http/Controllers/GroupControllerTest.php | 3 +- .../Controllers/StatisticControllerTest.php | 3 +- tests/Feature/Mail/AskRsTest.php | 5 +- 7 files changed, 34 insertions(+), 45 deletions(-) diff --git a/tests/Feature/Http/Controllers/CategoryControllerTest.php b/tests/Feature/Http/Controllers/CategoryControllerTest.php index 5921773..906fdc2 100644 --- a/tests/Feature/Http/Controllers/CategoryControllerTest.php +++ b/tests/Feature/Http/Controllers/CategoryControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\EduGainAddEntity; use App\Jobs\GitAddCategory; use App\Jobs\GitDeleteCategory; use App\Jobs\GitUpdateCategory; @@ -11,8 +10,8 @@ use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Bus; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class CategoryControllerTest extends TestCase @@ -451,6 +450,5 @@ public function an_admin_cannot_delete_an_existing_category_with_members() $this->assertEquals(1, $category->entities()->count()); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('categories.show', $category), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); } } diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index aee1bcf..3b44fb8 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -2,8 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\EduGainAddEntity; -use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderDeleteEntity; use App\Models\Entity; use App\Models\Federation; @@ -42,7 +40,7 @@ public function an_anonymouse_user_isnt_shown_an_entities_details() ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -87,7 +85,7 @@ public function an_anonymouse_user_cannot_see_entities_edit_page() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -103,7 +101,7 @@ public function an_anonymouse_user_cannot_edit_an_existing_entity() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -122,7 +120,6 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_state() $this->assertFalse($entity->trashed()); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); } @@ -157,7 +154,7 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_operators( $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -175,7 +172,7 @@ public function an_anonymouse_user_cannot_change_an_existing_entities_federation ->followingRedirects() ->post(route('entities.leave', $entity)) ->assertSeeText('login'); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -192,7 +189,7 @@ public function an_anonymouse_user_cannot_purge_an_existing_entity() ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -249,7 +246,7 @@ public function a_user_is_shown_a_entities_list() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -271,7 +268,7 @@ public function a_user_is_shown_a_entities_details() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', $entity), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -504,7 +501,7 @@ public function a_user_with_operator_permission_can_see_entities_edit_page() ->assertSeeText(__('entities.profile')); $this->assertEquals(route('entities.edit', $entity), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -746,7 +743,7 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ $entity->refresh(); $this->assertEquals(1, $entity->operators()->count()); $this->assertEquals(route('entities.show', $entity), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -771,7 +768,7 @@ public function a_user_with_operator_permission_can_change_an_existing_entities_ ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); $this->assertEquals(1, Membership::whereApproved(false)->count()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -785,7 +782,7 @@ public function a_user_without_operator_permission_cannot_see_entities_edit_page ->actingAs($user) ->get(route('entities.edit', $entity)) ->assertForbidden(); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -794,7 +791,6 @@ public function a_user_without_operator_permission_cannot_edit_an_existing_entit Queue::fake(); $entity = Entity::factory()->create(['entityid' => 'https://whoami.cesnet.cz/idp/shibboleth']); - $this ->followingRedirects() ->patch(route('entities.update', $entity), [ @@ -802,7 +798,7 @@ public function a_user_without_operator_permission_cannot_edit_an_existing_entit 'url' => 'https://whoami.cesnet.cz/idp/shibboleth', ]) ->assertSeeText('login'); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -818,7 +814,7 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent ->actingAs($user) ->patch(route('entities.update', $entity), ['action' => 'state']) ->assertForbidden(); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -847,7 +843,7 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent 'operators' => [$new_operator->id], ]) ->assertForbidden(); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -871,7 +867,7 @@ public function a_user_without_operator_permission_cannot_change_an_existing_ent ->assertForbidden(); $this->assertEquals(0, Membership::whereApproved(false)->count()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -888,7 +884,7 @@ public function a_user_cannot_purge_an_existing_entity() ->actingAs($user) ->delete(route('entities.destroy', $entity)) ->assertForbidden(); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -948,7 +944,7 @@ public function an_admin_is_shown_a_entities_list() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.index'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -968,7 +964,7 @@ public function an_admin_is_shown_a_entities_details() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.show', $entity), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -1172,7 +1168,7 @@ public function an_admin_can_see_entities_edit_page() $this->assertEquals(1, Entity::count()); $this->assertEquals(route('entities.edit', $entity), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -1432,7 +1428,7 @@ public function an_admin_can_change_an_existing_entities_operators() $entity->refresh(); $this->assertEquals(0, $entity->operators()->count()); $this->assertEquals(route('entities.show', $entity), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -1457,7 +1453,7 @@ public function an_admin_can_change_an_existing_entities_federation_membership() ->assertSeeText(__('entities.join_requested', ['name' => $federation->name])); $this->assertEquals(1, Membership::whereApproved(false)->count()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -1537,7 +1533,7 @@ public function not_even_an_admin_can_run_update_function_without_definig_action ->put(route('entities.update', $entity)); $this->assertEquals(route('home'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -1559,7 +1555,7 @@ public function ask_rs_isnt_shown_for_sp_entities_not_in_rs_federation() ->post(route('entities.rs', $entity)) ->assertStatus(403) ->assertSeeText(__('entities.rs_only_for_eduidcz_members')); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -1588,6 +1584,6 @@ public function ask_rs_is_shown_for_sp_entities_in_rs_federation() ->post(route('entities.rs', $entity)) ->assertStatus(200) ->assertSeeText(__('entities.rs_asked')); - Queue::assertPushed(EduGainAddEntity::class); + } } diff --git a/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php b/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php index eab166c..be23a3c 100644 --- a/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\EduGainAddEntity; use App\Models\Entity; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -23,7 +22,7 @@ public function anonymouse_user_is_redirected_to_login(): void ->followingRedirects() ->get(route('entities.metadata', $entity)) ->assertSeeText('login'); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ diff --git a/tests/Feature/Http/Controllers/FederationControllerTest.php b/tests/Feature/Http/Controllers/FederationControllerTest.php index 087297e..a397501 100644 --- a/tests/Feature/Http/Controllers/FederationControllerTest.php +++ b/tests/Feature/Http/Controllers/FederationControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\EduGainAddEntity; use App\Jobs\GitDeleteMembers; use App\Jobs\GitUpdateFederation; use App\Jobs\Old_GitAddFederation; @@ -13,9 +12,9 @@ use App\Notifications\FederationRejected; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class FederationControllerTest extends TestCase @@ -197,7 +196,7 @@ public function an_anonymouse_user_cannot_change_an_existing_federations_entitie $this->assertEquals(1, $federation->entities()->count()); $this->assertEquals(route('login'), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -710,7 +709,7 @@ public function a_user_without_operator_permission_cannot_change_an_existing_fed $federation->refresh(); $this->assertEquals(1, $federation->entities()->count()); $this->assertEquals(route('federations.show', $federation), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ diff --git a/tests/Feature/Http/Controllers/GroupControllerTest.php b/tests/Feature/Http/Controllers/GroupControllerTest.php index e450207..28a44cd 100644 --- a/tests/Feature/Http/Controllers/GroupControllerTest.php +++ b/tests/Feature/Http/Controllers/GroupControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\EduGainAddEntity; use App\Jobs\GitAddGroup; use App\Jobs\GitDeleteGroup; use App\Jobs\GitUpdateGroup; @@ -423,6 +422,6 @@ public function an_admin_cannot_delete_an_existing_group_with_members() $this->assertEquals(1, $group->entities()->count()); $this->assertEquals(1, Entity::count()); $this->assertEquals(route('groups.show', $group), url()->current()); - Queue::assertPushed(EduGainAddEntity::class); + } } diff --git a/tests/Feature/Http/Controllers/StatisticControllerTest.php b/tests/Feature/Http/Controllers/StatisticControllerTest.php index 71951ad..d3cb938 100644 --- a/tests/Feature/Http/Controllers/StatisticControllerTest.php +++ b/tests/Feature/Http/Controllers/StatisticControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\EduGainAddEntity; use App\Models\Category; use App\Models\Entity; use App\Models\Federation; @@ -84,6 +83,6 @@ public function it_produces_statistics(): void ], ], ]); - Queue::assertPushed(EduGainAddEntity::class); + } } diff --git a/tests/Feature/Mail/AskRsTest.php b/tests/Feature/Mail/AskRsTest.php index 5869a76..631f109 100644 --- a/tests/Feature/Mail/AskRsTest.php +++ b/tests/Feature/Mail/AskRsTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Mail; -use App\Jobs\EduGainAddEntity; use App\Mail\AskRs; use App\Models\Entity; use App\Models\Federation; @@ -43,7 +42,7 @@ public function email_is_queued_for_rs_federation_only() return $email->hasTo(config('mail.admin.address')) && $email->entity->is($entity); }); - Queue::assertPushed(EduGainAddEntity::class); + } /** @test */ @@ -61,6 +60,6 @@ public function email_isnt_queued_for_non_rs_federation() ->assertStatus(403); Mail::assertNotQueued(AskRs::class); - Queue::assertPushed(EduGainAddEntity::class); + } } From 50c6fd7e9861f3740898a993aae7dddf25487966 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 15 Jul 2024 13:59:33 +0200 Subject: [PATCH 33/53] EduGain hobs now can create a folder and delete dont call only on soft delete --- app/Jobs/EduGainAddEntity.php | 8 ++++++-- app/Jobs/EduGainDeleteEntity.php | 9 +++++++-- app/Listeners/SendDeletedEntityToDeleteJob.php | 12 +++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index 57b5c24..b43d768 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -4,6 +4,7 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Traits\EdugainTrait; use App\Traits\HandlesJobsFailuresTrait; use Exception; use Illuminate\Bus\Queueable; @@ -18,7 +19,7 @@ class EduGainAddEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - use HandlesJobsFailuresTrait; + use HandlesJobsFailuresTrait,EdugainTrait; public Entity $entity; @@ -37,6 +38,10 @@ public function handle(): void { $diskName = config('storageCfg.name'); $folderName = config('storageCfg.edu2edugain'); + if (! Storage::disk($diskName)->exists($folderName)) { + $this->makeEdu2Edugain(); + } + try { if (! Storage::disk($diskName)->exists($folderName)) { throw new Exception("No $folderName in $diskName"); @@ -51,7 +56,6 @@ public function handle(): void $lock->block(61); EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName); - //TODO write custom function to run special MDA script (ask about this) EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 0b951b4..e31cdf1 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -4,6 +4,7 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Traits\EdugainTrait; use App\Traits\HandlesJobsFailuresTrait; use Exception; use Illuminate\Bus\Queueable; @@ -22,7 +23,7 @@ class EduGainDeleteEntity implements ShouldQueue /** * trait with failure function */ - use HandlesJobsFailuresTrait; + use HandlesJobsFailuresTrait,EdugainTrait; public Entity $entity; @@ -41,6 +42,11 @@ public function handle(): void { $diskName = config('storageCfg.name'); $folderName = config('storageCfg.edu2edugain'); + + if (! Storage::disk($diskName)->exists($folderName)) { + $this->makeEdu2Edugain(); + } + try { if (! Storage::disk($diskName)->exists($folderName)) { throw new Exception("No $folderName in $diskName"); @@ -55,7 +61,6 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); - //TODO write custom function to run special MDA script (ask about this) EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index c8763ce..04420d1 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -21,11 +21,17 @@ public function __construct() */ public function handle(DeleteEntity $event): void { - FolderDeleteEntity::dispatch($event->entity); + $entity = $event->entity; - if ($event->entity->edugain == 1) { - EduGainDeleteEntity::dispatch($event->entity); + if(!$entity->isForceDeleting()) + { + FolderDeleteEntity::dispatch($event->entity); + + if ($event->entity->edugain == 1) { + EduGainDeleteEntity::dispatch($event->entity); + } } + } } From c3fbdc7f06a3ad3942d93bcf559a96de078cd875 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 16 Jul 2024 10:16:51 +0200 Subject: [PATCH 34/53] fix test and run pint --- app/Jobs/EduGainAddEntity.php | 2 +- app/Jobs/EduGainDeleteEntity.php | 5 ++--- app/Listeners/SendDeletedEntityToDeleteJob.php | 4 +--- tests/Feature/Http/Controllers/EntityControllerTest.php | 3 --- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index b43d768..0e7c94c 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -19,7 +19,7 @@ class EduGainAddEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - use HandlesJobsFailuresTrait,EdugainTrait; + use EdugainTrait,HandlesJobsFailuresTrait; public Entity $entity; diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index e31cdf1..d74847d 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -23,7 +23,7 @@ class EduGainDeleteEntity implements ShouldQueue /** * trait with failure function */ - use HandlesJobsFailuresTrait,EdugainTrait; + use EdugainTrait,HandlesJobsFailuresTrait; public Entity $entity; @@ -44,7 +44,7 @@ public function handle(): void $folderName = config('storageCfg.edu2edugain'); if (! Storage::disk($diskName)->exists($folderName)) { - $this->makeEdu2Edugain(); + $this->makeEdu2Edugain(); } try { @@ -61,7 +61,6 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); - EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php index 04420d1..36ff8e9 100644 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ b/app/Listeners/SendDeletedEntityToDeleteJob.php @@ -23,8 +23,7 @@ public function handle(DeleteEntity $event): void { $entity = $event->entity; - if(!$entity->isForceDeleting()) - { + if (! $entity->isForceDeleting()) { FolderDeleteEntity::dispatch($event->entity); if ($event->entity->edugain == 1) { @@ -32,6 +31,5 @@ public function handle(DeleteEntity $event): void } } - } } diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index 3b44fb8..d761b93 100644 --- a/tests/Feature/Http/Controllers/EntityControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityControllerTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Http\Controllers; -use App\Jobs\FolderDeleteEntity; use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; @@ -1474,7 +1473,6 @@ public function an_admin_can_purge_an_existing_entity() ->delete(route('entities.destroy', $entity)) ->assertSeeText(__('entities.destroyed', ['name' => $name])); - Queue::assertPushed(FolderDeleteEntity::class); } /** @test */ @@ -1496,7 +1494,6 @@ public function an_admin_can_reject_a_new_entity_request() ->delete(route('memberships.destroy', $membership)) ->assertSeeText(__('federations.membership_rejected', ['entity' => $entity->name_en])); - Queue::assertPushed(FolderDeleteEntity::class); } /** @test */ From 7c080674ed2ff7f525128af819680eba76f63bf3 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 16 Jul 2024 14:42:58 +0200 Subject: [PATCH 35/53] notifications (without Membership accepted ) --- app/Jobs/EduGainAddEntity.php | 3 ++ app/Jobs/EduGainDeleteEntity.php | 4 +- app/Jobs/FolderAddEntity.php | 12 ++++-- app/Listeners/SendUpdatedEntityToSaveJob.php | 6 ++- app/Services/NotificationService.php | 45 +++++++++++++++++++- 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index 0e7c94c..592ffd4 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -4,6 +4,8 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Notifications\EntityEdugainStatusChanged; +use App\Services\NotificationService; use App\Traits\EdugainTrait; use App\Traits\HandlesJobsFailuresTrait; use Exception; @@ -56,6 +58,7 @@ public function handle(): void $lock->block(61); EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName); + NotificationService::sendEntityNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index d74847d..9bbed1a 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -4,6 +4,8 @@ use App\Facades\EntityFacade; use App\Models\Entity; +use App\Notifications\EntityEdugainStatusChanged; +use App\Services\NotificationService; use App\Traits\EdugainTrait; use App\Traits\HandlesJobsFailuresTrait; use Exception; @@ -60,7 +62,7 @@ public function handle(): void try { $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); - + NotificationService::sendEntityNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index beda436..1162efe 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -66,10 +66,16 @@ public function handle(): void $lock->block(61); EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); - if ($this->entity->wasRecentlyCreated) { - NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); - } elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { + if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); + } else + { + if($this->entity->wasChanged('approved') && $this->entity->approved == 1) { + NotificationService::sendEntityNotification($this->entity,); + } + else { + NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); + } } RunMdaScript::dispatch($federation, $lock->owner()); diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index b6ef3cf..25860cc 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -6,6 +6,10 @@ use App\Jobs\EduGainAddEntity; use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; +use App\Notifications\EntityAddedToHfd; +use App\Notifications\EntityAddedToRs; +use App\Notifications\EntityDeletedFromHfd; +use App\Notifications\EntityDeletedFromRs; use App\Notifications\EntityUpdated; use App\Services\NotificationService; @@ -32,7 +36,7 @@ public function handle(UpdateEntity $event): void ) { FolderAddEntity::dispatch($event->entity); } elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) { - NotificationService::sendEntityNotification($entity, EntityUpdated::class); + NotificationService::sendUpdateNotification($entity); } if ($entity->wasChanged('edugain')) { if ($entity->edugain == 1) { diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 61097c0..66820d3 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -4,11 +4,16 @@ use App\Models\Entity; use App\Models\User; +use App\Notifications\EntityAddedToHfd; +use App\Notifications\EntityAddedToRs; +use App\Notifications\EntityDeletedFromHfd; +use App\Notifications\EntityDeletedFromRs; +use App\Notifications\EntityUpdated; use Illuminate\Support\Facades\Notification; class NotificationService { - public static function sendEntityNotification(Entity $entity, $notification) + public static function sendEntityNotification(Entity $entity, $notification): void { $admins = User::activeAdmins()->select('id', 'email')->get(); @@ -21,4 +26,42 @@ public static function sendEntityNotification(Entity $entity, $notification) Notification::sendNow($entity->operators, new $notification($entity)); Notification::sendNow($filteredAdmins, new $notification($entity)); } + + private static function sendRsNotification(Entity $entity): bool + { + if($entity->wasChanged('rs')) { + + if($entity->rs == 1) { + self::sendEntityNotification($entity,EntityAddedToRs::class); + } else { + self::sendEntityNotification($entity,EntityDeletedFromRs::class); + } + return true; + } + return false; + } + private static function sendHfDNotification(Entity $entity): bool + { + if ($entity->wasChanged('hfd')) { + + if($entity->hfd) { + self::sendEntityNotification($entity,EntityAddedToHfd::class); + } else { + self::sendEntityNotification($entity,EntityDeletedFromHfd::class); + } + return true; + } + return false; + } + + + public static function sendUpdateNotification(Entity $entity): void + { + + if( !self::sendRsNotification($entity) && !self::sendHfDNotification($entity)){ + self::sendEntityNotification($entity,EntityUpdated::class); + } + + } + } From ff6062a0b8ffe458bc739873d380bb194b1cd523 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 17 Jul 2024 13:48:12 +0200 Subject: [PATCH 36/53] make better seeder run pint and fix FolderAddEntity --- app/Jobs/FolderAddEntity.php | 10 ++--- app/Listeners/SendUpdatedEntityToSaveJob.php | 5 --- app/Services/NotificationService.php | 39 ++++++++++++-------- database/seeders/DatabaseSeeder.php | 14 +++++++ 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 1162efe..11b30c9 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -68,12 +68,10 @@ public function handle(): void if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); - } else - { - if($this->entity->wasChanged('approved') && $this->entity->approved == 1) { - NotificationService::sendEntityNotification($this->entity,); - } - else { + } else { + if ($this->entity->wasChanged('approved') && $this->entity->approved == 1) { + NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); + } else { NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 25860cc..333c102 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -6,11 +6,6 @@ use App\Jobs\EduGainAddEntity; use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; -use App\Notifications\EntityAddedToHfd; -use App\Notifications\EntityAddedToRs; -use App\Notifications\EntityDeletedFromHfd; -use App\Notifications\EntityDeletedFromRs; -use App\Notifications\EntityUpdated; use App\Services\NotificationService; class SendUpdatedEntityToSaveJob diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 66820d3..6c429b0 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -15,6 +15,10 @@ class NotificationService { public static function sendEntityNotification(Entity $entity, $notification): void { + if ($notification == null) { + return; + } + $admins = User::activeAdmins()->select('id', 'email')->get(); $operators = $entity->operators->pluck('id')->toArray(); @@ -29,39 +33,42 @@ public static function sendEntityNotification(Entity $entity, $notification): vo private static function sendRsNotification(Entity $entity): bool { - if($entity->wasChanged('rs')) { + if ($entity->wasChanged('rs')) { - if($entity->rs == 1) { - self::sendEntityNotification($entity,EntityAddedToRs::class); + if ($entity->rs == 1) { + self::sendEntityNotification($entity, EntityAddedToRs::class); } else { - self::sendEntityNotification($entity,EntityDeletedFromRs::class); + self::sendEntityNotification($entity, EntityDeletedFromRs::class); } + return true; } + return false; } - private static function sendHfDNotification(Entity $entity): bool + + private static function sendHfDNotification(Entity $entity): bool { if ($entity->wasChanged('hfd')) { - if($entity->hfd) { - self::sendEntityNotification($entity,EntityAddedToHfd::class); - } else { - self::sendEntityNotification($entity,EntityDeletedFromHfd::class); - } - return true; + if ($entity->hfd) { + self::sendEntityNotification($entity, EntityAddedToHfd::class); + } else { + self::sendEntityNotification($entity, EntityDeletedFromHfd::class); } + + return true; + } + return false; } - - public static function sendUpdateNotification(Entity $entity): void + public static function sendUpdateNotification(Entity $entity): void { - if( !self::sendRsNotification($entity) && !self::sendHfDNotification($entity)){ - self::sendEntityNotification($entity,EntityUpdated::class); + if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) { + self::sendEntityNotification($entity, EntityUpdated::class); } } - } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index f6d7ff9..0ee88e5 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -7,10 +7,14 @@ use App\Models\Federation; use App\Models\Group; use App\Models\User; +use App\Traits\FederationTrait; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Storage; class DatabaseSeeder extends Seeder { + use FederationTrait; + /** * Seed the application's database. * @@ -18,11 +22,21 @@ class DatabaseSeeder extends Seeder */ public function run() { + $diskName = config('storageCfg.name'); + + if (Storage::disk($diskName)->exists('')) { + Storage::disk($diskName)->deleteDirectory(''); + } + User::factory()->create(['active' => true, 'admin' => true]); User::factory()->create(['active' => true, 'admin' => true]); User::factory()->create(['active' => false, 'admin' => true]); User::factory()->create(['active' => true]); User::factory(96)->create(); + + $edu2edugain = config('storageCfg.edu2edugain'); + $this->createFederationFolder($edu2edugain); + /* Federation::factory(20)->create(); Entity::factory(100)->create();*/ /* Category::factory(20)->create(); From d0a1cff6f10943d02e5fe4e5b3d715370cb3de0a Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 17 Jul 2024 16:27:47 +0200 Subject: [PATCH 37/53] make event to work with membership table --- app/Events/AddMembership.php | 29 +++++++++++++++++++ app/Jobs/FolderAddEntity.php | 2 ++ app/Listeners/SendNewMemberToSaveJob.php | 37 ++++++++++++++++++++++++ app/Models/Membership.php | 8 +++++ app/Providers/EventServiceProvider.php | 5 ++++ 5 files changed, 81 insertions(+) create mode 100644 app/Events/AddMembership.php create mode 100644 app/Listeners/SendNewMemberToSaveJob.php diff --git a/app/Events/AddMembership.php b/app/Events/AddMembership.php new file mode 100644 index 0000000..13dab23 --- /dev/null +++ b/app/Events/AddMembership.php @@ -0,0 +1,29 @@ +membership = $membership; + } + +} diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 11b30c9..ab3a7e2 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -47,8 +47,10 @@ public function handle(): void { $federationMembershipId = Membership::select('federation_id') ->where('entity_id', $this->entity->id) + ->where('approved', 1) ->get(); + $diskName = config('storageCfg.name'); foreach ($federationMembershipId as $fedId) { diff --git a/app/Listeners/SendNewMemberToSaveJob.php b/app/Listeners/SendNewMemberToSaveJob.php new file mode 100644 index 0000000..7092bdd --- /dev/null +++ b/app/Listeners/SendNewMemberToSaveJob.php @@ -0,0 +1,37 @@ +membership->entity_id; + $entity = Entity::find($entityId); + + + if ($entity->approved == 1 && $event->membership->approved == 1 ) { + Log::info(" dispatch FolderAddEntity from Listener SendNewMemberToSaveJob"); + } + + } +} diff --git a/app/Models/Membership.php b/app/Models/Membership.php index 9585666..f8cfed8 100644 --- a/app/Models/Membership.php +++ b/app/Models/Membership.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Events\AddMembership; use Illuminate\Database\Eloquent\Relations\Pivot; class Membership extends Pivot @@ -31,4 +32,11 @@ public function approver() { return $this->belongsTo('App\Models\User', 'approved_by'); } + + protected $dispatchesEvents = [ + 'updated' => AddMembership::class, + // 'deleted' => DeleteEntity::class, + + ]; + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b07c157..9582197 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Events\AddMembership; use App\Events\CreateEntity; use App\Events\DeleteEntity; use App\Events\FederationApprove; @@ -9,6 +10,7 @@ use App\Listeners\CreateFederationFolder; use App\Listeners\SendCreatedEntityToSaveJob; use App\Listeners\SendDeletedEntityToDeleteJob; +use App\Listeners\SendNewMemberToSaveJob; use App\Listeners\SendUpdatedEntityToSaveJob; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; @@ -38,6 +40,9 @@ class EventServiceProvider extends ServiceProvider DeleteEntity::class => [ SendDeletedEntityToDeleteJob::class, ], + AddMembership::class => [ + SendNewMemberToSaveJob::class, + ], ]; From 89f8ca62fa007c5480ae04b0c0f6238fee66876c Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Thu, 18 Jul 2024 10:55:39 +0200 Subject: [PATCH 38/53] add new save membership job --- app/Events/AddMembership.php | 6 -- app/Jobs/FolderAddEntity.php | 4 +- app/Jobs/FolderAddMembership.php | 64 ++++++++++++++++++++ app/Jobs/FolderDeleteMembership.php | 30 +++++++++ app/Listeners/SendNewMemberToSaveJob.php | 14 +---- app/Listeners/SendUpdatedEntityToSaveJob.php | 5 +- app/Models/Membership.php | 3 +- 7 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 app/Jobs/FolderAddMembership.php create mode 100644 app/Jobs/FolderDeleteMembership.php diff --git a/app/Events/AddMembership.php b/app/Events/AddMembership.php index 13dab23..59e3aee 100644 --- a/app/Events/AddMembership.php +++ b/app/Events/AddMembership.php @@ -3,11 +3,7 @@ namespace App\Events; use App\Models\Membership; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; @@ -17,7 +13,6 @@ class AddMembership public Membership $membership; - /** * Create a new event instance. */ @@ -25,5 +20,4 @@ public function __construct(Membership $membership) { $this->membership = $membership; } - } diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index ab3a7e2..2a7686f 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -17,7 +17,6 @@ use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; @@ -50,7 +49,6 @@ public function handle(): void ->where('approved', 1) ->get(); - $diskName = config('storageCfg.name'); foreach ($federationMembershipId as $fedId) { @@ -80,7 +78,7 @@ public function handle(): void RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { - Log::error($e->getMessage()); + $this->fail($e); } finally { if ($lock->isOwnedByCurrentProcess()) { $lock->release(); diff --git a/app/Jobs/FolderAddMembership.php b/app/Jobs/FolderAddMembership.php new file mode 100644 index 0000000..7a6b1e0 --- /dev/null +++ b/app/Jobs/FolderAddMembership.php @@ -0,0 +1,64 @@ +membership = $membership; + } + + /** + * Execute the job. + */ + public function handle(): void + { + Log::info('MEMBERSHIP START'); + $federation = Federation::find($this->membership->federation_id); + $entity = Entity::find($this->membership->entity_id); + $diskName = config('storageCfg.name'); + if (! Storage::disk($diskName)->exists($federation->name)) { + $this->fail(); + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + + try { + $lock->block(61); + EntityFacade::saveMetadataToFederationFolder($entity->id, $federation->id); + RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + $this->fail($e); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + } +} diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php new file mode 100644 index 0000000..6864b8b --- /dev/null +++ b/app/Jobs/FolderDeleteMembership.php @@ -0,0 +1,30 @@ +membership->entity_id; - $entity = Entity::find($entityId); - - if ($entity->approved == 1 && $event->membership->approved == 1 ) { - Log::info(" dispatch FolderAddEntity from Listener SendNewMemberToSaveJob"); + if ($event->membership->approved == 1) { + FolderAddMembership::dispatch($event->membership); } } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 333c102..139028f 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -7,6 +7,7 @@ use App\Jobs\EduGainDeleteEntity; use App\Jobs\FolderAddEntity; use App\Services\NotificationService; +use Illuminate\Support\Facades\Log; class SendUpdatedEntityToSaveJob { @@ -26,11 +27,11 @@ public function handle(UpdateEntity $event): void $entity = $event->entity; - if ($entity->wasChanged('xml_file') || - ($entity->wasChanged('approved') && $entity->approved == 1) + if ($entity->wasChanged('xml_file') ) { FolderAddEntity::dispatch($event->entity); } elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) { + Log::info('update some entity in SendUpdatedEntityToSaveJob'); NotificationService::sendUpdateNotification($entity); } if ($entity->wasChanged('edugain')) { diff --git a/app/Models/Membership.php b/app/Models/Membership.php index f8cfed8..abedeab 100644 --- a/app/Models/Membership.php +++ b/app/Models/Membership.php @@ -35,8 +35,7 @@ public function approver() protected $dispatchesEvents = [ 'updated' => AddMembership::class, - // 'deleted' => DeleteEntity::class, + // 'deleted' => DeleteEntity::class, ]; - } From cb3d3022c9c93533ad8a6e1f46e72290a25aa398 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Fri, 19 Jul 2024 10:23:39 +0200 Subject: [PATCH 39/53] add delete from federation --- .../EntityFederationController.php | 7 ++- app/Jobs/FolderDeleteMembership.php | 47 +++++++++++++++++-- ...on.php => Old_GitDeleteFromFederation.php} | 2 +- app/Models/Membership.php | 2 - 4 files changed, 50 insertions(+), 8 deletions(-) rename app/Jobs/{GitDeleteFromFederation.php => Old_GitDeleteFromFederation.php} (97%) diff --git a/app/Http/Controllers/EntityFederationController.php b/app/Http/Controllers/EntityFederationController.php index 240cf48..a657705 100644 --- a/app/Http/Controllers/EntityFederationController.php +++ b/app/Http/Controllers/EntityFederationController.php @@ -3,7 +3,8 @@ namespace App\Http\Controllers; use App\Http\Requests\JoinFederation; -use App\Jobs\GitDeleteFromFederation; +use App\Jobs\FolderDeleteMembership; +use App\Jobs\Old_GitDeleteFromFederation; use App\Models\Entity; use App\Models\Federation; use App\Models\User; @@ -80,7 +81,9 @@ public function destroy(Request $request, Entity $entity) foreach (request('federations') as $f) { $federation = Federation::find($f); - GitDeleteFromFederation::dispatch($entity, $federation, Auth::user()); + + 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/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 6864b8b..edb5a82 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -2,22 +2,40 @@ namespace App\Jobs; +use App\Facades\EntityFacade; +use App\Models\Entity; +use App\Models\Federation; +use App\Models\Membership; +use App\Notifications\EntityDeletedFromHfd; +use App\Notifications\EntityStateChanged; +use App\Services\NotificationService; +use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Storage; +use Mockery\Exception; class FolderDeleteMembership implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use HandlesJobsFailuresTrait; + + public Federation $federation; + public Entity $entity; + /** * Create a new job instance. */ - public function __construct() + public function __construct(Entity $entity, Federation $federation) { - // + $this->federation = $federation; + $this->entity = $entity; } /** @@ -25,6 +43,29 @@ public function __construct() */ public function handle(): void { - // + Log::info('MEMBERSHIP DELETE START'); + $federation = $this->federation; + $entity = $this->entity; + $diskName = config('storageCfg.name'); + if (! Storage::disk($diskName)->exists($federation->name)) { + $this->fail(); + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + + try { + $lock->block(61); + EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); + + RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + $this->fail($e); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + } } diff --git a/app/Jobs/GitDeleteFromFederation.php b/app/Jobs/Old_GitDeleteFromFederation.php similarity index 97% rename from app/Jobs/GitDeleteFromFederation.php rename to app/Jobs/Old_GitDeleteFromFederation.php index b7dc670..898f97c 100644 --- a/app/Jobs/GitDeleteFromFederation.php +++ b/app/Jobs/Old_GitDeleteFromFederation.php @@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitDeleteFromFederation implements ShouldQueue +class Old_GitDeleteFromFederation implements ShouldQueue { use Dispatchable, GitTrait, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Models/Membership.php b/app/Models/Membership.php index abedeab..358125d 100644 --- a/app/Models/Membership.php +++ b/app/Models/Membership.php @@ -35,7 +35,5 @@ public function approver() protected $dispatchesEvents = [ 'updated' => AddMembership::class, - // 'deleted' => DeleteEntity::class, - ]; } From 32e3d30ec6f3b34bb74f0675ecdc1359e63ccb47 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Fri, 19 Jul 2024 10:58:57 +0200 Subject: [PATCH 40/53] fix notification --- app/Jobs/FolderDeleteEntity.php | 2 +- app/Listeners/SendUpdatedEntityToSaveJob.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 490faee..9ec9440 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -57,7 +57,7 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - NotificationService::sendEntityNotification($entity, EntityStateChanged::class); + NotificationService::sendEntityNotification($entity, new EntityStateChanged($entity)); if ($entity->hfd) { NotificationService::sendEntityNotification($entity, EntityDeletedFromHfd::class); } diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php index 139028f..f648197 100644 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ b/app/Listeners/SendUpdatedEntityToSaveJob.php @@ -30,9 +30,12 @@ public function handle(UpdateEntity $event): void if ($entity->wasChanged('xml_file') ) { FolderAddEntity::dispatch($event->entity); - } elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) { - Log::info('update some entity in SendUpdatedEntityToSaveJob'); - NotificationService::sendUpdateNotification($entity); + } elseif ($entity->approved == 1 && !$entity->wasChanged('approved') ){ + + if(!$entity->wasChanged('edugain')){ + NotificationService::sendUpdateNotification($entity); + } + } if ($entity->wasChanged('edugain')) { if ($entity->edugain == 1) { From 359483c809ffe1899c549637dd719764912670c8 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Fri, 19 Jul 2024 13:04:47 +0200 Subject: [PATCH 41/53] fix fail part --- app/Jobs/EduGainRunMdaScript.php | 4 +++- app/Jobs/FolderDeleteEntity.php | 3 ++- app/Services/EntityService.php | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php index c4f906e..ca4855f 100644 --- a/app/Jobs/EduGainRunMdaScript.php +++ b/app/Jobs/EduGainRunMdaScript.php @@ -2,6 +2,7 @@ namespace App\Jobs; +use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -15,6 +16,7 @@ class EduGainRunMdaScript implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use HandlesJobsFailuresTrait; public string $owner; @@ -48,7 +50,7 @@ public function handle(): void dump($res); } catch (Exception $e) { - Log::error($e->getMessage()); + $this->fail($e); } finally { Cache::restoreLock($lockKey, $this->owner)->release(); diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 9ec9440..580a781 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -21,6 +21,7 @@ class FolderDeleteEntity implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use HandlesJobsFailuresTrait; /** * trait with failure function @@ -64,7 +65,7 @@ public function handle(): void RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { - Log::error($e->getMessage()); + $this->fail($e); } finally { if ($lock->isOwnedByCurrentProcess()) { $lock->release(); diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index f07263e..c76572b 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -5,6 +5,7 @@ use App\Models\Entity; use App\Models\Federation; use Exception; +use http\Exception\InvalidArgumentException; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; @@ -57,10 +58,10 @@ public function deleteEntityMetadataFromFolder($fileName, $folderName): void try { Storage::disk($diskName)->delete($pathToFile); } catch (Exception $e) { - Log::error("Failed to delete file: {$pathToFile}. Error: ".$e->getMessage()); + throw new InvalidArgumentException("Unable to delete file $pathToFile"); } } else { - Log::warning("File does not exist: {$pathToFile}"); + throw new InvalidArgumentException("Unable to delete file $pathToFile"); } } From aa68ba6fe848ddcd86231ddbfa25e4ab97964988 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 22 Jul 2024 13:08:45 +0200 Subject: [PATCH 42/53] rewrite event to observer --- app/Events/CreateEntity.php | 23 ------ app/Events/DeleteEntity.php | 23 ------ app/Events/UpdateEntity.php | 23 ------ app/Http/Controllers/EntityController.php | 2 +- app/Listeners/SendCreatedEntityToSaveJob.php | 34 -------- .../SendDeletedEntityToDeleteJob.php | 35 -------- app/Listeners/SendUpdatedEntityToSaveJob.php | 49 ----------- app/Models/Entity.php | 7 -- app/Observers/EntityObserver.php | 81 +++++++++++++++++++ app/Providers/EventServiceProvider.php | 19 +---- 10 files changed, 85 insertions(+), 211 deletions(-) delete mode 100644 app/Events/CreateEntity.php delete mode 100644 app/Events/DeleteEntity.php delete mode 100644 app/Events/UpdateEntity.php delete mode 100644 app/Listeners/SendCreatedEntityToSaveJob.php delete mode 100644 app/Listeners/SendDeletedEntityToDeleteJob.php delete mode 100644 app/Listeners/SendUpdatedEntityToSaveJob.php create mode 100644 app/Observers/EntityObserver.php diff --git a/app/Events/CreateEntity.php b/app/Events/CreateEntity.php deleted file mode 100644 index ff1fb9d..0000000 --- a/app/Events/CreateEntity.php +++ /dev/null @@ -1,23 +0,0 @@ -entity = $entity; - } -} diff --git a/app/Events/DeleteEntity.php b/app/Events/DeleteEntity.php deleted file mode 100644 index f296424..0000000 --- a/app/Events/DeleteEntity.php +++ /dev/null @@ -1,23 +0,0 @@ -entity = $entity; - } -} diff --git a/app/Events/UpdateEntity.php b/app/Events/UpdateEntity.php deleted file mode 100644 index 7d1f123..0000000 --- a/app/Events/UpdateEntity.php +++ /dev/null @@ -1,23 +0,0 @@ -entity = $entity; - } -} diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index 60f23e4..d9f9ddf 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -270,7 +270,7 @@ public function update(Request $request, Entity $entity) ->with('status', __('entities.not_changed')); } - // TODO notification + // TODO entityUpdated (functional) /* Bus::chain([ new GitUpdateEntity($entity, Auth::user()), function () use ($entity) { diff --git a/app/Listeners/SendCreatedEntityToSaveJob.php b/app/Listeners/SendCreatedEntityToSaveJob.php deleted file mode 100644 index be43a24..0000000 --- a/app/Listeners/SendCreatedEntityToSaveJob.php +++ /dev/null @@ -1,34 +0,0 @@ -entity->approved == 1) { - FolderAddEntity::dispatch($event->entity); - - if ($event->entity->edugain == 1) { - EduGainAddEntity::dispatch($event->entity); - } - - } - } -} diff --git a/app/Listeners/SendDeletedEntityToDeleteJob.php b/app/Listeners/SendDeletedEntityToDeleteJob.php deleted file mode 100644 index 36ff8e9..0000000 --- a/app/Listeners/SendDeletedEntityToDeleteJob.php +++ /dev/null @@ -1,35 +0,0 @@ -entity; - - if (! $entity->isForceDeleting()) { - FolderDeleteEntity::dispatch($event->entity); - - if ($event->entity->edugain == 1) { - EduGainDeleteEntity::dispatch($event->entity); - } - } - - } -} diff --git a/app/Listeners/SendUpdatedEntityToSaveJob.php b/app/Listeners/SendUpdatedEntityToSaveJob.php deleted file mode 100644 index f648197..0000000 --- a/app/Listeners/SendUpdatedEntityToSaveJob.php +++ /dev/null @@ -1,49 +0,0 @@ -entity; - - if ($entity->wasChanged('xml_file') - ) { - FolderAddEntity::dispatch($event->entity); - } elseif ($entity->approved == 1 && !$entity->wasChanged('approved') ){ - - if(!$entity->wasChanged('edugain')){ - NotificationService::sendUpdateNotification($entity); - } - - } - if ($entity->wasChanged('edugain')) { - if ($entity->edugain == 1) { - EduGainAddEntity::dispatch($entity); - } else { - EduGainDeleteEntity::dispatch($entity); - } - } - - } -} diff --git a/app/Models/Entity.php b/app/Models/Entity.php index c6b497c..7b269c9 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -94,11 +94,4 @@ public function scopeSearch($query, ?string $search = null) ->orWhere('description_cs', 'like', "%$search%"); } - protected $dispatchesEvents = [ - 'created' => CreateEntity::class, - 'updated' => UpdateEntity::class, - 'deleted' => DeleteEntity::class, - 'restored' => CreateEntity::class, - - ]; } diff --git a/app/Observers/EntityObserver.php b/app/Observers/EntityObserver.php new file mode 100644 index 0000000..7f451a2 --- /dev/null +++ b/app/Observers/EntityObserver.php @@ -0,0 +1,81 @@ +wasChanged('xml_file') + ) { + FolderAddEntity::dispatch($entity); + } elseif ($entity->approved == 1 && !$entity->wasChanged('approved') ){ + + if(!$entity->wasChanged('edugain')){ + NotificationService::sendUpdateNotification($entity); + } + + } + if ($entity->wasChanged('edugain')) { + if ($entity->edugain == 1) { + EduGainAddEntity::dispatch($entity); + } else { + EduGainDeleteEntity::dispatch($entity); + } + } + } + + /** + * Handle the Entity "deleted" event. + */ + public function deleted(Entity $entity): void + { + if (! $entity->isForceDeleting()) { + FolderDeleteEntity::dispatch($entity); + + if ($entity->edugain == 1) { + EduGainDeleteEntity::dispatch($entity); + } + } + } + + /** + * Handle the Entity "restored" event. + */ + public function restored(Entity $entity): void + { + if ($entity->approved == 1) { + FolderAddEntity::dispatch($entity); + + if ($entity->edugain == 1) { + EduGainAddEntity::dispatch($entity); + } + } + } + + /** + * Handle the Entity "force deleted" event. + */ + public function forceDeleted(Entity $entity): void + { + // + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 9582197..252198c 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -3,15 +3,11 @@ namespace App\Providers; use App\Events\AddMembership; -use App\Events\CreateEntity; -use App\Events\DeleteEntity; use App\Events\FederationApprove; -use App\Events\UpdateEntity; use App\Listeners\CreateFederationFolder; -use App\Listeners\SendCreatedEntityToSaveJob; -use App\Listeners\SendDeletedEntityToDeleteJob; use App\Listeners\SendNewMemberToSaveJob; -use App\Listeners\SendUpdatedEntityToSaveJob; +use App\Models\Entity; +use App\Observers\EntityObserver; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -31,15 +27,6 @@ class EventServiceProvider extends ServiceProvider FederationApprove::class => [ CreateFederationFolder::class, ], - CreateEntity::class => [ - SendCreatedEntityToSaveJob::class, - ], - UpdateEntity::class => [ - SendUpdatedEntityToSaveJob::class, - ], - DeleteEntity::class => [ - SendDeletedEntityToDeleteJob::class, - ], AddMembership::class => [ SendNewMemberToSaveJob::class, ], @@ -53,6 +40,6 @@ class EventServiceProvider extends ServiceProvider */ public function boot() { - // + Entity::observe(EntityObserver::class); } } From 8ef930e26160720ba5daa940bed2f46a72e92068 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 22 Jul 2024 13:19:14 +0200 Subject: [PATCH 43/53] fix bug with second update --- app/Observers/EntityObserver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Observers/EntityObserver.php b/app/Observers/EntityObserver.php index 7f451a2..6c247c9 100644 --- a/app/Observers/EntityObserver.php +++ b/app/Observers/EntityObserver.php @@ -8,8 +8,9 @@ use App\Jobs\FolderDeleteEntity; use App\Models\Entity; use App\Services\NotificationService; +use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit; -class EntityObserver +class EntityObserver implements ShouldHandleEventsAfterCommit { /** * Handle the Entity "created" event. @@ -29,7 +30,7 @@ public function updated(Entity $entity): void FolderAddEntity::dispatch($entity); } elseif ($entity->approved == 1 && !$entity->wasChanged('approved') ){ - if(!$entity->wasChanged('edugain')){ + if(!$entity->wasChanged('edugain') && !$entity->wasChanged('deleted_at')){ NotificationService::sendUpdateNotification($entity); } From 4069f7c97472cb25d3a62d51a4a8884fa0bb4f84 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Mon, 22 Jul 2024 14:42:09 +0200 Subject: [PATCH 44/53] make NotificationService.php more abstract and add notification to FolderAddMembership.php --- app/Http/Controllers/EntityController.php | 12 ++++++------ app/Http/Controllers/MembershipController.php | 2 +- app/Jobs/FolderAddEntity.php | 6 +++--- app/Jobs/FolderAddMembership.php | 12 ++++++++++++ app/Jobs/FolderDeleteEntity.php | 2 +- app/Services/NotificationService.php | 14 +++++++------- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/EntityController.php b/app/Http/Controllers/EntityController.php index d9f9ddf..bae70ef 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -312,7 +312,7 @@ function () use ($entity) { if ($entity->trashed()) { $entity->restore(); - //TODO restore chain + //TODO restore chain (functional) /* Bus::chain([ new GitAddEntity($entity, Auth::user()), new GitAddToHfd($entity, Auth::user()), @@ -343,7 +343,7 @@ function () use ($federation, $entity) { } else { $entity->delete(); - //TODO delete chain + //TODO delete chain (functional) /* Bus::chain([ new GitDeleteEntity($entity, Auth::user()), new GitDeleteFromHfd($entity, Auth::user()), @@ -430,7 +430,7 @@ function () use ($entity) { $status = $entity->edugain ? 'edugain' : 'no_edugain'; $color = $entity->edugain ? 'green' : 'red'; - // TODO add and delete from EDUGAIN + // TODO add and delete from EDUGAIN (functional) /* if ($entity->edugain) { Bus::chain([ new GitAddToEdugain($entity, Auth::user()), @@ -473,7 +473,7 @@ function () use ($entity) { $status = $entity->rs ? 'rs' : 'no_rs'; $color = $entity->rs ? 'green' : 'red'; - // TODO notification + // TODO notification (not ready ask about this) /* if ($entity->rs) { GitAddToRs::dispatch($entity, Auth::user()); Notification::send($entity->operators, new EntityAddedToRs($entity)); @@ -506,7 +506,7 @@ function () use ($entity) { $entity->category()->associate($category); $entity->save(); - // TODO work with category + // TODO work with category (not ready) /* Bus::chain([ new GitDeleteFromCategory($old_category, $entity, Auth::user()), new GitAddToCategory($category, $entity, Auth::user()), @@ -542,7 +542,7 @@ function () use ($entity, $category) { $status = $entity->hfd ? 'hfd' : 'no_hfd'; $color = $entity->hfd ? 'red' : 'green'; - //TODO change HfD status + //TODO change HfD status (not working) /* if ($entity->hfd) { GitAddToHfd::dispatch($entity, Auth::user()); Notification::send($entity->operators, new EntityAddedToHfd($entity)); diff --git a/app/Http/Controllers/MembershipController.php b/app/Http/Controllers/MembershipController.php index 17e64cd..be70847 100644 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -39,7 +39,7 @@ public function update(Membership $membership) $membership->update(); }); - // TODO chain of update membership chain + // TODO chain of update membership chain (functional) /* Bus::chain([ new Old_GitAddEntity($membership->entity, Auth::user()), new GitAddToHfd($membership->entity, Auth::user()), diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 2a7686f..99f4d29 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -67,12 +67,12 @@ public function handle(): void EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { - NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); + NotificationService::sendEntityNotification($this->entity, new EntityStateChanged($this->entity)); } else { if ($this->entity->wasChanged('approved') && $this->entity->approved == 1) { - NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class); + NotificationService::sendEntityNotification($this->entity, new EntityStateChanged($this->entity)); } else { - NotificationService::sendEntityNotification($this->entity, EntityUpdated::class); + NotificationService::sendEntityNotification($this->entity, new EntityUpdated($this->entity)); } } diff --git a/app/Jobs/FolderAddMembership.php b/app/Jobs/FolderAddMembership.php index 7a6b1e0..bd1d145 100644 --- a/app/Jobs/FolderAddMembership.php +++ b/app/Jobs/FolderAddMembership.php @@ -6,6 +6,10 @@ use App\Models\Entity; use App\Models\Federation; use App\Models\Membership; +use App\Notifications\EntityAddedToHfd; +use App\Notifications\EntityStateChanged; +use App\Notifications\MembershipAccepted; +use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -51,6 +55,14 @@ public function handle(): void try { $lock->block(61); EntityFacade::saveMetadataToFederationFolder($entity->id, $federation->id); + + NotificationService::sendEntityNotification($entity, new MembershipAccepted($this->membership)); + +/* if($this->membership->entity->hfd) { + NotificationService::sendEntityNotification($entity, new EntityAddedToHfd($this->membership->entity)); + }*/ + + RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { $this->fail($e); diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 580a781..20b72e7 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -60,7 +60,7 @@ public function handle(): void NotificationService::sendEntityNotification($entity, new EntityStateChanged($entity)); if ($entity->hfd) { - NotificationService::sendEntityNotification($entity, EntityDeletedFromHfd::class); + NotificationService::sendUpdateNotification($entity); } RunMdaScript::dispatch($federation, $lock->owner()); diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 6c429b0..6d5ead9 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -27,8 +27,8 @@ public static function sendEntityNotification(Entity $entity, $notification): vo return ! in_array($admin->id, $operators); }); - Notification::sendNow($entity->operators, new $notification($entity)); - Notification::sendNow($filteredAdmins, new $notification($entity)); + Notification::sendNow($entity->operators, $notification); + Notification::sendNow($filteredAdmins, $notification); } private static function sendRsNotification(Entity $entity): bool @@ -36,9 +36,9 @@ private static function sendRsNotification(Entity $entity): bool if ($entity->wasChanged('rs')) { if ($entity->rs == 1) { - self::sendEntityNotification($entity, EntityAddedToRs::class); + self::sendEntityNotification($entity, new EntityAddedToRs($entity)); } else { - self::sendEntityNotification($entity, EntityDeletedFromRs::class); + self::sendEntityNotification($entity, new EntityDeletedFromRs($entity)); } return true; @@ -52,9 +52,9 @@ private static function sendHfDNotification(Entity $entity): bool if ($entity->wasChanged('hfd')) { if ($entity->hfd) { - self::sendEntityNotification($entity, EntityAddedToHfd::class); + self::sendEntityNotification($entity, new EntityAddedToHfd($entity)); } else { - self::sendEntityNotification($entity, EntityDeletedFromHfd::class); + self::sendEntityNotification($entity, new EntityDeletedFromHfd($entity)); } return true; @@ -67,7 +67,7 @@ public static function sendUpdateNotification(Entity $entity): void { if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) { - self::sendEntityNotification($entity, EntityUpdated::class); + self::sendEntityNotification($entity, new EntityUpdated($entity)); } } From 42f57919a61153607fc4b5a8efff1aa05c44d7e2 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 09:12:09 +0200 Subject: [PATCH 45/53] make notification to FolderDeleteMembership.php (not tested --- app/Http/Controllers/MembershipController.php | 4 ++-- app/Jobs/FolderDeleteMembership.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/MembershipController.php b/app/Http/Controllers/MembershipController.php index be70847..5f1e1a9 100644 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -83,9 +83,9 @@ public function destroy(Membership $membership) $membership->delete(); - $admins = User::activeAdmins()->select('id', 'email')->get(); +/* $admins = User::activeAdmins()->select('id', 'email')->get(); Notification::send($operators, new MembershipRejected($entity, $federation)); - Notification::send($admins, new MembershipRejected($entity, $federation)); + Notification::send($admins, new MembershipRejected($entity, $federation));*/ return redirect() ->back() diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index edb5a82..4509f84 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -8,6 +8,7 @@ use App\Models\Membership; use App\Notifications\EntityDeletedFromHfd; use App\Notifications\EntityStateChanged; +use App\Notifications\MembershipRejected; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; use Illuminate\Bus\Queueable; @@ -58,6 +59,9 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); + + NotificationService::sendEntityNotification($entity,new MembershipRejected($entity->entityid,$federation->name)); + RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { $this->fail($e); From a002d72d668bef533f6498e6423228be3ab37c2e Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 09:13:23 +0200 Subject: [PATCH 46/53] rin pint --- app/Http/Controllers/EntityFederationController.php | 3 +-- app/Http/Controllers/MembershipController.php | 6 +++--- app/Jobs/EduGainRunMdaScript.php | 1 - app/Jobs/FolderAddMembership.php | 8 +++----- app/Jobs/FolderDeleteEntity.php | 4 +--- app/Jobs/FolderDeleteMembership.php | 10 +++------- app/Models/Entity.php | 4 ---- app/Observers/EntityObserver.php | 4 ++-- app/Services/EntityService.php | 3 +-- 9 files changed, 14 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/EntityFederationController.php b/app/Http/Controllers/EntityFederationController.php index a657705..919f85f 100644 --- a/app/Http/Controllers/EntityFederationController.php +++ b/app/Http/Controllers/EntityFederationController.php @@ -4,7 +4,6 @@ use App\Http\Requests\JoinFederation; use App\Jobs\FolderDeleteMembership; -use App\Jobs\Old_GitDeleteFromFederation; use App\Models\Entity; use App\Models\Federation; use App\Models\User; @@ -82,7 +81,7 @@ public function destroy(Request $request, Entity $entity) foreach (request('federations') as $f) { $federation = Federation::find($f); - FolderDeleteMembership::dispatch($entity,$federation); + 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/MembershipController.php b/app/Http/Controllers/MembershipController.php index 5f1e1a9..8f6cd09 100644 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -83,9 +83,9 @@ public function destroy(Membership $membership) $membership->delete(); -/* $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($operators, new MembershipRejected($entity, $federation)); - Notification::send($admins, new MembershipRejected($entity, $federation));*/ + /* $admins = User::activeAdmins()->select('id', 'email')->get(); + Notification::send($operators, new MembershipRejected($entity, $federation)); + Notification::send($admins, new MembershipRejected($entity, $federation));*/ return redirect() ->back() diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php index ca4855f..8713d11 100644 --- a/app/Jobs/EduGainRunMdaScript.php +++ b/app/Jobs/EduGainRunMdaScript.php @@ -9,7 +9,6 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; diff --git a/app/Jobs/FolderAddMembership.php b/app/Jobs/FolderAddMembership.php index bd1d145..5fe5e12 100644 --- a/app/Jobs/FolderAddMembership.php +++ b/app/Jobs/FolderAddMembership.php @@ -7,7 +7,6 @@ use App\Models\Federation; use App\Models\Membership; use App\Notifications\EntityAddedToHfd; -use App\Notifications\EntityStateChanged; use App\Notifications\MembershipAccepted; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; @@ -58,10 +57,9 @@ public function handle(): void NotificationService::sendEntityNotification($entity, new MembershipAccepted($this->membership)); -/* if($this->membership->entity->hfd) { - NotificationService::sendEntityNotification($entity, new EntityAddedToHfd($this->membership->entity)); - }*/ - + /* if($this->membership->entity->hfd) { + NotificationService::sendEntityNotification($entity, new EntityAddedToHfd($this->membership->entity)); + }*/ RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index 20b72e7..c1223c1 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -4,7 +4,6 @@ use App\Facades\EntityFacade; use App\Models\Entity; -use App\Notifications\EntityDeletedFromHfd; use App\Notifications\EntityStateChanged; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; @@ -14,7 +13,6 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; @@ -65,7 +63,7 @@ public function handle(): void RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { - $this->fail($e); + $this->fail($e); } finally { if ($lock->isOwnedByCurrentProcess()) { $lock->release(); diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 4509f84..4b5d0f5 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -5,9 +5,6 @@ use App\Facades\EntityFacade; use App\Models\Entity; use App\Models\Federation; -use App\Models\Membership; -use App\Notifications\EntityDeletedFromHfd; -use App\Notifications\EntityStateChanged; use App\Notifications\MembershipRejected; use App\Services\NotificationService; use App\Traits\HandlesJobsFailuresTrait; @@ -26,9 +23,9 @@ class FolderDeleteMembership implements ShouldQueue use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use HandlesJobsFailuresTrait; - public Federation $federation; - public Entity $entity; + public Federation $federation; + public Entity $entity; /** * Create a new job instance. @@ -59,8 +56,7 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - - NotificationService::sendEntityNotification($entity,new MembershipRejected($entity->entityid,$federation->name)); + NotificationService::sendEntityNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { diff --git a/app/Models/Entity.php b/app/Models/Entity.php index 7b269c9..d0b3d3c 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -3,9 +3,6 @@ namespace App\Models; use App\Enums\EntityType; -use App\Events\CreateEntity; -use App\Events\DeleteEntity; -use App\Events\UpdateEntity; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -93,5 +90,4 @@ public function scopeSearch($query, ?string $search = null) ->orWhere('description_en', 'like', "%$search%") ->orWhere('description_cs', 'like', "%$search%"); } - } diff --git a/app/Observers/EntityObserver.php b/app/Observers/EntityObserver.php index 6c247c9..d32e112 100644 --- a/app/Observers/EntityObserver.php +++ b/app/Observers/EntityObserver.php @@ -28,9 +28,9 @@ public function updated(Entity $entity): void if ($entity->wasChanged('xml_file') ) { FolderAddEntity::dispatch($entity); - } elseif ($entity->approved == 1 && !$entity->wasChanged('approved') ){ + } elseif ($entity->approved == 1 && ! $entity->wasChanged('approved')) { - if(!$entity->wasChanged('edugain') && !$entity->wasChanged('deleted_at')){ + if (! $entity->wasChanged('edugain') && ! $entity->wasChanged('deleted_at')) { NotificationService::sendUpdateNotification($entity); } diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index c76572b..cca6d64 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -6,7 +6,6 @@ use App\Models\Federation; use Exception; use http\Exception\InvalidArgumentException; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; class EntityService @@ -58,7 +57,7 @@ public function deleteEntityMetadataFromFolder($fileName, $folderName): void try { Storage::disk($diskName)->delete($pathToFile); } catch (Exception $e) { - throw new InvalidArgumentException("Unable to delete file $pathToFile"); + throw new InvalidArgumentException("Unable to delete file $pathToFile"); } } else { throw new InvalidArgumentException("Unable to delete file $pathToFile"); From 6cb3e98e38eb0af98a844a7e4cc6f3b1d61ec523 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 10:18:50 +0200 Subject: [PATCH 47/53] make delete with observer (no test) --- app/Events/AddMembership.php | 23 ---------- app/Jobs/FolderDeleteMembership.php | 6 +++ app/Listeners/SendNewMemberToSaveJob.php | 29 ------------ app/Models/Membership.php | 5 --- app/Observers/MembershipObserver.php | 57 ++++++++++++++++++++++++ app/Providers/EventServiceProvider.php | 8 ++-- 6 files changed, 66 insertions(+), 62 deletions(-) delete mode 100644 app/Events/AddMembership.php delete mode 100644 app/Listeners/SendNewMemberToSaveJob.php create mode 100644 app/Observers/MembershipObserver.php diff --git a/app/Events/AddMembership.php b/app/Events/AddMembership.php deleted file mode 100644 index 59e3aee..0000000 --- a/app/Events/AddMembership.php +++ /dev/null @@ -1,23 +0,0 @@ -membership = $membership; - } -} diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 4b5d0f5..7c936bf 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; +use function PHPUnit\Framework\isNull; class FolderDeleteMembership implements ShouldQueue { @@ -48,6 +49,11 @@ public function handle(): void if (! Storage::disk($diskName)->exists($federation->name)) { $this->fail(); } + $pathToFile = $federation->name.'/'.$entity->file; + if(! Storage::disk($diskName)->exists($pathToFile)) { + return; + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; $lock = Cache::lock($lockKey, 61); diff --git a/app/Listeners/SendNewMemberToSaveJob.php b/app/Listeners/SendNewMemberToSaveJob.php deleted file mode 100644 index 4137276..0000000 --- a/app/Listeners/SendNewMemberToSaveJob.php +++ /dev/null @@ -1,29 +0,0 @@ -membership->approved == 1) { - FolderAddMembership::dispatch($event->membership); - } - - } -} diff --git a/app/Models/Membership.php b/app/Models/Membership.php index 358125d..9585666 100644 --- a/app/Models/Membership.php +++ b/app/Models/Membership.php @@ -2,7 +2,6 @@ namespace App\Models; -use App\Events\AddMembership; use Illuminate\Database\Eloquent\Relations\Pivot; class Membership extends Pivot @@ -32,8 +31,4 @@ public function approver() { return $this->belongsTo('App\Models\User', 'approved_by'); } - - protected $dispatchesEvents = [ - 'updated' => AddMembership::class, - ]; } diff --git a/app/Observers/MembershipObserver.php b/app/Observers/MembershipObserver.php new file mode 100644 index 0000000..3b0b1e4 --- /dev/null +++ b/app/Observers/MembershipObserver.php @@ -0,0 +1,57 @@ +approved == 1) { + FolderAddMembership::dispatch($membership); + } + } + + /** + * Handle the Membership "deleted" event. + */ + public function deleted(Membership $membership): void + { + $entity = $membership->entity; + $federation = $membership->federation; + FolderDeleteMembership::dispatch($entity, $federation); + + + } + + /** + * Handle the Membership "restored" event. + */ + public function restored(Membership $membership): void + { + // + } + + /** + * Handle the Membership "force deleted" event. + */ + public function forceDeleted(Membership $membership): void + { + // + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 252198c..675c0ff 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,12 +2,12 @@ namespace App\Providers; -use App\Events\AddMembership; use App\Events\FederationApprove; use App\Listeners\CreateFederationFolder; -use App\Listeners\SendNewMemberToSaveJob; use App\Models\Entity; +use App\Models\Membership; use App\Observers\EntityObserver; +use App\Observers\MembershipObserver; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -27,9 +27,6 @@ class EventServiceProvider extends ServiceProvider FederationApprove::class => [ CreateFederationFolder::class, ], - AddMembership::class => [ - SendNewMemberToSaveJob::class, - ], ]; @@ -41,5 +38,6 @@ class EventServiceProvider extends ServiceProvider public function boot() { Entity::observe(EntityObserver::class); + Membership::observe(MembershipObserver::class); } } From f0dfe3ae38c015173ff43c3da2f4a46d157e3d66 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 10:33:56 +0200 Subject: [PATCH 48/53] make better notification in FolderDeleteMembership.php --- app/Jobs/FolderDeleteMembership.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 7c936bf..8097188 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -51,6 +51,7 @@ public function handle(): void } $pathToFile = $federation->name.'/'.$entity->file; if(! Storage::disk($diskName)->exists($pathToFile)) { + NotificationService::sendEntityNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); return; } @@ -62,7 +63,6 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - NotificationService::sendEntityNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { From aa9bcb4798134281120a45b4d83535a9e05393d4 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 10:45:58 +0200 Subject: [PATCH 49/53] fix entity request without entity bug --- .../views/federations/requests.blade.php | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/resources/views/federations/requests.blade.php b/resources/views/federations/requests.blade.php index 6078862..332846b 100644 --- a/resources/views/federations/requests.blade.php +++ b/resources/views/federations/requests.blade.php @@ -6,32 +6,35 @@ @include('federations.navigation') @forelse ($joins as $join) -
-
-
- -
-
{{ __('common.requester') }}
-
{{ $join->requester->name }} -
-
-
-
{{ __('common.explanation') }}
-
{{ $join->explanation }}
-
-
+ @if($join->entity) +
+
+
+ +
+
{{ __('common.requester') }}
+
{{ $join->requester->name }} +
+
+
+
{{ __('common.explanation') }}
+
{{ $join->explanation }}
+
+
+
+
+ + +
-
- - -
-
+ @endif + @empty {{ __('common.no_requests') }} @endforelse From 6bb0dc3990b6b734495faeb57a7cf8ca6dc85e44 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 11:19:55 +0200 Subject: [PATCH 50/53] make NotificationService.php more abstract --- app/Jobs/EduGainAddEntity.php | 2 +- app/Jobs/EduGainDeleteEntity.php | 2 +- app/Jobs/FolderAddEntity.php | 6 +++--- app/Jobs/FolderAddMembership.php | 2 +- app/Jobs/FolderDeleteEntity.php | 2 +- app/Jobs/FolderDeleteMembership.php | 2 +- app/Services/NotificationService.php | 27 +++++++++++++++++---------- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index 592ffd4..18ee149 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -58,7 +58,7 @@ public function handle(): void $lock->block(61); EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName); - NotificationService::sendEntityNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); + NotificationService::sendModelNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 9bbed1a..ee1182a 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -62,7 +62,7 @@ public function handle(): void try { $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName); - NotificationService::sendEntityNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); + NotificationService::sendModelNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php index 99f4d29..0a95c70 100644 --- a/app/Jobs/FolderAddEntity.php +++ b/app/Jobs/FolderAddEntity.php @@ -67,12 +67,12 @@ public function handle(): void EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { - NotificationService::sendEntityNotification($this->entity, new EntityStateChanged($this->entity)); + NotificationService::sendModelNotification($this->entity, new EntityStateChanged($this->entity)); } else { if ($this->entity->wasChanged('approved') && $this->entity->approved == 1) { - NotificationService::sendEntityNotification($this->entity, new EntityStateChanged($this->entity)); + NotificationService::sendModelNotification($this->entity, new EntityStateChanged($this->entity)); } else { - NotificationService::sendEntityNotification($this->entity, new EntityUpdated($this->entity)); + NotificationService::sendModelNotification($this->entity, new EntityUpdated($this->entity)); } } diff --git a/app/Jobs/FolderAddMembership.php b/app/Jobs/FolderAddMembership.php index 5fe5e12..e785474 100644 --- a/app/Jobs/FolderAddMembership.php +++ b/app/Jobs/FolderAddMembership.php @@ -55,7 +55,7 @@ public function handle(): void $lock->block(61); EntityFacade::saveMetadataToFederationFolder($entity->id, $federation->id); - NotificationService::sendEntityNotification($entity, new MembershipAccepted($this->membership)); + NotificationService::sendModelNotification($entity, new MembershipAccepted($this->membership)); /* if($this->membership->entity->hfd) { NotificationService::sendEntityNotification($entity, new EntityAddedToHfd($this->membership->entity)); diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php index c1223c1..51c1517 100644 --- a/app/Jobs/FolderDeleteEntity.php +++ b/app/Jobs/FolderDeleteEntity.php @@ -56,7 +56,7 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - NotificationService::sendEntityNotification($entity, new EntityStateChanged($entity)); + NotificationService::sendModelNotification($entity, new EntityStateChanged($entity)); if ($entity->hfd) { NotificationService::sendUpdateNotification($entity); } diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index 8097188..e90a262 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -51,7 +51,7 @@ public function handle(): void } $pathToFile = $federation->name.'/'.$entity->file; if(! Storage::disk($diskName)->exists($pathToFile)) { - NotificationService::sendEntityNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); + NotificationService::sendModelNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); return; } diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 6d5ead9..c60feb7 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -3,42 +3,49 @@ namespace App\Services; use App\Models\Entity; +use App\Models\Federation; use App\Models\User; use App\Notifications\EntityAddedToHfd; use App\Notifications\EntityAddedToRs; use App\Notifications\EntityDeletedFromHfd; use App\Notifications\EntityDeletedFromRs; use App\Notifications\EntityUpdated; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Notification; +use InvalidArgumentException; class NotificationService { - public static function sendEntityNotification(Entity $entity, $notification): void + public static function sendModelNotification(Model $model, $notification): void { if ($notification == null) { return; } - $admins = User::activeAdmins()->select('id', 'email')->get(); + if (!method_exists($model, 'operators')) { + throw new InvalidArgumentException('The given model does not have an operators relationship.'); + } - $operators = $entity->operators->pluck('id')->toArray(); + $admins = User::activeAdmins()->select('id', 'email')->get(); + $operators = $model->operators->pluck('id')->toArray(); $filteredAdmins = $admins->filter(function ($admin) use ($operators) { - return ! in_array($admin->id, $operators); + return !in_array($admin->id, $operators); }); - Notification::sendNow($entity->operators, $notification); + Notification::sendNow($model->operators, $notification); Notification::sendNow($filteredAdmins, $notification); } + private static function sendRsNotification(Entity $entity): bool { if ($entity->wasChanged('rs')) { if ($entity->rs == 1) { - self::sendEntityNotification($entity, new EntityAddedToRs($entity)); + self::sendModelNotification($entity, new EntityAddedToRs($entity)); } else { - self::sendEntityNotification($entity, new EntityDeletedFromRs($entity)); + self::sendModelNotification($entity, new EntityDeletedFromRs($entity)); } return true; @@ -52,9 +59,9 @@ private static function sendHfDNotification(Entity $entity): bool if ($entity->wasChanged('hfd')) { if ($entity->hfd) { - self::sendEntityNotification($entity, new EntityAddedToHfd($entity)); + self::sendModelNotification($entity, new EntityAddedToHfd($entity)); } else { - self::sendEntityNotification($entity, new EntityDeletedFromHfd($entity)); + self::sendModelNotification($entity, new EntityDeletedFromHfd($entity)); } return true; @@ -67,7 +74,7 @@ public static function sendUpdateNotification(Entity $entity): void { if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) { - self::sendEntityNotification($entity, new EntityUpdated($entity)); + self::sendModelNotification($entity, new EntityUpdated($entity)); } } From f5ecf7c1ff1dcb67f552ff835b511b27300c49f3 Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Tue, 23 Jul 2024 13:40:01 +0200 Subject: [PATCH 51/53] rewrite notification in FederationController.php to NotificationService.php and remove GitJob (not tested and run pint) --- app/Http/Controllers/FederationController.php | 53 +++++++++++-------- app/Jobs/FolderDeleteMembership.php | 5 +- app/Observers/MembershipObserver.php | 2 - app/Services/NotificationService.php | 28 ++++++---- .../Controllers/FederationControllerTest.php | 16 +++--- 5 files changed, 59 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 870eb51..65d90ca 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -17,6 +17,7 @@ use App\Notifications\FederationStateChanged; use App\Notifications\FederationUpdated; use App\Notifications\YourFederationRightsChanged; +use App\Services\NotificationService; use App\Traits\GitTrait; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -132,9 +133,9 @@ public function update(UpdateFederation $request, Federation $federation) $operators = $federation->operators; $admins = User::activeAdmins()->select('id', 'email')->get(); $federation->forceDelete(); - - Notification::send($operators, new FederationRejected($name)); - Notification::send($admins, new FederationRejected($name)); + NotificationService::sendModelNotification($federation, new FederationRejected($name)); + /* Notification::send($operators, new FederationRejected($name)); + Notification::send($admins, new FederationRejected($name));*/ return redirect('federations') ->with('status', __('federations.rejected', ['name' => $name])); @@ -146,10 +147,11 @@ public function update(UpdateFederation $request, Federation $federation) $federation->approved = true; $federation->update(); + NotificationService::sendModelNotification($federation, new FederationApproved($federation)); //GitAddFederation::dispatch($federation, 'approve', Auth::user()); - Notification::send($federation->operators, new FederationApproved($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationApproved($federation)); + /* Notification::send($federation->operators, new FederationApproved($federation)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationApproved($federation));*/ return redirect() ->route('federations.show', $federation) @@ -181,10 +183,10 @@ public function update(UpdateFederation $request, Federation $federation) return redirect() ->route('federations.show', $federation); } - + NotificationService::sendModelNotification($federation, new FederationUpdated($federation)); // GitUpdateFederation::dispatch($federation, Auth::user()); - Notification::send($federation->operators, new FederationUpdated($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationUpdated($federation)); + /* Notification::send($federation->operators, new FederationUpdated($federation)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationUpdated($federation));*/ return redirect() ->route('federations.show', $federation) @@ -200,15 +202,16 @@ public function update(UpdateFederation $request, Federation $federation) $state = $federation->trashed() ? 'deleted' : 'restored'; $color = $federation->trashed() ? 'red' : 'green'; + NotificationService::sendModelNotification($federation, new FederationStateChanged($federation)); + /* if ($federation->trashed()) { GitDeleteFederation::dispatch($federation, Auth::user()); } else { GitAddFederation::dispatch($federation, 'state', Auth::user()); }*/ - - Notification::send($federation->operators, new FederationStateChanged($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationStateChanged($federation)); + /* Notification::send($federation->operators, new FederationStateChanged($federation)); + Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationStateChanged($federation));*/ return redirect() ->route('federations.show', $federation) @@ -231,9 +234,11 @@ public function update(UpdateFederation $request, Federation $federation) $federation->operators()->attach(request('operators')); $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($new_operators, new YourFederationRightsChanged($federation, 'added')); - Notification::send($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); - Notification::send($admins, new FederationOperatorsChanged($federation, $new_operators, 'added')); + Notification::sendNow($new_operators, new YourFederationRightsChanged($federation, 'added')); + NotificationService::sendOperatorNotification($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); + + /* Notification::send($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); + Notification::send($admins, new FederationOperatorsChanged($federation, $new_operators, 'added'));*/ return redirect() ->route('federations.operators', $federation) @@ -255,9 +260,11 @@ public function update(UpdateFederation $request, Federation $federation) $new_operators = $federation->operators; $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($old_operators, new YourFederationRightsChanged($federation, 'deleted')); - Notification::send($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'deleted')); - Notification::send($admins, new FederationOperatorsChanged($federation, $old_operators, 'deleted')); + Notification::sendNow($old_operators, new YourFederationRightsChanged($federation, 'deleted')); + NotificationService::sendOperatorNotification($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'added')); + + /* Notification::send($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'deleted')); + Notification::send($admins, new FederationOperatorsChanged($federation, $old_operators, 'deleted'));*/ return redirect() ->route('federations.operators', $federation) @@ -283,11 +290,12 @@ public function update(UpdateFederation $request, Federation $federation) ]); $new_entities = Entity::whereIn('id', request('entities'))->get(); + NotificationService::sendModelNotification($federation, new FederationMembersChanged($federation, $new_entities, 'added')); //TODO add members to federation // GitAddMembers::dispatch($federation, $new_entities, Auth::user()); - Notification::send($federation->operators, new FederationMembersChanged($federation, $new_entities, 'added')); - Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $new_entities, 'added')); + /* Notification::send($federation->operators, new FederationMembersChanged($federation, $new_entities, 'added')); + Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $new_entities, 'added'));*/ return redirect() ->route('federations.entities', $federation) @@ -307,9 +315,10 @@ public function update(UpdateFederation $request, Federation $federation) $federation->entities()->detach(request('entities')); $old_entities = Entity::whereIn('id', request('entities'))->get(); - GitDeleteMembers::dispatch($federation, $old_entities, Auth::user()); - Notification::send($federation->operators, new FederationMembersChanged($federation, $old_entities, 'deleted')); - Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $old_entities, 'deleted')); + // GitDeleteMembers::dispatch($federation, $old_entities, Auth::user()); + /* Notification::send($federation->operators, new FederationMembersChanged($federation, $old_entities, 'deleted')); + Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $old_entities, 'deleted'));*/ + NotificationService::sendModelNotification($federation, new FederationMembersChanged($federation, $old_entities, 'deleted')); return redirect() ->route('federations.entities', $federation) diff --git a/app/Jobs/FolderDeleteMembership.php b/app/Jobs/FolderDeleteMembership.php index e90a262..c7c5800 100644 --- a/app/Jobs/FolderDeleteMembership.php +++ b/app/Jobs/FolderDeleteMembership.php @@ -17,7 +17,6 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Mockery\Exception; -use function PHPUnit\Framework\isNull; class FolderDeleteMembership implements ShouldQueue { @@ -50,8 +49,9 @@ public function handle(): void $this->fail(); } $pathToFile = $federation->name.'/'.$entity->file; - if(! Storage::disk($diskName)->exists($pathToFile)) { + if (! Storage::disk($diskName)->exists($pathToFile)) { NotificationService::sendModelNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); + return; } @@ -63,7 +63,6 @@ public function handle(): void $lock->block(61); EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); - RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { $this->fail($e); diff --git a/app/Observers/MembershipObserver.php b/app/Observers/MembershipObserver.php index 3b0b1e4..c639907 100644 --- a/app/Observers/MembershipObserver.php +++ b/app/Observers/MembershipObserver.php @@ -5,7 +5,6 @@ use App\Jobs\FolderAddMembership; use App\Jobs\FolderDeleteMembership; use App\Models\Membership; -use Illuminate\Support\Facades\Log; class MembershipObserver { @@ -36,7 +35,6 @@ public function deleted(Membership $membership): void $federation = $membership->federation; FolderDeleteMembership::dispatch($entity, $federation); - } /** diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index c60feb7..c3854e0 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -3,7 +3,6 @@ namespace App\Services; use App\Models\Entity; -use App\Models\Federation; use App\Models\User; use App\Notifications\EntityAddedToHfd; use App\Notifications\EntityAddedToRs; @@ -11,6 +10,7 @@ use App\Notifications\EntityDeletedFromRs; use App\Notifications\EntityUpdated; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Notification; use InvalidArgumentException; @@ -18,26 +18,34 @@ class NotificationService { public static function sendModelNotification(Model $model, $notification): void { - if ($notification == null) { - return; + if (! method_exists($model, 'operators')) { + throw new InvalidArgumentException('The given model does not have an operators relationship.'); } - if (!method_exists($model, 'operators')) { - throw new InvalidArgumentException('The given model does not have an operators relationship.'); + $operators = $model->operators; + + self::sendOperatorNotification($operators, $notification); + } + + public static function sendOperatorNotification(Collection $operators, $notification): void + { + if ($notification == null) { + return; } $admins = User::activeAdmins()->select('id', 'email')->get(); - $operators = $model->operators->pluck('id')->toArray(); - $filteredAdmins = $admins->filter(function ($admin) use ($operators) { - return !in_array($admin->id, $operators); + $operatorIds = $operators->pluck('id'); + + $filteredAdmins = $admins->filter(function ($admin) use ($operatorIds) { + return ! $operatorIds->contains($admin->id); }); - Notification::sendNow($model->operators, $notification); + Notification::sendNow($operators, $notification); + Notification::sendNow($filteredAdmins, $notification); } - private static function sendRsNotification(Entity $entity): bool { if ($entity->wasChanged('rs')) { diff --git a/tests/Feature/Http/Controllers/FederationControllerTest.php b/tests/Feature/Http/Controllers/FederationControllerTest.php index a397501..c4c0a8c 100644 --- a/tests/Feature/Http/Controllers/FederationControllerTest.php +++ b/tests/Feature/Http/Controllers/FederationControllerTest.php @@ -534,10 +534,10 @@ public function a_user_with_operator_permission_can_change_an_existing_federatio $this->assertEquals(1, $federation->entities()->count()); $this->assertEquals(route('federations.entities', $federation), url()->current()); - Bus::assertDispatched(GitDeleteMembers::class, function ($job) use ($federation, $new_entity) { - return $job->federation->is($federation) && - $job->entities->contains($new_entity); - }); + /* Bus::assertDispatched(GitDeleteMembers::class, function ($job) use ($federation, $new_entity) { + return $job->federation->is($federation) && + $job->entities->contains($new_entity); + });*/ } /** @test */ @@ -1119,10 +1119,10 @@ public function an_admin_can_change_an_existing_federations_entities() $this->assertEquals(1, $federation->entities()->count()); $this->assertEquals(route('federations.entities', $federation), url()->current()); - Bus::assertDispatched(GitDeleteMembers::class, function ($job) use ($federation, $new_entity) { - return $job->federation->is($federation) && - $job->entities->contains($new_entity); - }); + /* Bus::assertDispatched(GitDeleteMembers::class, function ($job) use ($federation, $new_entity) { + return $job->federation->is($federation) && + $job->entities->contains($new_entity); + });*/ } /** @test */ From 89a2074609dac2a88d00d90213776d281f83d6ab Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 24 Jul 2024 09:29:44 +0200 Subject: [PATCH 52/53] delete old notification in FederationController.php --- app/Http/Controllers/FederationController.php | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 65d90ca..16225fb 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -83,7 +83,7 @@ public function store(StoreFederation $request) }); $admins = User::activeAdmins()->select('id', 'email')->get(); - Notification::send($admins, new FederationRequested($federation)); + Notification::sendNow($admins, new FederationRequested($federation)); return redirect('federations') ->with('status', __('federations.requested', ['name' => $federation->name])); @@ -130,12 +130,8 @@ public function update(UpdateFederation $request, Federation $federation) $this->authorize('update', $federation); $name = $federation->name; - $operators = $federation->operators; - $admins = User::activeAdmins()->select('id', 'email')->get(); $federation->forceDelete(); NotificationService::sendModelNotification($federation, new FederationRejected($name)); - /* Notification::send($operators, new FederationRejected($name)); - Notification::send($admins, new FederationRejected($name));*/ return redirect('federations') ->with('status', __('federations.rejected', ['name' => $name])); @@ -150,8 +146,6 @@ public function update(UpdateFederation $request, Federation $federation) NotificationService::sendModelNotification($federation, new FederationApproved($federation)); //GitAddFederation::dispatch($federation, 'approve', Auth::user()); - /* Notification::send($federation->operators, new FederationApproved($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationApproved($federation));*/ return redirect() ->route('federations.show', $federation) @@ -185,8 +179,6 @@ public function update(UpdateFederation $request, Federation $federation) } NotificationService::sendModelNotification($federation, new FederationUpdated($federation)); // GitUpdateFederation::dispatch($federation, Auth::user()); - /* Notification::send($federation->operators, new FederationUpdated($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationUpdated($federation));*/ return redirect() ->route('federations.show', $federation) @@ -210,8 +202,6 @@ public function update(UpdateFederation $request, Federation $federation) GitAddFederation::dispatch($federation, 'state', Auth::user()); }*/ - /* Notification::send($federation->operators, new FederationStateChanged($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationStateChanged($federation));*/ return redirect() ->route('federations.show', $federation) @@ -237,8 +227,7 @@ public function update(UpdateFederation $request, Federation $federation) Notification::sendNow($new_operators, new YourFederationRightsChanged($federation, 'added')); NotificationService::sendOperatorNotification($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); - /* Notification::send($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); - Notification::send($admins, new FederationOperatorsChanged($federation, $new_operators, 'added'));*/ + return redirect() ->route('federations.operators', $federation) @@ -263,8 +252,6 @@ public function update(UpdateFederation $request, Federation $federation) Notification::sendNow($old_operators, new YourFederationRightsChanged($federation, 'deleted')); NotificationService::sendOperatorNotification($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'added')); - /* Notification::send($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'deleted')); - Notification::send($admins, new FederationOperatorsChanged($federation, $old_operators, 'deleted'));*/ return redirect() ->route('federations.operators', $federation) @@ -294,8 +281,7 @@ public function update(UpdateFederation $request, Federation $federation) //TODO add members to federation // GitAddMembers::dispatch($federation, $new_entities, Auth::user()); - /* Notification::send($federation->operators, new FederationMembersChanged($federation, $new_entities, 'added')); - Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $new_entities, 'added'));*/ + return redirect() ->route('federations.entities', $federation) @@ -316,8 +302,6 @@ public function update(UpdateFederation $request, Federation $federation) $old_entities = Entity::whereIn('id', request('entities'))->get(); // GitDeleteMembers::dispatch($federation, $old_entities, Auth::user()); - /* Notification::send($federation->operators, new FederationMembersChanged($federation, $old_entities, 'deleted')); - Notification::send(User::activeAdmins()->select('id', 'emails')->get(), new FederationMembersChanged($federation, $old_entities, 'deleted'));*/ NotificationService::sendModelNotification($federation, new FederationMembersChanged($federation, $old_entities, 'deleted')); return redirect() From 44394f2acff9156a0b5e4c1e06f76d764b4e928b Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Wed, 24 Jul 2024 10:35:05 +0200 Subject: [PATCH 53/53] fix notification problem --- app/Http/Controllers/FederationController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 16225fb..4da909b 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -130,8 +130,8 @@ public function update(UpdateFederation $request, Federation $federation) $this->authorize('update', $federation); $name = $federation->name; - $federation->forceDelete(); NotificationService::sendModelNotification($federation, new FederationRejected($name)); + $federation->forceDelete(); return redirect('federations') ->with('status', __('federations.rejected', ['name' => $name])); @@ -227,8 +227,6 @@ public function update(UpdateFederation $request, Federation $federation) Notification::sendNow($new_operators, new YourFederationRightsChanged($federation, 'added')); NotificationService::sendOperatorNotification($old_operators, new FederationOperatorsChanged($federation, $new_operators, 'added')); - - return redirect() ->route('federations.operators', $federation) ->with('status', __('federations.operators_added')); @@ -252,7 +250,6 @@ public function update(UpdateFederation $request, Federation $federation) Notification::sendNow($old_operators, new YourFederationRightsChanged($federation, 'deleted')); NotificationService::sendOperatorNotification($new_operators, new FederationOperatorsChanged($federation, $old_operators, 'added')); - return redirect() ->route('federations.operators', $federation) ->with('status', __('federations.operators_deleted')); @@ -282,7 +279,6 @@ public function update(UpdateFederation $request, Federation $federation) //TODO add members to federation // GitAddMembers::dispatch($federation, $new_entities, Auth::user()); - return redirect() ->route('federations.entities', $federation) ->with('status', __('federations.entities_added'));