Skip to content

Commit

Permalink
Merge branch 'main' into feature/PPF-463
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/Domain/Integrations/Controllers/IntegrationController.php
  • Loading branch information
Anahkiasen committed Jul 11, 2024
2 parents 74221e0 + 0d0be90 commit 694b734
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 87 deletions.
42 changes: 31 additions & 11 deletions app/Domain/Integrations/Controllers/IntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use App\Domain\Organizations\Repositories\OrganizationRepository;
use App\Domain\Subscriptions\Repositories\SubscriptionRepository;
use App\Http\Controllers\Controller;
use App\Keycloak\Repositories\KeycloakClientRepository;
use App\ProjectAanvraag\ProjectAanvraagUrl;
use App\Router\TranslatedRoute;
use App\Search\Sapi3\SearchService;
Expand Down Expand Up @@ -73,6 +74,7 @@ public function __construct(
private readonly CouponRepository $couponRepository,
private readonly Auth0ClientRepository $auth0ClientRepository,
private readonly UiTiDv1ConsumerRepository $uitidV1ConsumerRepository,
private readonly KeycloakClientRepository $keycloakClientRepository,
private readonly KeyVisibilityUpgradeRepository $keyVisibilityUpgradeRepository,
private readonly SearchService $searchClient,
private readonly CurrentUser $currentUser
Expand All @@ -92,12 +94,14 @@ public function index(Request $request): Response

$auth0Clients = $this->auth0ClientRepository->getByIntegrationIds($integrationIds);
$uitidV1Consumers = $this->uitidV1ConsumerRepository->getByIntegrationIds($integrationIds);
$keycloakClients = $this->keycloakClientRepository->getByIntegrationIds($integrationIds);

return Inertia::render('Integrations/Index', [
'integrations' => $integrationsData->collection->map(fn (Integration $integration) => $integration->toArray()),
'credentials' => [
'auth0' => $auth0Clients,
'uitidV1' => $uitidV1Consumers,
'keycloak' => $keycloakClients,
],
'paginationInfo' => $integrationsData->paginationInfo,
]);
Expand Down Expand Up @@ -175,17 +179,7 @@ public function show(string $id): Response
$integration = $this->integrationRepository->getById(Uuid::fromString($id));
$oldCredentialsExpirationDate = $this->getExpirationDateForOldCredentials($integration->getKeyVisibilityUpgrade());

$organizerIds = collect($integration->organizers())->map(fn (Organizer $organizer) => $organizer->organizerId);
$uitpasOrganizers = $this->searchClient->findUiTPASOrganizers(...$organizerIds)->getMember()?->getItems();
$organizers = collect($uitpasOrganizers)->map(function (SapiOrganizer $organizer) {
$id = explode('/', $organizer->getId() ?? '');

return [
'id' => $id[count($id) - 1],
'name' => $organizer->getName()?->getValues() ?? $id,
'status' => $organizer->getWorkflowStatus() === 'ACTIVE' ? 'Live' : 'Test',
];
});
$organizers = $this->getIntegrationOrganizersWithTestOrganizer($integration);

return Inertia::render('Integrations/Detail', [
'integration' => $integration->toArray(),
Expand Down Expand Up @@ -405,4 +399,30 @@ private function guardUserIsContact(Request $request, string $integrationId): ?R

return null;
}


public function getIntegrationOrganizersWithTestOrganizer(Integration $integration): Collection
{
$organizerIds = collect($integration->organizers())->map(fn (Organizer $organizer) => $organizer->organizerId);
$uitpasOrganizers = $this->searchClient->findUiTPASOrganizers(...$organizerIds)->getMember()?->getItems();

$organizers = collect($uitpasOrganizers)->map(function (SapiOrganizer $organizer) {
$id = explode('/', $organizer->getId() ?? '');
$id = $id[count($id) - 1];

return [
'id' => $id,
'name' => $organizer->getName()?->getValues() ?? [],
'status' => 'Live',
];
});

$organizers->push([
'id' => '0ce87cbc-9299-4528-8d35-92225dc9489f',
'name' => ['nl' => 'UiTPAS Organisatie (Regio Gent + Paspartoe)'],
'status' => 'Test',
]);

return $organizers;
}
}
2 changes: 1 addition & 1 deletion app/Domain/Integrations/Models/IntegrationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function isWidgets(): bool

public function isUiTPAS(): bool
{
return $this->type === IntegrationType::UiTPAS->value;
return $this->type === IntegrationType::UiTPAS->value || $this->type === null;
}

protected static function booted(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Domain\Contacts\Models\ContactModel;
use App\Domain\Coupons\Models\CouponModel;
use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationType;
use App\Domain\Integrations\KeyVisibility;
use App\Domain\Integrations\Models\IntegrationModel;
use App\Pagination\PaginatedCollection;
use App\Pagination\PaginationInfo;
Expand Down Expand Up @@ -150,6 +152,11 @@ private function saveTransaction(Integration $integration, ?string $couponCode):
$this->useCouponOnIntegration($integration->id, $couponCode);
}

// https://jira.publiq.be/browse/PPF-555
if($integration->type === IntegrationType::UiTPAS) {
$integration = $integration->withKeyVisibility(KeyVisibility::v2);
}

IntegrationModel::query()->create([
'id' => $integration->id->toString(),
'type' => $integration->type,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function share(Request $request): array
'sentryDsn' => config('sentry.dsn'),
'sentryEnabled' => config('app.sentry.enabled'),
'uitpasEnabled' => config('uitpas.enabled'),
'keycloakEnabled' => config('keycloak.enabled'),
],
'widgetConfig' => [
'url' => config('uitidwidget.url'),
Expand Down
84 changes: 84 additions & 0 deletions app/Nova/Actions/ActivateUitpasIntegration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace App\Nova\Actions;

use App\Domain\Integrations\Models\IntegrationModel;
use App\Domain\Integrations\Organizer;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Integrations\Repositories\OrganizerRepository;
use App\Domain\Organizations\Models\OrganizationModel;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Ramsey\Uuid\Uuid;

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

public function __construct(
private readonly IntegrationRepository $integrationRepository,
private readonly OrganizerRepository $organizerRepository
) {
}

public function handle(ActionFields $fields, Collection $integrations): ActionResponse
{
/** @var IntegrationModel $integration */
$integration = $integrations->first();

/** @var string $organizationIdAsString */
$organizationIdAsString = $fields->get('organization');
$organizationId = Uuid::fromString($organizationIdAsString);

/** @var string $organizers */
$organizers = $fields->get('organizers');
$organizerArray = array_map('trim', explode(',', $organizers));

foreach ($organizerArray as $organizer) {
$this->organizerRepository->create(
new Organizer(
Uuid::uuid4(),
Uuid::fromString($integration->id),
$organizer
)
);
}

$this->integrationRepository->activateWithOrganization(
Uuid::fromString($integration->id),
$organizationId,
null
);

return Action::message('Integration "' . $integration->name . '" activated.');
}

public function fields(NovaRequest $request): array
{
return [
Select::make('Organization', 'organization')
->options(
OrganizationModel::query()->pluck('name', 'id')
)
->rules(
'required',
'exists:organizations,id'
),
Text::make('Organizer(s)', 'organizers')
->rules(
'nullable',
'string'
),
];
}
}
11 changes: 10 additions & 1 deletion app/Nova/Resources/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Domain\Integrations\Repositories\OrganizerRepository;
use App\Keycloak\KeycloakConfig;
use App\Nova\Actions\ActivateIntegration;
use App\Nova\Actions\ActivateUitpasIntegration;
use App\Nova\Actions\AddOrganizer;
use App\Nova\Actions\ApproveIntegration;
use App\Nova\Actions\Auth0\CreateMissingAuth0Clients;
Expand Down Expand Up @@ -227,7 +228,15 @@ public function actions(NovaRequest $request): array
->confirmText('Are you sure you want to activate this integration?')
->confirmButtonText('Activate')
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->canBeActivated())
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->canBeActivated() && !$this->isUiTPAS())
->canRun(fn (Request $request, IntegrationModel $model) => $model->canBeActivated()),

