From 1e912e640504dddd64155da159cf08071a3ff372 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 11 Jun 2023 22:11:10 +0200 Subject: [PATCH 01/41] Update API docs --- .../API/v1/GamejoltAccountBanController.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index ea71f665e..bd15d525c 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -50,9 +50,22 @@ public function index(Request $request) * @response 201 { * "data": { * "gamejoltaccount_id": 12345, - * "reason_id": 3, + * "reason": { + * "name": "Abusing in-game glitches", + * "created_at": "2022-04-02T18:51:14.000000Z", + * "updated_at": "2022-04-02T18:51:14.000000Z" + * }, * "expires_at": "2021-02-01T00:00:00.000000Z", - * "banned_by_id": 1, + * "banned_by": { + * "id": 1, + * "name": "John Doe", + * "email": "john.doe@example.com", + * "username": "john.doe", + * "email_verified_at": "2022-12-21T18:49:11.000000Z", + * "created_at": "2022-04-12T18:48:51.000000Z", + * "updated_at": "2023-06-11T16:45:56.000000Z", + * "profile_photo_url": "" + * }, * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", * "updated_at": "2021-01-01T17:57:10.000000Z", * "created_at": "2021-01-01T17:57:10.000000Z" From c55406af9b02e954834c24ce47b96a35b7ad7638 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Wed, 14 Jun 2023 21:07:07 +0200 Subject: [PATCH 02/41] Update scribe --- composer.json | 2 +- composer.lock | 47 +++++++++++++------------- config/scribe.php | 84 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 95 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index c1f8fa941..010d12ef4 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "kilobyteno/laravel-plausible": "^0.0.2", "kiritokatklian/nova-permission": "^4.0", "kkomelin/laravel-translatable-string-exporter": "^1.16", - "knuckleswtf/scribe": "^3.23", + "knuckleswtf/scribe": "^4.21.2", "laravel/framework": "^9.19", "laravel/jetstream": "^2.6", "laravel/nova": "^4.6", diff --git a/composer.lock b/composer.lock index 3b87a4d12..21229de88 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "84012992a865bf7406111c375689e851", + "content-hash": "2d5b4ac1b231f4a4de08a3d51f17e2c6", "packages": [ { "name": "akaunting/laravel-language", @@ -3887,16 +3887,16 @@ }, { "name": "knuckleswtf/scribe", - "version": "3.37.2", + "version": "4.21.2", "source": { "type": "git", "url": "https://github.com/knuckleswtf/scribe.git", - "reference": "74c483d8f14a57c36fad6a1063cab5437c312c6b" + "reference": "b4b190cd1f8a0c234061cb8d6cbe019eaa13c495" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/knuckleswtf/scribe/zipball/74c483d8f14a57c36fad6a1063cab5437c312c6b", - "reference": "74c483d8f14a57c36fad6a1063cab5437c312c6b", + "url": "https://api.github.com/repos/knuckleswtf/scribe/zipball/b4b190cd1f8a0c234061cb8d6cbe019eaa13c495", + "reference": "b4b190cd1f8a0c234061cb8d6cbe019eaa13c495", "shasum": "" }, "require": { @@ -3905,37 +3905,37 @@ "ext-json": "*", "ext-pdo": "*", "fakerphp/faker": "^1.9.1", - "illuminate/console": "^6.0|^7.0|^8.0|^9.0", - "illuminate/routing": "^6.0|^7.0|^8.0|^9.0", - "illuminate/support": "^6.0|^7.0|^8.0|^9.0", + "illuminate/console": "^8.0|^9.0|^10.0", + "illuminate/routing": "^8.0|^9.0|^10.0", + "illuminate/support": "^8.0|^9.0|^10.0", "league/flysystem": "^1.1.4|^2.1.1|^3.0", "mpociot/reflection-docblock": "^1.0.1", "nikic/php-parser": "^4.10", - "nunomaduro/collision": "^3.0|^4.0|^5.0|^6.0", - "php": ">=7.4", - "ramsey/uuid": "^3.8|^4.0", + "nunomaduro/collision": "^5.10|^6.0|^7.0", + "php": ">=8.0", + "ramsey/uuid": "^4.2.2", "shalvah/clara": "^3.1.0", - "shalvah/upgrader": "0.*", + "shalvah/upgrader": "^0.3.0", "spatie/data-transfer-object": "^2.6|^3.0", - "symfony/var-exporter": "^4.0|^5.0|^6.0", - "symfony/yaml": "^4.0|^5.0|^6.0" + "symfony/var-exporter": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0" }, "replace": { "mpociot/laravel-apidoc-generator": "*" }, "require-dev": { "brianium/paratest": "^6.0", - "dms/phpunit-arraysubset-asserts": "^0.2.0", + "dms/phpunit-arraysubset-asserts": "^0.4", "laravel/legacy-factories": "^1.3.0", - "laravel/lumen-framework": "^6.0|^7.0|^8.0|^9.0", - "league/fractal": "^0.19.0", + "laravel/lumen-framework": "^8.0|^9.0|^10.0", + "league/fractal": "^0.20", "nikic/fast-route": "^1.3", - "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0", + "orchestra/testbench": "^6.0|^7.0|^8.0", "pestphp/pest": "^1.21", "phpstan/phpstan": "^1.0", "phpunit/phpunit": "^9.0|^10.0", - "symfony/css-selector": "^5.3|^6.0", - "symfony/dom-crawler": "^5.3|^6.0" + "symfony/css-selector": "^5.4|^6.0", + "symfony/dom-crawler": "^5.4|^6.0" }, "type": "library", "extra": { @@ -3957,8 +3957,7 @@ ], "authors": [ { - "name": "Shalvah", - "email": "hello@shalvah.me" + "name": "Shalvah" } ], "description": "Generate API documentation for humans from your Laravel codebase.✍", @@ -3971,7 +3970,7 @@ ], "support": { "issues": "https://github.com/knuckleswtf/scribe/issues", - "source": "https://github.com/knuckleswtf/scribe/tree/3.37.2" + "source": "https://github.com/knuckleswtf/scribe/tree/4.21.2" }, "funding": [ { @@ -3979,7 +3978,7 @@ "type": "patreon" } ], - "time": "2022-09-07T23:13:06+00:00" + "time": "2023-06-05T17:37:20+00:00" }, { "name": "laravel/fortify", diff --git a/config/scribe.php b/config/scribe.php index 77cd02476..d80021ad2 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -252,9 +252,9 @@ * Text to place in the "Introduction" section, right after the `description`. Markdown and HTML are supported. */ 'intro_text' => <<<'INTRO' -This documentation aims to provide all the information you need to work with our API. This API only provides access to the functionallityt built into the website. +This documentation aims to provide all the information you need to work with our API. This API only provides access to the functionality built into the website. -This API is a work in progress and is subject to change. +This API is a work in progress and is subject to change. @@ -302,11 +302,6 @@ ], ], - /* - * Endpoints which don't have a @group will be placed in this default group. - */ - 'default_group' => 'Endpoints', - /* * Custom logo path. This will be used as the value of the src attribute for the tag, * so make sure it points to an accessible URL or path. Set to false to not use a logo. @@ -318,12 +313,6 @@ */ 'logo' => '../img/pokemon3d_logo.png', - /* - * If you would like the package to generate the same example values for parameters on each run, - * set this to any number (eg. 1234) - */ - 'faker_seed' => null, - /** * The strategies Scribe will use to extract information about your routes at each stage. * If you create or install a custom strategy, add it here. @@ -376,4 +365,73 @@ * If you only use one db connection, you can leave this as is. */ 'database_connections_to_transact' => [config('database.default')], + 'groups' => [ + /* + * Endpoints which don't have a @group will be placed in this default group. + */ + 'default' => 'Endpoints', + /* + * By default, Scribe will sort groups alphabetically, and endpoints in the order their routes are defined. + * You can override this by listing the groups, subgroups and endpoints here in the order you want them. + * + * Any groups, subgroups or endpoints you don't list here will be added as usual after the ones here. + * If an endpoint/subgroup is listed under a group it doesn't belong in, it will be ignored. + * Note: you must include the initial '/' when writing an endpoint. + */ + 'order' => [ + 'Ban Reason' => [ + 'Display a listing of the resource.', + 'Display the specified resource.', + ], + 'Ban Game Jolt Account' => [ + 'Display a listing of the resources.', + 'Store a newly created resource in storage.', + 'Display the specified resource.', + 'Remove the specified resource.', + ], + 'User' => [ + 'Display the specified resource.', + ], + 'Post' => [ + 'Store a newly created resource in storage.', + ], + 'Game Jolt Account' => [ + 'Display the specified resource.', + ], + 'Game - Badges' => [ + 'Display a listing of the resource.', + ], + 'Discord Bot' => [ + 'Display the first resource.', + 'Update the specified resource in storage.', + ], + 'Discord Account' => [ + 'Display the specified resource.', + ], + ], + ], + /** + * Customize the "Last updated" value displayed in the docs by specifying tokens and formats. + * Examples: + * - {date:F j Y} => March 28, 2022 + * - {git:short} => Short hash of the last Git commit + * + * Available tokens are `{date:}` and `{git:}`. + * The format you pass to `date` will be passed to PHP's `date()` function. + * The format you pass to `git` can be either "short" or "long". + */ + 'last_updated' => 'Last updated: {date:F j, Y}', + 'examples' => [ + /* + * If you would like the package to generate the same example values for parameters on each run, + * set this to any number (eg. 1234) + */ + 'faker_seed' => null, + /* + * With API resources and transformers, Scribe tries to generate example models to use in your API responses. + * By default, Scribe will try the model's factory, and if that fails, try fetching the first from the database. + * You can reorder or remove strategies here. + */ + 'models_source' => ['factoryCreate', 'factoryMake', 'databaseFirst'], + ], ]; From 6af879c4856b70ade8ce6ff4e1b3a8c62d67cdad Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Wed, 14 Jun 2023 21:27:53 +0200 Subject: [PATCH 03/41] Moved middleware for api --- app/Providers/RouteServiceProvider.php | 1 - routes/api.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index d66d5ad75..ac086b65c 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -31,7 +31,6 @@ public function boot() $this->routes(function () { Route::prefix('api') - ->middleware('api') ->group(base_path('routes/api.php')); Route::middleware('web')->group(base_path('routes/web.php')); diff --git a/routes/api.php b/routes/api.php index dfa01db4f..8d37444c0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -29,4 +29,4 @@ Route::apiResource('bot/discord/settings', DiscordBotSettingController::class); Route::apiResource('game/badges', BadgeController::class); Route::apiResource('post', PostController::class); -}); +})->middleware(['api']); From a92a36d7aacb8a5ddb6d8ef386a8d55bd443d1a8 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Wed, 14 Jun 2023 21:28:23 +0200 Subject: [PATCH 04/41] Added endpoint for converting openapi yaml to json #281 --- .../Controllers/API/v1/OpenAPIController.php | 40 +++++ composer.json | 1 + composer.lock | 141 +++++++++++++++++- routes/api.php | 3 + 4 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/API/v1/OpenAPIController.php diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php new file mode 100644 index 000000000..5a81b1ec2 --- /dev/null +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -0,0 +1,40 @@ +header('Content-Type', 'application/json'); + } + $json = Writer::writeToJson($openapi); + return response($json, 200)->header('Content-Type', 'application/json'); + } +} diff --git a/composer.json b/composer.json index 010d12ef4..eaae02f71 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "beyondcode/laravel-favicon": "dev-l9", "blade-ui-kit/blade-ui-kit": "^0.3.2", "bolechen/nova-activitylog": "^0.4.0", + "cebe/php-openapi": "^1.7", "cyrildewit/eloquent-viewable": "^6.0", "digikraaft/laravel-review-rating": "^2.3", "doctrine/dbal": "^3.3", diff --git a/composer.lock b/composer.lock index 21229de88..644d1cf09 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2d5b4ac1b231f4a4de08a3d51f17e2c6", + "content-hash": "d76f13f3f34d6aa9eadb51197c8adb88", "packages": [ { "name": "akaunting/laravel-language", @@ -866,6 +866,75 @@ ], "time": "2023-01-15T23:59:01+00:00" }, + { + "name": "cebe/php-openapi", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/cebe/php-openapi.git", + "reference": "020d72b8e3a9a60bc229953e93eda25c49f46f45" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cebe/php-openapi/zipball/020d72b8e3a9a60bc229953e93eda25c49f46f45", + "reference": "020d72b8e3a9a60bc229953e93eda25c49f46f45", + "shasum": "" + }, + "require": { + "ext-json": "*", + "justinrainbow/json-schema": "^5.2", + "php": ">=7.1.0", + "symfony/yaml": "^3.4 || ^4 || ^5 || ^6" + }, + "conflict": { + "symfony/yaml": "3.4.0 - 3.4.4 || 4.0.0 - 4.4.17 || 5.0.0 - 5.1.9 || 5.2.0" + }, + "require-dev": { + "apis-guru/openapi-directory": "1.0.0", + "cebe/indent": "*", + "mermade/openapi3-examples": "1.0.0", + "nexmo/api-specification": "1.0.0", + "oai/openapi-specification": "3.0.3", + "phpstan/phpstan": "^0.12.0", + "phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.4" + }, + "bin": [ + "bin/php-openapi" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "cebe\\openapi\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Carsten Brandt", + "email": "mail@cebe.cc", + "homepage": "https://cebe.cc/", + "role": "Creator" + } + ], + "description": "Read and write OpenAPI yaml/json files and make the content accessable in PHP objects.", + "homepage": "https://github.com/cebe/php-openapi#readme", + "keywords": [ + "openapi" + ], + "support": { + "issues": "https://github.com/cebe/php-openapi/issues", + "source": "https://github.com/cebe/php-openapi" + }, + "time": "2022-04-20T14:46:44+00:00" + }, { "name": "clue/stream-filter", "version": "v1.6.0", @@ -3628,6 +3697,76 @@ ], "time": "2020-06-13T08:05:20+00:00" }, + { + "name": "justinrainbow/json-schema", + "version": "5.2.12", + "source": { + "type": "git", + "url": "https://github.com/justinrainbow/json-schema.git", + "reference": "ad87d5a5ca981228e0e205c2bc7dfb8e24559b60" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/ad87d5a5ca981228e0e205c2bc7dfb8e24559b60", + "reference": "ad87d5a5ca981228e0e205c2bc7dfb8e24559b60", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", + "json-schema/json-schema-test-suite": "1.2.0", + "phpunit/phpunit": "^4.8.35" + }, + "bin": [ + "bin/validate-json" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "JsonSchema\\": "src/JsonSchema/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bruno Prieto Reis", + "email": "bruno.p.reis@gmail.com" + }, + { + "name": "Justin Rainbow", + "email": "justin.rainbow@gmail.com" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Robert Schönthal", + "email": "seroscho@googlemail.com" + } + ], + "description": "A library to validate a json schema.", + "homepage": "https://github.com/justinrainbow/json-schema", + "keywords": [ + "json", + "schema" + ], + "support": { + "issues": "https://github.com/justinrainbow/json-schema/issues", + "source": "https://github.com/justinrainbow/json-schema/tree/5.2.12" + }, + "time": "2022-04-13T08:02:27+00:00" + }, { "name": "kalnoy/nestedset", "version": "v6.0.2", diff --git a/routes/api.php b/routes/api.php index 8d37444c0..c6fec3624 100644 --- a/routes/api.php +++ b/routes/api.php @@ -6,6 +6,7 @@ use App\Http\Controllers\API\v1\Game\BadgeController; use App\Http\Controllers\API\v1\GamejoltAccountBanController; use App\Http\Controllers\API\v1\GamejoltAccountController; +use App\Http\Controllers\API\v1\OpenAPIController; use App\Http\Controllers\API\v1\PostController; use App\Http\Controllers\API\v1\UserController; use Illuminate\Support\Facades\Route; @@ -30,3 +31,5 @@ Route::apiResource('game/badges', BadgeController::class); Route::apiResource('post', PostController::class); })->middleware(['api']); + +Route::apiResource('openapi-json', OpenAPIController::class)->only('index'); From 62e2c5287c0a7bde5e9184efa05768fddccf1647 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Wed, 14 Jun 2023 21:29:46 +0200 Subject: [PATCH 05/41] Pint --- app/Http/Controllers/API/v1/OpenAPIController.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index 5a81b1ec2..d46743470 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -3,13 +3,11 @@ namespace App\Http\Controllers\API\v1; use App\Http\Controllers\Controller; -use App\Models\Post; use cebe\openapi\exceptions\IOException; use cebe\openapi\exceptions\TypeErrorException; use cebe\openapi\exceptions\UnresolvableReferenceException; use cebe\openapi\Reader; use cebe\openapi\Writer; -use Illuminate\Http\Request; /** * @group OpenAPI @@ -18,16 +16,16 @@ */ class OpenAPIController extends Controller { - /** * Show the OpenAPI documentation in JSON format. * * @response 200 {} + * * @unauthenticated **/ public function index() { - # Get YAML from storage + // Get YAML from storage $file_path = storage_path('app/scribe/openapi.yaml'); try { $openapi = Reader::readFromYamlFile($file_path); @@ -35,6 +33,7 @@ public function index() return response('', 500)->header('Content-Type', 'application/json'); } $json = Writer::writeToJson($openapi); + return response($json, 200)->header('Content-Type', 'application/json'); } } From 3863796c037847eb0a14130e4319be147a875621 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Thu, 15 Jun 2023 10:16:10 +0200 Subject: [PATCH 06/41] Reworked API docs --- app/Console/Commands/Update.php | 2 +- app/Console/Commands/UpdateAPIDocs.php | 50 +++++++++++++++++++ .../API/v1/BanReasonController.php | 16 ++++-- .../API/v1/DiscordAccountController.php | 7 ++- .../API/v1/DiscordBotSettingController.php | 9 +++- .../API/v1/Game/BadgeController.php | 2 +- .../API/v1/GamejoltAccountBanController.php | 23 +++++++-- .../API/v1/GamejoltAccountController.php | 7 ++- .../Controllers/API/v1/OpenAPIController.php | 16 +++--- .../Controllers/API/v1/PostController.php | 2 +- .../Controllers/API/v1/UserController.php | 7 ++- 11 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 app/Console/Commands/UpdateAPIDocs.php diff --git a/app/Console/Commands/Update.php b/app/Console/Commands/Update.php index 96e4d7882..7eb559caa 100644 --- a/app/Console/Commands/Update.php +++ b/app/Console/Commands/Update.php @@ -62,7 +62,7 @@ public function handle(): int $this->info('Running storage:link command...'); Artisan::call('storage:link'); $this->info('Generating API Docs...'); - Artisan::call('scribe:generate'); + Artisan::call('api:docs'); $this->info('Getting Github release...'); Artisan::call('github:syncrelease'); $this->info('Getting Discord roles...'); diff --git a/app/Console/Commands/UpdateAPIDocs.php b/app/Console/Commands/UpdateAPIDocs.php new file mode 100644 index 000000000..4d1a242b0 --- /dev/null +++ b/app/Console/Commands/UpdateAPIDocs.php @@ -0,0 +1,50 @@ +error($e->getMessage()); + return Command::FAILURE; + } + $json = Writer::writeToJson($openapi); + // Save JSON to storage + $file_path = storage_path('app/scribe/openapi.json'); + file_put_contents($file_path, $json); + $this->info('API documentation updated.'); + return Command::SUCCESS; + } +} diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index 8bbd3f982..f1a8ab0a0 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -22,7 +22,7 @@ public function __construct() /** * Display a listing of the resource. * - * @response { + * @jsonresponse { * "data": [ * { * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", @@ -46,6 +46,11 @@ public function __construct() */ public function index(Request $request) { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', @@ -61,7 +66,7 @@ public function index(Request $request) * * @urlParam id string required The UUID of the ban reason. * - * @response { + * @jsonresponse { * "data": [ * { * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", @@ -74,8 +79,13 @@ public function index(Request $request) * ] * } */ - public function show(Request $request, $id) + public function show(Request $request, $id): BanReasonResource|\Illuminate\Http\JsonResponse { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index c330ba82a..7c4388773 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -19,7 +19,7 @@ class DiscordAccountController extends Controller * * @urlParam id int required The ID of the Discord Account. * - * @response { + * @jsonresponse { * "data": [ * { * "id": 1, @@ -37,6 +37,11 @@ class DiscordAccountController extends Controller */ public function show(Request $request, $id) { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index 836c76ef7..fa678c6c7 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -16,7 +16,7 @@ class DiscordBotSettingController extends Controller /** * Display the first resource. * - * @response { + * @jsonresponse { * "data": [ * { * "category_id": 1, @@ -31,6 +31,11 @@ class DiscordBotSettingController extends Controller */ public function index(Request $request): \Illuminate\Http\JsonResponse { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', @@ -51,7 +56,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse * @bodyParam events_id int required The ID of your desired event channel. * @bodyParam hide_events json A JSON object. * - * @response 201 { + * @jsonresponse 201 { * "category_id": 1, * "chat_id": 1, * "events_id": 1, diff --git a/app/Http/Controllers/API/v1/Game/BadgeController.php b/app/Http/Controllers/API/v1/Game/BadgeController.php index 52ea1ac6d..156bc622b 100644 --- a/app/Http/Controllers/API/v1/Game/BadgeController.php +++ b/app/Http/Controllers/API/v1/Game/BadgeController.php @@ -17,7 +17,7 @@ class BadgeController extends Controller /** * Display a listing of the resource. * - * @response { + * @jsonresponse { * "boulder": { * "name": "Boulder", * "image": "https://pokemon3d.net/img/badge/Boulder.png" diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index bd15d525c..9f1cbc752 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -24,10 +24,20 @@ public function __construct() /** * Display a listing of the resources. * - * @return \Illuminate\Http\Response + * @jsonresponse 200 {} */ public function index(Request $request) { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', @@ -47,7 +57,7 @@ public function index(Request $request) * @bodyParam banned_by_gamejoltaccount_id int optional The ID of the Game Jolt Account. Cannot be used with banned_by_id. Example: 123456 * @bodyParam expires_at string optional The expiry of the ban. Example: 2020-01-01 * - * @response 201 { + * @jsonresponse 201 { * "data": { * "gamejoltaccount_id": 12345, * "reason": { @@ -124,7 +134,7 @@ public function store(Request $request) * * @urlParam id int required The ID of the Game Jolt Account. * - * @response { + * @jsonresponse 200 { * "data": [ * { * "id": 1, @@ -142,6 +152,11 @@ public function store(Request $request) */ public function show(Request $request, $id) { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', @@ -159,7 +174,7 @@ public function show(Request $request, $id) * * @urlParam id string required The UUID of the _ban_ you would like to remove * - * @response 202 { + * @jsonresponse 202 { * "success": 'Ban was removed!', * } */ diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index b40362b01..0c171d15e 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -24,7 +24,7 @@ public function __construct() * * @urlParam id int required The ID of the Game Jolt Account. * - * @response { + * @jsonresponse { * "data": { * "uuid": "5b52ee9f-2bc8-42a5-891b-27af579ea056", * "id": 94314, @@ -97,6 +97,11 @@ public function __construct() */ public function show(Request $request, $id) { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index d46743470..48ba0a85d 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -19,21 +19,21 @@ class OpenAPIController extends Controller /** * Show the OpenAPI documentation in JSON format. * - * @response 200 {} + * @jsonresponse {} * * @unauthenticated **/ public function index() { - // Get YAML from storage - $file_path = storage_path('app/scribe/openapi.yaml'); + // Get and return JSON from storage + $file_path = storage_path('app/scribe/openapi.json'); try { - $openapi = Reader::readFromYamlFile($file_path); - } catch (IOException|TypeErrorException|UnresolvableReferenceException $e) { - return response('', 500)->header('Content-Type', 'application/json'); + $json = file_get_contents($file_path); + } catch (\Exception $e) { + return response()->json([ + 'error' => $e->getMessage(), + ], 500); } - $json = Writer::writeToJson($openapi); - return response($json, 200)->header('Content-Type', 'application/json'); } } diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index b2d5a2fd6..f095e0bfe 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -28,7 +28,7 @@ public function __construct() * @bodyParam user_id int required The ID of the user. Example: 1 * @bodyParam published_at string optional The date the post was published. Example: 2021-01-01 * - * @response 201 { + * @jsonresponse 201 { * "title": "Test", * "body": "Test", * "active": True, diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index 4112dd968..961e03a72 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -24,7 +24,7 @@ public function __construct() * * @urlParam id int required The ID of the user. * - * @response { + * @jsonresponse { * "data": { * "id": 1, * "name": "Daniel S. Billing", @@ -73,6 +73,11 @@ public function __construct() */ public function show(Request $request, $id) { + if (! $request->user()) { + return response()->json([ + 'error' => 'Token does not have access!', + ]); + } if (! $request->user()->tokenCan('read')) { return response()->json([ 'error' => 'Token does not have access!', From de298b7f84d8e714bb1682478ba5f2945cd81074 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Thu, 15 Jun 2023 10:17:48 +0200 Subject: [PATCH 07/41] pint --- app/Console/Commands/UpdateAPIDocs.php | 2 ++ app/Http/Controllers/API/v1/OpenAPIController.php | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/UpdateAPIDocs.php b/app/Console/Commands/UpdateAPIDocs.php index 4d1a242b0..ea09fd717 100644 --- a/app/Console/Commands/UpdateAPIDocs.php +++ b/app/Console/Commands/UpdateAPIDocs.php @@ -38,6 +38,7 @@ public function handle() $openapi = Reader::readFromYamlFile($file_path); } catch (IOException|TypeErrorException|UnresolvableReferenceException $e) { $this->error($e->getMessage()); + return Command::FAILURE; } $json = Writer::writeToJson($openapi); @@ -45,6 +46,7 @@ public function handle() $file_path = storage_path('app/scribe/openapi.json'); file_put_contents($file_path, $json); $this->info('API documentation updated.'); + return Command::SUCCESS; } } diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index 48ba0a85d..8c2f1d0b7 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -3,11 +3,6 @@ namespace App\Http\Controllers\API\v1; use App\Http\Controllers\Controller; -use cebe\openapi\exceptions\IOException; -use cebe\openapi\exceptions\TypeErrorException; -use cebe\openapi\exceptions\UnresolvableReferenceException; -use cebe\openapi\Reader; -use cebe\openapi\Writer; /** * @group OpenAPI @@ -34,6 +29,7 @@ public function index() 'error' => $e->getMessage(), ], 500); } + return response($json, 200)->header('Content-Type', 'application/json'); } } From 0b7d1b935c91211bdc4ab6d3938ea073d74cf736 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 17:39:02 +0200 Subject: [PATCH 08/41] Reworked API docs again --- .../API/v1/BanReasonController.php | 2 +- .../API/v1/DiscordAccountController.php | 2 +- .../API/v1/GamejoltAccountBanController.php | 8 ++--- .../API/v1/GamejoltAccountController.php | 2 +- .../Controllers/API/v1/OpenAPIController.php | 6 ++-- .../Controllers/API/v1/PostController.php | 2 +- .../Controllers/API/v1/UserController.php | 2 +- config/scribe.php | 32 +------------------ 8 files changed, 13 insertions(+), 43 deletions(-) diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index f1a8ab0a0..5d7820fc7 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -44,7 +44,7 @@ public function __construct() * ] * } */ - public function index(Request $request) + public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { if (! $request->user()) { return response()->json([ diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index 7c4388773..a132bc765 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -35,7 +35,7 @@ class DiscordAccountController extends Controller * ] * } */ - public function show(Request $request, $id) + public function show(Request $request, $id): \Illuminate\Http\JsonResponse|DiscordAccountResource { if (! $request->user()) { return response()->json([ diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index 9f1cbc752..f5b2a3751 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -26,7 +26,7 @@ public function __construct() * * @jsonresponse 200 {} */ - public function index(Request $request) + public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { if (! $request->user()) { return response()->json([ @@ -82,7 +82,7 @@ public function index(Request $request) * } * } */ - public function store(Request $request) + public function store(Request $request): GamejoltAccountBanResource|\Illuminate\Http\JsonResponse { if (! $request->user()->tokenCan('create')) { return response()->json([ @@ -150,7 +150,7 @@ public function store(Request $request) * ] * } */ - public function show(Request $request, $id) + public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { if (! $request->user()) { return response()->json([ @@ -178,7 +178,7 @@ public function show(Request $request, $id) * "success": 'Ban was removed!', * } */ - public function destroy(Request $request, $uuid) + public function destroy(Request $request, $uuid): \Illuminate\Http\JsonResponse { if (! $request->user()->tokenCan('delete')) { return response()->json([ diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index 0c171d15e..dddf0e9b4 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -95,7 +95,7 @@ public function __construct() * }, * } */ - public function show(Request $request, $id) + public function show(Request $request, $id): \Illuminate\Http\JsonResponse|GamejoltAccountResource { if (! $request->user()) { return response()->json([ diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index 8c2f1d0b7..310333974 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -14,11 +14,11 @@ class OpenAPIController extends Controller /** * Show the OpenAPI documentation in JSON format. * - * @jsonresponse {} + * @jsonresponse 200 {} * * @unauthenticated **/ - public function index() + public function index(): \Illuminate\Http\JsonResponse { // Get and return JSON from storage $file_path = storage_path('app/scribe/openapi.json'); @@ -30,6 +30,6 @@ public function index() ], 500); } - return response($json, 200)->header('Content-Type', 'application/json'); + return response()->json($json, 200); } } diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index f095e0bfe..0621fb398 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -40,7 +40,7 @@ public function __construct() * "deleted_at": null, * } **/ - public function store(Request $request) + public function store(Request $request): \Illuminate\Http\JsonResponse { if (! $request->user()->tokenCan('create')) { return response()->json([ diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index 961e03a72..3ee241550 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -71,7 +71,7 @@ public function __construct() * }, * } */ - public function show(Request $request, $id) + public function show(Request $request, $id): \Illuminate\Http\JsonResponse|UserResource { if (! $request->user()) { return response()->json([ diff --git a/config/scribe.php b/config/scribe.php index d80021ad2..4b51d8ab9 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -378,37 +378,7 @@ * If an endpoint/subgroup is listed under a group it doesn't belong in, it will be ignored. * Note: you must include the initial '/' when writing an endpoint. */ - 'order' => [ - 'Ban Reason' => [ - 'Display a listing of the resource.', - 'Display the specified resource.', - ], - 'Ban Game Jolt Account' => [ - 'Display a listing of the resources.', - 'Store a newly created resource in storage.', - 'Display the specified resource.', - 'Remove the specified resource.', - ], - 'User' => [ - 'Display the specified resource.', - ], - 'Post' => [ - 'Store a newly created resource in storage.', - ], - 'Game Jolt Account' => [ - 'Display the specified resource.', - ], - 'Game - Badges' => [ - 'Display a listing of the resource.', - ], - 'Discord Bot' => [ - 'Display the first resource.', - 'Update the specified resource in storage.', - ], - 'Discord Account' => [ - 'Display the specified resource.', - ], - ], + 'order' => null, ], /** * Customize the "Last updated" value displayed in the docs by specifying tokens and formats. From 7d9007583ab865b22738c7846ecb9a368929da4c Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 17:40:59 +0200 Subject: [PATCH 09/41] Fixed JSON output --- app/Http/Controllers/API/v1/OpenAPIController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index 310333974..9a5daefbe 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -23,13 +23,13 @@ public function index(): \Illuminate\Http\JsonResponse // Get and return JSON from storage $file_path = storage_path('app/scribe/openapi.json'); try { - $json = file_get_contents($file_path); + $json = json_decode(file_get_contents($file_path)); } catch (\Exception $e) { return response()->json([ 'error' => $e->getMessage(), ], 500); } - return response()->json($json, 200); + return response()->json($json); } } From a089a32b19466daa93eefe70be7ea4808f898d15 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 17:42:37 +0200 Subject: [PATCH 10/41] Ignore custom openapi json endpoint --- config/scribe.php | 1 + 1 file changed, 1 insertion(+) diff --git a/config/scribe.php b/config/scribe.php index 4b51d8ab9..e23053cf0 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -62,6 +62,7 @@ */ 'exclude' => [ // '/health', 'admin.*' + '/openapi-json', ], /* From f91258fccb9571dc07922cb1580ac1859ccdf8e2 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 17:46:55 +0200 Subject: [PATCH 11/41] Update scribe.php --- config/scribe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/scribe.php b/config/scribe.php index e23053cf0..8116b16a6 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -87,7 +87,7 @@ * API calls will be made only for routes in this group matching these HTTP methods (GET, POST, etc). * List the methods here or use '*' to mean all methods. Leave empty to disable API calls. */ - 'methods' => ['GET'], + 'methods' => [], /* * Laravel config variables which should be set for the API call. From b17efd98a651534acfca89901258cbdc12ee088c Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 17:51:49 +0200 Subject: [PATCH 12/41] Convert back to normal response --- app/Http/Controllers/API/v1/BanReasonController.php | 4 ++-- app/Http/Controllers/API/v1/DiscordAccountController.php | 2 +- .../Controllers/API/v1/DiscordBotSettingController.php | 4 ++-- app/Http/Controllers/API/v1/Game/BadgeController.php | 2 +- .../Controllers/API/v1/GamejoltAccountBanController.php | 8 ++++---- app/Http/Controllers/API/v1/GamejoltAccountController.php | 2 +- app/Http/Controllers/API/v1/OpenAPIController.php | 2 +- app/Http/Controllers/API/v1/PostController.php | 2 +- app/Http/Controllers/API/v1/UserController.php | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index 5d7820fc7..4d9c9ba75 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -22,7 +22,7 @@ public function __construct() /** * Display a listing of the resource. * - * @jsonresponse { + * @response { * "data": [ * { * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", @@ -66,7 +66,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * * @urlParam id string required The UUID of the ban reason. * - * @jsonresponse { + * @response { * "data": [ * { * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index a132bc765..cd6312929 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -19,7 +19,7 @@ class DiscordAccountController extends Controller * * @urlParam id int required The ID of the Discord Account. * - * @jsonresponse { + * @response { * "data": [ * { * "id": 1, diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index fa678c6c7..2b8a9238b 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -16,7 +16,7 @@ class DiscordBotSettingController extends Controller /** * Display the first resource. * - * @jsonresponse { + * @response { * "data": [ * { * "category_id": 1, @@ -56,7 +56,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse * @bodyParam events_id int required The ID of your desired event channel. * @bodyParam hide_events json A JSON object. * - * @jsonresponse 201 { + * @response 201 { * "category_id": 1, * "chat_id": 1, * "events_id": 1, diff --git a/app/Http/Controllers/API/v1/Game/BadgeController.php b/app/Http/Controllers/API/v1/Game/BadgeController.php index 156bc622b..52ea1ac6d 100644 --- a/app/Http/Controllers/API/v1/Game/BadgeController.php +++ b/app/Http/Controllers/API/v1/Game/BadgeController.php @@ -17,7 +17,7 @@ class BadgeController extends Controller /** * Display a listing of the resource. * - * @jsonresponse { + * @response { * "boulder": { * "name": "Boulder", * "image": "https://pokemon3d.net/img/badge/Boulder.png" diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index f5b2a3751..3d68f2081 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -24,7 +24,7 @@ public function __construct() /** * Display a listing of the resources. * - * @jsonresponse 200 {} + * @response 200 {} */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -57,7 +57,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * @bodyParam banned_by_gamejoltaccount_id int optional The ID of the Game Jolt Account. Cannot be used with banned_by_id. Example: 123456 * @bodyParam expires_at string optional The expiry of the ban. Example: 2020-01-01 * - * @jsonresponse 201 { + * @response 201 { * "data": { * "gamejoltaccount_id": 12345, * "reason": { @@ -134,7 +134,7 @@ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\ * * @urlParam id int required The ID of the Game Jolt Account. * - * @jsonresponse 200 { + * @response 200 { * "data": [ * { * "id": 1, @@ -174,7 +174,7 @@ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illu * * @urlParam id string required The UUID of the _ban_ you would like to remove * - * @jsonresponse 202 { + * @response 202 { * "success": 'Ban was removed!', * } */ diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index dddf0e9b4..6c97ced43 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -24,7 +24,7 @@ public function __construct() * * @urlParam id int required The ID of the Game Jolt Account. * - * @jsonresponse { + * @response { * "data": { * "uuid": "5b52ee9f-2bc8-42a5-891b-27af579ea056", * "id": 94314, diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index 9a5daefbe..d788d4ccc 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -14,7 +14,7 @@ class OpenAPIController extends Controller /** * Show the OpenAPI documentation in JSON format. * - * @jsonresponse 200 {} + * @response 200 {} * * @unauthenticated **/ diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index 0621fb398..26d97c430 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -28,7 +28,7 @@ public function __construct() * @bodyParam user_id int required The ID of the user. Example: 1 * @bodyParam published_at string optional The date the post was published. Example: 2021-01-01 * - * @jsonresponse 201 { + * @response 201 { * "title": "Test", * "body": "Test", * "active": True, diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index 3ee241550..781b93e25 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -24,7 +24,7 @@ public function __construct() * * @urlParam id int required The ID of the user. * - * @jsonresponse { + * @response { * "data": { * "id": 1, * "name": "Daniel S. Billing", From 52630b75c182a8a8471cbc2d0c9c3ba5ae82a349 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 19:07:09 +0200 Subject: [PATCH 13/41] Reworked API docs again --- .../API/v1/BanReasonController.php | 39 ++-------- .../API/v1/DiscordAccountController.php | 18 +---- .../API/v1/GamejoltAccountBanController.php | 55 +++----------- .../API/v1/GamejoltAccountController.php | 73 +------------------ .../Controllers/API/v1/OpenAPIController.php | 3 +- .../Controllers/API/v1/PostController.php | 13 +--- .../Controllers/API/v1/UserController.php | 49 +------------ 7 files changed, 31 insertions(+), 219 deletions(-) diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index 4d9c9ba75..7437b4651 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -22,27 +22,9 @@ public function __construct() /** * Display a listing of the resource. * - * @response { - * "data": [ - * { - * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", - * "name": "Abusing in-game glitches", - * "user_id": 1, - * "created_at": "2021-01-01T17:57:10.000000Z", - * "updated_at": "2021-01-01T17:57:10.000000Z", - * "deleted_at": null - * }, - * { - * "id": 2, - * "uuid": "ba3900a8-bc82-43c6-9d4f-1760205f95f6", - * "name": "General hacking or cheating", - * "user_id": 1, - * "created_at": "2022-01-04T18:49:46.000000Z", - * "updated_at": "2022-01-04T18:49:46.000000Z", - * "deleted_at": null - * }, - * ] - * } + * @apiResourceCollection App\Http\Resources\API\v1\BanReasonResource + * @apiResourceModel App\Models\BanReason + * */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -66,18 +48,9 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * * @urlParam id string required The UUID of the ban reason. * - * @response { - * "data": [ - * { - * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", - * "name": "Abusing in-game glitches", - * "user_id": 1, - * "created_at": "2021-01-01T17:57:10.000000Z", - * "updated_at": "2021-01-01T17:57:10.000000Z", - * "deleted_at": null - * }, - * ] - * } + * @apiResource App\Http\Resources\API\v1\BanReasonResource + * @apiResourceModel App\Models\BanReason + * */ public function show(Request $request, $id): BanReasonResource|\Illuminate\Http\JsonResponse { diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index cd6312929..d6074ce60 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -19,21 +19,9 @@ class DiscordAccountController extends Controller * * @urlParam id int required The ID of the Discord Account. * - * @response { - * "data": [ - * { - * "id": 1, - * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", - * "id": 1234567890, - * "username": "DanielRTRD", - * "discriminator": 9659, - * "verified_at": "2021-01-01T17:57:10.000000Z", - * "created_at": "2021-01-01T17:57:10.000000Z", - * "updated_at": "2021-01-01T17:57:10.000000Z", - * "deleted_at": null - * }, - * ] - * } + * @apiResource App\Http\Resources\API\v1\DiscordAccountResource + * @apiResourceModel App\Models\DiscordAccount + * */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|DiscordAccountResource { diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index 3d68f2081..7930117e9 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -24,7 +24,9 @@ public function __construct() /** * Display a listing of the resources. * - * @response 200 {} + * @apiResourceCollection App\Http\Resources\API\v1\GamejoltAccountBanResource + * @apiResourceModel App\Models\GamejoltAccountBan + * */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -57,30 +59,9 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * @bodyParam banned_by_gamejoltaccount_id int optional The ID of the Game Jolt Account. Cannot be used with banned_by_id. Example: 123456 * @bodyParam expires_at string optional The expiry of the ban. Example: 2020-01-01 * - * @response 201 { - * "data": { - * "gamejoltaccount_id": 12345, - * "reason": { - * "name": "Abusing in-game glitches", - * "created_at": "2022-04-02T18:51:14.000000Z", - * "updated_at": "2022-04-02T18:51:14.000000Z" - * }, - * "expires_at": "2021-02-01T00:00:00.000000Z", - * "banned_by": { - * "id": 1, - * "name": "John Doe", - * "email": "john.doe@example.com", - * "username": "john.doe", - * "email_verified_at": "2022-12-21T18:49:11.000000Z", - * "created_at": "2022-04-12T18:48:51.000000Z", - * "updated_at": "2023-06-11T16:45:56.000000Z", - * "profile_photo_url": "" - * }, - * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", - * "updated_at": "2021-01-01T17:57:10.000000Z", - * "created_at": "2021-01-01T17:57:10.000000Z" - * } - * } + * @apiResource App\Http\Resources\API\v1\GamejoltAccountBanResource + * @apiResourceModel App\Models\GamejoltAccountBan + * */ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\Http\JsonResponse { @@ -134,21 +115,9 @@ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\ * * @urlParam id int required The ID of the Game Jolt Account. * - * @response 200 { - * "data": [ - * { - * "id": 1, - * "uuid": "1830ef92-b58b-4671-9096-2b7741c0b0d8", - * "gamejoltaccount_id": 12345, - * "banned_by_id": 1, - * "reason_id": 1, - * "expire_at": null, - * "created_at": "2021-01-01T17:57:10.000000Z", - * "updated_at": "2021-01-01T17:57:10.000000Z", - * "deleted_at": null - * }, - * ] - * } + * @apiResourceCollection App\Http\Resources\API\v1\GamejoltAccountBanResource + * @apiResourceModel App\Models\GamejoltAccountBan + * */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -174,9 +143,9 @@ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illu * * @urlParam id string required The UUID of the _ban_ you would like to remove * - * @response 202 { - * "success": 'Ban was removed!', - * } + * @apiResource App\Http\Resources\API\v1\GamejoltAccountBanResource + * @apiResourceModel App\Models\GamejoltAccountBan + * */ public function destroy(Request $request, $uuid): \Illuminate\Http\JsonResponse { diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index 6c97ced43..a194b4952 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -24,76 +24,9 @@ public function __construct() * * @urlParam id int required The ID of the Game Jolt Account. * - * @response { - * "data": { - * "uuid": "5b52ee9f-2bc8-42a5-891b-27af579ea056", - * "id": 94314, - * "username": "DanielRTRD", - * "verified_at": "2021-12-21T20:59:14.000000Z", - * "user_id": 1, - * "created_at": "2021-12-21T20:59:14.000000Z", - * "updated_at": "2021-12-21T20:59:14.000000Z", - * "deleted_at": null, - * "user": { - * "id": 1, - * "name": "Daniel S. Billing", - * "email": "daniel@rtrd.no", - * "username": "DanielRTRD", - * "about": null, - * "gender": 1, - * "location": null, - * "birthdate": null, - * "email_verified_at": "2021-12-21T20:59:59.000000Z", - * "current_team_id": null, - * "profile_photo_path": null, - * "created_at": "2021-12-21T20:58:39.000000Z", - * "updated_at": "2022-01-01T22:15:21.000000Z", - * "last_active_at": "2022-01-01T22:15:21.000000Z", - * "profile_photo_url": "https://ui-avatars.com/api/?name=Daniel+S.+Billing&color=7F9CF5&background=EBF4FF", - * "roles": [ - * { - * "id": 1, - * "name": "super-admin", - * "guard_name": "web", - * "created_at": "2022-01-01T22:49:45.000000Z", - * "updated_at": "2022-01-01T22:49:45.000000Z", - * "pivot": { - * "model_id": 1, - * "role_id": 1, - * "model_type": "App\\Models\\User" - * }, - * "permissions": [ - * { - * "id": 1, - * "name": "manage.users", - * "guard_name": "web", - * "created_at": "2022-01-01T22:49:45.000000Z", - * "updated_at": "2022-01-01T22:49:45.000000Z", - * "pivot": { - * "role_id": 1, - * "permission_id": 1 - * } - * } - * ] - * } - * ], - * "discord": { - * "uuid": "315fc5be-d0eb-40a0-ab10-416b48139363", - * "id": 1234567890, - * "username": "DanielRTRD", - * "email": "daniel@rtrd.no", - * "avatar": "https://cdn.discordapp.com/avatars/1234567890/1234567890.png", - * "discriminator": "9659", - * "verified_at": "2022-01-01T22:20:50.000000Z", - * "user_id": 1, - * "created_at": "2022-01-01T22:20:50.000000Z", - * "updated_at": "2022-01-01T22:20:50.000000Z", - * "deleted_at": null - * } - * }, - * "bans": [] - * }, - * } + * @apiResource App\Http\Resources\API\v1\GamejoltAccountResource + * @apiResourceModel App\Models\GamejoltAccount + * */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|GamejoltAccountResource { diff --git a/app/Http/Controllers/API/v1/OpenAPIController.php b/app/Http/Controllers/API/v1/OpenAPIController.php index d788d4ccc..d1cc0fa35 100644 --- a/app/Http/Controllers/API/v1/OpenAPIController.php +++ b/app/Http/Controllers/API/v1/OpenAPIController.php @@ -14,9 +14,10 @@ class OpenAPIController extends Controller /** * Show the OpenAPI documentation in JSON format. * - * @response 200 {} + * @response {} * * @unauthenticated + * **/ public function index(): \Illuminate\Http\JsonResponse { diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index 26d97c430..00e6a427b 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -28,17 +28,8 @@ public function __construct() * @bodyParam user_id int required The ID of the user. Example: 1 * @bodyParam published_at string optional The date the post was published. Example: 2021-01-01 * - * @response 201 { - * "title": "Test", - * "body": "Test", - * "active": True, - * "sticky": False, - * "user_id": 1, - * "published_at": "2021-12-21T20:59:14.000000Z", - * "created_at": "2021-12-21T20:59:14.000000Z", - * "updated_at": "2021-12-21T20:59:14.000000Z", - * "deleted_at": null, - * } + * @response {} + * **/ public function store(Request $request): \Illuminate\Http\JsonResponse { diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index 781b93e25..e6892ca7e 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -24,52 +24,9 @@ public function __construct() * * @urlParam id int required The ID of the user. * - * @response { - * "data": { - * "id": 1, - * "name": "Daniel S. Billing", - * "email": "daniel@rtrd.no", - * "username": "DanielRTRD", - * "about": null, - * "gender": 1, - * "location": null, - * "birthdate": null, - * "email_verified_at": "2021-12-21T20:59:59.000000Z", - * "current_team_id": null, - * "profile_photo_path": null, - * "created_at": "2021-12-21T20:58:39.000000Z", - * "updated_at": "2022-01-01T22:15:21.000000Z", - * "last_active_at": "2022-01-01T22:15:21.000000Z", - * "profile_photo_url": "https://ui-avatars.com/api/?name=Daniel+S.+Billing&color=7F9CF5&background=EBF4FF", - * "roles": [ - * { - * "id": 1, - * "name": "super-admin", - * "guard_name": "web", - * "created_at": "2022-01-01T22:49:45.000000Z", - * "updated_at": "2022-01-01T22:49:45.000000Z", - * "pivot": { - * "model_id": 1, - * "role_id": 1, - * "model_type": "App\\Models\\User" - * }, - * "permissions": [ - * { - * "id": 1, - * "name": "manage.users", - * "guard_name": "web", - * "created_at": "2022-01-01T22:49:45.000000Z", - * "updated_at": "2022-01-01T22:49:45.000000Z", - * "pivot": { - * "role_id": 1, - * "permission_id": 1 - * } - * } - * ] - * } - * ], - * }, - * } + * @apiResource App\Http\Resources\API\v1\UserResource + * @apiResourceModel App\Models\User + * */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|UserResource { From 5930421651835a903bedbf901c8efd8347d3617c Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 19:07:34 +0200 Subject: [PATCH 14/41] Added check if user is present or not --- app/Http/Resources/API/v1/BanReasonResource.php | 3 +++ app/Http/Resources/API/v1/DiscordAccountResource.php | 3 +++ app/Http/Resources/API/v1/GamejoltAccountBanResource.php | 3 +++ app/Http/Resources/API/v1/GamejoltAccountResource.php | 3 +++ app/Http/Resources/API/v1/UserResource.php | 3 +++ 5 files changed, 15 insertions(+) diff --git a/app/Http/Resources/API/v1/BanReasonResource.php b/app/Http/Resources/API/v1/BanReasonResource.php index 3bb051053..c4d7141ee 100644 --- a/app/Http/Resources/API/v1/BanReasonResource.php +++ b/app/Http/Resources/API/v1/BanReasonResource.php @@ -14,6 +14,9 @@ class BanReasonResource extends JsonResource */ public function toArray($request) { + if (!$request->user()) { + return []; + } if ($request->user()->can('api.full')) { return parent::toArray($request); } diff --git a/app/Http/Resources/API/v1/DiscordAccountResource.php b/app/Http/Resources/API/v1/DiscordAccountResource.php index 032d04eb9..b45d33cb4 100644 --- a/app/Http/Resources/API/v1/DiscordAccountResource.php +++ b/app/Http/Resources/API/v1/DiscordAccountResource.php @@ -14,6 +14,9 @@ class DiscordAccountResource extends JsonResource */ public function toArray($request) { + if (!$request->user()) { + return []; + } if ($request->user()->can('api.full')) { return parent::toArray($request); } diff --git a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php index 3a5308feb..f6fdc63a0 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php @@ -14,6 +14,9 @@ class GamejoltAccountBanResource extends JsonResource */ public function toArray($request) { + if (!$request->user()) { + return []; + } if ($request->user()->can('api.full')) { return parent::toArray($request); } diff --git a/app/Http/Resources/API/v1/GamejoltAccountResource.php b/app/Http/Resources/API/v1/GamejoltAccountResource.php index edd76dc50..10f55e1c4 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountResource.php @@ -14,6 +14,9 @@ class GamejoltAccountResource extends JsonResource */ public function toArray($request) { + if (!$request->user()) { + return []; + } if ($request->user()->can('api.full')) { return parent::toArray($request); } diff --git a/app/Http/Resources/API/v1/UserResource.php b/app/Http/Resources/API/v1/UserResource.php index 7c04b2cc1..3ed25e59c 100644 --- a/app/Http/Resources/API/v1/UserResource.php +++ b/app/Http/Resources/API/v1/UserResource.php @@ -14,6 +14,9 @@ class UserResource extends JsonResource */ public function toArray($request) { + if (!$request->user()) { + return []; + } if ($request->user()->can('api.full')) { return parent::toArray($request); } From a0ff71fec87010c8bed02178d53bf464fde6016f Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 19:07:41 +0200 Subject: [PATCH 15/41] Fixed scribe config --- config/scribe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/scribe.php b/config/scribe.php index 8116b16a6..605e15d79 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -379,7 +379,7 @@ * If an endpoint/subgroup is listed under a group it doesn't belong in, it will be ignored. * Note: you must include the initial '/' when writing an endpoint. */ - 'order' => null, + 'order' => [], ], /** * Customize the "Last updated" value displayed in the docs by specifying tokens and formats. From eace609400c2922df56e88fa1ba1250ccd3e0b7f Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 19:08:36 +0200 Subject: [PATCH 16/41] pint --- app/Http/Controllers/API/v1/BanReasonController.php | 4 ++-- app/Http/Controllers/API/v1/DiscordAccountController.php | 2 +- .../Controllers/API/v1/GamejoltAccountBanController.php | 8 ++++---- app/Http/Controllers/API/v1/GamejoltAccountController.php | 2 +- app/Http/Controllers/API/v1/UserController.php | 2 +- app/Http/Resources/API/v1/BanReasonResource.php | 2 +- app/Http/Resources/API/v1/DiscordAccountResource.php | 2 +- app/Http/Resources/API/v1/GamejoltAccountBanResource.php | 2 +- app/Http/Resources/API/v1/GamejoltAccountResource.php | 2 +- app/Http/Resources/API/v1/UserResource.php | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index 7437b4651..6befde8ec 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -23,8 +23,8 @@ public function __construct() * Display a listing of the resource. * * @apiResourceCollection App\Http\Resources\API\v1\BanReasonResource - * @apiResourceModel App\Models\BanReason * + * @apiResourceModel App\Models\BanReason */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -49,8 +49,8 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * @urlParam id string required The UUID of the ban reason. * * @apiResource App\Http\Resources\API\v1\BanReasonResource - * @apiResourceModel App\Models\BanReason * + * @apiResourceModel App\Models\BanReason */ public function show(Request $request, $id): BanReasonResource|\Illuminate\Http\JsonResponse { diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index d6074ce60..83f4ee1f3 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -20,8 +20,8 @@ class DiscordAccountController extends Controller * @urlParam id int required The ID of the Discord Account. * * @apiResource App\Http\Resources\API\v1\DiscordAccountResource - * @apiResourceModel App\Models\DiscordAccount * + * @apiResourceModel App\Models\DiscordAccount */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|DiscordAccountResource { diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index 7930117e9..62d71da9d 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -25,8 +25,8 @@ public function __construct() * Display a listing of the resources. * * @apiResourceCollection App\Http\Resources\API\v1\GamejoltAccountBanResource - * @apiResourceModel App\Models\GamejoltAccountBan * + * @apiResourceModel App\Models\GamejoltAccountBan */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -60,8 +60,8 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * @bodyParam expires_at string optional The expiry of the ban. Example: 2020-01-01 * * @apiResource App\Http\Resources\API\v1\GamejoltAccountBanResource - * @apiResourceModel App\Models\GamejoltAccountBan * + * @apiResourceModel App\Models\GamejoltAccountBan */ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\Http\JsonResponse { @@ -116,8 +116,8 @@ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\ * @urlParam id int required The ID of the Game Jolt Account. * * @apiResourceCollection App\Http\Resources\API\v1\GamejoltAccountBanResource - * @apiResourceModel App\Models\GamejoltAccountBan * + * @apiResourceModel App\Models\GamejoltAccountBan */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { @@ -144,8 +144,8 @@ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illu * @urlParam id string required The UUID of the _ban_ you would like to remove * * @apiResource App\Http\Resources\API\v1\GamejoltAccountBanResource - * @apiResourceModel App\Models\GamejoltAccountBan * + * @apiResourceModel App\Models\GamejoltAccountBan */ public function destroy(Request $request, $uuid): \Illuminate\Http\JsonResponse { diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index a194b4952..88f0f7e66 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -25,8 +25,8 @@ public function __construct() * @urlParam id int required The ID of the Game Jolt Account. * * @apiResource App\Http\Resources\API\v1\GamejoltAccountResource - * @apiResourceModel App\Models\GamejoltAccount * + * @apiResourceModel App\Models\GamejoltAccount */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|GamejoltAccountResource { diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index e6892ca7e..a2c525fab 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -25,8 +25,8 @@ public function __construct() * @urlParam id int required The ID of the user. * * @apiResource App\Http\Resources\API\v1\UserResource - * @apiResourceModel App\Models\User * + * @apiResourceModel App\Models\User */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|UserResource { diff --git a/app/Http/Resources/API/v1/BanReasonResource.php b/app/Http/Resources/API/v1/BanReasonResource.php index c4d7141ee..c2fd88284 100644 --- a/app/Http/Resources/API/v1/BanReasonResource.php +++ b/app/Http/Resources/API/v1/BanReasonResource.php @@ -14,7 +14,7 @@ class BanReasonResource extends JsonResource */ public function toArray($request) { - if (!$request->user()) { + if (! $request->user()) { return []; } if ($request->user()->can('api.full')) { diff --git a/app/Http/Resources/API/v1/DiscordAccountResource.php b/app/Http/Resources/API/v1/DiscordAccountResource.php index b45d33cb4..23b3857eb 100644 --- a/app/Http/Resources/API/v1/DiscordAccountResource.php +++ b/app/Http/Resources/API/v1/DiscordAccountResource.php @@ -14,7 +14,7 @@ class DiscordAccountResource extends JsonResource */ public function toArray($request) { - if (!$request->user()) { + if (! $request->user()) { return []; } if ($request->user()->can('api.full')) { diff --git a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php index f6fdc63a0..0eec9e56a 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php @@ -14,7 +14,7 @@ class GamejoltAccountBanResource extends JsonResource */ public function toArray($request) { - if (!$request->user()) { + if (! $request->user()) { return []; } if ($request->user()->can('api.full')) { diff --git a/app/Http/Resources/API/v1/GamejoltAccountResource.php b/app/Http/Resources/API/v1/GamejoltAccountResource.php index 10f55e1c4..7a80e8eff 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountResource.php @@ -14,7 +14,7 @@ class GamejoltAccountResource extends JsonResource */ public function toArray($request) { - if (!$request->user()) { + if (! $request->user()) { return []; } if ($request->user()->can('api.full')) { diff --git a/app/Http/Resources/API/v1/UserResource.php b/app/Http/Resources/API/v1/UserResource.php index 3ed25e59c..aa5a550c7 100644 --- a/app/Http/Resources/API/v1/UserResource.php +++ b/app/Http/Resources/API/v1/UserResource.php @@ -14,7 +14,7 @@ class UserResource extends JsonResource */ public function toArray($request) { - if (!$request->user()) { + if (! $request->user()) { return []; } if ($request->user()->can('api.full')) { From d2a8db6f17c976899c63e749cd96f266f0942f54 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Fri, 16 Jun 2023 19:11:08 +0200 Subject: [PATCH 17/41] Update UpdateAPIDocs.php --- app/Console/Commands/UpdateAPIDocs.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Console/Commands/UpdateAPIDocs.php b/app/Console/Commands/UpdateAPIDocs.php index ea09fd717..11cb31299 100644 --- a/app/Console/Commands/UpdateAPIDocs.php +++ b/app/Console/Commands/UpdateAPIDocs.php @@ -8,6 +8,7 @@ use cebe\openapi\Reader; use cebe\openapi\Writer; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Artisan; class UpdateAPIDocs extends Command { @@ -32,6 +33,9 @@ class UpdateAPIDocs extends Command */ public function handle() { + // Generate Scribe API Docs + Artisan::call('scribe:generate'); + // Get YAML from storage $file_path = storage_path('app/scribe/openapi.yaml'); try { From 12d65f3602cbaaab2704502f779de3bf991de827 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 11:48:03 +0200 Subject: [PATCH 18/41] Added back jsonresponse for manual endpoints --- app/Http/Controllers/API/v1/DiscordBotSettingController.php | 2 +- app/Http/Controllers/API/v1/Game/BadgeController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index 2b8a9238b..3a1ef1964 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -56,7 +56,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse * @bodyParam events_id int required The ID of your desired event channel. * @bodyParam hide_events json A JSON object. * - * @response 201 { + * @jsonresponse 201 { * "category_id": 1, * "chat_id": 1, * "events_id": 1, diff --git a/app/Http/Controllers/API/v1/Game/BadgeController.php b/app/Http/Controllers/API/v1/Game/BadgeController.php index 52ea1ac6d..156bc622b 100644 --- a/app/Http/Controllers/API/v1/Game/BadgeController.php +++ b/app/Http/Controllers/API/v1/Game/BadgeController.php @@ -17,7 +17,7 @@ class BadgeController extends Controller /** * Display a listing of the resource. * - * @response { + * @jsonresponse { * "boulder": { * "name": "Boulder", * "image": "https://pokemon3d.net/img/badge/Boulder.png" From b0f0bbde3e282c16a1acd40ac816fc943d665185 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 11:48:11 +0200 Subject: [PATCH 19/41] Create BanReasonFactory.php --- database/factories/BanReasonFactory.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 database/factories/BanReasonFactory.php diff --git a/database/factories/BanReasonFactory.php b/database/factories/BanReasonFactory.php new file mode 100644 index 000000000..da3a5b61c --- /dev/null +++ b/database/factories/BanReasonFactory.php @@ -0,0 +1,24 @@ + + */ +class BanReasonFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'name' => $this->faker->sentence, + 'user_id' => \App\Models\User::factory(), + ]; + } +} From 7f7dd9dfaa6bd5578ae96c5dfd61779ed9ef4841 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 11:48:14 +0200 Subject: [PATCH 20/41] Create DiscordAccountFactory.php --- database/factories/DiscordAccountFactory.php | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 database/factories/DiscordAccountFactory.php diff --git a/database/factories/DiscordAccountFactory.php b/database/factories/DiscordAccountFactory.php new file mode 100644 index 000000000..5d03dc413 --- /dev/null +++ b/database/factories/DiscordAccountFactory.php @@ -0,0 +1,29 @@ + + */ +class DiscordAccountFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'id' => $this->faker->uuid, + 'username' => $this->faker->userName, + 'email' => $this->faker->email, + 'avatar' => $this->faker->imageUrl(), + 'discriminator' => $this->faker->randomNumber(4), + 'verified_at' => $this->faker->dateTime(), + 'user_id' => \App\Models\User::factory(), + ]; + } +} From c132523c5e7ac8273fb90000b1ff8a23b2be9b63 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 11:48:16 +0200 Subject: [PATCH 21/41] Create GamejoltAccountBanFactory.php --- .../factories/GamejoltAccountBanFactory.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 database/factories/GamejoltAccountBanFactory.php diff --git a/database/factories/GamejoltAccountBanFactory.php b/database/factories/GamejoltAccountBanFactory.php new file mode 100644 index 000000000..5adaf2dec --- /dev/null +++ b/database/factories/GamejoltAccountBanFactory.php @@ -0,0 +1,27 @@ + + */ +class GamejoltAccountBanFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'gamejoltaccount_id' => \App\Models\GamejoltAccount::factory(), + 'banned_by_id' => \App\Models\User::factory(), + 'reason_id' => \App\Models\BanReason::factory(), + 'expires_at' => $this->faker->dateTime(), + ]; + } +} From f5c59a42ab7c38cb799ffd6d6c0daf29a77c6b5a Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 11:48:18 +0200 Subject: [PATCH 22/41] Create GamejoltAccountFactory.php --- database/factories/GamejoltAccountFactory.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 database/factories/GamejoltAccountFactory.php diff --git a/database/factories/GamejoltAccountFactory.php b/database/factories/GamejoltAccountFactory.php new file mode 100644 index 000000000..7d5a8575c --- /dev/null +++ b/database/factories/GamejoltAccountFactory.php @@ -0,0 +1,27 @@ + + */ +class GamejoltAccountFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'id' => $this->faker->uuid, + 'username' => $this->faker->userName, + 'token' => $this->faker->uuid, + 'verified_at' => $this->faker->dateTime(), + 'user_id' => \App\Models\User::factory(), + ]; + } +} From beb5ccfafe097690256777cc56700204eaae1689 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 11:48:40 +0200 Subject: [PATCH 23/41] Updated api routes to only include the ones that exists --- routes/api.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/routes/api.php b/routes/api.php index c6fec3624..459665a75 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,14 +22,14 @@ | */ Route::prefix('v1')->group(function () { - Route::apiResource('user', UserController::class); - Route::apiResource('gamejoltaccount', GamejoltAccountController::class); - Route::apiResource('ban/gamejoltaccount', GamejoltAccountBanController::class); - Route::apiResource('banreason', BanReasonController::class); - Route::apiResource('discordaccount', DiscordAccountController::class); - Route::apiResource('bot/discord/settings', DiscordBotSettingController::class); - Route::apiResource('game/badges', BadgeController::class); - Route::apiResource('post', PostController::class); + Route::apiResource('user', UserController::class)->only('show'); + Route::apiResource('gamejoltaccount', GamejoltAccountController::class)->only('show'); + Route::apiResource('ban/gamejoltaccount', GamejoltAccountBanController::class)->only(['index', 'show', 'destroy']); + Route::apiResource('banreason', BanReasonController::class)->only(['index', 'show']); + Route::apiResource('discordaccount', DiscordAccountController::class)->only('show'); + Route::apiResource('bot/discord/settings', DiscordBotSettingController::class)->only(['index', 'update']); + Route::apiResource('game/badges', BadgeController::class)->only('index'); + Route::apiResource('post', PostController::class)->only('post'); })->middleware(['api']); Route::apiResource('openapi-json', OpenAPIController::class)->only('index'); From b7c0557138a7a01c60ffaee3bf025b7ffd57195e Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:01:01 +0200 Subject: [PATCH 24/41] Reworked all API resroucres --- .../Resources/API/v1/BanReasonResource.php | 33 ++++----------- .../API/v1/DiscordAccountResource.php | 39 ++++-------------- .../Resources/API/v1/DiscordRoleResource.php | 33 ++++----------- .../API/v1/GamejoltAccountBanResource.php | 40 ++++--------------- .../API/v1/GamejoltAccountResource.php | 30 +------------- .../Resources/API/v1/PermissionResource.php | 33 ++++----------- 6 files changed, 37 insertions(+), 171 deletions(-) diff --git a/app/Http/Resources/API/v1/BanReasonResource.php b/app/Http/Resources/API/v1/BanReasonResource.php index c2fd88284..7a76b33b8 100644 --- a/app/Http/Resources/API/v1/BanReasonResource.php +++ b/app/Http/Resources/API/v1/BanReasonResource.php @@ -2,39 +2,22 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class BanReasonResource extends JsonResource { + /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if (! $request->user()) { - return []; - } - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'name' => $this->name, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'name' => $this->name, - ]; - } - - return [ - 'name' => $this->name, - ]; + return parent::toArray($request); } } diff --git a/app/Http/Resources/API/v1/DiscordAccountResource.php b/app/Http/Resources/API/v1/DiscordAccountResource.php index 23b3857eb..2d1e07834 100644 --- a/app/Http/Resources/API/v1/DiscordAccountResource.php +++ b/app/Http/Resources/API/v1/DiscordAccountResource.php @@ -2,46 +2,21 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class DiscordAccountResource extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if (! $request->user()) { - return []; - } - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'username' => $this->username, - 'discriminator' => $this->discriminator, - 'verified_at' => $this->verified_at, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'user' => new UserResource($this->user), - 'roles' => DiscordRoleResource::collection($this->whenLoaded('roles')), - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'id' => $this->id, - 'username' => $this->username, - 'verified_at' => $this->verified_at, - ]; - } - - return [ - 'id' => $this->id, - ]; + return parent::toArray($request); } } diff --git a/app/Http/Resources/API/v1/DiscordRoleResource.php b/app/Http/Resources/API/v1/DiscordRoleResource.php index 74a0d7857..40dec2597 100644 --- a/app/Http/Resources/API/v1/DiscordRoleResource.php +++ b/app/Http/Resources/API/v1/DiscordRoleResource.php @@ -2,40 +2,21 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class DiscordRoleResource extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'color' => $this->color, - 'managed' => $this->managed, - 'mentionable' => $this->mentionable, - 'name' => $this->name, - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'id' => $this->id, - 'username' => $this->username, - 'verified_at' => $this->verified_at, - ]; - } - - return [ - 'id' => $this->id, - ]; + return parent::toArray($request); } } diff --git a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php index 0eec9e56a..8210562c1 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php @@ -2,47 +2,21 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class GamejoltAccountBanResource extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if (! $request->user()) { - return []; - } - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'uuid' => $this->uuid, - 'gamejoltaccount' => new GamejoltAccountResource($this->gamejoltaccount), - 'reason' => new BanReasonResource($this->reason), - 'banned_by' => new UserResource($this->banned_by), - 'updated_at' => $this->updated_at, - 'expire_at' => $this->expire_at, - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'uuid' => $this->uuid, - 'gamejoltaccount' => new GamejoltAccountResource($this->gamejoltaccount), - 'reason' => new BanReasonResource($this->reason), - 'expire_at' => $this->expire_at, - ]; - } - - return [ - 'gamejoltaccount' => new GamejoltAccountResource($this->gamejoltaccount), - 'reason' => new BanReasonResource($this->reason), - ]; + return parent::toArray($request); } } diff --git a/app/Http/Resources/API/v1/GamejoltAccountResource.php b/app/Http/Resources/API/v1/GamejoltAccountResource.php index 7a80e8eff..777618804 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountResource.php @@ -14,34 +14,6 @@ class GamejoltAccountResource extends JsonResource */ public function toArray($request) { - if (! $request->user()) { - return []; - } - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'username' => $this->username, - 'verified_at' => $this->verified_at, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'user' => new UserResource($this->user), - 'bans' => GamejoltAccountBanResource::collection($this->whenLoaded('bans')), - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'id' => $this->id, - 'username' => $this->username, - 'verified_at' => $this->verified_at, - ]; - } - - return [ - 'id' => $this->id, - 'username' => $this->username, - ]; + return parent::toArray($request); } } diff --git a/app/Http/Resources/API/v1/PermissionResource.php b/app/Http/Resources/API/v1/PermissionResource.php index afcd9c4a9..5a5f4832d 100644 --- a/app/Http/Resources/API/v1/PermissionResource.php +++ b/app/Http/Resources/API/v1/PermissionResource.php @@ -2,40 +2,21 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class PermissionResource extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'created_at' => $this->created_at, - ]; - } - - return [ - 'id' => $this->id, - 'name' => $this->name, - ]; + return parent::toArray($request); } } From 5a145c4af75b8fcff8bdaee2551fb6332825fbe6 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:01:07 +0200 Subject: [PATCH 25/41] Create PostResource.php --- app/Http/Resources/API/v1/PostResource.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/Http/Resources/API/v1/PostResource.php diff --git a/app/Http/Resources/API/v1/PostResource.php b/app/Http/Resources/API/v1/PostResource.php new file mode 100644 index 000000000..cb626b9a9 --- /dev/null +++ b/app/Http/Resources/API/v1/PostResource.php @@ -0,0 +1,22 @@ + Date: Sun, 18 Jun 2023 16:01:19 +0200 Subject: [PATCH 26/41] Reworked all API resources --- app/Http/Resources/API/v1/RoleResource.php | 34 ++++-------------- app/Http/Resources/API/v1/UserResource.php | 42 ++++------------------ 2 files changed, 14 insertions(+), 62 deletions(-) diff --git a/app/Http/Resources/API/v1/RoleResource.php b/app/Http/Resources/API/v1/RoleResource.php index 56c7f8e16..a7e519da0 100644 --- a/app/Http/Resources/API/v1/RoleResource.php +++ b/app/Http/Resources/API/v1/RoleResource.php @@ -2,41 +2,21 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class RoleResource extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'permissions' => PermissionResource::collection($this->whenLoaded('permissions')), - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'created_at' => $this->created_at, - ]; - } - - return [ - 'id' => $this->id, - 'name' => $this->name, - ]; + return parent::toArray($request); } } diff --git a/app/Http/Resources/API/v1/UserResource.php b/app/Http/Resources/API/v1/UserResource.php index aa5a550c7..4ea09e5d2 100644 --- a/app/Http/Resources/API/v1/UserResource.php +++ b/app/Http/Resources/API/v1/UserResource.php @@ -2,49 +2,21 @@ namespace App\Http\Resources\API\v1; +use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use JsonSerializable; class UserResource extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @param Request $request + * @return array|Arrayable|JsonSerializable */ - public function toArray($request) + public function toArray($request): array|JsonSerializable|Arrayable { - if (! $request->user()) { - return []; - } - if ($request->user()->can('api.full')) { - return parent::toArray($request); - } - if ($request->user()->can('api.moderate')) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'email' => $this->email, - 'username' => $this->username, - 'email_verified_at' => $this->email_verified_at, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'profile_photo_url' => $this->profile_photo_url, - 'roles' => RoleResource::collection($this->whenLoaded('roles')), - ]; - } - if ($request->user()->can('api.minimal')) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'email' => $this->email, - 'created_at' => $this->created_at, - ]; - } - - return [ - 'id' => $this->id, - 'name' => $this->name, - ]; + return parent::toArray($request); } } From 8fe0cc429bc9dbe75b28cb3d3948f60761e1e951 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:02:31 +0200 Subject: [PATCH 27/41] Removed permission check in API controllers --- .../API/v1/BanReasonController.php | 20 ----------- .../API/v1/DiscordAccountController.php | 10 ------ .../API/v1/DiscordBotSettingController.php | 15 -------- .../API/v1/GamejoltAccountBanController.php | 35 ------------------- .../API/v1/GamejoltAccountController.php | 10 ------ .../Controllers/API/v1/PostController.php | 5 --- .../Controllers/API/v1/UserController.php | 10 ------ 7 files changed, 105 deletions(-) diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index 6befde8ec..2a3464795 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -28,16 +28,6 @@ public function __construct() */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $resources = BanReason::all(); return BanReasonResource::collection($resources); @@ -54,16 +44,6 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina */ public function show(Request $request, $id): BanReasonResource|\Illuminate\Http\JsonResponse { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $resource = BanReason::findOrFail($id); return new BanReasonResource($resource); diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index 83f4ee1f3..117db8733 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -25,16 +25,6 @@ class DiscordAccountController extends Controller */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|DiscordAccountResource { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $account = DiscordAccount::with(['roles', 'user.roles.permissions'])->findOrFail($id); return new DiscordAccountResource($account); diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index 3a1ef1964..bb5bdbc8a 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -31,16 +31,6 @@ class DiscordBotSettingController extends Controller */ public function index(Request $request): \Illuminate\Http\JsonResponse { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $discordBotSetting = DiscordBotSetting::first(); // Only show first in table return response()->json($discordBotSetting); @@ -67,11 +57,6 @@ public function index(Request $request): \Illuminate\Http\JsonResponse */ public function update(Request $request, int $id): \Illuminate\Http\JsonResponse { - if (! $request->user()->tokenCan('update')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } if ($id !== 1) { return response()->json([ 'error' => 'Invalid ID!', diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index 62d71da9d..d242402a6 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -30,21 +30,6 @@ public function __construct() */ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $resources = GamejoltAccountBan::with(['reason', 'gamejoltaccount'])->get(); return GamejoltAccountBanResource::collection($resources); @@ -65,11 +50,6 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina */ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\Http\JsonResponse { - if (! $request->user()->tokenCan('create')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $request->validate([ 'gamejoltaccount_id' => 'required|integer', 'reason_id' => 'required|integer', @@ -121,16 +101,6 @@ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\ */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $resources = GamejoltAccountBan::with(['reason', 'gamejoltaccount', 'banned_by']) ->where('gamejoltaccount_id', $id) ->get(); @@ -149,11 +119,6 @@ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illu */ public function destroy(Request $request, $uuid): \Illuminate\Http\JsonResponse { - if (! $request->user()->tokenCan('delete')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $resource = GamejoltAccountBan::where('uuid', $uuid)->firstOrFail(); $resource->delete(); diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index 88f0f7e66..89b888508 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -30,16 +30,6 @@ public function __construct() */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|GamejoltAccountResource { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $gja = GamejoltAccount::with(['user.roles.permissions', 'bans', 'user.discord']) ->where('id', $id) ->firstOrFail(); diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index 00e6a427b..875c6f8b7 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -33,11 +33,6 @@ public function __construct() **/ public function store(Request $request): \Illuminate\Http\JsonResponse { - if (! $request->user()->tokenCan('create')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $request->validate([ 'title' => 'required|string', 'body' => 'required|string', diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index a2c525fab..964c2f765 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -30,16 +30,6 @@ public function __construct() */ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|UserResource { - if (! $request->user()) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } - if (! $request->user()->tokenCan('read')) { - return response()->json([ - 'error' => 'Token does not have access!', - ]); - } $user = User::with(['roles.permissions', 'gamejolt', 'forum'])->findOrFail($id); return new UserResource($user); From 2de5a912af87a8fd8591183701145071e80b3146 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:02:37 +0200 Subject: [PATCH 28/41] Update scribe.php --- config/scribe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/scribe.php b/config/scribe.php index 605e15d79..2bec53ceb 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -87,7 +87,7 @@ * API calls will be made only for routes in this group matching these HTTP methods (GET, POST, etc). * List the methods here or use '*' to mean all methods. Leave empty to disable API calls. */ - 'methods' => [], + 'methods' => ['GET'], /* * Laravel config variables which should be set for the API call. From 3d1316256e552630694a925056553afe869c3066 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:03:26 +0200 Subject: [PATCH 29/41] Reworked permissions structure --- .../Controllers/API/v1/PostController.php | 2 +- app/Http/Controllers/TagController.php | 8 +- database/seeders/PermissionSeeder.php | 90 +++++++++---------- resources/views/navigation-menu.blade.php | 4 +- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index 875c6f8b7..66b86aaa0 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -15,7 +15,7 @@ class PostController extends Controller { public function __construct() { - $this->middleware(['permission:posts.create'])->only(['store']); + $this->middleware(['permission:post.create'])->only(['store']); } /** diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 27215193c..18accfc8a 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -9,10 +9,10 @@ class TagController extends Controller { public function __construct() { - $this->middleware(['permission:tags.create|tags.update|tags.destroy'])->only(['index']); - $this->middleware(['permission:tags.create'])->only(['create', 'store']); - $this->middleware(['permission:tags.update'])->only(['update', 'edit']); - $this->middleware(['permission:tags.destroy'])->only(['destroy']); + $this->middleware(['permission:tag.create|tag.update|tag.destroy'])->only(['index']); + $this->middleware(['permission:tag.create'])->only(['create', 'store']); + $this->middleware(['permission:tag.update'])->only(['update', 'edit']); + $this->middleware(['permission:tag.destroy'])->only(['destroy']); } /** diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index 623204891..0df277c4b 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -4,6 +4,7 @@ use App\Models\User; use Illuminate\Database\Seeder; +use Illuminate\Support\Str; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; @@ -16,63 +17,62 @@ class PermissionSeeder extends Seeder */ public function run() { - $r1 = Role::firstOrCreate(['name' => 'super-admin']); - $r2 = Role::firstOrCreate(['name' => 'admin']); - $r3 = Role::firstOrCreate(['name' => 'moderator']); + $super_admin = Role::firstOrCreate(['name' => 'super-admin']); + $admin = Role::firstOrCreate(['name' => 'admin']); + $moderator = Role::firstOrCreate(['name' => 'moderator']); - $p1 = Permission::firstOrCreate(['name' => 'manage.users']); - $p2 = Permission::firstOrCreate(['name' => 'manage.roles']); - $p3 = Permission::firstOrCreate(['name' => 'manage.permissions']); + Permission::firstOrCreate(['name' => 'manage.users']); + Permission::firstOrCreate(['name' => 'manage.roles']); + Permission::firstOrCreate(['name' => 'manage.permissions']); - $p4 = Permission::firstOrCreate(['name' => 'api']); - $p5 = Permission::firstOrCreate(['name' => 'api.minimal']); - $p6 = Permission::firstOrCreate(['name' => 'api.moderate']); - $p7 = Permission::firstOrCreate(['name' => 'api.full']); + Permission::firstOrCreate(['name' => 'api']); - $p8 = Permission::firstOrCreate(['name' => 'posts.create']); - $p9 = Permission::firstOrCreate(['name' => 'posts.update']); - $p10 = Permission::firstOrCreate(['name' => 'posts.destroy']); + Permission::firstOrCreate(['name' => 'post.show']); + Permission::firstOrCreate(['name' => 'post.create']); + Permission::firstOrCreate(['name' => 'post.update']); + Permission::firstOrCreate(['name' => 'post.destroy']); - $p11 = Permission::firstOrCreate(['name' => 'tags.create']); - $p12 = Permission::firstOrCreate(['name' => 'tags.update']); - $p13 = Permission::firstOrCreate(['name' => 'tags.destroy']); + Permission::firstOrCreate(['name' => 'tag.show']); + Permission::firstOrCreate(['name' => 'tag.create']); + Permission::firstOrCreate(['name' => 'tag.update']); + Permission::firstOrCreate(['name' => 'tag.destroy']); - $p14 = Permission::firstOrCreate(['name' => 'categories.create']); - $p15 = Permission::firstOrCreate(['name' => 'categories.update']); - $p16 = Permission::firstOrCreate(['name' => 'categories.destroy']); + Permission::firstOrCreate(['name' => 'ban_reason.show']); + Permission::firstOrCreate(['name' => 'ban_reason.create']); + Permission::firstOrCreate(['name' => 'ban_reason.update']); + Permission::firstOrCreate(['name' => 'ban_reason.destroy']); - $p17 = Permission::firstOrCreate(['name' => 'stats']); - $p18 = Permission::firstOrCreate(['name' => 'analytics']); + Permission::firstOrCreate(['name' => 'category.show']); + Permission::firstOrCreate(['name' => 'category.create']); + Permission::firstOrCreate(['name' => 'category.update']); + Permission::firstOrCreate(['name' => 'category.destroy']); + + Permission::firstOrCreate(['name' => 'stats']); + Permission::firstOrCreate(['name' => 'analytics']); + + + // Get all permissions + $permissions = Permission::all(); // Super Admin permissions - $r1->givePermissionTo(Permission::all()); + $super_admin->givePermissionTo($permissions); // Admin permissions - $r2->givePermissionTo($p2->name); - $r2->givePermissionTo($p3->name); - $r1->givePermissionTo($p4->name); - $r1->givePermissionTo($p5->name); - $r2->givePermissionTo($p8->name); - $r2->givePermissionTo($p9->name); - $r2->givePermissionTo($p10->name); - $r2->givePermissionTo($p11->name); - $r2->givePermissionTo($p12->name); - $r2->givePermissionTo($p13->name); - $r2->givePermissionTo($p14->name); - $r2->givePermissionTo($p17->name); + // Give all permissions except for permissions containing 'manage' + $admin->givePermissionTo($permissions->filter(function ($permission) { + return !Str::contains($permission->name, ['manage']); + })); // Moderator permissions - $r3->givePermissionTo($p4->name); - $r3->givePermissionTo($p8->name); - $r3->givePermissionTo($p9->name); - $r3->givePermissionTo($p10->name); - $r3->givePermissionTo($p11->name); - $r3->givePermissionTo($p12->name); - $r3->givePermissionTo($p13->name); - - $user = User::first(); - if ($user) { - $user->assignRole($r1); + // Give all permissions except for permissions containing 'destroy' and 'manage' + $moderator->givePermissionTo($permissions->filter(function ($permission) { + return !Str::contains($permission->name, ['destroy', 'manage']); + })); + + + $first_user = User::first(); + if ($first_user) { + $first_user->assignRole($super_admin); } } } diff --git a/resources/views/navigation-menu.blade.php b/resources/views/navigation-menu.blade.php index ec04604db..287abfceb 100644 --- a/resources/views/navigation-menu.blade.php +++ b/resources/views/navigation-menu.blade.php @@ -167,7 +167,7 @@
{{ __('Content') }}
- @canany(['tags.create','tags.update','tags.destroy']) + @canany(['tag.create','tag.update','tag.destroy']) {{ __('Tags') }} @@ -310,7 +310,7 @@
{{ __('Content') }}
- @canany(['tags.create','tags.update','tags.destroy']) + @canany(['tag.create','tag.update','tag.destroy']) {{ __('Tags') }} From 4da2a5a433f28d26f486ecd6bf4681231e6ced77 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:03:33 +0200 Subject: [PATCH 30/41] Update PostController.php --- app/Http/Controllers/API/v1/PostController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/API/v1/PostController.php b/app/Http/Controllers/API/v1/PostController.php index 66b86aaa0..495f59ad8 100644 --- a/app/Http/Controllers/API/v1/PostController.php +++ b/app/Http/Controllers/API/v1/PostController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\API\v1; use App\Http\Controllers\Controller; +use App\Http\Resources\API\v1\PostResource; use App\Models\Post; use Illuminate\Http\Request; @@ -28,10 +29,12 @@ public function __construct() * @bodyParam user_id int required The ID of the user. Example: 1 * @bodyParam published_at string optional The date the post was published. Example: 2021-01-01 * - * @response {} + * @apiResourceModel App\Models\Post + * + * @apiResource App\Http\Resources\API\v1\PostResource * **/ - public function store(Request $request): \Illuminate\Http\JsonResponse + public function store(Request $request): PostResource { $request->validate([ 'title' => 'required|string', @@ -43,6 +46,6 @@ public function store(Request $request): \Illuminate\Http\JsonResponse ]); $post = Post::create($request->all()); - return response()->json($post, 201); + return new PostResource($post); } } From 3d6dac2c440d515c146203f666803670c7cab8d5 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:09:43 +0200 Subject: [PATCH 31/41] Added permission check for all API endpoints --- app/Http/Controllers/API/v1/BanReasonController.php | 2 +- .../Controllers/API/v1/DiscordAccountController.php | 5 +++++ .../API/v1/DiscordBotSettingController.php | 6 ++++++ .../API/v1/GamejoltAccountBanController.php | 4 +++- .../Controllers/API/v1/GamejoltAccountController.php | 2 +- app/Http/Controllers/API/v1/UserController.php | 2 +- database/seeders/PermissionSeeder.php | 11 +++++++++++ 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/API/v1/BanReasonController.php b/app/Http/Controllers/API/v1/BanReasonController.php index 2a3464795..3ad1e9283 100644 --- a/app/Http/Controllers/API/v1/BanReasonController.php +++ b/app/Http/Controllers/API/v1/BanReasonController.php @@ -16,7 +16,7 @@ class BanReasonController extends Controller { public function __construct() { - //$this->middleware(['permission:api']); + $this->middleware('permission:ban_reason.show')->only(['index', 'show']); } /** diff --git a/app/Http/Controllers/API/v1/DiscordAccountController.php b/app/Http/Controllers/API/v1/DiscordAccountController.php index 117db8733..7434123f6 100644 --- a/app/Http/Controllers/API/v1/DiscordAccountController.php +++ b/app/Http/Controllers/API/v1/DiscordAccountController.php @@ -14,6 +14,11 @@ */ class DiscordAccountController extends Controller { + public function __construct() + { + $this->middleware('permission:discord_account.show')->only(['show']); + } + /** * Display the specified resource. * diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index bb5bdbc8a..2c786d1d5 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -13,6 +13,12 @@ */ class DiscordBotSettingController extends Controller { + public function __construct() + { + $this->middleware('permission:discord_bot_setting.show')->only(['index']); + $this->middleware('permission:discord_bot_setting.update')->only(['update']); + } + /** * Display the first resource. * diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index d242402a6..7aaaa402a 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -18,7 +18,9 @@ class GamejoltAccountBanController extends Controller { public function __construct() { - //$this->middleware(['permission:api']); + $this->middleware('permission:gamejolt_account_ban.show')->only(['index', 'show']); + $this->middleware('permission:gamejolt_account_ban.create')->only(['store']); + $this->middleware('permission:gamejolt_account_ban.destroy')->only(['destroy']); } /** diff --git a/app/Http/Controllers/API/v1/GamejoltAccountController.php b/app/Http/Controllers/API/v1/GamejoltAccountController.php index 89b888508..a63132c03 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountController.php @@ -16,7 +16,7 @@ class GamejoltAccountController extends Controller { public function __construct() { - //$this->middleware(['permission:api']); + $this->middleware('permission:gamejolt_account.show')->only(['show']); } /** diff --git a/app/Http/Controllers/API/v1/UserController.php b/app/Http/Controllers/API/v1/UserController.php index 964c2f765..54ce8f555 100644 --- a/app/Http/Controllers/API/v1/UserController.php +++ b/app/Http/Controllers/API/v1/UserController.php @@ -16,7 +16,7 @@ class UserController extends Controller { public function __construct() { - //$this->middleware(['permission:api']); + $this->middleware('permission:user.show')->only(['show']); } /** diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index 0df277c4b..b96ecd505 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -47,6 +47,17 @@ public function run() Permission::firstOrCreate(['name' => 'category.update']); Permission::firstOrCreate(['name' => 'category.destroy']); + Permission::firstOrCreate(['name' => 'gamejolt_account_ban.show']); + Permission::firstOrCreate(['name' => 'gamejolt_account_ban.create']); + Permission::firstOrCreate(['name' => 'gamejolt_account_ban.destroy']); + + Permission::firstOrCreate(['name' => 'gamejolt_account.show']); + + Permission::firstOrCreate(['name' => 'discord_bot_setting.show']); + Permission::firstOrCreate(['name' => 'discord_bot_setting.update']); + + Permission::firstOrCreate(['name' => 'user.show']); + Permission::firstOrCreate(['name' => 'stats']); Permission::firstOrCreate(['name' => 'analytics']); From 6c7e57ad1bda6c2bd865cecc6c6f28a6af581521 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:23:29 +0200 Subject: [PATCH 32/41] Updated exception handler to handle unauthorized for API --- app/Exceptions/Handler.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index dc6b7b3d4..ffe4b6bc9 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,7 +2,11 @@ namespace App\Exceptions; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Http\JsonResponse; +use Spatie\Permission\Exceptions\UnauthorizedException; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; @@ -50,4 +54,17 @@ public function register() } }); } + + public function render($request, Throwable $e): \Illuminate\Http\Response|JsonResponse|Response + { + if ($e instanceof AuthorizationException && $request->expectsJson()) { + return response()->json(['error' => 'Unauthorized'], 403); + } + + if ($e instanceof UnauthorizedException && $request->expectsJson()) { + return response()->json(['error' => 'Unauthorized'], 403); + } + + return parent::render($request, $e); + } } From bd3152fa2777ab2cecf2fdf66c7c59ac5ee7e346 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:24:04 +0200 Subject: [PATCH 33/41] pint --- app/Http/Resources/API/v1/BanReasonResource.php | 2 -- app/Http/Resources/API/v1/DiscordAccountResource.php | 1 - app/Http/Resources/API/v1/DiscordRoleResource.php | 1 - app/Http/Resources/API/v1/GamejoltAccountBanResource.php | 1 - app/Http/Resources/API/v1/PermissionResource.php | 1 - app/Http/Resources/API/v1/PostResource.php | 1 - app/Http/Resources/API/v1/RoleResource.php | 1 - app/Http/Resources/API/v1/UserResource.php | 1 - 8 files changed, 9 deletions(-) diff --git a/app/Http/Resources/API/v1/BanReasonResource.php b/app/Http/Resources/API/v1/BanReasonResource.php index 7a76b33b8..76b34015e 100644 --- a/app/Http/Resources/API/v1/BanReasonResource.php +++ b/app/Http/Resources/API/v1/BanReasonResource.php @@ -9,12 +9,10 @@ class BanReasonResource extends JsonResource { - /** * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/DiscordAccountResource.php b/app/Http/Resources/API/v1/DiscordAccountResource.php index 2d1e07834..95f15b061 100644 --- a/app/Http/Resources/API/v1/DiscordAccountResource.php +++ b/app/Http/Resources/API/v1/DiscordAccountResource.php @@ -13,7 +13,6 @@ class DiscordAccountResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/DiscordRoleResource.php b/app/Http/Resources/API/v1/DiscordRoleResource.php index 40dec2597..64b00b6ad 100644 --- a/app/Http/Resources/API/v1/DiscordRoleResource.php +++ b/app/Http/Resources/API/v1/DiscordRoleResource.php @@ -13,7 +13,6 @@ class DiscordRoleResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php index 8210562c1..f18d4b594 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php @@ -13,7 +13,6 @@ class GamejoltAccountBanResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/PermissionResource.php b/app/Http/Resources/API/v1/PermissionResource.php index 5a5f4832d..61e8fffc5 100644 --- a/app/Http/Resources/API/v1/PermissionResource.php +++ b/app/Http/Resources/API/v1/PermissionResource.php @@ -13,7 +13,6 @@ class PermissionResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/PostResource.php b/app/Http/Resources/API/v1/PostResource.php index cb626b9a9..75acc8756 100644 --- a/app/Http/Resources/API/v1/PostResource.php +++ b/app/Http/Resources/API/v1/PostResource.php @@ -13,7 +13,6 @@ class PostResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/RoleResource.php b/app/Http/Resources/API/v1/RoleResource.php index a7e519da0..93c4b91d4 100644 --- a/app/Http/Resources/API/v1/RoleResource.php +++ b/app/Http/Resources/API/v1/RoleResource.php @@ -13,7 +13,6 @@ class RoleResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { diff --git a/app/Http/Resources/API/v1/UserResource.php b/app/Http/Resources/API/v1/UserResource.php index 4ea09e5d2..366f5cffd 100644 --- a/app/Http/Resources/API/v1/UserResource.php +++ b/app/Http/Resources/API/v1/UserResource.php @@ -13,7 +13,6 @@ class UserResource extends JsonResource * Transform the resource into an array. * * @param Request $request - * @return array|Arrayable|JsonSerializable */ public function toArray($request): array|JsonSerializable|Arrayable { From 4d49c1bf0410052da47fd4e6ba9f382a7d4d1316 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:24:31 +0200 Subject: [PATCH 34/41] Run all endpoints --- config/scribe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/scribe.php b/config/scribe.php index 2bec53ceb..e899d20ee 100644 --- a/config/scribe.php +++ b/config/scribe.php @@ -87,7 +87,7 @@ * API calls will be made only for routes in this group matching these HTTP methods (GET, POST, etc). * List the methods here or use '*' to mean all methods. Leave empty to disable API calls. */ - 'methods' => ['GET'], + 'methods' => ['*'], /* * Laravel config variables which should be set for the API call. From 14f2f5d6eca8c30fbd1ea551f49735e2b1354900 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:24:46 +0200 Subject: [PATCH 35/41] Update DiscordBotSettingController.php --- app/Http/Controllers/API/v1/DiscordBotSettingController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index 2c786d1d5..2611244c7 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -22,7 +22,7 @@ public function __construct() /** * Display the first resource. * - * @response { + * @jsonresponse { * "data": [ * { * "category_id": 1, From b0defb51cc4d27bb3c9cd79e48cf7b7f8b4f0af4 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Sun, 18 Jun 2023 16:25:00 +0200 Subject: [PATCH 36/41] pint --- .../API/v1/DiscordBotSettingController.php | 5 +++-- .../API/v1/GamejoltAccountBanController.php | 10 ++++++---- database/seeders/PermissionSeeder.php | 14 ++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/API/v1/DiscordBotSettingController.php b/app/Http/Controllers/API/v1/DiscordBotSettingController.php index 2611244c7..5d0f10167 100644 --- a/app/Http/Controllers/API/v1/DiscordBotSettingController.php +++ b/app/Http/Controllers/API/v1/DiscordBotSettingController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Models\DiscordBotSetting; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; /** @@ -35,7 +36,7 @@ public function __construct() * ] * } */ - public function index(Request $request): \Illuminate\Http\JsonResponse + public function index(Request $request): JsonResponse { $discordBotSetting = DiscordBotSetting::first(); // Only show first in table @@ -61,7 +62,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse * "updated_at": "2021-01-01T17:57:10.000000Z", * } */ - public function update(Request $request, int $id): \Illuminate\Http\JsonResponse + public function update(Request $request, int $id): JsonResponse { if ($id !== 1) { return response()->json([ diff --git a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php index 7aaaa402a..5c9c99ebd 100644 --- a/app/Http/Controllers/API/v1/GamejoltAccountBanController.php +++ b/app/Http/Controllers/API/v1/GamejoltAccountBanController.php @@ -7,7 +7,9 @@ use App\Models\GamejoltAccount; use App\Models\GamejoltAccountBan; use App\Models\User; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Resources\Json\AnonymousResourceCollection; /** * @group Ban Game Jolt Account @@ -30,7 +32,7 @@ public function __construct() * * @apiResourceModel App\Models\GamejoltAccountBan */ - public function index(Request $request): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection + public function index(Request $request): JsonResponse|AnonymousResourceCollection { $resources = GamejoltAccountBan::with(['reason', 'gamejoltaccount'])->get(); @@ -50,7 +52,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse|\Illumina * * @apiResourceModel App\Models\GamejoltAccountBan */ - public function store(Request $request): GamejoltAccountBanResource|\Illuminate\Http\JsonResponse + public function store(Request $request): GamejoltAccountBanResource|JsonResponse { $request->validate([ 'gamejoltaccount_id' => 'required|integer', @@ -101,7 +103,7 @@ public function store(Request $request): GamejoltAccountBanResource|\Illuminate\ * * @apiResourceModel App\Models\GamejoltAccountBan */ - public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\AnonymousResourceCollection + public function show(Request $request, $id): JsonResponse|AnonymousResourceCollection { $resources = GamejoltAccountBan::with(['reason', 'gamejoltaccount', 'banned_by']) ->where('gamejoltaccount_id', $id) @@ -119,7 +121,7 @@ public function show(Request $request, $id): \Illuminate\Http\JsonResponse|\Illu * * @apiResourceModel App\Models\GamejoltAccountBan */ - public function destroy(Request $request, $uuid): \Illuminate\Http\JsonResponse + public function destroy(Request $request, $uuid): JsonResponse { $resource = GamejoltAccountBan::where('uuid', $uuid)->firstOrFail(); $resource->delete(); diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index b96ecd505..e1bbde741 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -61,26 +61,24 @@ public function run() Permission::firstOrCreate(['name' => 'stats']); Permission::firstOrCreate(['name' => 'analytics']); - // Get all permissions - $permissions = Permission::all(); + $all_permissions = Permission::all(); // Super Admin permissions - $super_admin->givePermissionTo($permissions); + $super_admin->givePermissionTo($all_permissions); // Admin permissions // Give all permissions except for permissions containing 'manage' - $admin->givePermissionTo($permissions->filter(function ($permission) { - return !Str::contains($permission->name, ['manage']); + $admin->givePermissionTo($all_permissions->filter(function ($permission) { + return ! Str::contains($permission->name, ['manage']); })); // Moderator permissions // Give all permissions except for permissions containing 'destroy' and 'manage' - $moderator->givePermissionTo($permissions->filter(function ($permission) { - return !Str::contains($permission->name, ['destroy', 'manage']); + $moderator->givePermissionTo($all_permissions->filter(function ($permission) { + return ! Str::contains($permission->name, ['destroy', 'manage']); })); - $first_user = User::first(); if ($first_user) { $first_user->assignRole($super_admin); From c567bca0661137b02f571f12066fa8ef17aff274 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 19 Jun 2023 20:10:17 +0200 Subject: [PATCH 37/41] Added relations to GamejoltAccountBanResource --- app/Http/Resources/API/v1/GamejoltAccountBanResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php index f18d4b594..836ea0fa8 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php @@ -16,6 +16,7 @@ class GamejoltAccountBanResource extends JsonResource */ public function toArray($request): array|JsonSerializable|Arrayable { + $this->loadMissing(['banned_by', 'reason']); // Eager load relationships return parent::toArray($request); } } From 360d5bc603d466062ecd9949132d93092a6d20c1 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 19 Jun 2023 20:11:21 +0200 Subject: [PATCH 38/41] pint --- app/Http/Resources/API/v1/GamejoltAccountBanResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php index 836ea0fa8..50d686c8d 100644 --- a/app/Http/Resources/API/v1/GamejoltAccountBanResource.php +++ b/app/Http/Resources/API/v1/GamejoltAccountBanResource.php @@ -17,6 +17,7 @@ class GamejoltAccountBanResource extends JsonResource public function toArray($request): array|JsonSerializable|Arrayable { $this->loadMissing(['banned_by', 'reason']); // Eager load relationships + return parent::toArray($request); } } From f1fb23d6779409711125f388d5090439de06b3da Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 17 Jul 2023 21:01:15 +0200 Subject: [PATCH 39/41] Try fixing file size validation --- app/Http/Livewire/Resource/UpdateCreate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Livewire/Resource/UpdateCreate.php b/app/Http/Livewire/Resource/UpdateCreate.php index f6cb588e5..f3ad82ad9 100644 --- a/app/Http/Livewire/Resource/UpdateCreate.php +++ b/app/Http/Livewire/Resource/UpdateCreate.php @@ -30,7 +30,7 @@ class UpdateCreate extends ModalComponent protected array $rules = [ 'version' => ['required', 'string'], 'description' => ['required', 'string'], - 'file' => ['required', 'file', 'mimes:zip', 'max:100000'], //100mb + 'file' => ['required', 'file', 'mimes:zip', 'size:100000'], //100mb 'gameversion' => ['required'], ]; From 3f6607e19a9e5fb948716304fc1ebabc3d13a6cb Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 17 Jul 2023 21:06:14 +0200 Subject: [PATCH 40/41] Revert "Try fixing file size validation" This reverts commit f1fb23d6779409711125f388d5090439de06b3da. --- app/Http/Livewire/Resource/UpdateCreate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Livewire/Resource/UpdateCreate.php b/app/Http/Livewire/Resource/UpdateCreate.php index f3ad82ad9..f6cb588e5 100644 --- a/app/Http/Livewire/Resource/UpdateCreate.php +++ b/app/Http/Livewire/Resource/UpdateCreate.php @@ -30,7 +30,7 @@ class UpdateCreate extends ModalComponent protected array $rules = [ 'version' => ['required', 'string'], 'description' => ['required', 'string'], - 'file' => ['required', 'file', 'mimes:zip', 'size:100000'], //100mb + 'file' => ['required', 'file', 'mimes:zip', 'max:100000'], //100mb 'gameversion' => ['required'], ]; From 09f5a2849b475a56f0a561751357d0b0f7fc52ba Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 17 Jul 2023 21:10:37 +0200 Subject: [PATCH 41/41] Create livewire.php --- config/livewire.php | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 config/livewire.php diff --git a/config/livewire.php b/config/livewire.php new file mode 100644 index 000000000..03f1501e3 --- /dev/null +++ b/config/livewire.php @@ -0,0 +1,7 @@ + [ + 'rules' => 'file|max:100000', // (100MB max, and only pngs, jpegs, and pdfs.) + ], +];