Skip to content

Commit

Permalink
Merge branch 'main' into PPF-396-duplicate-contact
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Apr 16, 2024
2 parents 77e9bb5 + abdac2d commit 8346b7a
Show file tree
Hide file tree
Showing 31 changed files with 401 additions and 151 deletions.
11 changes: 9 additions & 2 deletions app/Domain/Auth/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ public function register(): void
{
$this->app->bind(Auth0Interface::class, Auth0::class);

/** @var array $adminEmails */
$adminEmails = config('nova.users');

$this->app->when(AccessController::class)
->needs('$adminEmails')
->give(config('nova.users'));
->give($adminEmails);

Gate::define('access-integration', function (UserModel $user, string $integrationId) use ($adminEmails): bool {
if (in_array($user->email, $adminEmails)) {
return true;
}

Gate::define('access-integration', function (UserModel $user, string $integrationId): bool {
/**
* @var ContactRepository $contactRepository
*/
Expand Down
15 changes: 15 additions & 0 deletions app/Domain/Integrations/Controllers/IntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
use App\Domain\Integrations\Mappers\UpdateIntegrationUrlsMapper;
use App\Domain\Integrations\Repositories\IntegrationRepository;
use App\Domain\Integrations\Repositories\IntegrationUrlRepository;
use App\Domain\KeyVisibilityUpgrades\KeyVisibilityUpgrade;
use App\Domain\Organizations\Repositories\OrganizationRepository;
use App\Domain\Subscriptions\Repositories\SubscriptionRepository;
use App\Domain\KeyVisibilityUpgrades\Repositories\KeyVisibilityUpgradeRepository;
use App\Http\Controllers\Controller;
use App\ProjectAanvraag\ProjectAanvraagUrl;
use App\Router\TranslatedRoute;
use App\UiTiDv1\Repositories\UiTiDv1ConsumerRepository;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\UniqueConstraintViolationException;
use Illuminate\Http\RedirectResponse;
Expand Down Expand Up @@ -147,12 +149,25 @@ public function update(UpdateIntegrationRequest $request, string $id): RedirectR
return Redirect::back();
}

private function getExpirationDateForOldCredentials(?KeyVisibilityUpgrade $upgrade): ?string
{
$createdAt = $upgrade?->getCreatedAt();
if ($createdAt === null) {
return null;
}
$expirationAmountInDays = config('key_visibility.oldCredentialsExpirationAmountInDays');
$expirationDate = (new Carbon($createdAt))->addDays($expirationAmountInDays);
return $expirationDate->toISOString();
}

public function show(string $id): Response
{
$integration = $this->integrationRepository->getById(Uuid::fromString($id));
$oldCredentialsExpirationDate = $this->getExpirationDateForOldCredentials($integration->getKeyVisibilityUpgrade());

return Inertia::render('Integrations/Detail', [
'integration' => $integration->toArray(),
'oldCredentialsExpirationDate' => $oldCredentialsExpirationDate,
'email' => Auth::user()?->email,
'subscriptions' => $this->subscriptionRepository->all(),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function rules(): array
return [
'environment' => ['required', new Enum(Environment::class)],
'type' => ['required', new Enum(IntegrationUrlType::class)],
'url' => ['required', 'url:https', 'max:255'],
'url' => ['required', 'url:http,https', 'max:255'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function rules(): array
'id' => ['string'],
'environment' => ['required', new Enum(Environment::class)],
'type' => ['required', new Enum(IntegrationUrlType::class)],
'url' => ['required', 'url:https', 'max:255', new UniqueIntegrationUrl($this->input('urls'))],
'url' => ['required', 'url:http,https', 'max:255', new UniqueIntegrationUrl($this->input('urls'))],
]),
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Nova/Resources/IntegrationUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function fields(NovaRequest $request): array

Text::make('Url')
->sortable()
->rules('required', 'url:https', 'max:255', Rule::unique('integrations_urls')->where(function ($query) use ($request) {
->rules('required', 'url:http,https', 'max:255', Rule::unique('integrations_urls')->where(function ($query) use ($request) {
return $query->where('integration_id', $request->integration)
->where('environment', $request->environment)
->where('type', $request->type);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"require-dev": {
"barryvdh/laravel-debugbar": "^3.7",
"fakerphp/faker": "^1.9.1",
"larastan/larastan": "^2.0",
"laravel/sail": "^1.16",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.5",
"nunomaduro/larastan": "^2.0",
"phpunit/phpunit": "^10.2.2",
"publiq/php-cs-fixer-config": "^2.0",
"spatie/laravel-ignition": "^2.1.3"
Expand Down
209 changes: 104 additions & 105 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/key_visibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

return [
'oldCredentialsExpirationAmountInDays' => 180,
];
14 changes: 3 additions & 11 deletions e2e/tests/integrations/admin/create-coupon.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { expect, test } from "@playwright/test";
import { faker } from "@faker-js/faker";
import { createCoupon } from "./create-coupon.js";

test.use({ storageState: "playwright/.auth/admin.json" });

test("As an admin I can create a coupon)", async ({ page }) => {
await page.goto("/admin");
await page.getByRole("link", { name: "Coupons" }).click();
await page.getByRole("link", { name: "Create Coupon" }).click();
await page.waitForLoadState("networkidle");

const couponCode = faker.string.uuid();

await page.getByLabel("Coupon code").fill(couponCode);
await page.getByRole("button", { name: "Create Coupon" }).click();
await page.waitForLoadState("networkidle");

const { couponCode } = await createCoupon(page);

await expect(
page.locator("h1").getByText(`Coupon Details: ${couponCode}`)
Expand Down
17 changes: 17 additions & 0 deletions e2e/tests/integrations/admin/create-coupon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type Page } from "@playwright/test";
import { faker } from "@faker-js/faker";

export async function createCoupon(page: Page) {
await page.goto("/admin");
await page.getByRole("link", { name: "Coupons" }).click();
await page.getByRole("link", { name: "Create Coupon" }).click();
await page.waitForLoadState("networkidle");

const couponCode = faker.string.uuid();

await page.getByLabel("Coupon code").fill(couponCode);
await page.getByRole("button", { name: "Create Coupon" }).click();
await page.waitForLoadState("networkidle");

return { couponCode, page };
}
Loading

0 comments on commit 8346b7a

Please sign in to comment.