Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ngm committed May 3, 2023
2 parents bdc210f + d47a983 commit 25ef522
Show file tree
Hide file tree
Showing 18 changed files with 878 additions and 86 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ jobs:
- run: cp .env /tmp/.env
- run: echo "" >> /tmp/.env
- run: echo GOOGLE_API_CONSOLE_KEY=$GOOGLE_API_CONSOLE_KEY >> /tmp/.env
- run: echo MAPBOX_TOKEN=$MAPBOX_TOKEN >> /tmp/.env
- run: sudo cp /tmp/.env /home/circleci/project/.env

# Now run the tests.
Expand Down
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ DISCOURSE_APIKEY=1234

REPAIRDIRECTORY_URL=http://map.restarters.test

MAPBOX_TOKEN=1234
GOOGLE_ANALYTICS_TRACKING_ID=UA-12345678-1
GOOGLE_TAG_MANAGER_ID=GTM-1ABCDEF
GOOGLE_API_CONSOLE_KEY=1234
Expand Down
80 changes: 80 additions & 0 deletions app/Console/Commands/SetPlaceNetworkData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace App\Console\Commands;

use App\Group;
use App\Network;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Geocoder\Provider\Mapbox\Mapbox;
use Illuminate\Console\Command;

class SetPlaceNetworkData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'set:networkdata:place {networkname}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Set the place field in network_data';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$networkname = $this->argument('networkname');

// Find or fail network
$network = Network::where('name', $networkname)->first();

if ($network) {
foreach ($network->groups as $group)
{
$this->info('Check group ' . $group->idgroups . ' ' . $group->name);

if ($group->latitude || $group->longitude)
{
$this->info("...geocode {$group->latitude}, {$group->longitude}");
$loc = [];
$geocodeResponse = app('geocoder')->reverseQuery(ReverseQuery::fromCoordinates($group->latitude, $group->longitude)->withData('location_type', [ Mapbox::TYPE_PLACE ])->withLocale($network->default_language));
$addressCollection = $geocodeResponse->get();
$address = $addressCollection->get(0);
if ($address) {
$loc['place'] = $address->getStreetName();
}

if ($loc && $loc['place']) {
$this->info('...found place ' . $loc['place']);
$g = Group::findOrFail($group->idgroups);
$g->network_data = [
'place' => $loc['place'],
];
$g->save();
} else {
$this->error($group->id . ' ' . $group->name . " couldn't reverse geocode");
}
}
}
}
}
}
76 changes: 0 additions & 76 deletions app/Console/Commands/SetPostcodes.php

This file was deleted.

8 changes: 7 additions & 1 deletion app/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ class Group extends Model implements Auditable
'external_id',
'devices_updated_at',
'timezone',
'phone'
'phone',
'network_data',
];

protected $appends = ['ShareableLink', 'auto_approve'];

protected $casts = [
// JSON fields in the database should be converted to/from arrays.
'network_data' => 'array'
];

// The distance is not in the groups table; we add it on some queries from the select.
private $distance = null;

Expand Down
26 changes: 20 additions & 6 deletions app/Http/Controllers/API/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static function getGroupsByUsersNetworks(Request $request)
],
'created_at' => new \Carbon\Carbon($group->created_at),
'updated_at' => new \Carbon\Carbon($group->max_updated_at_devices_updated_at),

'network_data' => $group->network_data
]);

foreach ($group->upcomingParties() as $event) {
Expand Down Expand Up @@ -565,7 +565,12 @@ public function moderateGroupsv2(Request $request) {
* description="Image for the group",
* property="image",
* type="string", format="binary"
* )
* ),
* @OA\Property(
* description="Network-defined JSON data",
* property="network_data",
* @OA\Schema()
* ),
* )
* )
* ),
Expand All @@ -586,7 +591,7 @@ public function createGroupv2(Request $request) {
$user = $this->getUser();
$user->convertToHost();

list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country) = $this->validateGroupParams(
list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country, $network_data) = $this->validateGroupParams(
$request,
true
);
Expand All @@ -604,6 +609,7 @@ public function createGroupv2(Request $request) {
'shareable_code' => Fixometer::generateUniqueShareableCode(\App\Group::class, 'shareable_code'),
'timezone' => $timezone,
'phone' => $phone,
'network_data' => $network_data,
];

