diff --git a/.env.example b/.env.example index 1070d8f..d7863f2 100644 --- a/.env.example +++ b/.env.example @@ -62,6 +62,10 @@ 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 +EDU_TO_EDUGAIN_FOLDER="eduid2edugain" + GIT_REMOTE=user@git.example.org:repository GIT_REMOTE_BRANCH=main GIT_LOCAL=/home/user/metaman/storage/git @@ -86,4 +90,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/app/Console/Commands/DumpFromGit.php b/app/Console/Commands/DumpFromGit.php index 4113418..28db647 100644 --- a/app/Console/Commands/DumpFromGit.php +++ b/app/Console/Commands/DumpFromGit.php @@ -2,8 +2,8 @@ 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; @@ -14,17 +14,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,35 +42,37 @@ 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'); + } + 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(); - $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/Console/Commands/ValidateMetaConsole.php b/app/Console/Commands/ValidateMetaConsole.php index 55cab09..f60d0ef 100644 --- a/app/Console/Commands/ValidateMetaConsole.php +++ b/app/Console/Commands/ValidateMetaConsole.php @@ -3,8 +3,10 @@ namespace App\Console\Commands; 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 @@ -23,32 +25,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 +50,59 @@ 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) { } } } + 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->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/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 1a08c1d..bae70ef 100644 --- a/app/Http/Controllers/EntityController.php +++ b/app/Http/Controllers/EntityController.php @@ -3,20 +3,15 @@ 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; @@ -51,8 +46,8 @@ class EntityController extends Controller { - use ValidatorTrait, GitTrait; use DeleteFromEntity,UpdateEntity; + use GitTrait, ValidatorTrait; public function __construct() { @@ -130,7 +125,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()); @@ -139,7 +134,6 @@ public function store(StoreEntity $request) 'requested_by' => Auth::id(), ]); - $this->updateEntityXml(Entity::where('id', $entity['id'])->first()); return $entity; }); @@ -157,7 +151,6 @@ public function store(StoreEntity $request) ->back() ->with('status', "{$result['error']} {$result['message']}") ->with('color', 'red'); - break; default: @@ -171,7 +164,6 @@ public function store(StoreEntity $request) /** * Display the specified resource. * - * @param \App\Models\Entity $entity * @return \Illuminate\Http\Response */ public function show(Entity $entity) @@ -198,7 +190,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) @@ -213,8 +204,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) @@ -256,19 +245,24 @@ public function update(Request $request, Entity $entity) switch ($result['code']) { case '0': - $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'], - ]); - - if ($entity->type->value === 'idp') { - $entity->update(['rs' => $updated_entity['rs']]); - } + $xml_file = $this->deleteTags($updated_entity['metadata']); + + 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,14 +270,15 @@ public function update(Request $request, Entity $entity) ->with('status', __('entities.not_changed')); } - 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(); + // TODO entityUpdated (functional) + /* 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) @@ -313,53 +308,57 @@ function () use ($entity) { case 'state': $this->authorize('delete', $entity); + // TODO restore 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(); - - 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(); - } + //TODO restore chain (functional) + /* 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(); + }*/ } else { $entity->delete(); - 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(); + //TODO delete chain (functional) + /* 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'; @@ -431,25 +430,26 @@ function () use ($entity) { $status = $entity->edugain ? 'edugain' : 'no_edugain'; $color = $entity->edugain ? 'green' : 'red'; - 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(); - } + // TODO add and delete from EDUGAIN (functional) + /* 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() @@ -473,15 +473,16 @@ function () use ($entity) { $status = $entity->rs ? 'rs' : 'no_rs'; $color = $entity->rs ? 'green' : 'red'; - 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)); - } + // TODO notification (not ready ask about this) + /* 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() @@ -505,14 +506,15 @@ function () use ($entity) { $entity->category()->associate($category); $entity->save(); - 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(); + // TODO work with category (not ready) + /* 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() @@ -540,16 +542,17 @@ function () use ($entity, $category) { $status = $entity->hfd ? 'hfd' : 'no_hfd'; $color = $entity->hfd ? 'red' : 'green'; - 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)); - } + //TODO change HfD status (not working) + /* 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) @@ -566,7 +569,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) @@ -579,7 +581,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/EntityFederationController.php b/app/Http/Controllers/EntityFederationController.php index 240cf48..919f85f 100644 --- a/app/Http/Controllers/EntityFederationController.php +++ b/app/Http/Controllers/EntityFederationController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use App\Http\Requests\JoinFederation; -use App\Jobs\GitDeleteFromFederation; +use App\Jobs\FolderDeleteMembership; use App\Models\Entity; use App\Models\Federation; use App\Models\User; @@ -80,7 +80,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/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..4da909b 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; @@ -18,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; @@ -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, @@ -86,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])); @@ -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) @@ -136,13 +130,9 @@ public function update(UpdateFederation $request, Federation $federation) $this->authorize('update', $federation); $name = $federation->name; - $operators = $federation->operators; - $admins = User::activeAdmins()->select('id', 'email')->get(); + NotificationService::sendModelNotification($federation, new FederationRejected($name)); $federation->forceDelete(); - Notification::send($operators, new FederationRejected($name)); - Notification::send($admins, new FederationRejected($name)); - return redirect('federations') ->with('status', __('federations.rejected', ['name' => $name])); @@ -153,10 +143,9 @@ 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)); return redirect() ->route('federations.show', $federation) @@ -164,20 +153,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'; } @@ -190,10 +177,8 @@ public function update(UpdateFederation $request, Federation $federation) return redirect() ->route('federations.show', $federation); } - - // GitUpdateFederation::dispatch($federation, Auth::user()); - Notification::send($federation->operators, new FederationUpdated($federation)); - Notification::send(User::activeAdmins()->select('id', 'email')->get(), new FederationUpdated($federation)); + NotificationService::sendModelNotification($federation, new FederationUpdated($federation)); + // GitUpdateFederation::dispatch($federation, Auth::user()); return redirect() ->route('federations.show', $federation) @@ -209,16 +194,14 @@ 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 { + /* 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)); + GitAddFederation::dispatch($federation, 'state', Auth::user()); + }*/ return redirect() ->route('federations.show', $federation) @@ -241,9 +224,8 @@ 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')); return redirect() ->route('federations.operators', $federation) @@ -265,9 +247,8 @@ 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')); return redirect() ->route('federations.operators', $federation) @@ -293,9 +274,10 @@ public function update(UpdateFederation $request, Federation $federation) ]); $new_entities = Entity::whereIn('id', request('entities'))->get(); - 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')); + NotificationService::sendModelNotification($federation, new FederationMembersChanged($federation, $new_entities, 'added')); + + //TODO add members to federation + // GitAddMembers::dispatch($federation, $new_entities, Auth::user()); return redirect() ->route('federations.entities', $federation) @@ -315,9 +297,8 @@ 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()); + NotificationService::sendModelNotification($federation, new FederationMembersChanged($federation, $old_entities, 'deleted')); return redirect() ->route('federations.entities', $federation) @@ -333,7 +314,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..8f6cd09 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; @@ -26,7 +24,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) @@ -42,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 (functional) + /* 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() @@ -65,7 +63,6 @@ function () use ($membership) { /** * Remove the specified resource from storage. * - * @param \App\Models\Membership $membership * @return \Illuminate\Http\Response */ public function destroy(Membership $membership) @@ -86,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/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/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php new file mode 100644 index 0000000..18ee149 --- /dev/null +++ b/app/Jobs/EduGainAddEntity.php @@ -0,0 +1,73 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + 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"); + } + } 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::saveEntityMetadataToFolder($this->entity->id, $folderName); + + NotificationService::sendModelNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); + EduGainRunMdaScript::dispatch($lock->owner()); + + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + } +} diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php new file mode 100644 index 0000000..ee1182a --- /dev/null +++ b/app/Jobs/EduGainDeleteEntity.php @@ -0,0 +1,75 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + 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"); + } + } 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); + NotificationService::sendModelNotification($this->entity, new EntityEdugainStatusChanged($this->entity)); + EduGainRunMdaScript::dispatch($lock->owner()); + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + } +} diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php new file mode 100644 index 0000000..8713d11 --- /dev/null +++ b/app/Jobs/EduGainRunMdaScript.php @@ -0,0 +1,59 @@ +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) { + $this->fail($e); + } finally { + Cache::restoreLock($lockKey, $this->owner)->release(); + + } + + } +} diff --git a/app/Jobs/FolderAddEntity.php b/app/Jobs/FolderAddEntity.php new file mode 100644 index 0000000..0a95c70 --- /dev/null +++ b/app/Jobs/FolderAddEntity.php @@ -0,0 +1,100 @@ +entity = $entity; + } + + /** + * Execute the job. + */ + 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) { + + $federation = Federation::where('id', $fedId->federation_id)->first(); + + if (! Storage::disk($diskName)->exists($federation->name)) { + continue; + } + $pathToDirectory = Storage::disk($diskName)->path($federation->name); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $lock = Cache::lock($lockKey, 61); + + try { + $lock->block(61); + EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id); + + if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) { + NotificationService::sendModelNotification($this->entity, new EntityStateChanged($this->entity)); + } else { + if ($this->entity->wasChanged('approved') && $this->entity->approved == 1) { + NotificationService::sendModelNotification($this->entity, new EntityStateChanged($this->entity)); + } else { + NotificationService::sendModelNotification($this->entity, new EntityUpdated($this->entity)); + } + } + + RunMdaScript::dispatch($federation, $lock->owner()); + } catch (Exception $e) { + $this->fail($e); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + } + } + + /** + * 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/FolderAddMembership.php b/app/Jobs/FolderAddMembership.php new file mode 100644 index 0000000..e785474 --- /dev/null +++ b/app/Jobs/FolderAddMembership.php @@ -0,0 +1,74 @@ +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); + + NotificationService::sendModelNotification($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); + } finally { + if ($lock->isOwnedByCurrentProcess()) { + $lock->release(); + } + } + + } +} diff --git a/app/Jobs/FolderDeleteEntity.php b/app/Jobs/FolderDeleteEntity.php new file mode 100644 index 0000000..51c1517 --- /dev/null +++ b/app/Jobs/FolderDeleteEntity.php @@ -0,0 +1,76 @@ +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, 61); + try { + $lock->block(61); + EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id); + + NotificationService::sendModelNotification($entity, new EntityStateChanged($entity)); + if ($entity->hfd) { + NotificationService::sendUpdateNotification($entity); + } + + 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..c7c5800 --- /dev/null +++ b/app/Jobs/FolderDeleteMembership.php @@ -0,0 +1,76 @@ +federation = $federation; + $this->entity = $entity; + } + + /** + * Execute the job. + */ + 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(); + } + $pathToFile = $federation->name.'/'.$entity->file; + if (! Storage::disk($diskName)->exists($pathToFile)) { + NotificationService::sendModelNotification($entity, new MembershipRejected($entity->entityid, $federation->name)); + + return; + } + + $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/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/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/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/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/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/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/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/GitAddEntity.php b/app/Jobs/Old_GitAddEntity.php similarity index 93% rename from app/Jobs/GitAddEntity.php rename to app/Jobs/Old_GitAddEntity.php index d90ad2f..2925379 100644 --- a/app/Jobs/GitAddEntity.php +++ b/app/Jobs/Old_GitAddEntity.php @@ -16,9 +16,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddEntity implements ShouldQueue +class Old_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/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/GitAddMember.php b/app/Jobs/Old_GitAddMember.php similarity index 93% rename from app/Jobs/GitAddMember.php rename to app/Jobs/Old_GitAddMember.php index 593543a..8535026 100644 --- a/app/Jobs/GitAddMember.php +++ b/app/Jobs/Old_GitAddMember.php @@ -17,9 +17,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddMember implements ShouldQueue +class Old_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/Old_GitAddMembers.php similarity index 93% rename from app/Jobs/GitAddMembers.php rename to app/Jobs/Old_GitAddMembers.php index 7ccab14..c2dcd9e 100644 --- a/app/Jobs/GitAddMembers.php +++ b/app/Jobs/Old_GitAddMembers.php @@ -17,9 +17,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddMembers implements ShouldQueue +class Old_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/Old_GitAddMembership.php similarity index 94% rename from app/Jobs/GitAddMembership.php rename to app/Jobs/Old_GitAddMembership.php index ac30523..60dfe1c 100644 --- a/app/Jobs/GitAddMembership.php +++ b/app/Jobs/Old_GitAddMembership.php @@ -16,9 +16,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddMembership implements ShouldQueue +class Old_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/GitAddToRs.php b/app/Jobs/Old_GitAddToRs.php similarity index 93% rename from app/Jobs/GitAddToRs.php rename to app/Jobs/Old_GitAddToRs.php index bba57d3..532c9ab 100644 --- a/app/Jobs/GitAddToRs.php +++ b/app/Jobs/Old_GitAddToRs.php @@ -16,9 +16,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitAddToRs implements ShouldQueue +class Old_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/GitDeleteEntity.php b/app/Jobs/Old_GitDeleteEntity.php similarity index 94% rename from app/Jobs/GitDeleteEntity.php rename to app/Jobs/Old_GitDeleteEntity.php index 9657845..894af03 100644 --- a/app/Jobs/GitDeleteEntity.php +++ b/app/Jobs/Old_GitDeleteEntity.php @@ -16,9 +16,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitDeleteEntity implements ShouldQueue +class Old_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/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/GitDeleteFromFederation.php b/app/Jobs/Old_GitDeleteFromFederation.php similarity index 93% rename from app/Jobs/GitDeleteFromFederation.php rename to app/Jobs/Old_GitDeleteFromFederation.php index d6e69ed..898f97c 100644 --- a/app/Jobs/GitDeleteFromFederation.php +++ b/app/Jobs/Old_GitDeleteFromFederation.php @@ -17,9 +17,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitDeleteFromFederation implements ShouldQueue +class Old_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/GitUpdateEntity.php b/app/Jobs/Old_GitUpdateEntity.php similarity index 93% rename from app/Jobs/GitUpdateEntity.php rename to app/Jobs/Old_GitUpdateEntity.php index aeca68b..8e34422 100644 --- a/app/Jobs/GitUpdateEntity.php +++ b/app/Jobs/Old_GitUpdateEntity.php @@ -16,9 +16,9 @@ use Illuminate\Support\Facades\Storage; use Throwable; -class GitUpdateEntity implements ShouldQueue +class Old_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/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/Jobs/RunMdaScript.php b/app/Jobs/RunMdaScript.php new file mode 100644 index 0000000..43318e2 --- /dev/null +++ b/app/Jobs/RunMdaScript.php @@ -0,0 +1,87 @@ +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'); + + $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(); + + } + + } + + /** + * Get the middleware the job should pass through. + * + * @return array + */ + public function middleware(): array + { + $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/Listeners/CreateFederationFolder.php b/app/Listeners/CreateFederationFolder.php index deaf14b..dd69582 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 @@ -25,11 +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 ($federation->approved) { + if (! Storage::disk($diskName)->exists($federation->name)) { $this->createFederationFolder($federation->name); } } 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 eb914f3..d0b3d3c 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -81,7 +81,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%") 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/Observers/EntityObserver.php b/app/Observers/EntityObserver.php new file mode 100644 index 0000000..d32e112 --- /dev/null +++ b/app/Observers/EntityObserver.php @@ -0,0 +1,82 @@ +wasChanged('xml_file') + ) { + FolderAddEntity::dispatch($entity); + } elseif ($entity->approved == 1 && ! $entity->wasChanged('approved')) { + + if (! $entity->wasChanged('edugain') && ! $entity->wasChanged('deleted_at')) { + 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/Observers/MembershipObserver.php b/app/Observers/MembershipObserver.php new file mode 100644 index 0000000..c639907 --- /dev/null +++ b/app/Observers/MembershipObserver.php @@ -0,0 +1,55 @@ +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/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..c206604 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,9 +2,12 @@ namespace App\Providers; -use App\Services\EntityService; +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 @@ -30,5 +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); + });*/ + } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index c9661ca..675c0ff 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -4,6 +4,10 @@ use App\Events\FederationApprove; use App\Listeners\CreateFederationFolder; +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; @@ -20,10 +24,10 @@ class EventServiceProvider extends ServiceProvider Registered::class => [ SendEmailVerificationNotification::class, ], - FederationApprove::class => - [ + FederationApprove::class => [ CreateFederationFolder::class, - ] + ], + ]; /** @@ -33,6 +37,7 @@ class EventServiceProvider extends ServiceProvider */ public function boot() { - // + Entity::observe(EntityObserver::class); + Membership::observe(MembershipObserver::class); } } diff --git a/app/Services/EntityService.php b/app/Services/EntityService.php index a58ed2e..cca6d64 100644 --- a/app/Services/EntityService.php +++ b/app/Services/EntityService.php @@ -1,49 +1,67 @@ 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 { + $diskName = config('storageCfg.name'); + $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)) - { - Storage::disk('metadata')->makeDirectory($folderName); + if (! Storage::disk($diskName)->exists($folderName)) { + Storage::disk($diskName)->makeDirectory($folderName); } - $filePath = $folderName . '/' . $fileName; + $filePath = $folderName.'/'.$fileName; $content = $entity->xml_file; - Storage::disk('metadata')->put($filePath, $content); - + 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) { + throw new InvalidArgumentException("Unable to delete file $pathToFile"); + } + } else { + throw new InvalidArgumentException("Unable to delete file $pathToFile"); + } + + } } diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php new file mode 100644 index 0000000..c3854e0 --- /dev/null +++ b/app/Services/NotificationService.php @@ -0,0 +1,89 @@ +operators; + + self::sendOperatorNotification($operators, $notification); + } + + public static function sendOperatorNotification(Collection $operators, $notification): void + { + if ($notification == null) { + return; + } + + $admins = User::activeAdmins()->select('id', 'email')->get(); + + $operatorIds = $operators->pluck('id'); + + $filteredAdmins = $admins->filter(function ($admin) use ($operatorIds) { + return ! $operatorIds->contains($admin->id); + }); + + Notification::sendNow($operators, $notification); + + Notification::sendNow($filteredAdmins, $notification); + } + + private static function sendRsNotification(Entity $entity): bool + { + if ($entity->wasChanged('rs')) { + + if ($entity->rs == 1) { + self::sendModelNotification($entity, new EntityAddedToRs($entity)); + } else { + self::sendModelNotification($entity, new EntityDeletedFromRs($entity)); + } + + return true; + } + + return false; + } + + private static function sendHfDNotification(Entity $entity): bool + { + if ($entity->wasChanged('hfd')) { + + if ($entity->hfd) { + self::sendModelNotification($entity, new EntityAddedToHfd($entity)); + } else { + self::sendModelNotification($entity, new EntityDeletedFromHfd($entity)); + } + + return true; + } + + return false; + } + + public static function sendUpdateNotification(Entity $entity): void + { + + if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) { + self::sendModelNotification($entity, new EntityUpdated($entity)); + } + + } +} 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..0970a31 100644 --- a/app/Traits/EdugainTrait.php +++ b/app/Traits/EdugainTrait.php @@ -1,27 +1,23 @@ get(); + $folderName = config('storageCfg.edu2edugain'); + $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..6aaf753 100644 --- a/app/Traits/FederationTrait.php +++ b/app/Traits/FederationTrait.php @@ -1,25 +1,26 @@ makeDirectory($name); + + Storage::disk(config('storageCfg.name'))->makeDirectory($name); } + public function updateFederationFolders(): void { - $federations = Federation::select('name')->get(); + $federations = Federation::all(); foreach ($federations as $fed) { - if(!Storage::disk('metadata')->exists($fed['name'])){ - $this->createFederationFolder($fed['name']); + if (! Storage::disk(config('storageCfg.name'))->exists($fed['xml_id'])) { + $this->createFederationFolder($fed['xml_id']); } } } - - } diff --git a/app/Traits/HandlesJobsFailuresTrait.php b/app/Traits/HandlesJobsFailuresTrait.php new file mode 100644 index 0000000..7c10aa9 --- /dev/null +++ b/app/Traits/HandlesJobsFailuresTrait.php @@ -0,0 +1,23 @@ +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(), + ])); + } +} 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/storageCfg.php b/config/storageCfg.php new file mode 100644 index 0000000..f007043 --- /dev/null +++ b/config/storageCfg.php @@ -0,0 +1,8 @@ + 'metadata', + 'mdaConfigFolder' => env('MDA_CONFIG_FOLDER'), + 'mdaScript' => env('MDA_SCRIPT'), + 'edu2edugain' => env('EDU_TO_EDUGAIN_FOLDER'), +]; 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..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,14 +22,24 @@ 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(); -/* Federation::factory(20)->create(); - Entity::factory(100)->create();*/ -/* Category::factory(20)->create(); - Group::factory(20)->create();*/ + + $edu2edugain = config('storageCfg.edu2edugain'); + $this->createFederationFolder($edu2edugain); + + /* Federation::factory(20)->create(); + Entity::factory(100)->create();*/ + /* Category::factory(20)->create(); + Group::factory(20)->create();*/ } } 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 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/CategoryControllerTest.php b/tests/Feature/Http/Controllers/CategoryControllerTest.php index b5b6f24..906fdc2 100644 --- a/tests/Feature/Http/Controllers/CategoryControllerTest.php +++ b/tests/Feature/Http/Controllers/CategoryControllerTest.php @@ -11,6 +11,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 CategoryControllerTest extends TestCase @@ -430,6 +431,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()); diff --git a/tests/Feature/Http/Controllers/EntityControllerTest.php b/tests/Feature/Http/Controllers/EntityControllerTest.php index 3e5eb87..d761b93 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; @@ -12,6 +9,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 @@ -22,9 +20,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()); } @@ -32,23 +30,25 @@ 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 - ->followingRedirects() - ->get(route('entities.show', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->get(route('entities.show', $entity)) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); + } /** @test */ 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()); @@ -74,50 +74,58 @@ 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 - ->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()); + } /** @test */ public function an_anonymouse_user_cannot_edit_an_existing_entity() { + Queue::fake(); $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()); + } /** @test */ public function an_anonymouse_user_cannot_change_an_existing_entities_state() { + Queue::fake(); + $entity = Entity::factory()->create(); $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()); + } /** @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()); @@ -125,57 +133,62 @@ 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()); + } /** @test */ public function an_anonymouse_user_cannot_change_an_existing_entities_federation_membership() { + Queue::fake(); $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 */ public function an_anonymouse_user_cannot_purge_an_existing_entity() { + Queue::fake(); $entity = Entity::factory()->create([ 'deleted_at' => now(), ]); $this - ->followingRedirects() - ->delete(route('entities.destroy', $entity)) - ->assertSeeText('login'); + ->followingRedirects() + ->delete(route('entities.destroy', $entity)) + ->assertSeeText('login'); $this->assertEquals(route('login'), url()->current()); + } /** @test */ @@ -191,9 +204,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 +222,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 */ @@ -219,18 +232,20 @@ public function a_user_is_shown_a_entities_list() { $this->assertEquals(0, Entity::count()); + Queue::fake(); $user = User::factory()->create(); $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()); + } /** @test */ @@ -238,19 +253,21 @@ public function a_user_is_shown_a_entities_details() { $this->assertEquals(0, Entity::count()); + Queue::fake(); $user = User::factory()->create(); $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()); + } /** @test */ @@ -259,9 +276,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 +290,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 */ @@ -292,9 +309,9 @@ public function a_user_can_add_a_new_entity() $whoami = ' - + - + @@ -309,7 +326,7 @@ public function a_user_can_add_a_new_entity() - + cesnet.cz @@ -323,7 +340,7 @@ public function a_user_can_add_a_new_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -382,19 +399,19 @@ public function a_user_can_add_a_new_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -403,7 +420,7 @@ public function a_user_can_add_a_new_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -423,46 +440,46 @@ public function a_user_can_add_a_new_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; // 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()); @@ -471,17 +488,19 @@ 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); $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()); + } /** @test */ @@ -496,9 +515,9 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() $whoami = ' - + - + @@ -513,7 +532,7 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() - + cesnet.cz @@ -527,7 +546,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 +605,19 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -607,7 +626,7 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -627,23 +646,23 @@ public function a_user_with_operator_permission_can_edit_an_existing_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; $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,37 +678,38 @@ 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 */ 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); @@ -698,35 +718,37 @@ 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()); $this->assertEquals(route('entities.show', $entity), url()->current()); + } /** @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); @@ -736,87 +758,97 @@ 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()); + } /** @test */ public function a_user_without_operator_permission_cannot_see_entities_edit_page() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $this - ->actingAs($user) - ->get(route('entities.edit', $entity)) - ->assertForbidden(); + ->actingAs($user) + ->get(route('entities.edit', $entity)) + ->assertForbidden(); + } /** @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), [ - '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 */ public function a_user_without_operator_permission_cannot_change_an_existing_entities_state() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create(); $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 */ 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(); $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 */ 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(); @@ -825,30 +857,33 @@ 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()); + } /** @test */ public function a_user_cannot_purge_an_existing_entity() { + Queue::fake(); $user = User::factory()->create(); $entity = Entity::factory()->create([ 'deleted_at' => now(), ]); $this - ->followingRedirects() - ->actingAs($user) - ->delete(route('entities.destroy', $entity)) - ->assertForbidden(); + ->followingRedirects() + ->actingAs($user) + ->delete(route('entities.destroy', $entity)) + ->assertForbidden(); + } /** @test */ @@ -865,10 +900,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,45 +921,49 @@ 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 */ public function an_admin_is_shown_a_entities_list() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $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()); + } /** @test */ public function an_admin_is_shown_a_entities_details() { + Queue::fake(); $admin = User::factory()->create(['admin' => true]); $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()); + } /** @test */ @@ -933,9 +972,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()); } @@ -949,9 +988,9 @@ public function an_admin_can_add_a_new_entity() $whoami = ' - + - + @@ -966,7 +1005,7 @@ public function an_admin_can_add_a_new_entity() - + cesnet.cz @@ -980,7 +1019,7 @@ public function an_admin_can_add_a_new_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -1039,19 +1078,19 @@ public function an_admin_can_add_a_new_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -1060,7 +1099,7 @@ public function an_admin_can_add_a_new_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -1080,34 +1119,34 @@ public function an_admin_can_add_a_new_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; // 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()); @@ -1116,17 +1155,19 @@ 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(); $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()); + } /** @test */ @@ -1140,9 +1181,9 @@ public function an_admin_can_edit_an_existing_entity() $whoami = ' - + - + @@ -1157,7 +1198,7 @@ public function an_admin_can_edit_an_existing_entity() - + cesnet.cz @@ -1171,7 +1212,7 @@ public function an_admin_can_edit_an_existing_entity() https://whoami.cesnet.cz/idp/images/cesnet-logo-40.png - + @@ -1230,19 +1271,19 @@ public function an_admin_can_edit_an_existing_entity() - + - + - + - + CESNET, a. l. e. CESNET, z. s. p. o. @@ -1251,7 +1292,7 @@ public function an_admin_can_edit_an_existing_entity() https://www.ces.net/ https://www.cesnet.cz/ - + Jan Oppolzer @@ -1271,22 +1312,22 @@ public function an_admin_can_edit_an_existing_entity() CESNET-CERTS mailto:abuse@cesnet.cz - + '; $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,37 +1342,38 @@ 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 */ 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(); @@ -1341,56 +1383,58 @@ 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()); $this->assertEquals(route('entities.show', $entity), url()->current()); + } /** @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(); @@ -1399,20 +1443,24 @@ 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()); + } /** @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(), @@ -1420,15 +1468,17 @@ 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 */ 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]); @@ -1439,10 +1489,11 @@ 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,49 +1511,54 @@ 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 */ 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(); $this - ->followingRedirects() - ->actingAs($admin) - ->put(route('entities.update', $entity)); + ->followingRedirects() + ->actingAs($admin) + ->put(route('entities.update', $entity)); $this->assertEquals(route('home'), url()->current()); + } /** @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); $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 */ 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); @@ -1515,15 +1571,16 @@ 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/EntityMetadataControllerTest.php b/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php index 711c2d9..be23a3c 100644 --- a/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php +++ b/tests/Feature/Http/Controllers/EntityMetadataControllerTest.php @@ -5,6 +5,7 @@ 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 +15,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'); + } /** @test */ diff --git a/tests/Feature/Http/Controllers/FederationControllerTest.php b/tests/Feature/Http/Controllers/FederationControllerTest.php index bec4c36..c4c0a8c 100644 --- a/tests/Feature/Http/Controllers/FederationControllerTest.php +++ b/tests/Feature/Http/Controllers/FederationControllerTest.php @@ -2,11 +2,9 @@ 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; @@ -16,6 +14,7 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Facades\Queue; use Tests\TestCase; class FederationControllerTest extends TestCase @@ -162,6 +161,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(); @@ -196,6 +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()); + } /** @test */ @@ -392,9 +393,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 +422,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 +440,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 */ @@ -515,10 +516,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() @@ -533,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 */ @@ -606,7 +607,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 */ @@ -669,6 +670,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(); @@ -707,6 +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()); + } /** @test */ @@ -960,9 +963,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 +979,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 */ @@ -1087,10 +1090,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() @@ -1116,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 */ @@ -1210,9 +1213,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 */ diff --git a/tests/Feature/Http/Controllers/GroupControllerTest.php b/tests/Feature/Http/Controllers/GroupControllerTest.php index 7726d77..28a44cd 100644 --- a/tests/Feature/Http/Controllers/GroupControllerTest.php +++ b/tests/Feature/Http/Controllers/GroupControllerTest.php @@ -11,6 +11,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 +403,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 +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()); + } } diff --git a/tests/Feature/Http/Controllers/StatisticControllerTest.php b/tests/Feature/Http/Controllers/StatisticControllerTest.php index 536eec1..d3cb938 100644 --- a/tests/Feature/Http/Controllers/StatisticControllerTest.php +++ b/tests/Feature/Http/Controllers/StatisticControllerTest.php @@ -7,6 +7,7 @@ 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 +17,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 +83,6 @@ public function it_produces_statistics(): void ], ], ]); + } } diff --git a/tests/Feature/Mail/AskRsTest.php b/tests/Feature/Mail/AskRsTest.php index 1a6aa85..631f109 100644 --- a/tests/Feature/Mail/AskRsTest.php +++ b/tests/Feature/Mail/AskRsTest.php @@ -8,6 +8,7 @@ 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 +19,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 +42,14 @@ public function email_is_queued_for_rs_federation_only() return $email->hasTo(config('mail.admin.address')) && $email->entity->is($entity); }); + } /** @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 +60,6 @@ public function email_isnt_queued_for_non_rs_federation() ->assertStatus(403); Mail::assertNotQueued(AskRs::class); + } }