diff --git a/CHANGELOG.md b/CHANGELOG.md index f57bca5c..1bf97a5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/ +## [v2.10.3] - 2020-05-09 +### Fixed +- We have updated the delete resource type action; we have added additional checks before we attempt to delete, it was possible to remove relationship values which made the resource type inaccessible. + ## [v2.10.2] - 2020-04-30 ### Changed - We have updated all item endpoints to return `updated`; this is the date and time an item was updated, not its category assignments. diff --git a/app/Http/Controllers/ResourceTypeController.php b/app/Http/Controllers/ResourceTypeController.php index e2a96990..c0f2e243 100644 --- a/app/Http/Controllers/ResourceTypeController.php +++ b/app/Http/Controllers/ResourceTypeController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Category; use App\Models\ItemType; use App\Models\PermittedUser; use App\Models\Resource; @@ -295,15 +296,41 @@ public function delete( true ); - try { - (new ResourceTypeItemType())->instance($resource_type_id)->delete(); - (new PermittedUser())->instance($resource_type_id, Auth::user()->id)->delete(); - (new ResourceType())->find($resource_type_id)->delete(); - UtilityResponse::successNoContent(); - } catch (QueryException $e) { + $resource_type_item_type = (new ResourceTypeItemType())->instance($resource_type_id); + $permitted_user = (new PermittedUser())->instance($resource_type_id, Auth::user()->id); + $resource_type = (new ResourceType())->find($resource_type_id); + + $categories = (new Category())->total( + $resource_type_id, + $this->permitted_resource_types, + $this->include_public + ); + + $resources = (new Resource())->totalCount( + $resource_type_id, + $this->permitted_resource_types, + $this->include_public + ); + + if ( + $categories === 0 && + $resources === 0 && + $resource_type_item_type !== null && + $permitted_user !== null && + $resource_type !== null + ) { + try { + $resource_type_item_type->delete(); + $permitted_user->delete(); + $resource_type->delete(); + UtilityResponse::successNoContent(); + } catch (QueryException $e) { + UtilityResponse::foreignKeyConstraintError(); + } catch (Exception $e) { + UtilityResponse::notFound(trans('entities.resource-type'), $e); + } + } else { UtilityResponse::foreignKeyConstraintError(); - } catch (Exception $e) { - UtilityResponse::notFound(trans('entities.resource-type'), $e); } } diff --git a/config/api/app/version.php b/config/api/app/version.php index e9293f3d..67fa1b81 100644 --- a/config/api/app/version.php +++ b/config/api/app/version.php @@ -3,9 +3,9 @@ declare(strict_types=1); return [ - 'version'=> '2.10.2', + 'version'=> '2.10.3', 'prefix' => 'v2', - 'release_date' => '2020-04-30', + 'release_date' => '2020-05-09', 'changelog' => [ 'api' => '/v2/changelog', 'markdown' => 'https://github.com/costs-to-expect/api/blob/master/CHANGELOG.md' diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 05e549a4..9d246018 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -251,6 +251,7 @@ function gtag(){dataLayer.push(arguments);}
  • We have corrected a typo on the landing page.
  • We have switched the table we look at to return created at for an item; we should be using the sub table, not the base item table.
  • We have corrected the `/resource-types/` OPTIONS request; `public` is not a required field.
  • +
  • We have updated the delete resource type action; we have added additional checks before we attempt to delete, it was possible to remove relationship values which made the resource type inaccessible.