Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPF-460-UiTPAS activation #1214

Merged
merged 46 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
14fd54a
Add getOrganizers
vhande Jun 19, 2024
25635ae
Create GetOrganizersRequest.php
vhande Jun 19, 2024
4159067
Modify UITPAS integration rules
vhande Jun 19, 2024
5d59592
Add validation organizers
vhande Jun 19, 2024
dd7c27a
Add translations uitpas activation
vhande Jun 19, 2024
1dd1912
Add organizers to the activation dialog
vhande Jun 19, 2024
a1beecb
Update styling
vhande Jun 19, 2024
d786366
Add route organizers
vhande Jun 19, 2024
9ed7a86
Fix linting
vhande Jun 19, 2024
94c1347
Add organizer object
vhande Jun 24, 2024
99ce6a9
Change route get
vhande Jun 24, 2024
850dfb1
Fix linting
vhande Jun 24, 2024
6451864
Change rule
vhande Jun 24, 2024
ebbad23
Save organizers
vhande Jun 24, 2024
c34de55
Update handleAddOrganizers
vhande Jun 24, 2024
c5b0168
Use search service
vhande Jun 25, 2024
38d5dd6
Add limit
vhande Jun 25, 2024
e4045cf
Fix stan
vhande Jun 25, 2024
cc7b4c4
Merge branch 'main' into PPF-460-uitpas-activation
vhande Jun 25, 2024
d173e1b
Move `getOrganizers` to dedicated controller
LucWollants Jun 25, 2024
362755b
Remove the `getOrganizers` from `IntegrationController`
LucWollants Jun 25, 2024
039502e
Rename search parameter to `name`
LucWollants Jun 25, 2024
fc19b03
Use new `organizers` endpoint
LucWollants Jun 25, 2024
0c21ea7
Linting
LucWollants Jun 25, 2024
edcde23
Use JsonResponse
vhande Jun 26, 2024
364fda1
Use fetch
vhande Jun 26, 2024
2f6f67e
Create type UiTPASOrganizer
vhande Jun 26, 2024
ffe01fa
Fix linting
vhande Jun 26, 2024
6654804
Fix import
vhande Jun 26, 2024
410fd61
Change debounce time
vhande Jun 26, 2024
46f085b
Input forwardRef
vhande Jun 27, 2024
a7328ec
Improve ActivationDialog
vhande Jun 27, 2024
a13158e
Improve styling
vhande Jun 27, 2024
706447f
Change function name
vhande Jun 27, 2024
67c9548
Create function fetchIntegration
vhande Jun 27, 2024
49d0458
Fix stan
vhande Jun 27, 2024
9195009
Add DB::transaction
vhande Jun 27, 2024
c17bec6
Handle exception
vhande Jun 27, 2024
2a88221
Fix linting
vhande Jun 27, 2024
327a8a8
Add OrganizerMapper
vhande Jun 27, 2024
8c330f6
Implement DB logic
vhande Jun 27, 2024
7f78b20
Fix stan
vhande Jun 27, 2024
08e23ff
Merge branch 'main' into PPF-460-uitpas-activation
vhande Jun 27, 2024
19416af
Improve keyboard accessibility
vhande Jun 27, 2024
6ab22c3
Merge branch 'main' into PPF-460-uitpas-activation
vhande Jun 28, 2024
a35457e
Merge branch 'main' into PPF-460-uitpas-activation
vhande Jun 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use App\Domain\Integrations\IntegrationUrl;
use App\Domain\Integrations\KeyVisibility;
use App\Domain\Integrations\Mappers\OrganizationMapper;
use App\Domain\Integrations\Mappers\OrganizerMapper;
use App\Domain\Integrations\Mappers\StoreContactMapper;
use App\Domain\Integrations\Mappers\StoreIntegrationMapper;
use App\Domain\Integrations\Mappers\StoreIntegrationUrlMapper;
Expand All @@ -33,6 +34,7 @@
use App\Domain\Integrations\Mappers\UpdateIntegrationUrlsMapper;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Integrations\Repositories\IntegrationUrlRepository;
use App\Domain\Integrations\Repositories\OrganizerRepository;
use App\Domain\KeyVisibilityUpgrades\KeyVisibilityUpgrade;
use App\Domain\Organizations\Repositories\OrganizationRepository;
use App\Domain\Subscriptions\Repositories\SubscriptionRepository;
Expand Down Expand Up @@ -63,6 +65,7 @@ public function __construct(
private readonly ContactRepository $contactRepository,
private readonly ContactKeyVisibilityRepository $contactKeyVisibilityRepository,
private readonly OrganizationRepository $organizationRepository,
private readonly OrganizerRepository $organizerRepository,
private readonly CouponRepository $couponRepository,
private readonly Auth0ClientRepository $auth0ClientRepository,
private readonly UiTiDv1ConsumerRepository $uitidV1ConsumerRepository,
Expand Down Expand Up @@ -172,6 +175,7 @@ public function show(string $id): Response
'oldCredentialsExpirationDate' => $oldCredentialsExpirationDate,
'email' => Auth::user()?->email,
'subscriptions' => $this->subscriptionRepository->all(),
'organizers' => session('organizers'),
]);
}