$group = Group::create($data);
Expand Down Expand Up @@ -696,7 +702,12 @@ public function createGroupv2(Request $request) {
* description="Image for the group",
* property="image",
* type="string", format="binary"
* )
* ),
* @OA\Property(
* description="Network-defined JSON data",
* property="network_data",
* @OA\Schema()
* ),
* )
* )
* ),
Expand All @@ -716,7 +727,7 @@ public function createGroupv2(Request $request) {
public function updateGroupv2(Request $request, $idGroup) {
$user = $this->getUser();

list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country) = $this->validateGroupParams(
list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country, $network_data) = $this->validateGroupParams(
$request,
false
);
Expand All @@ -741,6 +752,7 @@ public function updateGroupv2(Request $request, $idGroup) {
'free_text' => $description,
'timezone' => $timezone,
'phone' => $phone,
'network_data' => $network_data,
];

if ($user->hasRole('Administrator') || $user->hasRole('NetworkCoordinator')) {
Expand Down Expand Up @@ -857,6 +869,7 @@ private function validateGroupParams(Request $request, $create): array {
$website = $request->input('website');
$description = $request->input('description');
$timezone = $request->input('timezone');
$network_data = $request->input('network_data');

$latitude = null;
$longitude = null;
Expand Down Expand Up @@ -891,7 +904,8 @@ private function validateGroupParams(Request $request, $create): array {
$timezone,
$latitude,
$longitude,
$country
$country,
$network_data,
);
}
}
6 changes: 6 additions & 0 deletions app/Http/Resources/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
* example="true"
* ),
* @OA\Property(
* description="Network-defined JSON data",
* property="network_data",
* @OA\Schema()
* ),
* @OA\Property(
* property="stats",
* title="stats",
* description="An array of statistics about the activity of a group.",
Expand Down Expand Up @@ -274,6 +279,7 @@ public function toArray($request)
'tags' => new TagCollection($this->group_tags),
'timezone' => $this->timezone,
'approved' => $this->approved ? true : false,
'network_data' => $this->network_data,
'full' => true
];

Expand Down
6 changes: 6 additions & 0 deletions app/Http/Resources/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
* type="boolean",
* ),
* @OA\Property(
* description="Network-defined JSON data",
* property="network_data",
* @OA\Schema()
* ),
* @OA\Property(
* property="stats",
* title="stats",
* description="An array of statistics about the activity of an event.",
Expand Down Expand Up @@ -250,6 +255,7 @@ public function toArray($request)
'stats' => $this->resource->getEventStats(),
'updated_at' => Carbon::parse($this->updated_at)->toIso8601String(),
'approved' => $this->approved ? true : false,
'network_data' => $this->network_data,
'full' => true,
];
}
Expand Down
8 changes: 7 additions & 1 deletion app/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Party extends Model implements Auditable
'devices_updated_at',
'link',
'timezone',
'user_id'
'user_id',
'network_data',
];
protected $hidden = ['created_at', 'deleted_at', 'frequency', 'group', 'group', 'user_id', 'wordpress_post_id', 'cancelled', 'devices_updated_at'];

Expand All @@ -58,6 +59,11 @@ class Party extends Model implements Auditable
// Append data to Model
protected $appends = ['participants', 'ShareableLink', 'event_date_local', 'start_local', 'end_local'];

protected $casts = [
// JSON fields in the database should be converted to/from arrays.
'network_data' => 'array'
];

//Getters
public function findAllSearchable()
{
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"doctrine/dbal": "^2.13",
"egulias/email-validator": "^3.0.0",
"filp/whoops": "^2.14",
"geocoder-php/mapbox-provider": "^1.4",
"guzzlehttp/guzzle": "^7.2",
"hieu-le/wordpress-xmlrpc-client": "~2.0",
"intervention/image": "^2.7",
Expand All @@ -41,6 +42,7 @@
"symfony/http-client": "^6.2",
"symfony/http-foundation": "^6.0",
"symfony/mailgun-mailer": "^6.2",
"toin0u/geocoder-laravel": "^4.6",
"twbs/bootstrap": "4.1.0",
"wouternl/laravel-drip": "^1.2.4"
},
Expand Down
Loading

0 comments on commit 25ef522

Please sign in to comment.