Skip to content

Commit

Permalink
Merge branch 'main' into PPF-485-unblock-insightly
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVHG authored Jun 3, 2024
2 parents e1cd609 + 59bf964 commit 14507f4
Show file tree
Hide file tree
Showing 20 changed files with 867 additions and 482 deletions.
2 changes: 1 addition & 1 deletion .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ E2E_TEST_PASSWORD=
E2E_TEST_ADMIN_EMAIL=[email protected]
E2E_TEST_ADMIN_PASSWORD=

UITPAS_INTEGRATION_TYPE_ENABLED=true
UITPAS_INTEGRATION_TYPE_ENABLED=false
VITE_UITPAS_INTEGRATION_TYPE_ENABLED=${UITPAS_INTEGRATION_TYPE_ENABLED}

SEARCH_BASE_URI=https://search-acc.uitdatabank.be/
Expand Down
3 changes: 3 additions & 0 deletions app/Domain/Integrations/IntegrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use App\Domain\Integrations\Listeners\UpgradeKeyVisibility;
use App\Domain\Integrations\Repositories\EloquentIntegrationRepository;
use App\Domain\Integrations\Repositories\EloquentIntegrationUrlRepository;
use App\Domain\Integrations\Repositories\EloquentOrganizerRepository;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Integrations\Repositories\IntegrationUrlRepository;
use App\Domain\Integrations\Repositories\OrganizerRepository;
use App\Domain\KeyVisibilityUpgrades\Events\KeyVisibilityUpgradeCreated;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
Expand All @@ -21,6 +23,7 @@ public function register(): void
{
$this->app->bind(IntegrationRepository::class, EloquentIntegrationRepository::class);
$this->app->bind(IntegrationUrlRepository::class, EloquentIntegrationUrlRepository::class);
$this->app->bind(OrganizerRepository::class, EloquentOrganizerRepository::class);

Event::listen(IntegrationCreated::class, [ActivateIntegration::class, 'handle']);
Event::listen(KeyVisibilityUpgradeCreated::class, [UpgradeKeyVisibility::class, 'handle']);
Expand Down
38 changes: 21 additions & 17 deletions app/Domain/Integrations/Models/IntegrationModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use App\Domain\Integrations\Events\IntegrationBlocked;
use App\Domain\Integrations\Events\IntegrationCreated;
use App\Domain\Integrations\Events\IntegrationDeleted;
use App\Domain\Integrations\Events\IntegrationUnblocked;
use App\Domain\Integrations\Events\IntegrationUpdated;
use App\Domain\Integrations\Integration;
use App\Domain\Integrations\IntegrationPartnerStatus;
Expand Down Expand Up @@ -93,6 +92,11 @@ public function isWidgets(): bool
return $this->type === IntegrationType::Widgets->value;
}

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

