Skip to content

Commit

Permalink
Merge branch 'release/v2.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
appsol committed Dec 11, 2023
2 parents d09cd9a + de4a331 commit d201de1
Show file tree
Hide file tree
Showing 45 changed files with 5,589 additions and 4,860 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QUEUE_CONNECTION=sync

# The AWS SQS config.
# Cloudformation Template Outputs: DefaultQueueUrl up to last forward slash
# e.g. https://sqs.[]AWS Default region].amazonaws.com/[AWS Account ID]/
# e.g. https://sqs.[AWS Default region].amazonaws.com/[AWS Account ID]/
SQS_PREFIX=
# Cloudformation Template Outputs: DefaultQueue after the word 'default'
# e.g. -[UUID]-[environment]
Expand Down
1 change: 1 addition & 0 deletions app/Docs/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static function create(string $objectId = null): BaseObject
Paths\UpdateRequests\UpdateRequestsIndexPath::create(),
Paths\UpdateRequests\UpdateRequestsNestedPath::create(),
Paths\UpdateRequests\UpdateRequestsApprovePath::create(),
Paths\UpdateRequests\UpdateRequestsRejectPath::create(),
Paths\Users\UsersRootPath::create(),
Paths\Users\UsersIndexPath::create(),
Paths\Users\UsersNestedPath::create(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace App\Docs\Operations\UpdateRequests;

use App\Docs\Responses\ResourceDeletedResponse;
use App\Docs\Schemas\UpdateRequest\UpdateRequestRejectSchema;
use App\Docs\Tags\UpdateRequestsTag;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Operation;
use GoldSpecDigital\ObjectOrientedOAS\Objects\RequestBody;

class DestroyUpdateRequestOperation extends Operation
{
Expand All @@ -15,10 +18,17 @@ class DestroyUpdateRequestOperation extends Operation
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->action(static::ACTION_DELETE)
->action(static::ACTION_PUT)
->tags(UpdateRequestsTag::create())
->summary('Delete a specific update request')
->description('**Permission:** `Super Admin`')
->requestBody(
RequestBody::create()
->required()
->content(
MediaType::json()->schema(UpdateRequestRejectSchema::create())
)
)
->responses(
ResourceDeletedResponse::create(null, 'update request')
);
Expand Down
4 changes: 1 addition & 3 deletions app/Docs/Paths/UpdateRequests/UpdateRequestsNestedPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Docs\Paths\UpdateRequests;

use App\Docs\Operations\UpdateRequests\DestroyUpdateRequestOperation;
use App\Docs\Operations\UpdateRequests\ShowUpdateRequestOperation;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Parameter;
Expand All @@ -26,8 +25,7 @@ public static function create(string $objectId = null): BaseObject
->schema(Schema::string()->format(Schema::FORMAT_UUID))
)
->operations(
ShowUpdateRequestOperation::create(),
DestroyUpdateRequestOperation::create()
ShowUpdateRequestOperation::create()
);
}
}
31 changes: 31 additions & 0 deletions app/Docs/Paths/UpdateRequests/UpdateRequestsRejectPath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Docs\Paths\UpdateRequests;

use App\Docs\Operations\UpdateRequests\DestroyUpdateRequestOperation;
use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Parameter;
use GoldSpecDigital\ObjectOrientedOAS\Objects\PathItem;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;

