Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/Console/Commands/SearchUiTPASOrganizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Console\Commands;

use App\Search\SearchServiceProvider;
use App\Search\Sapi3\SearchService;
use CultuurNet\SearchV3\ValueObjects\Organizer;
use Illuminate\Console\Command;
Expand All @@ -20,7 +19,7 @@ final class SearchUiTPASOrganizer extends Command

public function handle(): int
{
$this->searchService = $this->laravel->get(SearchServiceProvider::PROD_SEARCH_SERVICE);
$this->searchService = $this->laravel->get(SearchService::class);

$name = $this->argument('name');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
final readonly class GetIntegrationOrganizersWithTestOrganizer
{
public function __construct(
private SearchService $testSearchService,
private SearchService $prodSearchService,
private UiTPASApiInterface $UiTPASApi,
private ClientCredentialsContext $testCredentialsContext,
Expand All @@ -31,7 +30,7 @@ public function __construct(

public function getAndEnrichOrganisations(Integration $integration): Collection
{
$prodOrganizers = $testOrganizers = [];
$prodOrganizers = [];
$keycloakClientCache = [];
foreach ($integration->udbOrganizers() as $udbOrganizer) {
//@todo this can be simplified once client id can no longer be null
Expand All @@ -44,27 +43,15 @@ public function getAndEnrichOrganisations(Integration $integration): Collection
$keycloakClient = $this->keycloakClientRepository->getById($udbOrganizer->clientId);
$keycloakClientCache[$udbOrganizer->clientId->toString()] = $keycloakClient;

if ($keycloakClient->environment === Environment::Production) {
$prodOrganizers[] = $udbOrganizer;
} else {
$testOrganizers[] = $udbOrganizer;
}
$prodOrganizers[] = $udbOrganizer;
} catch (ModelNotFoundException) {
$prodOrganizers[] = $udbOrganizer;
}
}

$organizers = collect()
->merge($this->mapOrganizers($this->testSearchService, $this->testCredentialsContext, $testOrganizers, 'Test', $integration, $keycloakClientCache))
return collect()
->merge($this->addTestOrganizer($integration))
->merge($this->mapOrganizers($this->prodSearchService, $this->prodCredentialsContext, $prodOrganizers, 'Live', $integration, $keycloakClientCache));

// Only add demo user if not already added from the database.
$testOrgId = (string)config(UiTPASConfig::TEST_ORGANISATION->value);
if (!$organizers->contains(fn (array $organizer) => $organizer['id'] === $testOrgId)) {
$organizers = $organizers->merge($this->addTestOrganizer($integration));
}

return $organizers;
}

private function getClientByEnv(Integration $integration, Environment $environment): ?Client
Expand Down
4 changes: 2 additions & 2 deletions app/Notifications/NotificationsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Notifications\Listeners\NotifyIntegrationChanged;
use App\Notifications\Slack\SlackMessageBuilder;
use App\Notifications\Slack\SlackNotifier;
use App\Search\SearchServiceProvider;
use App\Search\Sapi3\SearchService;
use App\Search\UdbOrganizerNameResolver;
use App\UiTPAS\UiTPASConfig;
use Illuminate\Support\Facades\Event;
Expand All @@ -36,7 +36,7 @@ public function register(): void
new SlackMessageBuilder(
$this->app->get(SubscriptionRepository::class),
$this->app->get(UdbOrganizerNameResolver::class),
$this->app->get(SearchServiceProvider::PROD_SEARCH_SERVICE),
$this->app->get(SearchService::class),
config(UiTPASConfig::CLIENT_PERMISSIONS_URI->value),
config(UiTPASConfig::UDB_BASE_URI->value),
config('app.url'),
Expand Down
3 changes: 2 additions & 1 deletion app/Nova/Actions/UdbOrganizer/RequestUdbOrganizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public function fields(NovaRequest $request): array
Environment::Production->value => 'Production',
])
->default(Environment::Production->value)
->rules('required'),
->rules('required')
->readonly(),
];
}

Expand Down
4 changes: 2 additions & 2 deletions app/Nova/Resources/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use App\Nova\Actions\UiTPAS\SynchronizeUiTPASPermissions;
use App\Nova\Filters\AdminInformationFilter;
use App\Nova\Resource;
use App\Search\SearchServiceProvider;
use App\Search\Sapi3\SearchService;
use App\UiTPAS\SynchronizeUiTPASPermissionsHandler;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -305,7 +305,7 @@ public function actions(NovaRequest $request): array

