Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Dec 22, 2023
1 parent 9bd83c0 commit c90ac8e
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 81 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build and push image to registry

on:
push:
branches:
- main
tags:
- v*

jobs:
build:
uses: code4romania/.github/.github/workflows/build-push-image.yml@main
with:
images: code4romania/sunrise
secrets:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
token: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
php-version:
- "8.3"
- "8.2"

env:
extensions: mbstring, pdo, pdo_mysql, intl, gd
Expand Down
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.3-fpm-alpine AS vendor
FROM php:8.2-fpm-alpine AS vendor

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /tmp
Expand All @@ -16,12 +16,14 @@ RUN apk update && \
#
# install extensions
install-php-extensions \
excimer \
exif \
gd \
pdo_mysql \
zip \
imagick \
intl \
mbstring \
exif
pdo_mysql \
zip

COPY --chown=www-data:www-data . /var/www
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
Expand Down Expand Up @@ -52,7 +54,7 @@ RUN npm run build

FROM vendor

ARG S6_OVERLAY_VERSION=3.1.6.1
ARG S6_OVERLAY_VERSION=3.1.6.2

ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
Expand All @@ -72,6 +74,11 @@ ENV APP_ENV production
ENV APP_DEBUG false
ENV LOG_CHANNEL stderr

# determines what the container should do if one of the service scripts fails
# 0: Continue silently even if a script has failed.
# 1: Continue but warn with an annoying error message.ext script
# 2: Stop the container.
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME 0

EXPOSE 80
4 changes: 4 additions & 0 deletions app/Concerns/BelongsToOrganization.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ protected static function bootBelongsToOrganization(): void
return;
}

if (! Filament::hasTenancy()) {
return;
}

$model->organization_id = filament()->getTenant()->id;
});

Expand Down
22 changes: 0 additions & 22 deletions app/Http/Middleware/ApplyTenantScopes.php

This file was deleted.

5 changes: 1 addition & 4 deletions app/Providers/Filament/OrganizationPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Filament\Organizations\Pages;
use App\Filament\Organizations\Pages\Profile\UserPersonalInfo;
use App\Http\Middleware\ApplyTenantScopes;
use App\Models\Organization;
use Filament\Facades\Filament;
use Filament\Forms\Components\DateTimePicker;
Expand Down Expand Up @@ -129,9 +128,7 @@ public function panel(Panel $panel): Panel
])
->tenant(Organization::class, 'slug')
->tenantProfile(Pages\Tenancy\EditOrganizationProfile::class)
->tenantMiddleware([
// ApplyTenantScopes::class,
], isPersistent: true);
->tenantRoutePrefix('org');
}

protected function setDefaultDateTimeDisplayFormats(): void
Expand Down
71 changes: 26 additions & 45 deletions database/factories/OrganizationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,81 +46,62 @@ public function definition(): array
];
}

public function configure(): static
public function withUsers(int $count = 25): static
{
return $this->afterCreating(function (Organization $organization) {
return $this->afterCreating(function (Organization $organization) use ($count) {
$organization->users()->attach(
User::factory()
->count(25)
->count($count)
->sequence(fn (Sequence $sequence) => [
'email' => sprintf('user-%d-%[email protected]', $organization->id, $sequence->index + 1),
])
->create()
->pluck('id')
->toArray()
);
});
}

public function withCommunityProfile(): static
{
return $this->afterCreating(function (Organization $organization) {
CommunityProfile::factory()
->for($organization)
->create();
});
}

public function withBeneficiaries(int $count = 50): static
{
return $this->afterCreating(function (Organization $organization) use ($count) {
Beneficiary::factory()
->count(5)
->withContactNotes()
->withChildren()
->withAntecedents()
->for($organization)
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->count($count)
->withCNP()
->withChildren()
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withID()
->withChildren()
->withAntecedents()
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withID()
->withLegalResidence()
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withEffectiveResidence()
->withContactNotes()
->withChildren()
->withAntecedents()
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withLegalResidence()
->withEffectiveResidence()
->withAntecedents()
->create();
});
}

public function withInterventions(int $count = 5): static
{
return $this->afterCreating(function (Organization $organization) use ($count) {
Service::query()
->inRandomOrder()
->limit(5)
->limit($count)
->get()
->each(function (Service $service) use ($organization) {
Intervention::factory()
->count(5)
->each(
fn (Service $service) => Intervention::factory()
->count($count)
->for($organization)
->for($service)
->create();
});
->create()
);
});
}
}
12 changes: 12 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Database\Factories;

use App\Models\Organization;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -51,4 +53,14 @@ public function admin(): static
'is_admin' => true,
]);
}

public function withOrganization(): static
{
return $this->afterCreating(function (User $user) {
$user->organizations()->attach(
Organization::factory()
->create()
);
});
}
}
4 changes: 4 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function run(): void

Organization::factory()
->count(10)
->withBeneficiaries()
->withCommunityProfile()
->withInterventions()
->withUsers()
->create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
it('can authenticate', function () {
$this->assertGuest();

$user = User::factory()->create();
$user = User::factory()
->withOrganization()
->create();

livewire(Login::class)
->fillForm([
Expand All @@ -35,7 +37,9 @@
it('can authenticate and redirect user to their intended URL', function () {
session()->put('url.intended', $intendedUrl = Str::random());

$user = User::factory()->create();
$user = User::factory()
->withOrganization()
->create();

livewire(Login::class)
->fillForm([
Expand All @@ -52,7 +56,9 @@
});

it('cannot authenticate with incorrect credentials', function () {
$user = User::factory()->create();
$user = User::factory()
->withOrganization()
->create();

livewire(Login::class)
->fillForm([
Expand All @@ -68,7 +74,9 @@
it('can throttle authentication attempts', function () {
$this->assertGuest();

$user = User::factory()->create();
$user = User::factory()
->withOrganization()
->create();

collect(range(1, 5))
->each(function () use ($user) {
Expand Down

0 comments on commit c90ac8e

Please sign in to comment.