Skip to content

Commit

Permalink
Merge branch 'master' into 624-recent-updates-feed-on-main-page
Browse files Browse the repository at this point in the history
  • Loading branch information
florence-77 committed Aug 9, 2024
2 parents 43857be + 4836c12 commit 4f2a84d
Show file tree
Hide file tree
Showing 82 changed files with 123,878 additions and 1,017 deletions.
6 changes: 5 additions & 1 deletion app/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Filter extends Model
'diameterNumeric',
'heightNumeric',
'breastNumeric',
'willowHeightNumeric',
'hemlockDiameter',
];

/**
Expand All @@ -64,6 +66,7 @@ class Filter extends Model
'Butternut' => 'butternut',
'Pinyon Pine' => 'pinyonPine',
'Ozark Chinquapin' => 'ozarkChinquapin',
'Alaskan Willow' => 'alaskanWillow',
'Other' => 'other',
];

Expand All @@ -84,7 +87,8 @@ class Filter extends Model
'beechBarkDiseaseSymptoms',
'hybridTraits',
'laurelWilt',
'hemlockLocationCharacteristics'
'hemlockLocationCharacteristics',
'nearbyWillowSpecies'
];

/**
Expand Down
70 changes: 70 additions & 0 deletions app/Http/Controllers/Admin/DeleteAccountRequestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Http\Controllers\Admin;

use App\DeleteAccountRequest;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\Responds;
use App\Jobs\SendAccountRequestDeletionNotification;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteAccountRequestController extends Controller
{
use Responds;

/**
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function index(): JsonResponse
{
$this->authorize('viewAny', DeleteAccountRequest::class);

return $this->success(DeleteAccountRequest::orderByDesc('id')->paginate(20));
}

/**
* @return \Illuminate\Http\JsonResponse
*/
public function myIndex(): JsonResponse
{
return $this->success(DeleteAccountRequest::where('user_id', auth()->id())
->orderByDesc('id')
->paginate(20));
}

/**
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function create(Request $request): JsonResponse
{
$this->authorize('create', DeleteAccountRequest::class);

$deleteAccountRequest = DeleteAccountRequest::create($request->only([
'reason',
]) + [
'user_id' => $request->user()->id,
]);

dispatch(new SendAccountRequestDeletionNotification($deleteAccountRequest));

return $this->success($deleteAccountRequest);
}

/**
* @param \App\DeleteAccountRequest $deleteRequest
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function delete(DeleteAccountRequest $deleteRequest): JsonResponse
{
$this->authorize('delete', $deleteRequest);

$deleteRequest->delete();

return $this->created();
}
}
67 changes: 67 additions & 0 deletions app/Http/Controllers/Api/v1/ContactController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Http\Controllers\Api\v1;

use App\Contact;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\Responds;
use App\Mail\ContactRequest;
use App\Mail\ContactUser;
use App\User;
use Illuminate\Http\Request;
use ReCaptcha\ReCaptcha;
use Illuminate\Support\Facades\Mail;

class ContactController extends Controller
{
use Responds;

/**
* Contact administrators.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function send(Request $request)
{
$this->validate($request, [
'name' => 'required|min:3',
'email' => 'required|email',
'subject' => 'required',
'message' => 'required',
'recaptcha' => 'required',
]);

$recaptcha = new ReCaptcha(config('services.google.recaptcha'));
$verify = $recaptcha->verify($request->recaptcha, $request->ip());

if (!$verify->isSuccess()) {
return $this->validationError([
'recaptcha' => ['Please verify you are not a robot.'],
]);
}

Mail::to($this->getSubscribedAdmins())->queue(new ContactRequest((object)$request->all()));

return $this->success('Message Sent');
}

/**
* Get all Staton Lab admins who subscribed to contact requests.
*/
protected function getSubscribedAdmins()
{
// return User::with('role')->whereHas('subscriptionTopics', function ($query) {
// $query->where('key', 'contact');
// })->get()->reject(function ($user) {
// return $user->role->name !== 'Admin';
// })->map(function ($user) {
// return $user->email;
// });
return collect([
// "[email protected]",
"[email protected]",
// "[email protected]"
]);
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/v1/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function create(Request $request)
'is_private' => $request->is_private ? 1 : 0,
'zipcode' => $request->zipcode,
'api_token' => $api_token,
'birth_year' => $request->birth_year,
'birth_year' => intval($request->birth_year),
'units' => $request->units ? $request->units : 'US',
'role_id' => Role::where('name', 'User')->first()->id,
]);
Expand Down Expand Up @@ -124,7 +124,7 @@ public function update(Request $request)
'email' => $request->email,
'is_anonymous' => $request->is_anonymous,
'is_private' => $request->is_private ? 1 : 0,
'birth_year' => $request->birth_year,
'birth_year' => intval($request->birth_year),
'zipcode' => $request->zipcode,
'units' => $request->units ? $request->units : 'US',
]);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function handleAppleResponse($response)
'is_private' => false,
'is_anonymous' => false,
'role_id' => $role->id,
'avatar' => isset($response->avatar) ? $response->avatar : null,
'avatar' => null, // isset($response->avatar) ? $response->avatar : null,
'units' => 'US',
]);

