Skip to content

Commit

Permalink
Merge branch 'release/v2.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
appsol committed Jan 16, 2024
2 parents c47d7d0 + 57706c2 commit d1024dc
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,30 @@ public static function create(string $objectId = null): BaseObject
* Service location: `name` or `address_line_1` for associated location
* Organisation: `name`
* Organisation sign up form: `name` for organisation
EOT
)
->schema(Schema::string()),
FilterParameter::create(null, 'type')
->description(
<<<'EOT'
Type to filter by:
* Service update: `services`
* New Service: `new_service_created_by_global_admin`
* Location: `locations`
* Service location: `service_locations`
* Organisation update: `organisations`
* New Organisation: `new_organisation_created_by_global_admin`
* Organisation sign up form: `organisation_sign_up_form`
* Event update: `organisation_events`
* New Event: `new_organisation_event_created_by_org_admin`
* Page update: `pages`
* New Page: `new_page`
* Referral: `referrals`
EOT
)
->schema(Schema::string()),
IncludeParameter::create(null, ['user']),
SortParameter::create(null, ['entry', 'created_at'], '-created_at')
SortParameter::create(null, ['entry','created_at'], '-created_at')
)
->responses(
Response::ok()->content(
Expand Down
3 changes: 3 additions & 0 deletions app/Docs/Schemas/Service/UpdateServiceSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static function create(string $objectId = null): BaseObject
'name',
'slug',
'type',
'organisation_id',
'status',
'intro',
'description',
Expand Down Expand Up @@ -54,6 +55,8 @@ public static function create(string $objectId = null): BaseObject
Service::TYPE_CLUB,
Service::TYPE_GROUP
),
Schema::string('organisation_id')
->format(static::FORMAT_UUID),
Schema::string('status')
->enum(Service::STATUS_ACTIVE, Service::STATUS_INACTIVE),
Schema::integer('score')
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Core/V1/UpdateRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Events\EndpointHit;
use App\Http\Controllers\Controller;
use App\Http\Filters\UpdateRequest\EntryFilter;
use App\Http\Filters\UpdateRequest\TypeFilter;
use App\Http\Requests\UpdateRequest\DestroyRequest;
use App\Http\Requests\UpdateRequest\IndexRequest;
use App\Http\Requests\UpdateRequest\ShowRequest;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function index(IndexRequest $request): AnonymousResourceCollection
AllowedFilter::scope('location_id'),
AllowedFilter::scope('organisation_id'),
AllowedFilter::custom('entry', new EntryFilter()),
AllowedFilter::custom('type', new TypeFilter()),
])
->allowedIncludes(['user'])
->allowedSorts([
Expand Down
22 changes: 22 additions & 0 deletions app/Http/Filters/UpdateRequest/TypeFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Filters\UpdateRequest;

use App\Models\UpdateRequest;
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\Filters\Filter;

class TypeFilter implements Filter
{
public function __invoke(Builder $query, $value, string $property): Builder
{
if ($value === UpdateRequest::NEW_TYPE_SERVICE_ORG_ADMIN || $value == UpdateRequest::NEW_TYPE_SERVICE_GLOBAL_ADMIN) {
$value = [
UpdateRequest::NEW_TYPE_SERVICE_ORG_ADMIN,
UpdateRequest::NEW_TYPE_SERVICE_GLOBAL_ADMIN,
];
}

return $query->whereIn('updateable_type', (array)$value);
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/OrganisationEvent/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ 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_date' => ['required', 'date_format:Y-m-d', new DateSanity($this)],
'end_date' => ['required', 'date_format:Y-m-d', 'after_or_equal:today', new DateSanity($this)],
'start_time' => ['required', 'date_format:H:i:s', new DateSanity($this)],
'end_time' => ['required', 'date_format:H:i:s', new DateSanity($this)],
'intro' => ['required', 'string', 'min:1', 'max:300'],
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Requests/OrganisationEvent/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function rules(): array
$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_date' => ['date_format:Y-m-d', new DateSanity($this)],
'end_date' => ['date_format:Y-m-d', 'after_or_equal:today', new DateSanity($this)],
'start_time' => ['date_format:H:i:s', new DateSanity($this)],
'end_time' => ['date_format:H:i:s', new DateSanity($this)],
'intro' => ['string', 'min:1', 'max:300'],
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Scopes/UserScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public function getHighestRoleOrderSql(): array

$bindings = [
Role::superAdmin()->id,
Role::globalAdmin()->id,
Role::organisationAdmin()->id,
Role::serviceAdmin()->id,
Role::serviceWorker()->id,
Role::globalAdmin()->id,
Role::contentAdmin()->id,
];

Expand Down
5 changes: 5 additions & 0 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\AppliesUpdateRequests;
use App\Emails\Email;
use App\Http\Requests\Service\UpdateRequest as UpdateServiceRequest;
use App\Http\Resources\OrganisationResource;
use App\Models\Mutators\ServiceMutators;
use App\Models\Relationships\ServiceRelationships;
use App\Models\Scopes\ServiceScopes;
Expand Down Expand Up @@ -327,6 +328,10 @@ public function applyUpdateRequest(UpdateRequest $updateRequest): UpdateRequest
*/
public function getData(array $data): array
{
if (isset($data['organisation_id'])) {
$data['organisation'] = new OrganisationResource(Organisation::find($data['organisation_id']));
}

return $data;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Search/ElasticSearch/ServiceEloquentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function paginate(SearchRequestBuilder $esQuery, int $page = null, int $p
$page = page($page);
$perPage = per_page($perPage);

$esQuery->load(['serviceLocations'], Service::class);
$esQuery->load(['serviceLocations.location'], Service::class);

$queryRequest = $esQuery->buildSearchRequest()->toArray();

Expand Down
180 changes: 180 additions & 0 deletions tests/Feature/OrganisationEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,186 @@ public function postCreateOrganisationEventWithBookingDetailsRequiresAllBookingF
$response->assertStatus(Response::HTTP_OK);
}

/**
* @test
*/
public function postCreateOrganisationEventStartsInPastAsOrganisationAdmin200(): void
{
$organisation = Organisation::factory()->create();
$location = Location::factory()->create();
$user = User::factory()->create()->makeOrganisationAdmin($organisation);

Passport::actingAs($user);

$start = $this->faker->dateTimeBetween('-7 days', '-1 days')->format('Y-m-d');
$end = $this->faker->dateTimeBetween('+1 days', '+7 days')->format('Y-m-d');

$payload = [
'title' => $this->faker->sentence(3),
'start_date' => $start,
'end_date' => $end,
'start_time' => '09:00:00',
'end_time' => '13:00:00',
'intro' => $this->faker->sentence(),
'description' => $this->faker->paragraph(),
'is_free' => true,
'fees_text' => null,
'fees_url' => null,
'organiser_name' => null,
'organiser_phone' => null,
'organiser_email' => null,
'organiser_url' => null,
'booking_title' => null,
'booking_summary' => null,
'booking_url' => null,
'booking_cta' => null,
'homepage' => false,
'is_virtual' => true,
'location_id' => null,
'organisation_id' => $organisation->id,
'category_taxonomies' => [],
];

$response = $this->json('POST', '/core/v1/organisation-events', $payload);

$response->assertStatus(Response::HTTP_OK);
}

/**
* @test
*/
public function postCreateOrganisationEventEndsInPastAsOrganisationAdmin422(): void
{
$organisation = Organisation::factory()->create();
$location = Location::factory()->create();
$user = User::factory()->create()->makeOrganisationAdmin($organisation);

Passport::actingAs($user);

$start = $this->faker->dateTimeBetween('-7 days', '-4 days')->format('Y-m-d');
$end = $this->faker->dateTimeBetween('-3 days', '-1 days')->format('Y-m-d');

$payload = [
'title' => $this->faker->sentence(3),
'start_date' => $start,
'end_date' => $end,
'start_time' => '09:00:00',
'end_time' => '13:00:00',
'intro' => $this->faker->sentence(),
'description' => $this->faker->paragraph(),
'is_free' => true,
'fees_text' => null,
'fees_url' => null,
'organiser_name' => null,
'organiser_phone' => null,
'organiser_email' => null,
'organiser_url' => null,
'booking_title' => null,
'booking_summary' => null,
'booking_url' => null,
'booking_cta' => null,
'homepage' => false,
'is_virtual' => true,
'location_id' => null,
'organisation_id' => $organisation->id,
'category_taxonomies' => [],
];

$response = $this->json('POST', '/core/v1/organisation-events', $payload);

$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
}

/**
* @test
*/
public function postCreateOrganisationEventEndsBeforeItStartsAsOrganisationAdmin422(): void
{
$organisation = Organisation::factory()->create();
$location = Location::factory()->create();
$user = User::factory()->create()->makeOrganisationAdmin($organisation);

Passport::actingAs($user);

$start = $this->faker->dateTimeBetween('+4 days', '+7 days')->format('Y-m-d');
$end = $this->faker->dateTimeBetween('+1 days', '+3 days')->format('Y-m-d');

$payload = [
'title' => $this->faker->sentence(3),
'start_date' => $start,
'end_date' => $end,
'start_time' => '09:00:00',
'end_time' => '13:00:00',
'intro' => $this->faker->sentence(),
'description' => $this->faker->paragraph(),
'is_free' => true,
'fees_text' => null,
'fees_url' => null,
'organiser_name' => null,
'organiser_phone' => null,
'organiser_email' => null,
'organiser_url' => null,
'booking_title' => null,
'booking_summary' => null,
'booking_url' => null,
'booking_cta' => null,
'homepage' => false,
'is_virtual' => true,
'location_id' => null,
'organisation_id' => $organisation->id,
'category_taxonomies' => [],
];

$response = $this->json('POST', '/core/v1/organisation-events', $payload);

$response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
}

/**
* @test
*/
public function postCreateOrganisationEventStartsTodayAsOrganisationAdmin200(): void
{
$organisation = Organisation::factory()->create();
$location = Location::factory()->create();
$user = User::factory()->create()->makeOrganisationAdmin($organisation);

Passport::actingAs($user);

$start = Carbon::now()->format('Y-m-d');
$end = Carbon::now()->addDay()->format('Y-m-d');

$payload = [
'title' => $this->faker->sentence(3),
'start_date' => $start,
'end_date' => $end,
'start_time' => '09:00:00',
'end_time' => '21:00:00',
'intro' => $this->faker->sentence(),
'description' => $this->faker->paragraph(),
'is_free' => true,
'fees_text' => null,
'fees_url' => null,
'organiser_name' => null,
'organiser_phone' => null,
'organiser_email' => null,
'organiser_url' => null,
'booking_title' => null,
'booking_summary' => null,
'booking_url' => null,
'booking_cta' => null,
'homepage' => false,
'is_virtual' => true,
'location_id' => null,
'organisation_id' => $organisation->id,
'category_taxonomies' => [],
];

$response = $this->json('POST', '/core/v1/organisation-events', $payload);

$response->assertStatus(Response::HTTP_OK);
}

/**
* Get a single OrganisationEvent
*/
Expand Down
Loading

0 comments on commit d1024dc

Please sign in to comment.