Expand Down Expand Up @@ -288,6 +292,9 @@ public function requestActivation(string $id, RequestActivationRequest $request)
$organization = OrganizationMapper::mapActivationRequest($request);
$this->organizationRepository->save($organization);

$organizers = OrganizerMapper::map($request, $id);
$this->organizerRepository->create(...$organizers);

$this->integrationRepository->requestActivation(Uuid::fromString($id), $organization->id, $request->input('coupon'));

return Redirect::back();
Expand Down
42 changes: 42 additions & 0 deletions app/Domain/Integrations/Controllers/OrganizerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Controllers;

use App\Domain\Integrations\FormRequests\GetOrganizersRequest;
use App\Http\Controllers\Controller;
use App\Search\Sapi3\SearchService;
use CultuurNet\SearchV3\ValueObjects\Organizer;
use Illuminate\Http\JsonResponse;

final class OrganizerController extends Controller
{
public function __construct(private readonly SearchService $searchService)
{
}

public function index(GetOrganizersRequest $request): JsonResponse
{
try {
$organizerName = $request->input('name');

$data = $this->searchService->searchUiTPASOrganizer($organizerName)->getMember()?->getItems() ?? [];

return new JsonResponse(
array_map(function (Organizer $organizer) {
return [
'id' => $organizer->getCdbid(),
'name' => $organizer->getName()?->getValues(),
];
}, $data)
);

} catch (\Exception $e) {
return new JsonResponse(
['exception' => $e->getMessage()]
);
;
}
vhande marked this conversation as resolved.
Show resolved Hide resolved
}
}
20 changes: 20 additions & 0 deletions app/Domain/Integrations/FormRequests/GetOrganizersRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\FormRequests;

use Illuminate\Foundation\Http\FormRequest;