class UpdateRequestsRejectPath extends PathItem
{
/**
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\InvalidArgumentException
*/
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->route('/update-requests/{update_request}/reject')
->parameters(
Parameter::path()
->name('update_request')
->description('The ID of the update request')
->required()
->schema(Schema::string()->format(Schema::FORMAT_UUID))
)
->operations(
DestroyUpdateRequestOperation::create()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function create(string $objectId = null): BaseObject
->properties(
Schema::string('id')
->format(Schema::FORMAT_UUID),
Schema::string('slug'),
Schema::string('organisation_id')
->format(Schema::FORMAT_UUID),
Schema::string('title'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static function create(string $objectId = null): BaseObject
->required('title', 'intro', 'description', 'start_date', 'end_date', 'start_time', 'end_time', 'is_free', 'is_virtual')
->properties(
Schema::string('title'),
Schema::string('slug'),
Schema::string('intro'),
Schema::string('description'),
Schema::string('start_date')
Expand Down
21 changes: 21 additions & 0 deletions app/Docs/Schemas/UpdateRequest/UpdateRequestRejectSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Docs\Schemas\UpdateRequest;

use GoldSpecDigital\ObjectOrientedOAS\Objects\BaseObject;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;

class UpdateRequestRejectSchema extends Schema
{
public static function create(string $objectId = null): BaseObject
{
return parent::create($objectId)
->type(static::TYPE_OBJECT)
->required(
'message'
)
->properties(
Schema::string('message'),
);
}
}
3 changes: 3 additions & 0 deletions app/Http/Controllers/Core/V1/UpdateRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function show(ShowRequest $request, UpdateRequest $updateRequest): Update
public function destroy(DestroyRequest $request, UpdateRequest $updateRequest)
{
return DB::transaction(function () use ($request, $updateRequest) {
$updateRequest->update([
'rejection_message' => $request->input('message'),
]);
event(EndpointHit::onDelete($request, "Deleted update request [{$updateRequest->id}]", $updateRequest));

$updateRequest->delete($request->user('api'));
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Requests/OrganisationEvent/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Rules\MarkdownMaxLength;
use App\Rules\MarkdownMinLength;
use App\Rules\RootTaxonomyIs;
use App\Rules\Slug;
use App\Rules\UkPhoneNumber;
use App\Rules\UserHasRole;
use Illuminate\Foundation\Http\FormRequest;
Expand Down Expand Up @@ -51,6 +52,7 @@ function ($attribute, $value, $fail) {
},
],
'title' => ['required', 'string', 'min:1', 'max:255'],
'slug' => ['string', 'min:1', 'max:255', new Slug()],
'start_date' => ['required', 'date_format:Y-m-d', 'after:today', new DateSanity($this)],
'end_date' => ['required', 'date_format:Y-m-d', new DateSanity($this)],
'start_time' => ['required', 'date_format:H:i:s', new DateSanity($this)],
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Requests/OrganisationEvent/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Requests\HasMissingValues;
use App\Models\File;
use App\Models\OrganisationEvent;
use App\Models\Role;
use App\Models\Taxonomy;
use App\Models\UserRole;
Expand All @@ -15,6 +16,7 @@
use App\Rules\MarkdownMinLength;
use App\Rules\NullableIf;
use App\Rules\RootTaxonomyIs;
use App\Rules\Slug;
use App\Rules\UkPhoneNumber;
use App\Rules\UserHasRole;
use Illuminate\Foundation\Http\FormRequest;
Expand Down Expand Up @@ -43,6 +45,21 @@ public function rules(): array
{
return [
'title' => ['string', 'min:1', 'max:255'],
'slug' => [
'string',
'min:1',
'max:255',
Rule::unique(table(OrganisationEvent::class), 'slug')->ignoreModel($this->organisation_event),
new Slug(),
new UserHasRole(
$this->user('api'),
new UserRole([
'user_id' => $this->user('api')->id,
'role_id' => Role::organisationAdmin()->id,
]),
$this->organisation_event->slug
),
],
'start_date' => ['date_format:Y-m-d', 'after:today', new DateSanity($this)],
'end_date' => ['date_format:Y-m-d', new DateSanity($this)],
'start_time' => ['date_format:H:i:s', new DateSanity($this)],
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Requests/OrganisationSignUpForm/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Rules\UserEmailNotTaken;
use App\Rules\VideoEmbed;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;

class StoreRequest extends FormRequest
Expand Down Expand Up @@ -225,4 +226,23 @@ public function messages(): array
'service.contact_email.email' => "4. Service, Additional Info tab - Please enter an email address users can use to contact your {$type} (eg. [email protected]).",
];
}

/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$user = $this->user;
$user['phone'] = Str::remove(' ', $user['phone']);

$organisation = $this->organisation;
if ($organisation['phone'] ?? false) {
$organisation['phone'] = Str::remove(' ', $organisation['phone']);
}

$this->merge([
'user' => $user,
'organisation' => $organisation,
]);
}
}
7 changes: 6 additions & 1 deletion app/Http/Requests/UpdateRequest/DestroyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public function authorize(): bool
public function rules(): array
{
return [
//
'message' => [
'required',
'string',
'min:1',
'max:1000',
],
];
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/OrganisationEventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function toArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => $this->slug,
'has_image' => $this->hasImage(),
'title' => $this->title,
'intro' => $this->intro,
Expand Down
6 changes: 6 additions & 0 deletions app/Listeners/Notifications/UpdateRequestRejected.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Location;
use App\Models\Notification;
use App\Models\Organisation;
use App\Models\Page;
use App\Models\Service;
use App\Models\ServiceLocation;
use App\Models\UpdateRequest;
Expand Down Expand Up @@ -59,13 +60,17 @@ protected function notifySubmitterForExisting(UpdateRequest $updateRequest)
} elseif ($updateRequest->getUpdateable() instanceof Organisation) {
$resourceName = $updateRequest->getUpdateable()->name;
$resourceType = 'organisation';
} elseif ($updateRequest->getUpdateable() instanceof Page) {
$resourceName = $updateRequest->getUpdateable()->title;
$resourceType = 'page';
}

$updateRequest->user->sendEmail(new NotifySubmitterEmail($updateRequest->user->email, [
'SUBMITTER_NAME' => $updateRequest->user->first_name,
'RESOURCE_NAME' => $resourceName,
'RESOURCE_TYPE' => $resourceType,
'REQUEST_DATE' => $updateRequest->created_at->format('j/n/Y'),
'REJECTION_MESSAGE' => $updateRequest->rejection_message,
]));
}

Expand All @@ -83,6 +88,7 @@ protected function notifySubmitterForNew(UpdateRequest $updateRequest)
'ORGANISATION_NAME' => Arr::get($updateRequest->data, 'organisation.name'),
'REQUEST_DATE' => $updateRequest->created_at->format('j/n/Y'),
'TANDC_URL' => config('local.tandc_uri'),
'REJECTION_MESSAGE' => $updateRequest->rejection_message,
]
)
);
Expand Down
9 changes: 7 additions & 2 deletions app/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public function hasAppend(string $name): bool
*
* @author
*/
public function onlyAlphaNumeric($string)
public function makeSearchable($string)
{
return preg_replace('/[^\w\d\s]+/i', '', $string);
$string = mb_strtolower($string);
preg_match_all('/(?:\b([A-Z,a-z]+)\b)/i', $string, $words);

return implode(' ', array_filter($words[1], function ($word) {
return mb_strlen($word) > 2;
}));
}
}
18 changes: 14 additions & 4 deletions app/Models/OrganisationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Contracts\AppliesUpdateRequests;
use App\Generators\UniqueSlugGenerator;
use App\Http\Requests\OrganisationEvent\UpdateRequest as UpdateOrganisationEventRequest;
use App\Models\Mutators\OrganisationEventMutators;
use App\Models\Relationships\OrganisationEventRelationships;
Expand Down Expand Up @@ -59,14 +60,14 @@ public function toSearchableArray(): array
{
$organisationEvent = [
'id' => $this->id,
'title' => $this->onlyAlphaNumeric($this->title),
'intro' => $this->onlyAlphaNumeric($this->intro),
'description' => $this->onlyAlphaNumeric($this->description),
'title' => $this->makeSearchable($this->title),
'intro' => $this->makeSearchable($this->intro),
'description' => $this->makeSearchable($this->description),
'start_date' => $this->start_date->setTimeFromTimeString($this->start_time)->toDateTimeLocalString(),
'end_date' => $this->end_date->setTimeFromTimeString($this->end_time)->toDateTimeLocalString(),
'is_free' => $this->is_free,
'is_virtual' => $this->is_virtual,
'organisation_name' => $this->onlyAlphaNumeric($this->organisation->name),
'organisation_name' => $this->makeSearchable($this->organisation->name),
'taxonomy_categories' => $this->taxonomies()->pluck('name')->toArray(),
'collection_categories' => $this->collections()->pluck('name')->toArray(),
'event_location' => null,
Expand Down Expand Up @@ -116,7 +117,12 @@ public function validateUpdateRequest(UpdateRequest $updateRequest): Validator
*/
public function applyUpdateRequest(UpdateRequest $updateRequest): UpdateRequest
{
$slugGenerator = app(UniqueSlugGenerator::class);
$data = $updateRequest->data;
$slug = Arr::get($data, 'slug', $this->slug);
if ($slug !== $this->slug) {
$slug = $slugGenerator->generate($slug, 'pages');
}

// Update the Image File entity if new
if (Arr::get($data, 'image_file_id', $this->image_file_id) !== $this->image_file_id && !empty($data['image_file_id'])) {
Expand All @@ -133,6 +139,7 @@ public function applyUpdateRequest(UpdateRequest $updateRequest): UpdateRequest
$this->update([
'organisation_id' => $this->organisation_id,
'title' => Arr::get($data, 'title', $this->title),
'slug' => $slug,
'intro' => Arr::get($data, 'intro', $this->intro),
'description' => sanitize_markdown(
Arr::get($data, 'description', $this->description)
Expand Down Expand Up @@ -164,6 +171,9 @@ public function applyUpdateRequest(UpdateRequest $updateRequest): UpdateRequest
$this->syncTaxonomyRelationships($taxonomies);
}

// Update the search index
$this->save();

// Ensure conditional fields are reset if needed.
$this->resetConditionalFields();

Expand Down
Loading

0 comments on commit d201de1

Please sign in to comment.