Expand All @@ -195,7 +195,7 @@ protected function handleGoogleResponse($response)
$user = $this->findOrCreateUser([
'email' => $response->getEmail(),
'name' => $response->getName(),
'avatar' => $response->avatar,
'avatar' => null, // $response->avatar,
'birth_year' => $birth_year,
'provider' => 'google',
'provider_id' => $response->getId(),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\User;
use Illuminate\Http\Request;
use ReCaptcha\ReCaptcha;
use Mail;
use Illuminate\Support\Facades\Mail;

class ContactController extends Controller
{
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/DeleteAccountRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\DeleteAccountRequest;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Traits\Responds;
use App\Jobs\SendAccountRequestDeletionNotification;
use Illuminate\Http\JsonResponse;
Expand Down
11 changes: 4 additions & 7 deletions app/Http/Controllers/ObservationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,18 @@ public function delete($id, Request $request)
public function getObservationFeed(Request $request)
{
$this->validate($request, [
'limit' => 'nullable|integer|min:6|max:90',
'page' => 'nullable|integer|min:0|max:100',
]);

$limit = $request->limit ?: 10;

$observations = Observation::with([
'user' => function ($query) {
$query->select(['id', 'is_anonymous', 'name']);
},
])
->select(['id', 'user_id', 'observation_category', 'created_at', 'thumbnail'])
->orderBy('created_at', 'desc')
->orderBy('id', 'desc')
->where('is_private', false)
->limit($limit)
->get();
->paginate(10);

$observations->map(function ($observation) {
if ($observation->user->is_anonymous) {
Expand All @@ -295,6 +292,6 @@ public function getObservationFeed(Request $request)
$observation->date = $observation->created_at->diffForHumans();
});

return $this->success($observations);
return $observations->toArray();
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Traits/CreatesUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function findOrCreateUser($user)
'is_private' => false,
'is_anonymous' => false,
'role_id' => $role->id,
'avatar' => isset($user['avatar']) ? $user['avatar'] : null,
'avatar' => null, // isset($user['avatar']) ? $user['avatar'] : null,
'units' => 'US',
'provider' => $user['provider'],
'provider_id' => $user['provider_id'],
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Traits/Observes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ trait Observes
'Pinyon Pine',
'Sassafras',
'Ozark Chinquapin',
'Alaskan Willow',
'Other',
];

Expand Down
24 changes: 20 additions & 4 deletions app/Http/Controllers/TreetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function index(Request $request)
->orderBy('created_at', 'desc')
->limit($limit)
->get();

$treets->map(function ($treet) {
$treet->date = $treet->created_at->format('m/d/y');
});
Expand All @@ -37,11 +37,20 @@ public function create(Request $request)
{
$this->authorize('create', Treet::class);

$urls = ['Treesnap' => "https://treesnap.org/",
'FlorestaDB' => "https://app.florestadb.org/login",
'HealthyWoods' => "https://healthywoodsapp.org/",
'Avid Deer' => "https://aviddeer.com/",
'Eastern Forest Pests' => "https://easternforestpests.com/"];


$treet = Treet::create([
'app_name' => $request->app_name,
'image_path' => $request->image_path,
'description' => $request->description
'description' => $request->description,
'url' => $urls[$request->app_name]
]);

return $this->created($treet);

}
Expand All @@ -50,14 +59,21 @@ public function create(Request $request)
*/
public function edit(Request $request, Treet $treet)
{
$urls = ['Treesnap' => "https://treesnap.org/",
'FlorestaDB' => "https://app.florestadb.org/login",
'HealthyWoods' => "https://healthywoodsapp.org/",
'Avid Deer' => "https://aviddeer.com/",
'Eastern Forest Pests' => "https://easternforestpests.com/"];

$this->authorize('edit', Treet::class);

$treet = Treet::find($request->id);

$treet->update([
'app_name' => $request->app_name ?: $treet->app_name,
'image_path' => $request->image_path ?: $treet->image_path,
'description' => $request->description ?: $treet->description
'description' => $request->description ?: $treet->description,
'url' => $urls[$request->app_name]
]);
return $this->success($treet);

Expand All @@ -73,5 +89,5 @@ public function destroy(Request $request, Treet $treet)
$treet->find($request->id)->delete();
return $this->success($treet);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function format(Observation $observation)
'images' => $this->attachUrlToImages($observation->images),
'longitude' => $has_privileges ? $observation->longitude : $observation->fuzzy_coords['longitude'],
'latitude' => $has_privileges ? $observation->latitude : $observation->fuzzy_coords['latitude'],
'location_accuracy' => $has_privileges ? "Within $observation->location_accuracy meters radius" : 'Within 8 kilometers radius',
'location_accuracy' => $has_privileges ? "Within $observation->location_accuracy meter radius" : 'Within 8 kilometers radius',
'collection_date' => Carbon::createFromDate($observation->collection_date)->format('Y-m-d H:i:s \G\M\T O'),
'meta_data' => $this->constructMetaDataArray($observation->data, $include_comments),
'url' => url("/observation/$observation->id"),
Expand Down
36 changes: 36 additions & 0 deletions app/Services/Analytics/ObservationStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,40 @@ public function aggregateObservationsByMonth($months = 6)

return $indexed;
}

/**
* Get a list of observation counts aggregated by country.
* @return array
*/
public function aggregateObservationsByCountry()
{
$observations = Observation::select([
DB::raw('COUNT(*) as observations_count'),
'address',
])
->groupBy('address')
->get();

$countries = [];

foreach ($observations as $observation) {
if (empty($observation->address)) {
continue;
}

foreach ($observation->address['components'] as $component) {
if (in_array('country', $component['types'])) {
if (isset($countries[$component['long_name']])) {
$countries[$component['long_name']] += $observation->observations_count;
} else {
$countries[$component['long_name']] = $observation->observations_count;
}
}
}
}

arsort($countries);

return $countries;
}
}
Loading

0 comments on commit 4f2a84d

Please sign in to comment.