(new ActivateUitpasIntegration(App::make(IntegrationRepository::class), App::make(OrganizerRepository::class)))
->exceptOnIndex()
->confirmText('Are you sure you want to activate this integration?')
->confirmButtonText('Activate')
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->canBeActivated() && $this->isUiTPAS())
->canRun(fn (Request $request, IntegrationModel $model) => $model->canBeActivated()),

(new ApproveIntegration(App::make(IntegrationRepository::class)))
Expand Down
2 changes: 1 addition & 1 deletion config/keycloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Auth0\SDK\Configuration\SdkConfiguration;

return [

'enabled' => env('KEYCLOAK_ENABLED', false),
'loginEnabled' => env('KEYCLOAK_LOGIN_ENABLED', false),
'creationEnabled' => env('KEYCLOAK_CREATION_ENABLED', false),
'login' => [
Expand Down
2 changes: 1 addition & 1 deletion resources/ts/Components/CopyText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const CopyText = ({ text, isSecret }: Props) => {
className="font-mono whitespace-pre text-ellipsis overflow-hidden text-sm text-publiq-orange max-md:max-w-[15rem] max-xl:max-w-[30rem]"
ref={codeFieldRef}
>
{!isSecret || isSecretVisible ? text : "*".repeat(text?.length ?? 36)}
{!isSecret || isSecretVisible ? text : "".repeat(text?.length ?? 36)}
</span>
<Tooltip visible={isVisible} text={t("tooltip.copy")} className="w-auto">
<ButtonIconCopy
Expand Down
78 changes: 55 additions & 23 deletions resources/ts/Components/IntegrationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Alert } from "./Alert";
import { classNames } from "../utils/classNames";
import { usePolling } from "../hooks/usePolling";
import { ButtonSecondary } from "./ButtonSecondary";
import { usePageProps } from "../hooks/usePageProps";

type Props = Integration &
Credentials & {
Expand Down Expand Up @@ -67,39 +68,70 @@ export const IntegrationCard = ({
legacyProdConsumer,
testClient,
prodClient,
keycloakTestClient,
keycloakProdClient,
keyVisibility,
onEdit,
}: Props) => {
const { t } = useTranslation();
const { config } = usePageProps();
const keycloakEnabled = config.keycloakEnabled;

const integrationTypesInfo = useIntegrationTypesInfo();

const auth0TestClientWithLabels = [
{
label: "details.credentials.client_id",
value: testClient?.clientId,
},
{
label: "details.credentials.client_secret",
value: testClient?.clientSecret,
},
];
const testClientWithLabels = keycloakEnabled
? [
{
label: "details.credentials.client_id",
value: keycloakTestClient?.clientId,
},
{
label: "details.credentials.client_secret",
value: keycloakTestClient?.clientSecret,
},
]
: [
{
label: "details.credentials.client_id",
value: testClient?.clientId,
},
{
label: "details.credentials.client_secret",
value: testClient?.clientSecret,
},
];

const auth0ProdClientWithLabels = [
{
label: "details.credentials.client_id",
value: prodClient?.clientId,
},
{
label: "details.credentials.client_secret",
value: prodClient?.clientSecret,
},
];
const prodClientWithLabels = keycloakEnabled
? [
{
label: "details.credentials.client_id",
value: keycloakProdClient?.clientId,
},
{
label: "details.credentials.client_secret",
value: keycloakProdClient?.clientSecret,
},
]
: [
{
label: "details.credentials.client_id",
value: prodClient?.clientId,
},
{
label: "details.credentials.client_secret",
value: prodClient?.clientSecret,
},
];

const clientSecretLabel = t("details.credentials.client_secret");

const hasAnyCredentials = Boolean(
legacyTestConsumer || legacyProdConsumer || testClient || prodClient
legacyTestConsumer ||
legacyProdConsumer ||
testClient ||
prodClient ||
keycloakProdClient ||
keycloakProdClient
);

usePolling(!hasAnyCredentials, { only: ["credentials"] });
Expand All @@ -120,7 +152,7 @@ export const IntegrationCard = ({
</Heading>
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-2">
{auth0TestClientWithLabels.map((client) => (
{testClientWithLabels.map((client) => (
<div
key={`${client.label}-${client.value}`}
className="flex gap-1 max-md:flex-col max-md:items-start"
Expand Down Expand Up @@ -189,7 +221,7 @@ export const IntegrationCard = ({
)}
{status === IntegrationStatus.Active && (
<div className="flex flex-col gap-2">
{auth0ProdClientWithLabels.map((client) => (
{prodClientWithLabels.map((client) => (
<div
key={`${client.label}-${client.value}`}
className="flex gap-1 max-md:flex-col max-md:items-start"
Expand Down
Loading

0 comments on commit 694b734

Please sign in to comment.