(new RequestUdbOrganizer(
App::make(UdbOrganizerRepository::class),
App::make(SearchServiceProvider::PROD_SEARCH_SERVICE),
App::make(SearchService::class),
App::make(IntegrationRepository::class),
))
->exceptOnIndex()
Expand Down
3 changes: 1 addition & 2 deletions app/Nova/Resources/UdbOrganizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use App\Nova\Filters\UdbOrganizerStatusFilter;
use App\Nova\Resource;
use App\Search\Sapi3\SearchService;
use App\Search\SearchServiceProvider;
use App\Search\UdbOrganizerNameResolver;
use App\UiTPAS\ClientCredentialsContextFactory;
use App\UiTPAS\Dto\UiTPASPermission;
Expand Down Expand Up @@ -102,7 +101,7 @@ public function fields(NovaRequest $request): array
$udbOrganizerNameResolver = App::get(UdbOrganizerNameResolver::class);

/** @var SearchService $searchService */
$searchService = App::get(SearchServiceProvider::PROD_SEARCH_SERVICE);
$searchService = App::get(SearchService::class);

$name = $udbOrganizerNameResolver->getName($searchService->findOrganizers($model->toDomain()->organizerId));

Expand Down
29 changes: 2 additions & 27 deletions app/Search/SearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Search;

use App\Search\Sapi3\Sapi3SearchService;
use App\Search\Sapi3\SearchService;
use App\Search\UiTPAS\CachedUiTPASLabelProvider;
use App\Search\UiTPAS\HttpUiTPASLabelProvider;
use App\UiTPAS\UiTPASConfig;
Expand All @@ -17,12 +18,9 @@

final class SearchServiceProvider extends ServiceProvider
{
public const TEST_SEARCH_SERVICE = 'TEST_SAPI3_SEARCH_SERVICE';
public const PROD_SEARCH_SERVICE = 'PROD_SAPI3_SEARCH_SERVICE';

public function register(): void
{
$this->app->singleton(self::PROD_SEARCH_SERVICE, function () {
$this->app->singleton(SearchService::class, function () {
return new Sapi3SearchService(
new SearchClient(
new Client([
Expand All @@ -44,28 +42,5 @@ public function register(): void
)
);
});

$this->app->singleton(self::TEST_SEARCH_SERVICE, function () {
return new Sapi3SearchService(
new SearchClient(
new Client([
'base_uri' => config('search.base_test_uri'),
'headers' => [
'X-Api-Key' => config('search.api_test_key'),
],
]),
new Serializer()
),
new CachedUiTPASLabelProvider(
new HttpUiTPASLabelProvider(
new Client([
'base_uri' => config(UiTPASConfig::UDB_BASE_TEST_IO_URI->value),
]),
$this->app->get(LoggerInterface::class),
),
$this->app->make(CacheRepository::class)
)
);
});
}
}
7 changes: 3 additions & 4 deletions app/UiTPAS/UiTPASServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use App\Keycloak\Repositories\KeycloakClientRepository;
use App\Notifications\MessageBuilder;
use App\Notifications\Slack\SlackNotifier;
use App\Search\SearchServiceProvider;
use App\Search\Sapi3\SearchService;
use App\Search\UdbOrganizerNameResolver;
use App\UiTPAS\Event\UdbOrganizerApproved;
use App\UiTPAS\Event\UdbOrganizerDeleted;
Expand Down Expand Up @@ -65,8 +65,7 @@ public function register(): void

$this->app->singleton(GetIntegrationOrganizersWithTestOrganizer::class, function () {
return new GetIntegrationOrganizersWithTestOrganizer(
$this->app->get(SearchServiceProvider::TEST_SEARCH_SERVICE),
$this->app->get(SearchServiceProvider::PROD_SEARCH_SERVICE),
$this->app->get(SearchService::class),
$this->app->get(UiTPASApiInterface::class),
ClientCredentialsContextFactory::getUitIdTestContext(),
ClientCredentialsContextFactory::getUitIdProdContext(),
Expand All @@ -92,7 +91,7 @@ public function register(): void
$this->app->get(Mailer::class),
$this->app->get(IntegrationRepository::class),
$this->app->get(UdbOrganizerNameResolver::class),
$this->app->get(SearchServiceProvider::PROD_SEARCH_SERVICE),
$this->app->get(SearchService::class),
$this->app->get(UrlGenerator::class),
new Address(config('mail.from.address'), config('mail.from.name')),
);
Expand Down
Loading