final class GetOrganizersRequest extends FormRequest
{
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => ['required', 'string'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Domain\Integrations\FormRequests;

use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationType;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Subscriptions\Repositories\SubscriptionRepository;
Expand All @@ -24,25 +25,44 @@ public function rules(): array
$rules = collect([
...(new CreateOrganizationRequest())->rules(),
'coupon' => ['nullable', 'string', 'max:255'],
'organizers' => ['required','array'],
'organizers.*.name' => ['required', 'string'],
'organizers.*.id' => ['required', 'string'],
]);

if (!$this->isAccountingInfoRequired()) {
if (!$this->isAccountingInfoRequired() || $this->isUITPAS()) {
$rules->forget(['organization.invoiceEmail', 'organization.vat', 'coupon']);
}

if (!$this->isUITPAS()) {
$rules->forget(['organizers']);
}

return $rules->toArray();
}

private function isAccountingInfoRequired(): bool
private function fetchIntegration(): Integration
{
/** @var IntegrationRepository $integrationRepository */
$integrationRepository = App::get(IntegrationRepository::class);
$integration = $integrationRepository->getById(Uuid::fromString($this->id));
return $integrationRepository->getById(Uuid::fromString($this->id));
}


private function isAccountingInfoRequired(): bool
{
$integration = $this->fetchIntegration();

/** @var SubscriptionRepository $subscriptionRepository */
$subscriptionRepository = App::get(SubscriptionRepository::class);
$subscription = $subscriptionRepository->getById($integration->subscriptionId);

return $integration->type !== IntegrationType::EntryApi || $subscription->price > 0.0;
}

private function isUITPAS(): bool
{
$integration = $this->fetchIntegration();
return $integration->type === IntegrationType::UiTPAS;
}
}
33 changes: 33 additions & 0 deletions app/Domain/Integrations/Mappers/OrganizerMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Mappers;

use App\Domain\Integrations\FormRequests\RequestActivationRequest;
use App\Domain\Integrations\Organizer;
use Ramsey\Uuid\Uuid;

final class OrganizerMapper
{
/**
* @return Organizer[]
*/
public static function map(RequestActivationRequest $request, string $id): array
{
/**
* @var Organizer[] $organizers
*/
$organizers = [];

foreach ($request->input('organizers') ?? [] as $organizer) {
$organizers[] = new Organizer(
Uuid::uuid4(),
Uuid::fromString($id),
Uuid::fromString($organizer['id'])
);
}

return $organizers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

use App\Domain\Integrations\Models\OrganizerModel;
use App\Domain\Integrations\Organizer;
use Illuminate\Support\Facades\DB;

final class EloquentOrganizerRepository implements OrganizerRepository
{
public function create(Organizer $organizer): void
public function create(Organizer ...$organizers): void
{
OrganizerModel::query()->create([
'id' => $organizer->id->toString(),
'integration_id' => $organizer->integrationId->toString(),
'organizer_id' => $organizer->organizerId->toString(),
]);
DB::transaction(function () use ($organizers): void {
foreach ($organizers as $organizer) {
OrganizerModel::query()->create([
'id' => $organizer->id->toString(),
'integration_id' => $organizer->integrationId->toString(),
'organizer_id' => $organizer->organizerId->toString(),
]);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

interface OrganizerRepository
{
public function create(Organizer $organizer): void;
public function create(Organizer ...$organizer): void;
}
1 change: 1 addition & 0 deletions app/Search/Sapi3/Sapi3SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function searchUiTPASOrganizer(string $name): PagedCollection
$searchQuery = new SearchQuery();
$searchQuery->addParameter(new Label('UiTPAS'));
$searchQuery->addParameter(new Name($name));
$searchQuery->setLimit(5);
$searchQuery->setEmbed(true);

return $this->searchClient->searchOrganizers($searchQuery);
Expand Down
1 change: 1 addition & 0 deletions lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
'organization.address.zip' => 'postcode',
'organization.address.city' => 'city',
'organization.vat' => 'VAT or company number',
'organizers' => 'organizers'
],

];
1 change: 1 addition & 0 deletions lang/nl/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
'organization.address.zip' => 'postcode',
'organization.address.city' => 'gemeente',
'organization.vat' => 'BTW of ondernemingsnummer',
'organizers' => 'organisaties'
],

];
Expand Down
8 changes: 8 additions & 0 deletions resources/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
"coupon": "Coupon",
"plan": "Subscription",
"year": "year"
},
"uitpas": {
"partner": "Partner",
"organizers": {
"title": "UiTdatabank organizers",
"info": "Enter the UiTdatabank organizers for which you want to execute actions in UiTPAS.",
"label": "Organizers"
}
}
},
"documentation": {
Expand Down
8 changes: 8 additions & 0 deletions resources/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
"coupon": "Coupon",
"plan": "Abonnement",
"year": "jaar"
},
"uitpas": {
"partner": "Partner",
"organizers": {
"title": "UiTdatabank organisaties",
"info": "Geef de UiTdatabank organisaties op waarvoor je acties in UiTPAS wilt uitvoeren.",
"label": "Organisaties"
}
}
},
"documentation": {
Expand Down
Loading
Loading