Skip to content

Commit

Permalink
Merge pull request #470 from wri/release/outstanding-oak
Browse files Browse the repository at this point in the history
[RELEASE] Outstanding Oak
  • Loading branch information
roguenet authored Sep 20, 2024
2 parents 7745b35 + 7fd861e commit c48eb41
Show file tree
Hide file tree
Showing 155 changed files with 2,659 additions and 618 deletions.
5 changes: 4 additions & 1 deletion app/Console/Commands/SendTerrafundReportRemindersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ public function handle(): int
->chunkById(100, function ($programmes) {
$programmes->each(function ($programme) {
if ($programme->users->count()) {
Mail::to($programme->users->pluck('email_address'))->queue(new TerrafundReportReminder($programme->id));
$programme->users->each(function ($user) use ($programme) {
Mail::to($user->email_address)
->queue(new TerrafundReportReminder($programme->id, $user));

NotifyTerrafundReportReminderJob::dispatch($user, $programme);
});

}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public function handle(): int
->chunkById(100, function ($programmes) {
$programmes->each(function ($programme) {
if ($programme->users->count()) {
Mail::to($programme->users->pluck('email_address'))->queue(new TerrafundSiteAndNurseryReminder($programme->id));
$programme->users->each(function ($user) use ($programme) {
Mail::to($user->email_address)
->queue(new TerrafundSiteAndNurseryReminder($programme->id, $user));
});
}
});
});
Expand Down
11 changes: 6 additions & 5 deletions app/Console/Commands/UploadShapefileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

class UploadShapefileCommand extends Command
{
protected $signature = 'shapefile:upload {file} {--site_uuid=}';
protected $signature = 'shapefile:upload {file} {--site_uuid=} {--submit_polygon_loaded=}';

protected $description = 'Upload a shapefile to the application';

public function handle()
{
$filePath = $this->argument('file');
$siteUuid = $this->option('site_uuid');
$submitPolygonLoaded = $this->option('submit_polygon_loaded');

if (! file_exists($filePath)) {
$this->error("File not found: $filePath");
Expand All @@ -33,12 +34,12 @@ public function handle()
true // Set test mode to true to prevent the file from being moved
);

// Create a fake request with the uploaded file and site UUID
$request = new Request();
$request->files->set('file', $uploadedFile);
$request->request->set('uuid', $siteUuid);

// Instantiate the controller and call the method
$request->merge([
'uuid' => $siteUuid,
'submit_polygon_loaded' => $submitPolygonLoaded,
]);
$controller = new TerrafundCreateGeometryController();
$response = $controller->uploadShapefile($request);

Expand Down
3 changes: 0 additions & 3 deletions app/Helpers/GeometryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public function updateProjectCentroid(string $projectUuid)
'long' => $longitude,
]);


Log::info("Centroid updated for projectUuid: $projectUuid");

return response()->json([
'message' => 'Centroid updated',
'centroid' => $centroid,
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/InterestsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function createAction(StoreInterestRequest $request): JsonResponse
}
$initiator = $data['initiator'] == 'offer' ? $offer : $pitch;
$this->authorize('update', $initiator);
$me = Auth::user();
$data['organisation_id'] = $me->organisation_id;
$user = Auth::user();
$data['organisation_id'] = $user->organisation_id;
$exists = InterestModel::where('organisation_id', '=', $data['organisation_id'])
->where('initiator', '=', $data['initiator'])
->where('offer_id', '=', $data['offer_id'])
Expand All @@ -50,7 +50,7 @@ public function createAction(StoreInterestRequest $request): JsonResponse
$interest = new InterestModel($data);
$interest->saveOrFail();
$interest->refresh();
NotifyInterestJob::dispatch($interest);
NotifyInterestJob::dispatch($interest, $user);

return JsonResponseHelper::success(new InterestResource($interest), 201);
}
Expand Down Expand Up @@ -88,14 +88,14 @@ public function deleteAction(InterestModel $interest): JsonResponse
public function readAllByTypeAction(Request $request, string $type): JsonResponse
{
$this->authorize('readAll', \App\Models\Interest::class);
$me = Auth::user();
$user = Auth::user();
switch ($type) {
case 'initiated':
$ids = InterestHelper::findInitiated($me->organisation_id);
$ids = InterestHelper::findInitiated($user->organisation_id);

break;
case 'received':
$ids = InterestHelper::findReceived($me->organisation_id);
$ids = InterestHelper::findReceived($user->organisation_id);

break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __invoke(Request $request): ApplicationsCollection
}

if (! empty($request->query('search'))) {
$ids = Application::search(trim($request->query('search')))->get()->pluck('id')->toArray();
$ids = Application::searchApplications(trim($request->query('search')))->pluck('id')->toArray();
$qry->whereIn('id', $ids);
}

Expand Down
10 changes: 7 additions & 3 deletions app/Http/Controllers/V2/AuditStatus/GetAuditStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ private function getAudits($auditable)
}

$audits = $auditable->audits()
->orderBy('updated_at', 'desc')
->orderBy('created_at', 'desc')
->get();
->where(function ($query) {
$query->where('created_at', '<', '2024-09-01')
->orWhere('updated_at', '<', '2024-09-01');
})
->orderByDesc('updated_at')
->orderByDesc('created_at')
->get();

return $audits->map(function ($audit) {
return AuditStatusDTO::fromAudits($audit);
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/V2/AuditStatus/StoreAuditStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\V2\AuditStatus\AuditStatusCreateRequest;
use App\Http\Resources\V2\AuditStatusResource;
use App\Jobs\V2\SendProjectManagerJob as SendProjectManagerJobs;
use App\Models\Traits\SaveAuditStatusTrait;
use App\Models\V2\AuditableModel;
use App\Models\V2\AuditStatus\AuditStatus;
use App\Models\V2\Sites\Site;
use App\Models\V2\Sites\SitePolygon;

class StoreAuditStatusController extends Controller
{
Expand All @@ -26,6 +29,13 @@ public function __invoke(AuditStatusCreateRequest $auditStatusCreateRequest, Aud
$auditStatus = $this->saveAuditStatus(get_class($auditable), $auditable->id, $body['status'], $body['comment'], $body['type'], $body['is_active'], $body['request_removed']);
} else {
$auditStatus = $this->saveAuditStatus(get_class($auditable), $auditable->id, $body['status'], $body['comment'], $body['type']);
if ($body['type'] == 'comment' && get_class($auditable) != SitePolygon::class) {
SendProjectManagerJobs::dispatch($auditable);
}
if (get_class($auditable) === SitePolygon::class) {
$sitePolygon = Site::where('uuid', $auditable->site_id)->first();
SendProjectManagerJobs::dispatch($sitePolygon);
}
}
$auditStatus->entity_name = $auditable->name;

Expand Down
24 changes: 24 additions & 0 deletions app/Http/Controllers/V2/Entities/AdminSendReminderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Controllers\V2\Entities;

use App\Http\Controllers\Controller;
use App\Http\Requests\V2\Reminder\SendReminderRequest;
use App\Jobs\V2\SendReportReminderEmailsJob;
use App\Models\Traits\SaveAuditStatusTrait;
use App\Models\V2\EntityModel;

class AdminSendReminderController extends controller
{
use SaveAuditStatusTrait;

public function __invoke(SendReminderRequest $request, EntityModel $entity)
{
$data = $request->validated();

SendReportReminderEmailsJob::dispatch($entity, data_get($data, 'feedback'));
$this->saveAuditStatusAdminSendReminder($entity, data_get($data, 'feedback'));

return response()->json(['message' => 'Reminder sent successfully.']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\V2\UpdateRequests\StatusChangeRequest;
use App\Models\Traits\SaveAuditStatusTrait;
use App\Models\V2\EntityModel;
use App\Models\V2\Sites\Site;
use Illuminate\Http\JsonResponse;

class AdminStatusEntityController extends Controller
{
use SaveAuditStatusTrait;

public function __invoke(StatusChangeRequest $request, EntityModel $entity, string $status)
{
$data = $request->validated();
Expand All @@ -18,17 +21,20 @@ public function __invoke(StatusChangeRequest $request, EntityModel $entity, stri
switch($status) {
case 'approve':
$entity->approve(data_get($data, 'feedback'));
$this->saveAuditStatusAdminApprove($data, $entity);

break;

case 'moreinfo':
$entity->needsMoreInformation(data_get($data, 'feedback'), data_get($data, 'feedback_fields'));
$this->saveAuditStatusAdminMoreInfo($data, $entity);

break;

case 'restoration-in-progress':
if (get_class($entity) === Site::class) {
$entity->restorationInProgress();
$this->saveAuditStatusAdminRestorationInProgress($entity);

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\V2\Entities;

use App\Http\Controllers\Controller;
use App\Jobs\V2\SendProjectManagerJob as SendProjectManagerJobs;
use App\Models\Traits\SaveAuditStatusTrait;
use App\Models\V2\Action;
use App\Models\V2\EntityModel;
Expand Down Expand Up @@ -34,6 +35,7 @@ public function __invoke(EntityModel $entity, Request $request)
$entity->submitForApproval();
}

SendProjectManagerJobs::dispatch($entity);
Action::forTarget($entity)->delete();

return $entity->createSchemaResource();
Expand Down
27 changes: 27 additions & 0 deletions app/Http/Controllers/V2/Exports/ExportImageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Controllers\V2\Exports;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class ExportImageController extends Controller
{
public function __invoke(Request $request)
{
$request->validate([
'imageUrl' => 'required|url',
]);

$imageUrl = $request->input('imageUrl');

$imageContent = Http::get($imageUrl)->body();

$filename = basename($imageUrl);

return response($imageContent)
->header('Content-Type', 'image/jpeg')
->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function __invoke(Request $request, Nursery $nursery): GallerysCollection

$perPage = $request->query('per_page') ?? config('app.pagination_default', 15);
$entity = $request->query('model_name');
$searchTerm = $request->query('search');
$isGeotagged = $request->query('is_geotagged');
$sortOrder = $request->query('sort_order', 'asc');

$models = [];
! empty($entity) && $entity != 'nurseries' ?: $models[] = ['type' => get_class($nursery), 'ids' => [$nursery->id]];
Expand All @@ -33,11 +36,42 @@ public function __invoke(Request $request, Nursery $nursery): GallerysCollection
}
});

if (! empty($searchTerm)) {
$mediaIds = Media::where('name', 'LIKE', "%{$searchTerm}%")
->orWhere('file_name', 'LIKE', "%{$searchTerm}%")
->pluck('id');
$mediaQueryBuilder->whereIn('media.id', $mediaIds);
}
if ($isGeotagged === '1') {
$mediaQueryBuilder->whereNotNull('lat')->whereNotNull('lng');
} elseif ($isGeotagged === '2') {
$mediaQueryBuilder->whereNull('lat')->whereNull('lng');
}

// Map model types to classes
$modelTypeMap = [
'nurseries' => [Nursery::class],
'reports' => [NurseryReport::class],
];

$query = QueryBuilder::for($mediaQueryBuilder)
->allowedFilters([
AllowedFilter::exact('file_type'),
AllowedFilter::exact('is_public'),
]);
AllowedFilter::callback('model_type', function ($query, $value) use ($modelTypeMap) {
$classNames = $modelTypeMap[$value] ?? null;
if ($classNames) {
$query->where(function ($subQuery) use ($classNames) {
foreach ($classNames as $className) {
$subQuery->orWhere('model_type', $className);
}
});
}
}),
])
->allowedSorts(['created_at']);

$query->orderBy('created_at', $sortOrder);

$collection = $query->paginate($perPage)
->appends(request()->query());
Expand Down
Loading

0 comments on commit c48eb41

Please sign in to comment.