Can again destroy data.

This commit is contained in:
James Cole 2021-03-07 08:16:33 +01:00
parent f2e5e7d182
commit d6dd6795fe
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
6 changed files with 53 additions and 60 deletions

View File

@ -1,7 +1,7 @@
<?php
/**
/*
* DestroyController.php
* Copyright (c) 2020 james@firefly-iii.org
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@ -24,7 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Data;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\DataDestroyRequest;
use FireflyIII\Api\V1\Requests\Data\DestroyRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -52,9 +52,12 @@ use Illuminate\Http\JsonResponse;
class DestroyController extends Controller
{
/**
* @param DestroyRequest $request
*
* @return JsonResponse
* @throws FireflyException
*/
public function destroy(DataDestroyRequest $request): JsonResponse
public function destroy(DestroyRequest $request): JsonResponse
{
$objects = $request->getObjects();

View File

@ -1,8 +1,8 @@
<?php
/**
/*
* UserController.php
* Copyright (c) 2019 james@firefly-iii.org
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@ -22,10 +22,11 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
namespace FireflyIII\Api\V1\Controllers\System;
use FireflyIII\Api\V1\Requests\UserStoreRequest;
use FireflyIII\Api\V1\Requests\UserUpdateRequest;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\System\UserStoreRequest;
use FireflyIII\Api\V1\Requests\System\UserUpdateRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\UserTransformer;
@ -72,10 +73,14 @@ class UserController extends Controller
* @throws FireflyException
* @codeCoverageIgnore
*/
public function delete(User $user): JsonResponse
public function destroy(User $user): JsonResponse
{
/** @var User $admin */
$admin = auth()->user();
if($admin->id === $user->id) {
return response()->json([], 500);
}
if ($admin->id !== $user->id && $this->repository->hasRole($admin, 'owner')) {
$this->repository->destroy($user);

View File

@ -21,16 +21,16 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\Data;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class DataDestroyRequest
* Class DestroyRequest
*/
class DataDestroyRequest extends FormRequest
class DestroyRequest extends FormRequest
{
use ConvertsDataTypes, ChecksLogin;

View File

@ -1,8 +1,8 @@
<?php
/**
/*
* UserStoreRequest.php
* Copyright (c) 2019 james@firefly-iii.org
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@ -22,7 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\System;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Support\Request\ChecksLogin;

View File

@ -1,8 +1,8 @@
<?php
/**
/*
* UserUpdateRequest.php
* Copyright (c) 2019 james@firefly-iii.org
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@ -22,7 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\System;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Support\Request\ChecksLogin;

View File

@ -67,7 +67,7 @@ Route::group(
/**
* DATA ROUTES
*/
// EXPORT
// Export data API routes
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\Data\Export', 'prefix' => 'data/export',
'as' => 'api.v1.data.export.',],
@ -83,6 +83,14 @@ Route::group(
Route::get('transactions', ['uses' => 'ExportController@transactions', 'as' => 'transactions']);
}
);
// Destroy data API route
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\Data', 'prefix' => 'data/destroy',
'as' => 'api.v1.data.',],
static function () {
Route::delete('', ['uses' => 'DestroyController@destroy', 'as' => 'destroy']);
}
);
/**
* INSIGHTS ROUTES
@ -488,7 +496,7 @@ Route::group(
}
);
// Dynamic configuration API routes
// Configuration API routes
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\System', 'prefix' => 'configuration',
'as' => 'api.v1.configuration.',],
@ -499,18 +507,21 @@ Route::group(
}
);
// STATIC CONFIGURATION (NOT CHANGEABLE)
// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers\System', 'prefix' => 'configuration/static',
// 'as' => 'api.v1.configuration.static.',],
// static function () {
//
// // Configuration API routes:
// Route::get('', ['uses' => 'StaticConfigController@index', 'as' => 'index']);
// Route::get('{staticConfigKey}', ['uses' => 'StaticConfigController@show', 'as' => 'show']);
// }
//);
// Users API routes:
Route::group(
['middleware' => ['auth:api', 'bindings', IsAdmin::class], 'namespace' => 'FireflyIII\Api\V1\Controllers\System', 'prefix' => 'users',
'as' => 'api.v1.users.',],
static function () {
Route::get('', ['uses' => 'UserController@index', 'as' => 'index']);
Route::post('', ['uses' => 'UserController@store', 'as' => 'store']);
Route::get('{user}', ['uses' => 'UserController@show', 'as' => 'show']);
Route::put('{user}', ['uses' => 'UserController@update', 'as' => 'update']);
Route::delete('{user}', ['uses' => 'UserController@destroy', 'as' => 'delete']);
}
);
@ -633,19 +644,7 @@ Route::group(
//);
//
//
//// destroy data route.
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'data',
// 'as' => 'api.v1.data.',],
// static function () {
//
// // Overview API routes:
// Route::delete('destroy', ['uses' => 'Data\DestroyController@destroy', 'as' => 'destroy']);
// }
//);
//
//
//
@ -673,17 +672,3 @@ Route::group(
// }
//);
//
//// TODO VERIFY API DOCS
//Route::group(
// ['middleware' => ['auth:api', 'bindings', IsAdmin::class], 'namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'users',
// 'as' => 'api.v1.users.',],
// static function () {
//
// // Users API routes:
// Route::get('', ['uses' => 'UserController@index', 'as' => 'index']);
// Route::post('', ['uses' => 'UserController@store', 'as' => 'store']);
// Route::get('{user}', ['uses' => 'UserController@show', 'as' => 'show']);
// Route::put('{user}', ['uses' => 'UserController@update', 'as' => 'update']);
// Route::delete('{user}', ['uses' => 'UserController@delete', 'as' => 'delete']);
// }
//);