From dbeb7b783552960d471da7e61f6f16bbdec7c552 Mon Sep 17 00:00:00 2001 From: korridor <26689068+korridor@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:47:16 +0200 Subject: [PATCH] Fixed private build --- .github/workflows/build-private.yml | 18 ++++++++++++++++++ .github/workflows/build-public.yml | 8 ++++++++ .gitignore | 1 + app/Models/User.php | 10 ++++++++++ tests/Unit/Model/UserModelTest.php | 22 ++++++++++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/.github/workflows/build-private.yml b/.github/workflows/build-private.yml index 985b7a23..b4fc20e7 100644 --- a/.github/workflows/build-private.yml +++ b/.github/workflows/build-private.yml @@ -1,5 +1,13 @@ on: push: + branches: + - main + - develop + pull_request: + paths: + - 'workflows/build-private.yml' + - 'docker/prod/**' + workflow_dispatch: name: Build - Private jobs: @@ -29,6 +37,12 @@ jobs: only_args: --no-dev --no-ansi --no-interaction --prefer-dist --ignore-platform-reqs --classmap-authoritative php_version: 8.3 + - name: "Setup PHP with PECL extension" + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + extensions: mbstring, dom, fileinfo, pgsql, swoole + - name: "Install dependencies" uses: php-actions/composer@v6 if: steps.cache-vendor.outputs.cache-hit != 'true' # Skip if cache hit @@ -48,6 +62,9 @@ jobs: - name: "Build" run: npm run build + - name: "Activate billing extension" + run: php artisan module:enable Billing + - name: "Login to GitHub Container Registry" uses: docker/login-action@v3 with: @@ -65,6 +82,7 @@ jobs: type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} + type=sha,format=long - name: "Set up Docker Buildx" uses: docker/setup-buildx-action@v3 diff --git a/.github/workflows/build-public.yml b/.github/workflows/build-public.yml index b1dedbc9..b618e8c8 100644 --- a/.github/workflows/build-public.yml +++ b/.github/workflows/build-public.yml @@ -1,5 +1,13 @@ on: push: + branches: + - main + - develop + pull_request: + paths: + - 'workflows/build-public.yml' + - 'docker/prod/**' + workflow_dispatch: name: Build - Public jobs: diff --git a/.gitignore b/.gitignore index fdf83066..fba1e433 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ yarn-error.log !/extensions/extensions_autoload.php /auth.json /modules_statuses.json +/k8s diff --git a/app/Models/User.php b/app/Models/User.php index 0ebb13a9..cc44c244 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -30,6 +30,7 @@ * @property string $timezone * @property bool $is_placeholder * @property Weekday $week_start + * @property-read Organization $currentTeam * @property Collection $organizations * @property Collection $timeEntries * @@ -37,6 +38,7 @@ * @method static UserFactory factory() * @method static Builder query() * @method Builder belongsToOrganization(Organization $organization) + * @method Builder active() */ class User extends Authenticatable implements FilamentUser { @@ -131,6 +133,14 @@ public function timeEntries(): HasMany return $this->hasMany(TimeEntry::class); } + /** + * @param Builder $builder + */ + public function scopeActive(Builder $builder): void + { + $builder->where('is_placeholder', '=', false); + } + /** * @param Builder $builder * @return Builder diff --git a/tests/Unit/Model/UserModelTest.php b/tests/Unit/Model/UserModelTest.php index 228284cf..63d3b9c8 100644 --- a/tests/Unit/Model/UserModelTest.php +++ b/tests/Unit/Model/UserModelTest.php @@ -10,7 +10,11 @@ use App\Providers\Filament\AdminPanelProvider; use Filament\Panel; use Illuminate\Support\Facades\Config; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; +#[CoversClass(User::class)] +#[UsesClass(User::class)] class UserModelTest extends ModelTestAbstract { public function test_normal_user_can_not_access_admin_panel(): void @@ -87,4 +91,22 @@ public function test_it_has_many_time_entries(): void $this->assertCount(3, $timeEntriesRel); $this->assertTrue($timeEntriesRel->first()->is($timeEntries->first())); } + + public function test_scope_active_returns_only_non_placeholder_users(): void + { + // Arrange + $placeholder = User::factory()->create([ + 'is_placeholder' => true, + ]); + $user = User::factory()->create([ + 'is_placeholder' => false, + ]); + + // Act + $activeUsers = User::query()->active()->get(); + + // Assert + $this->assertCount(1, $activeUsers); + $this->assertTrue($activeUsers->first()->is($user)); + } }