protected static function booted(): void
{
self::created(
Expand Down Expand Up @@ -161,22 +165,14 @@ public function block(): void

public function unblock(): void
{
$integrationPreviousStatusBuilder = IntegrationPreviousStatusModel::query()
->where('id', '=', $this->id);

if ($integrationPreviousStatusBuilder->count() === 0) {
$this->update([
'status' => IntegrationStatus::Draft,
]);
} else {
/** @var IntegrationPreviousStatusModel $integrationPreviousStatusModel */
$integrationPreviousStatusModel = $integrationPreviousStatusBuilder->first();
$this->update([
'status' => $integrationPreviousStatusModel->status,
]);
$integrationPreviousStatusModel->delete();
}
IntegrationUnblocked::dispatch(Uuid::fromString($this->id));
/** @var ?IntegrationPreviousStatusModel $integrationPreviousStatus */
$integrationPreviousStatus = IntegrationPreviousStatusModel::query()->find($this->id);

$this->update([
'status' => $integrationPreviousStatus ? $integrationPreviousStatus->status : IntegrationStatus::Draft,
]);

$integrationPreviousStatus?->delete();
}

/**
Expand All @@ -187,6 +183,14 @@ public function keyVisibilityUpgrade(): HasOne
return $this->hasOne(KeyVisibilityUpgradeModel::class, 'integration_id');
}

/**
* @return HasMany<OrganizerModel>
*/
public function organizers(): HasMany
{
return $this->hasMany(OrganizerModel::class, 'integration_id');
}

/**
* @return HasMany<ContactModel>
*/
Expand Down
29 changes: 29 additions & 0 deletions app/Domain/Integrations/Models/OrganizerModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Models;

use App\Domain\Integrations\Organizer;
use App\Models\UuidModel;
use Ramsey\Uuid\Uuid;

final class OrganizerModel extends UuidModel
{
protected $table = 'organizers';

protected $fillable = [
'id',
'integration_id',
'organizer_id',
];

public function toDomain(): Organizer
{
return new Organizer(
Uuid::fromString($this->id),
Uuid::fromString($this->integration_id),
Uuid::fromString($this->organizer_id),
);
}
}
17 changes: 17 additions & 0 deletions app/Domain/Integrations/Organizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations;

use Ramsey\Uuid\UuidInterface;

final readonly class Organizer
{
public function __construct(
public UuidInterface $id,
public UuidInterface $integrationId,
public UuidInterface $organizerId
) {
}
}
51 changes: 51 additions & 0 deletions app/Domain/Integrations/Policies/OrganizerPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Policies;

use App\Domain\Auth\Models\UserModel;
use App\Domain\Integrations\Models\OrganizerModel;

final class OrganizerPolicy
{
public function viewAny(UserModel $userModel): bool
{
return true;
}

public function view(UserModel $userModel, OrganizerModel $organizerModel): bool
{
return true;
}

public function create(UserModel $userModel): bool
{
return false;
}

public function update(UserModel $userModel, OrganizerModel $organizerModel): bool
{
return false;
}

public function delete(UserModel $userModel, OrganizerModel $organizerModel): bool
{
return true;
}

public function restore(UserModel $userModel, OrganizerModel $organizerModel): bool
{
return false;
}

public function replicate(UserModel $userModel, OrganizerModel $organizerModel): bool
{
return false;
}

public function forceDelete(UserModel $userModel, OrganizerModel $organizerModel): bool
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Repositories;

use App\Domain\Integrations\Models\OrganizerModel;
use App\Domain\Integrations\Organizer;

final class EloquentOrganizerRepository implements OrganizerRepository
{
public function create(Organizer $organizer): void
{
OrganizerModel::query()->create([
'id' => $organizer->id->toString(),
'integration_id' => $organizer->integrationId->toString(),
'organizer_id' => $organizer->organizerId->toString(),
]);
}
}
12 changes: 12 additions & 0 deletions app/Domain/Integrations/Repositories/OrganizerRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Domain\Integrations\Repositories;

use App\Domain\Integrations\Organizer;

interface OrganizerRepository
{
public function create(Organizer $organizer): void;
}
61 changes: 61 additions & 0 deletions app/Nova/Actions/AddOrganizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\OrganizerRepository;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Actions\ActionResponse;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Ramsey\Uuid\Uuid;

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

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

public function handle(ActionFields $fields, Collection $integrations): ActionResponse
{
Log::info('AddOrganizer action started.');
/** @var IntegrationModel $integration */
$integration = $integrations->first();

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

$this->organizerRepository->create(
new Organizer(
Uuid::uuid4(),
Uuid::fromString($integration->id),
$organizationId
)
);

return Action::message('Organizer "' . $organizationIdAsString . '" added.');
}

public function fields(NovaRequest $request): array
{
return [
Text::make('Organizer ID', 'organizer_id')
->rules(
'required',
'string'
),
];
}
}
6 changes: 5 additions & 1 deletion app/Nova/Resources/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public function fields(NovaRequest $request): array
->rules('required', 'email', 'max:255'),

Select::make('Type')
->filterable(fn ($request, $query, $value) => $query->where('contacts.type', 'LIKE', $value))
->filterable(
function (NovaRequest $request, Builder $query, $value): void {
$query->where('contacts.type', 'LIKE', $value);
}
)
->sortable()
->options([
ContactType::Functional->value => ContactType::Functional->name,
Expand Down
12 changes: 12 additions & 0 deletions app/Nova/Resources/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use App\Domain\Integrations\KeyVisibility;
use App\Domain\Integrations\Models\IntegrationModel;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Integrations\Repositories\OrganizerRepository;
use App\Nova\Actions\ActivateIntegration;
use App\Nova\Actions\AddOrganizer;
use App\Nova\Actions\ApproveIntegration;
use App\Nova\Actions\Auth0\CreateMissingAuth0Clients;
use App\Nova\Actions\BlockIntegration;
Expand Down Expand Up @@ -176,6 +178,8 @@ public function fields(NovaRequest $request): array
HasMany::make('UiTiD v1 Consumer Credentials', 'uiTiDv1Consumers', UiTiDv1::class),
HasMany::make('UiTiD v2 Client Credentials (Auth0)', 'auth0Clients', Auth0Client::class),

HasMany::make('Organizers'),

HasMany::make('Contacts'),

HasMany::make('Urls', 'urls', IntegrationUrl::class),
Expand Down Expand Up @@ -242,6 +246,14 @@ public function actions(NovaRequest $request): array
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->hasMissingUiTiDv1Consumers())
->canRun(fn (Request $request, IntegrationModel $model) => $model->hasMissingUiTiDv1Consumers()),

(new AddOrganizer(App::make(OrganizerRepository::class)))
->exceptOnIndex()
->confirmText('Are you sure you want to add an organizer?')
->confirmButtonText('Add')
->cancelButtonText('Cancel')
->canSee(fn (Request $request) => $request instanceof ActionRequest || $this->isUiTPAS())
->canRun(fn (Request $request, IntegrationModel $model) => $model->isUiTPAS()),
];
}
}
51 changes: 51 additions & 0 deletions app/Nova/Resources/Organizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace App\Nova\Resources;

use App\Domain\Integrations\Models\OrganizerModel;
use App\Nova\Resource;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

/**
* @mixin OrganizerModel
*/
final class Organizer extends Resource
{
public static string $model = OrganizerModel::class;

public static $title = 'organizer_id';

public static $displayInNavigation = false;

/**
* @var array<string>
*/
public static $search = [
'id',
'integration_id',
'organizer_id',
];

/**
* @return array<Field>
*/
public function fields(NovaRequest $request): array
{
return [
ID::make()
->readonly()
->hideFromIndex(),

Text::make('organizer_id')
->readonly(),

HasMany::make('Activity Log'),
];
}
}
Loading

0 comments on commit 14507f4

Please sign in to comment.