mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-19 17:20:30 +00:00
✨ Add OAuth functionality, MCP tools, and feature tests
- 🔒 Added migrations for `oauth_access_tokens`, `oauth_refresh_tokens`, `oauth_auth_codes`, `oauth_clients`, and `oauth_device_codes`. - 🤖 Created MCP tools (Meetups, Cities, Venues, Courses, Lecturers) for managing entities with authentication and validation. - 🛠️ Implemented Passport-backed OAuth API guard configuration and validation endpoints. - ✅ Added comprehensive feature tests for MCP tools and OAuth functionality (access control, validation, and token-based authentication).
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\City;
|
||||
|
||||
use App\Http\Requests\Api\StoreCityRequest;
|
||||
use App\Http\Resources\CityResource;
|
||||
use App\Models\City;
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
|
||||
#[Description('Legt eine neue Stadt für den authentifizierten Nutzer an. Der Ersteller (created_by) wird automatisch gesetzt.')]
|
||||
class CreateCityTool extends Tool
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if ($user === null || Gate::forUser($user)->denies('create', City::class)) {
|
||||
return Response::error('Nicht berechtigt, eine Stadt anzulegen.');
|
||||
}
|
||||
|
||||
$storeRequest = new StoreCityRequest;
|
||||
|
||||
$validated = $request->validate(
|
||||
$storeRequest->rules(),
|
||||
$storeRequest->messages(),
|
||||
);
|
||||
|
||||
$city = City::create($validated);
|
||||
|
||||
return Response::json(CityResource::make($city->fresh())->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'country_id' => $schema->integer()->description('ID des zugehörigen Landes.')->required(),
|
||||
'name' => $schema->string()->description('Name der Stadt.')->required(),
|
||||
'longitude' => $schema->number()->description('Längengrad der Stadt.')->required(),
|
||||
'latitude' => $schema->number()->description('Breitengrad der Stadt.')->required(),
|
||||
'population' => $schema->integer()->description('Einwohnerzahl der Stadt.'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\City;
|
||||
|
||||
use App\Http\Resources\CityResource;
|
||||
use App\Models\City;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
#[Description('Listet alle vom authentifizierten Nutzer erstellten Städte, alphabetisch sortiert.')]
|
||||
class ListMyCitiesTool extends Tool
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if ($user === null || Gate::forUser($user)->denies('viewAny', City::class)) {
|
||||
return Response::error('Nicht authentifiziert.');
|
||||
}
|
||||
|
||||
$cities = City::query()
|
||||
->where('created_by', $user->getAuthIdentifier())
|
||||
->orderBy('name')
|
||||
->get();
|
||||
|
||||
return Response::json(CityResource::collection($cities)->resolve());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\City;
|
||||
|
||||
use App\Http\Resources\CityResource;
|
||||
use App\Models\City;
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
use Laravel\Mcp\Server\Tools\Annotations\IsReadOnly;
|
||||
|
||||
#[IsReadOnly]
|
||||
#[Description('Zeigt eine einzelne, vom authentifizierten Nutzer erstellte Stadt.')]
|
||||
class ShowMyCityTool extends Tool
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$city = City::find($request->get('id'));
|
||||
|
||||
if (! $city) {
|
||||
return Response::error('Stadt nicht gefunden.');
|
||||
}
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
if ($user === null || Gate::forUser($user)->denies('view', $city)) {
|
||||
return Response::error('Nur der Ersteller oder ein Super-Admin darf diese Stadt sehen.');
|
||||
}
|
||||
|
||||
return Response::json(CityResource::make($city)->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'id' => $schema->integer()->description('ID der Stadt.')->required(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\City;
|
||||
|
||||
use App\Http\Requests\Api\UpdateCityRequest;
|
||||
use App\Http\Resources\CityResource;
|
||||
use App\Models\City;
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Illuminate\JsonSchema\Types\Type;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Tool;
|
||||
|
||||
#[Description('Aktualisiert eine bestehende Stadt. Nur der Ersteller oder ein Super-Admin darf sie ändern.')]
|
||||
class UpdateCityTool extends Tool
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$city = City::find($request->get('id'));
|
||||
|
||||
if (! $city) {
|
||||
return Response::error('Stadt nicht gefunden.');
|
||||
}
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
if ($user === null || Gate::forUser($user)->denies('update', $city)) {
|
||||
return Response::error('Nur der Ersteller oder ein Super-Admin darf diese Stadt ändern.');
|
||||
}
|
||||
|
||||
$validated = $request->validate((new UpdateCityRequest)->rules());
|
||||
|
||||
$city->update($validated);
|
||||
|
||||
return Response::json(CityResource::make($city->fresh())->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Type>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'id' => $schema->integer()->description('ID der zu aktualisierenden Stadt.')->required(),
|
||||
'country_id' => $schema->integer()->description('ID des zugehörigen Landes.'),
|
||||
'name' => $schema->string()->description('Name der Stadt.'),
|
||||
'longitude' => $schema->number()->description('Längengrad der Stadt.'),
|
||||
'latitude' => $schema->number()->description('Breitengrad der Stadt.'),
|
||||
'population' => $schema->integer()->description('Einwohnerzahl der Stadt.'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user