Skip to content

Commit

Permalink
Add Nova actions to create the missing clients and consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
LucWollants committed Apr 19, 2024
1 parent bc751f8 commit 4e1e7c9
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/Nova/Actions/Auth0/CreateMissingAuth0Clients.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Actions\Auth0;

use App\Auth0\Jobs\CreateMissingClients as CreateMissingAuth0ClientsJob;
use App\Domain\Integrations\Models\IntegrationModel;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Event;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionModelCollection;
use Laravel\Nova\Fields\ActionFields;
use Ramsey\Uuid\Uuid;

final class CreateMissingAuth0Clients extends Action
{
use InteractsWithQueue;
use Queueable;

public function __construct()
{
}

public function handle(ActionFields $fields, ActionModelCollection $actionModelCollection): void
{
foreach ($actionModelCollection as $integrationModel) {
if (!$integrationModel instanceof IntegrationModel) {
continue;
}

Event::dispatch(new CreateMissingAuth0ClientsJob(Uuid::fromString($integrationModel->id)));
}
}
}
36 changes: 36 additions & 0 deletions app/Nova/Actions/UiTiDv1/CreateMissingUiTiDv1Consumers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Nova\Actions\UiTiDv1;

use App\Domain\Integrations\Models\IntegrationModel;
use App\UiTiDv1\Jobs\CreateMissingConsumers as CreateMissingUiTiDv1ConsumersJob;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Event;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionModelCollection;
use Laravel\Nova\Fields\ActionFields;
use Ramsey\Uuid\Uuid;

final class CreateMissingUiTiDv1Consumers extends Action
{
use InteractsWithQueue;
use Queueable;

public function __construct()
{
}

public function handle(ActionFields $fields, ActionModelCollection $actionModelCollection): void
{
foreach ($actionModelCollection as $integrationModel) {
if (!$integrationModel instanceof IntegrationModel) {
continue;
}

Event::dispatch(new CreateMissingUiTiDv1ConsumersJob(Uuid::fromString($integrationModel->id)));
}
}
}
20 changes: 20 additions & 0 deletions app/Nova/Resources/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Nova\Actions\ActivateIntegration;
use App\Nova\Actions\ApproveIntegration;
use App\Nova\Actions\Auth0\CreateMissingAuth0Clients;
use App\Nova\Actions\BlockIntegration;
use App\Nova\Actions\OpenWidgetManager;
use App\Nova\Actions\UiTiDv1\CreateMissingUiTiDv1Consumers;
use App\Nova\Resource;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
Expand Down Expand Up @@ -191,6 +193,24 @@ public function actions(NovaRequest $request): array
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->canBeBlocked())
->canRun(fn (Request $request, IntegrationModel $model) => $model->canBeBlocked()),

(new CreateMissingAuth0Clients())
->withName('Create missing Auth0 Clients')
->exceptOnIndex()
->confirmText('Are you sure you want to create missing Auth0 clients for this integration?')
->confirmButtonText('Create')
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->hasMissingAuth0Clients())
->canRun(fn (Request $request, IntegrationModel $model) => $model->hasMissingAuth0Clients()),

(new CreateMissingUiTiDv1Consumers())
->withName('Create missing UiTiD v1 Consumers')
->exceptOnIndex()
->confirmText('Are you sure you want to create missing UiTiD v1 consumers for this integration?')
->confirmButtonText('Create')
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->hasMissingUiTiDv1Consumers())
->canRun(fn (Request $request, IntegrationModel $model) => $model->hasMissingUiTiDv1Consumers()),
];
}
}

0 comments on commit 4e1e7c9

Please sign in to comment.