From fd73aa158096bc3be6c66dba85d8e102ba1466af Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 00:41:23 +0100 Subject: [PATCH 1/9] Custom domain - Addec custom domain for mailgun, --- .env.example | 1 + config/services.php | 1 + 2 files changed, 2 insertions(+) diff --git a/.env.example b/.env.example index c8fbbd90..f39ef074 100644 --- a/.env.example +++ b/.env.example @@ -56,6 +56,7 @@ XDEBUG_CONFIG=remote_host=host.docker.internal MAILGUN_DOMAIN= MAILGUN_SECRET= +MAILGUN_ENDPOINT=api.eu.mailgun.net MAIL_FROM_ADDRESS= MAIL_TO_ADDRESS= diff --git a/config/services.php b/config/services.php index aa1f7f82..2849c5e1 100644 --- a/config/services.php +++ b/config/services.php @@ -17,6 +17,7 @@ 'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), 'secret' => env('MAILGUN_SECRET'), + 'endpoint' => env('MAILGUN_ENDPOINT'), ], 'ses' => [ From 55c7120f8a655c56ffb4a9f1625cab3dced492dc Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 00:48:14 +0100 Subject: [PATCH 2/9] Updated CHANGELOG - Updated the CHANGELOG. - Set version, - web,conifig missing PATCH --- CHANGELOG.md | 5 +++++ config/api/version.php | 4 ++-- public/web.config | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b34bc1..be1082f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The complete changelog for the Costs to Expect REST API, follows the format defined at https://keepachangelog.com/en/1.0.0/ +## [v1.22.1] - 2019-09-xx +### Changed +- We have updated the domain for Mailgun, now mail.costs-to-expect.com. +- `PATCH` missing from web.config + ## [v1.22.0] - 2019-08-25 ### Added - We have added PATCH support for categories; if authenticated, you can update the selected category. diff --git a/config/api/version.php b/config/api/version.php index 1392bab8..1eb5300b 100644 --- a/config/api/version.php +++ b/config/api/version.php @@ -1,9 +1,9 @@ '1.22.0', + 'version'=> '1.22.1', 'prefix' => 'v1', - 'release_date' => '2019-08-25', + 'release_date' => '2019-09-xx', 'changelog' => [ 'api' => '/v1/changelog', 'markdown' => 'https://github.com/costs-to-expect/api/blob/master/CHANGELOG.md' diff --git a/public/web.config b/public/web.config index bcdc1924..e6e9cef0 100644 --- a/public/web.config +++ b/public/web.config @@ -14,8 +14,8 @@ - - + + From 483bf0e6972fadd91ed395ee365ab98cc3442310 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 17:27:30 +0100 Subject: [PATCH 3/9] Add validation to OPTIONS requests - Continuing to unify information names in OPTIONS requests, dash instead of underscores. - Added string length validation for category POST. - Added validation data to the OPTIONS request. - Removed commented out code. --- app/Http/Controllers/CategoryController.php | 2 +- app/Http/Controllers/IndexController.php | 4 ++-- app/Http/Controllers/ItemController.php | 19 ------------------- app/Option/Delete.php | 2 +- app/Option/Get.php | 2 +- app/Option/Patch.php | 2 +- app/Option/Post.php | 2 +- app/Validators/Request/Fields/Category.php | 2 ++ config/api/category/fields.php | 7 +++++++ config/api/category/validation.php | 2 +- 10 files changed, 17 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 946ae249..628df05b 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -279,7 +279,7 @@ private function conditionalPostParameters(): array UtilityResponse::unableToDecode(); } - $conditional_post_fields['resource_type_id']['allowed_values'][$id] = [ + $conditional_post_fields['resource_type_id']['allowed-values'][$id] = [ 'value' => $id, 'name' => $resource_type['resource_type_name'], 'description' => $resource_type['resource_type_description'] diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 4bf05e16..7b31194f 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -70,7 +70,7 @@ public function optionsIndex(Request $request) [ 'GET' => [ 'description' => trans('route-descriptions.api_GET_index'), - 'authentication_required' => false, + 'authentication-required' => false, 'parameters' => [] ] ] @@ -137,7 +137,7 @@ public function optionsChangeLog(Request $request) [ 'GET' => [ 'description' => trans('route-descriptions.api_GET_changelog'), - 'authentication_required' => false, + 'authentication-required' => false, 'parameters' => [] ] ] diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index fe36bda9..d121d413 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -191,25 +191,6 @@ public function optionsIndex( $get + $post, 200 ); - - /*return $this->generateOptionsForIndex( - [ - 'description_localisation_string' => 'route-descriptions.item_GET_index', - 'parameters_config_string' => 'api.item.parameters.collection', - 'conditionals_config' => $conditional_parameters, - 'sortable_config' => 'api.item.sortable', - 'searchable_config' => 'api.item.searchable', - 'enable_pagination' => true, - 'allow_entire_collection' => $this->allow_entire_collection, - 'authentication_required' => false - ], - [ - 'description_localisation_string' => 'route-descriptions.item_POST', - 'fields_config' => 'api.item.fields', - 'conditionals_config' => [], - 'authentication_required' => true - ] - );*/ } /** diff --git a/app/Option/Delete.php b/app/Option/Delete.php index dc6ffeee..55e309ad 100644 --- a/app/Option/Delete.php +++ b/app/Option/Delete.php @@ -69,7 +69,7 @@ static public function option(): array return [ 'DELETE' => [ 'description' => self::$description, - 'authentication_required' => self::$authentication + 'authentication-required' => self::$authentication ] ]; } diff --git a/app/Option/Get.php b/app/Option/Get.php index 688c6caa..b520b81e 100644 --- a/app/Option/Get.php +++ b/app/Option/Get.php @@ -205,7 +205,7 @@ static public function option(): array return [ 'GET' => [ 'description' => self::$description, - 'authentication_required' => self::$authentication, + 'authentication-required' => self::$authentication, 'sortable' => self::$sortable_parameters, 'searchable' => self::$searchable_parameters, 'parameters' => self::$localised_parameters diff --git a/app/Option/Patch.php b/app/Option/Patch.php index 7f1cdf1b..6bbe0ec8 100644 --- a/app/Option/Patch.php +++ b/app/Option/Patch.php @@ -124,7 +124,7 @@ static public function option(): array return [ 'PATCH' => [ 'description' => self::$description, - 'authentication_required' => self::$authentication, + 'authentication-required' => self::$authentication, 'fields' => self::$localised_fields ] ]; diff --git a/app/Option/Post.php b/app/Option/Post.php index a8feeeef..35984c6f 100644 --- a/app/Option/Post.php +++ b/app/Option/Post.php @@ -125,7 +125,7 @@ static public function option(): array return [ 'POST' => [ 'description' => self::$description, - 'authentication_required' => self::$authentication, + 'authentication-required' => self::$authentication, 'fields' => self::$localised_fields ] ]; diff --git a/app/Validators/Request/Fields/Category.php b/app/Validators/Request/Fields/Category.php index 4de7557f..0be4f812 100644 --- a/app/Validators/Request/Fields/Category.php +++ b/app/Validators/Request/Fields/Category.php @@ -31,6 +31,7 @@ private function createRules(int $resource_type_id = null): array 'name' => [ 'required', 'string', + 'max:255', 'unique:category,name,null,id,resource_type_id,' . $resource_type_id ], ], @@ -53,6 +54,7 @@ private function updateRules(int $category_id, int $resource_type_id): array 'name' => [ 'sometimes', 'string', + 'max:255', 'unique:category,name,'. $category_id . ',id,resource_type_id,' . $resource_type_id ], ], diff --git a/config/api/category/fields.php b/config/api/category/fields.php index 222fc0b8..5e315a5c 100644 --- a/config/api/category/fields.php +++ b/config/api/category/fields.php @@ -8,6 +8,10 @@ 'title' => 'category/fields.title-name', 'description' => 'category/fields.description-name', 'type' => 'string', + 'validation' => [ + 'unique-for' => 'resource_type_id', + 'max-length' => 255 + ], 'required' => true ], 'description' => [ @@ -15,6 +19,9 @@ 'title' => 'category/fields.title-description', 'description' => 'category/fields.description-description', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ], 'resource_type_id' => [ diff --git a/config/api/category/validation.php b/config/api/category/validation.php index 4ec65877..bf4e5fed 100644 --- a/config/api/category/validation.php +++ b/config/api/category/validation.php @@ -14,7 +14,7 @@ ], 'PATCH' => [ 'fields' => [ - 'description' => 'sometimes|string' + 'description' => 'sometimes|string|max:255' ], 'messages' => [ 'name.unique' => 'category/validation.name-unique' From 02f5b6207060ef7c2b56bdaf21872c9f0db43249 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 17:35:25 +0100 Subject: [PATCH 4/9] Add validation to OPTIONS requests - Add validation data for patch fields. --- config/api/category/fields-patch.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/api/category/fields-patch.php b/config/api/category/fields-patch.php index 4bc783ea..32f03e6b 100644 --- a/config/api/category/fields-patch.php +++ b/config/api/category/fields-patch.php @@ -8,6 +8,10 @@ 'title' => 'category/fields.title-name', 'description' => 'category/fields.description-name', 'type' => 'string', + 'validation' => [ + 'unique-for' => 'resource_type_id', + 'max-length' => 255 + ], 'required' => true ], 'description' => [ @@ -15,6 +19,9 @@ 'title' => 'category/fields.title-description', 'description' => 'category/fields.description-description', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ] ]; From eedf7a00f4cbc2f986b85887d2264202416db464 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 17:45:09 +0100 Subject: [PATCH 5/9] Add validation to OPTIONS requests - Add validation data to OPTIONS requests for subcategories. - Add string length validation rules. --- app/Validators/Request/Fields/SubCategory.php | 2 ++ config/api/subcategory/fields.php | 7 +++++++ config/api/subcategory/validation.php | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Validators/Request/Fields/SubCategory.php b/app/Validators/Request/Fields/SubCategory.php index 176a064d..4eff3e7d 100644 --- a/app/Validators/Request/Fields/SubCategory.php +++ b/app/Validators/Request/Fields/SubCategory.php @@ -31,6 +31,7 @@ private function createRules(int $category_id): array 'name' => [ 'required', 'string', + 'max:255', 'unique:sub_category,name,null,id,category_id,' . $category_id ], ], @@ -53,6 +54,7 @@ private function updateRules(int $category_id, int $subcategory_id): array 'name' => [ 'sometimes', 'string', + 'max:255', 'unique:sub_category,name,'. $subcategory_id . ',id,category_id,' . $category_id ], ], diff --git a/config/api/subcategory/fields.php b/config/api/subcategory/fields.php index eebf8bb1..52c9dd86 100644 --- a/config/api/subcategory/fields.php +++ b/config/api/subcategory/fields.php @@ -8,6 +8,10 @@ 'title' => 'subcategory/fields.title-name', 'description' => 'subcategory/fields.description-name', 'type' => 'string', + 'validation' => [ + 'unique-for' => 'category_id', + 'max-length' => 255 + ], 'required' => true ], 'description' => [ @@ -15,6 +19,9 @@ 'title' => 'subcategory/fields.title-description', 'description' => 'subcategory/fields.description-description', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ] ]; diff --git a/config/api/subcategory/validation.php b/config/api/subcategory/validation.php index a7fcb86e..d732b4e2 100644 --- a/config/api/subcategory/validation.php +++ b/config/api/subcategory/validation.php @@ -5,7 +5,7 @@ return [ 'POST' => [ 'fields' => [ - 'description' => 'required|string' + 'description' => 'required|string|max:255' ], 'messages' => [ 'name.unique' => 'subcategory/validation.name-unique' @@ -13,7 +13,7 @@ ], 'PATCH' => [ 'fields' => [ - 'description' => 'sometimes|string' + 'description' => 'sometimes|string|max:255' ], 'messages' => [ 'name.unique' => 'subcategory/validation.name-unique' From 20d0b3ceab1f6d93124bf23d9d0538a8d151438f Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 17:54:03 +0100 Subject: [PATCH 6/9] Add validation to OPTIONS requests - Added validation data to OPTIONS requests for resource types. - Added string length validation rules for resource type POST/PATCH --- app/Validators/Request/Fields/ResourceType.php | 1 + config/api/resource-type/fields.php | 6 ++++++ config/api/resource-type/validation.php | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Validators/Request/Fields/ResourceType.php b/app/Validators/Request/Fields/ResourceType.php index 5a2c8569..e7e5d45b 100644 --- a/app/Validators/Request/Fields/ResourceType.php +++ b/app/Validators/Request/Fields/ResourceType.php @@ -31,6 +31,7 @@ private function updateRules(int $resource_type_id): array 'name' => [ 'sometimes', 'string', + 'max:255', 'unique:resource_type,name,'. $resource_type_id . ',id' ], ], diff --git a/config/api/resource-type/fields.php b/config/api/resource-type/fields.php index 8d0f9a58..b163470f 100644 --- a/config/api/resource-type/fields.php +++ b/config/api/resource-type/fields.php @@ -8,6 +8,9 @@ 'title' => 'resource-type/fields.title-name', 'description' => 'resource-type/fields.description-name', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ], 'description' => [ @@ -15,6 +18,9 @@ 'title' => 'resource-type/fields.title-description', 'description' => 'resource-type/fields.description-description', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ], 'private' => [ diff --git a/config/api/resource-type/validation.php b/config/api/resource-type/validation.php index e6c6c3cb..4ea9c323 100644 --- a/config/api/resource-type/validation.php +++ b/config/api/resource-type/validation.php @@ -5,8 +5,8 @@ return [ 'POST' => [ 'fields' => [ - 'name' => 'required|string|unique:resource_type,name', - 'description' => 'required|string', + 'name' => 'required|string|max:255|unique:resource_type,name', + 'description' => 'required|string|max:255', 'private' => 'sometimes|boolean' ], 'messages' => [ @@ -15,7 +15,7 @@ ], 'PATCH' => [ 'fields' => [ - 'description' => 'sometimes|string', + 'description' => 'sometimes|string|max:255', 'private' => 'sometimes|boolean' ], 'messages' => [ From 81801a5a5aba01a1bc81d10f4ca6e04fc150d677 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Fri, 30 Aug 2019 18:00:55 +0100 Subject: [PATCH 7/9] Add validation to OPTIONS request - Added validation data to OPTIONS requests for resource POST/PATCH. - Added string length validation to name and description. --- app/Validators/Request/Fields/Resource.php | 2 ++ config/api/resource/fields.php | 7 +++++++ config/api/resource/validation.php | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Validators/Request/Fields/Resource.php b/app/Validators/Request/Fields/Resource.php index 48597d83..5bcc17f5 100644 --- a/app/Validators/Request/Fields/Resource.php +++ b/app/Validators/Request/Fields/Resource.php @@ -32,6 +32,7 @@ private function createRules(int $resource_type_id): array 'name' => [ 'required', 'string', + 'max:255', 'unique:resource,name,null,id,resource_type_id,' . $resource_type_id ], ], @@ -54,6 +55,7 @@ private function updateRules(int $resource_type_id, int $resource_id): array 'name' => [ 'sometimes', 'string', + 'max:255', 'unique:resource,name,'. $resource_id . ',id,resource_type_id,' . $resource_type_id ], ], diff --git a/config/api/resource/fields.php b/config/api/resource/fields.php index 06345a77..69cdd90b 100644 --- a/config/api/resource/fields.php +++ b/config/api/resource/fields.php @@ -8,6 +8,10 @@ 'title' => 'resource/fields.title-name', 'description' => 'resource/fields.description-name', 'type' => 'string', + 'validation' => [ + 'unique-for' => 'resource_type_id', + 'max-length' => 255 + ], 'required' => true ], 'description' => [ @@ -15,6 +19,9 @@ 'title' => 'resource/fields.title-description', 'description' => 'resource/fields.description-description', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ], 'effective_date' => [ diff --git a/config/api/resource/validation.php b/config/api/resource/validation.php index 44b52dae..3fba8ce9 100644 --- a/config/api/resource/validation.php +++ b/config/api/resource/validation.php @@ -7,7 +7,8 @@ 'fields' => [ 'description' => [ 'required', - 'string' + 'string', + 'max:255' ], 'effective_date' => [ 'required', @@ -23,7 +24,8 @@ 'fields' => [ 'description' => [ 'sometimes', - 'string' + 'string', + 'max:255' ], 'effective_date' => [ 'sometimes', From f4b42c5c25e8095ef0aa38761335bad92deaf132 Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Sat, 31 Aug 2019 00:00:44 +0100 Subject: [PATCH 8/9] Add validation to OPTIONS request - Added validation data to OPTIONS request for item PATCH/POST. - Added string length validation for item description. --- config/api/item/fields.php | 9 ++++++++- config/api/item/validation.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config/api/item/fields.php b/config/api/item/fields.php index 37cd9304..670f9b07 100644 --- a/config/api/item/fields.php +++ b/config/api/item/fields.php @@ -8,6 +8,9 @@ 'title' => 'item/fields.title-description', 'description' => 'item/fields.description-description', 'type' => 'string', + 'validation' => [ + 'max-length' => 255 + ], 'required' => true ], 'effective_date' => [ @@ -35,7 +38,11 @@ 'field' => 'percentage', 'title' => 'item/fields.title-percentage', 'description' => 'item/fields.description-percentage', - 'type' => 'string', + 'type' => 'integer', + 'validation' => [ + 'min' => 1, + 'max' => 100 + ], 'required' => false ] ]; diff --git a/config/api/item/validation.php b/config/api/item/validation.php index e2bdbee1..fbb42798 100644 --- a/config/api/item/validation.php +++ b/config/api/item/validation.php @@ -5,7 +5,7 @@ return [ 'POST' => [ 'fields' => [ - 'description' => 'required|string', + 'description' => 'required|string|max:255', 'effective_date' => 'required|date_format:Y-m-d', 'publish_after' => 'sometimes|date_format:Y-m-d', 'total' => 'required|string|regex:/^\d+\.\d{2}$/', From fe0840f6a53342589d6b83d5e41d562c89ddc23f Mon Sep 17 00:00:00 2001 From: Dean Blackborough Date: Sat, 31 Aug 2019 00:43:49 +0100 Subject: [PATCH 9/9] Release - Modified the send email name and email - Updated the CHANGELOG. - Set the version. --- .env.example | 1 + CHANGELOG.md | 12 +++++++++--- app/Mail/RequestError.php | 6 ++++-- config/api/mail/request-error.php | 3 ++- config/api/version.php | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index f39ef074..a879cd28 100644 --- a/.env.example +++ b/.env.example @@ -59,4 +59,5 @@ MAILGUN_SECRET= MAILGUN_ENDPOINT=api.eu.mailgun.net MAIL_FROM_ADDRESS= +MAIL_FROM_NAME MAIL_TO_ADDRESS= diff --git a/CHANGELOG.md b/CHANGELOG.md index be1082f4..eef7b090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,16 @@ The complete changelog for the Costs to Expect REST API, follows the format defined at https://keepachangelog.com/en/1.0.0/ -## [v1.22.1] - 2019-09-xx +## [v1.22.1] - 2019-09-01 ### Changed -- We have updated the domain for Mailgun, now mail.costs-to-expect.com. -- `PATCH` missing from web.config +- We have updated the domain for Mailgun, now mail.costs-to-expect.com rather than the temp domain. +- We have updated the OPTIONS requestion, they now show additional validation data if necessary. +- We have continued to unify information names in the OPTIONS requests; we use dashes instead of underscores. +- We have updated the from setting for emails so 'on behalf of' doesn't show for sent emails. + +### Fixed +- `PATCH` missing from web.config, we have also corrected the PHP version number. +- String length validation rules missing from validation checks. ## [v1.22.0] - 2019-08-25 ### Added diff --git a/app/Mail/RequestError.php b/app/Mail/RequestError.php index 1c2f888f..637bfca0 100644 --- a/app/Mail/RequestError.php +++ b/app/Mail/RequestError.php @@ -13,6 +13,7 @@ class RequestError extends Mailable use Queueable, SerializesModels; public $api_from_mail; + public $api_from_name; public $request_error; /** @@ -24,7 +25,8 @@ class RequestError extends Mailable */ public function __construct(array $request_error) { - $this->api_from_mail = Config::get('api.mail.request-error.from'); + $this->api_from_mail = Config::get('api.mail.request-error.from_mail'); + $this->api_from_name = Config::get('api.mail.request-error.from_name'); $this->request_error = $request_error; } @@ -35,7 +37,7 @@ public function __construct(array $request_error) */ public function build() { - return $this->from($this->api_from_mail)-> + return $this->from($this->api_from_mail, $this->api_from_name)-> view('mail.request-error')-> subject('Costs to Expect API: Request error'); } diff --git a/config/api/mail/request-error.php b/config/api/mail/request-error.php index 338b96bf..e14f7626 100644 --- a/config/api/mail/request-error.php +++ b/config/api/mail/request-error.php @@ -3,6 +3,7 @@ declare(strict_types=1); return [ - 'from' => env('MAIL_FROM_ADDRESS'), + 'from_mail' => env('MAIL_FROM_ADDRESS'), + 'from_name' => env('MAIL_FROM_NAME'), 'to' => env('MAIL_TO_ADDRESS'), ]; diff --git a/config/api/version.php b/config/api/version.php index 1eb5300b..d4d06a71 100644 --- a/config/api/version.php +++ b/config/api/version.php @@ -3,7 +3,7 @@ return [ 'version'=> '1.22.1', 'prefix' => 'v1', - 'release_date' => '2019-09-xx', + 'release_date' => '2019-09-01', 'changelog' => [ 'api' => '/v1/changelog', 'markdown' => 'https://github.com/costs-to-expect/api/blob/master/CHANGELOG.md'