Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ npm-debug.log
yarn-error.log
.DS_Store
_architecture
_docker_production_test
.devcontainer
.agents
skills-lock.json
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked \
# Install dev.command.sh
COPY --chmod=755 --chown=www-data:www-data docker/app/dev.command.sh /usr/bin/dev.command.sh

# -----------------------------------------------------
# APP - TEST
# -----------------------------------------------------
FROM app_root AS app_test

COPY --chown=www-data:www-data . .
COPY --from=node_builder --chown=www-data:www-data /var/www/html/public/build /var/www/html/public/build

RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,id=apt-lib,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get upgrade -y && apt-get install -y \
tmux \
&& pecl install xdebug-3.5.0 \
&& docker-php-ext-enable xdebug

RUN mkdir -p /var/www/html/storage/framework/cache \
&& mkdir -p /var/www/html/storage/framework/sessions \
&& mkdir -p /var/www/html/storage/framework/views \
&& mkdir -p /var/www/html/storage/logs \
&& mkdir -p /var/www/html/storage/app/public \
&& chown -R www-data:www-data /var/www/html/storage \
&& composer install --no-cache --no-progress --no-interaction --verbose \
&& composer clear-cache

ENV XDEBUG_MODE=coverage
# -----------------------------------------------------
# APP - PROD
# -----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/CreateSanctumTokenForUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function handle(): void
return;
}

if ($user->isRemoved === false) {
if ($user->isRemoved) {
$this->error('User account is suspended!');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Removeuser.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle(ProfileService $profileService)
$this->error('User not found!');
return;
}
if($user->isRemoved === false){
if($user->isRemoved){
$this->error('User is already removed!');
return;
}
Expand Down
22 changes: 11 additions & 11 deletions app/Services/Profile/ApiTokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@

namespace App\Services\Profile;

use App\Models\User;
use App\Services\Profile\Exception\NoCurrentUserException;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Contracts\Auth\Factory as AuthFactory;
use Illuminate\Support\Collection;
use Laravel\Sanctum\NewAccessToken;
use Psr\Log\LoggerInterface;

readonly class ApiTokenService
{
public function __construct(
#[CurrentUser]
private User|null $currentUser,
private AuthFactory $auth,
private LoggerInterface $logger
)
{
}

public function createApiToken(string $name): NewAccessToken
{
if (!$this->currentUser) {
$user = $this->auth->user();
if (!$user) {
throw NoCurrentUserException::forMethod(__METHOD__);
}
return $this->currentUser->createToken($name);
return $user->createToken($name);
}

/**
* @return Collection<array{id: int, name: string}>
*/
public function fetchTokenList(): Collection
{
if (!$this->currentUser) {
$user = $this->auth->user();
if (!$user) {
throw NoCurrentUserException::forMethod(__METHOD__);
}

// Construct an array of token data
return $this->currentUser->tokens()->get()->map(function ($token) {
return $user->tokens()->get()->map(function ($token) {
return [
'id' => $token->id,
'name' => $token->name,
Expand All @@ -47,11 +46,12 @@ public function fetchTokenList(): Collection

public function revokeToken(int $tokenId): void
{
if (!$this->currentUser) {
$user = $this->auth->user();
if (!$user) {
throw NoCurrentUserException::forMethod(__METHOD__);
}
try {
$token = $this->currentUser->tokens()->where('id', $tokenId);
$token = $user->tokens()->where('id', $tokenId);
$token->delete();
} catch (\Throwable $e) {
$this->logger->error('Error revoking API token', ['token_id' => $tokenId, 'exception' => $e]);
Expand Down
17 changes: 17 additions & 0 deletions bin/_env/addons/ci_phpunit.addon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { AddonEntrypoint } from '@/loadAddons.ts';

export const addon: AddonEntrypoint = async (context) => ({
commands: async (program) => {
program
.command('ci:phpunit')
.description('runs the phpunit test suite for laravel as service')
.allowExcessArguments(true)
.allowUnknownOption(true)
.action(async (_, command) => {
await context.docker.executeComposeCommand(
['-f', 'docker-compose.ci.yml','run', '--build', '--rm', 'test', ...command.args],
{ cwd: context.paths.projectDir, interactive: true }
);
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UpdateEnumTypeOnUsageRecordsTable extends Migration
{
public function up()
{
if(env('DB_CONNECTION') == 'pgsql') {
if (env('DB_CONNECTION') == 'pgsql') {
// Check if the column uses a custom enum type or is just a varchar with a check constraint:
// Query information_schema to get the column type
$columnType = DB::table('information_schema.columns')
Expand All @@ -32,8 +32,12 @@ public function up()
CHECK (type IN ('private', 'group', 'api'));"
);
}
}
else{
} elseif (DB::getDriverName() === 'sqlite') {
// SQLite doesn't support enum → use string instead
Schema::table('usage_records', function (Blueprint $table) {
$table->string('type', 50)->change();
});
} else {
// This updates the 'type' column to include 'api'.
DB::statement("
ALTER TABLE `usage_records`
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
test:
container_name: ${PROJECT_NAME:-hawki}-test
build:
context: .
target: app_test
environment:
- APP_KEY=${APP_KEY:-N9bC6l&vZY2EO4be%Sty3hDOQSfPB7e0}
- APP_ENV=testing
- DB_CONNECTION=sqlite
- "DB_DATABASE=:memory:"
- CACHE_STORE=array
- SESSION_DRIVER=array
- QUEUE_CONNECTION=sync
- MAIL_MAILER=array
entrypoint: ["sh", "-c", "APP_ENV=testing php vendor/bin/phpunit"]
Loading