Skip to content

Commit

Permalink
feature/new-organisation-sign-up-form (#251)
Browse files Browse the repository at this point in the history
* Updated database ERD

* Updated dependencies

* Added migration to make update_requests.updateable_id nullable

* Update request updateable_type values refactored

They now use string constants on the UpdateRequest class.

* Test log cleared when tests first ran

* Update request observer no longer removes fields for new requests

* Update request updateable_id nullable in API docs

* Fixed typo

* Used scope instead of where clause

* Updated API docs with new endpoint

* Made update_requests.user_id nullable

* Endpoint created with no data

* Added request validation

* Added store update request logic to controller

* Linted code

* Added failing test for approving update request

* Working test for organisation sign up form approval

* Fixed permissions not being set for service

* Linted code
  • Loading branch information
matthew-inamdar committed Sep 6, 2019
1 parent 424fa69 commit d4db477
Show file tree
Hide file tree
Showing 36 changed files with 1,570 additions and 363 deletions.
2 changes: 2 additions & 0 deletions app/Docs/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static function create(string $objectId = null): BaseObject
Paths\Organisations\OrganisationsIndexPath::create(),
Paths\Organisations\OrganisationsNestedPath::create(),
Paths\Organisations\OrganisationsLogoPath::create(),
Paths\OrganisationSignUpForms\OrganisationSignUpFormsRootPath::create(),
Paths\PageFeedbacks\PageFeedbacksRootPath::create(),
Paths\PageFeedbacks\PageFeedbacksIndexPath::create(),
Paths\PageFeedbacks\PageFeedbacksNestedPath::create(),
Expand Down Expand Up @@ -99,6 +100,7 @@ public static function create(string $objectId = null): BaseObject
Tags\FilesTag::create(),
Tags\LocationsTag::create(),
Tags\NotificationsTag::create(),
Tags\OrganisationSignUpFormsTag::create(),
Tags\OrganisationsTag::create(),
Tags\PageFeedbacksTag::create(),
Tags\ReferralsTag::create(),
Expand Down
8 changes: 5 additions & 3 deletions app/Docs/Operations/Locations/UpdateLocationOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public static function create(string $objectId = null): BaseObject
->summary('Update a specific location')
->description('**Permission:** `Service Admin`')
->requestBody(
RequestBody::create()->content(
MediaType::json()->schema(UpdateLocationSchema::create())
)
RequestBody::create()
->required()
->content(
MediaType::json()->schema(UpdateLocationSchema::create())
)
)
->responses(
UpdateRequestReceivedResponse::create(null, UpdateLocationSchema::create())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Docs\Operations\OrganisationSignUpForms;

use App\Docs\Responses\UpdateRequestReceivedResponse;
use App\Docs\Schemas\OrganisationSignUpForm\StoreOrganisationSignUpFormSchema;
use App\Docs\Tags\OrganisationSignUpFormsTag;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Operation;
use GoldSpecDigital\ObjectOrientedOAS\Objects\RequestBody;

class StoreOrganisationSignUpFormOperation extends Operation
{
/**
* @param string|null $objectId
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
* @return static
*/
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->action(static::ACTION_POST)
->tags(OrganisationSignUpFormsTag::create())
->summary('Submit an organisation sign up form')
->description('**Permission:** `Open`')
->noSecurity()
->requestBody(
RequestBody::create()
->required()
->content(
MediaType::json()->schema(
StoreOrganisationSignUpFormSchema::create()
)
)
)
->responses(
UpdateRequestReceivedResponse::create(null, StoreOrganisationSignUpFormSchema::create())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public static function create(string $objectId = null): BaseObject
->summary('Create an organisation')
->description('**Permission:** `Global Admin`')
->requestBody(
RequestBody::create()->content(
MediaType::json()->schema(StoreOrganisationSchema::create())
)
RequestBody::create()
->required()
->content(
MediaType::json()->schema(StoreOrganisationSchema::create())
)
)
->responses(
Response::created()->content(
Expand Down
8 changes: 5 additions & 3 deletions app/Docs/Operations/Referrals/StoreReferralOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public static function create(string $objectId = null): BaseObject
->description('**Permission:** `Open`')
->noSecurity()
->requestBody(
RequestBody::create()->content(
MediaType::json()->schema(StoreReferralSchema::create())
)
RequestBody::create()
->required()
->content(
MediaType::json()->schema(StoreReferralSchema::create())
)
)
->responses(
Response::created()->content(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public static function create(string $objectId = null): BaseObject
->summary('Update a specific report schedule')
->description('**Permission:** `Global Admin`')
->requestBody(
RequestBody::create()->content(
MediaType::json()->schema(UpdateReportScheduleSchema::create())
)
RequestBody::create()
->required()
->content(
MediaType::json()->schema(UpdateReportScheduleSchema::create())
)
)
->responses(
Response::ok()->content(
Expand Down
8 changes: 5 additions & 3 deletions app/Docs/Operations/Search/StoreSearchOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public static function create(string $objectId = null): BaseObject
PerPageParameter::create()
)
->requestBody(
RequestBody::create()->content(
MediaType::json()->schema(StoreSearchSchema::create())
)
RequestBody::create()
->required()
->content(
MediaType::json()->schema(StoreSearchSchema::create())
)
)
->responses(
Response::ok()->content(
Expand Down
8 changes: 5 additions & 3 deletions app/Docs/Operations/Services/RefreshServiceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public static function create(string $objectId = null): BaseObject
->description('**Permission:** `Open`')
->noSecurity()
->requestBody(
RequestBody::create()->content(
MediaType::json()->schema(RefreshServiceSchema::create())
)
RequestBody::create()
->required()
->content(
MediaType::json()->schema(RefreshServiceSchema::create())
)
)
->responses(
Response::ok()->content(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static function create(string $objectId = null): BaseObject
* Location: `address_line_1`
* Service location: `name` or `address_line_1` for associated location
* Organisation: `name`
* Organisation sign up form: `name` for organisation
EOT
)
->schema(Schema::string()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Docs\Paths\OrganisationSignUpForms;

use App\Docs\Operations\OrganisationSignUpForms\StoreOrganisationSignUpFormOperation;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\PathItem;

class OrganisationSignUpFormsRootPath extends PathItem
{
/**
* @param string|null $objectId
* @return static
*/
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->route('/organisation-sign-up-forms')
->operations(
StoreOrganisationSignUpFormOperation::create()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace App\Docs\Schemas\OrganisationSignUpForm;

use App\Docs\Schemas\Organisation\StoreOrganisationSchema;
use App\Docs\Schemas\Service\StoreServiceSchema;
use App\Docs\Schemas\User\StoreUserSchema;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;

class StoreOrganisationSignUpFormSchema extends Schema
{
/**
* @param string|null $objectId
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
* @return static
*/
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->type(static::TYPE_OBJECT)
->required(
'user',
'organisation',
'service'
)
->properties(
StoreUserSchema::create('user')
->required(
...array_filter(
StoreUserSchema::create()->required,
function (string $required): bool {
return !in_array($required, ['roles']);
}
)
)
->properties(
...array_filter(
StoreUserSchema::create()->properties,
function (Schema $property): bool {
return !in_array($property->objectId, ['roles']);
}
)
),
StoreOrganisationSchema::create('organisation')
->properties(
...array_filter(
StoreOrganisationSchema::create()->properties,
function (Schema $property): bool {
return !in_array($property->objectId, ['logo_file_id']);
}
)
),
StoreServiceSchema::create('service')
->required(
...array_filter(
StoreServiceSchema::create()->required,
function (string $required): bool {
return !in_array($required, [
'organisation_id',
'status',
'show_referral_disclaimer',
'referral_method',
'referral_button_text',
'referral_email',
'referral_url',
'gallery_items',
'category_taxonomies',
]);
}
)
)
->properties(
...array_filter(
StoreServiceSchema::create()->properties,
function (Schema $property): bool {
return !in_array($property->objectId, [
'organisation_id',
'status',
'show_referral_disclaimer',
'referral_method',
'referral_button_text',
'referral_email',
'referral_url',
'logo_file_id',
'gallery_items',
'category_taxonomies',
]);
}
)
)
);
}
}
20 changes: 12 additions & 8 deletions app/Docs/Schemas/UpdateRequest/UpdateRequestSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Docs\Schemas\UpdateRequest;

use App\Models\UpdateRequest;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;

Expand All @@ -19,18 +20,21 @@ public static function create(string $objectId = null): BaseObject
Schema::string('id')
->format(Schema::FORMAT_UUID),
Schema::string('user_id')
->format(Schema::FORMAT_UUID),
->format(Schema::FORMAT_UUID)
->nullable(),
Schema::string('updateable_type')
->enum(
'locations',
'referrals',
'services',
'service_locations',
'organisations',
'users'
UpdateRequest::EXISTING_TYPE_LOCATION,
UpdateRequest::EXISTING_TYPE_REFERRAL,
UpdateRequest::EXISTING_TYPE_SERVICE,
UpdateRequest::EXISTING_TYPE_SERVICE_LOCATION,
UpdateRequest::EXISTING_TYPE_ORGANISATION,
UpdateRequest::EXISTING_TYPE_USER,
UpdateRequest::NEW_TYPE_ORGANISATION_SIGN_UP_FORM
),
Schema::string('updateable_id')
->format(Schema::FORMAT_UUID),
->format(Schema::FORMAT_UUID)
->nullable(),
Schema::string('entry'),
Schema::object('data'),
Schema::string('created_at')
Expand Down
19 changes: 19 additions & 0 deletions app/Docs/Tags/OrganisationSignUpFormsTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Docs\Tags;

use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Tag;

class OrganisationSignUpFormsTag extends Tag
{
/**
* @param string|null $objectId
* @return static
*/
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->name('Organisation Sign Up Forms');
}
}
Loading

0 comments on commit d4db477

Please sign in to comment.