Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /var/www
# Install dependencies
RUN sudo apt-get update && \
sudo apt install dnsutils openssl zip unzip git libxml2-dev libzip-dev zlib1g-dev libcurl4-openssl-dev iputils-ping default-mysql-client vim libpng-dev libgmp-dev libjpeg-turbo8-dev && \
sudo apt install php8.1-xmlrpc php8.1-intl php8.1-xdebug php8.1-xmlrpc php8.1-mbstring php8.1-simplexml php8.1-curl php8.1-zip python postgresql-client
sudo apt install php8.1-xmlrpc php8.1-intl php8.1-xdebug php8.1-xmlrpc php8.1-mbstring php8.1-simplexml php8.1-curl php8.1-zip python2 postgresql-client procps telnet vim openssh-server php-xmlrpc

# Clear cache - reduces image size.
RUN sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/*
Expand All @@ -28,8 +28,6 @@ RUN wget https://getcomposer.org/composer-1.phar
EXPOSE 9000

# Install sshd
RUN sudo apt-get update
RUN sudo apt-get install vim openssh-server
RUN sudo sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN sudo mkdir /var/run/sshd
RUN sudo bash -c 'install -m755 <(printf "#!/bin/sh\nexit 0") /usr/sbin/policy-rc.d'
Expand All @@ -39,9 +37,8 @@ RUN sudo RUNLEVEL=1 dpkg-reconfigure openssh-server
RUN sudo ssh-keygen -A -v
RUN sudo update-rc.d ssh defaults

RUN sudo apt-get install python2
RUN sudo pecl install channel://pecl.php.net/xmlrpc-1.0.0RC3 xmlrpc

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

CMD ["bash", "docker_run.sh"]
59 changes: 17 additions & 42 deletions app/Helpers/Geocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,31 @@

namespace App\Helpers;

use Geocoder\Query\GeocodeQuery;
use Geocoder\Query\ReverseQuery;
use Geocoder\Provider\Mapbox\Mapbox;

class Geocoder
{
public function __construct()
{
}

private function googleKey()
{
// We have this so that we can change the key in testing.
return config('GOOGLE_API_CONSOLE_KEY') ?? env('GOOGLE_API_CONSOLE_KEY');
}

public function geocode($location)
{
if ($location != 'ForceGeocodeFailure') {
$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($location).'&key='.$this->googleKey());

if ($json) {
$res = json_decode($json);

if ($res && $res->results && count($res->results)) {
$decoded = json_decode($json)->results[0];

$latitude = $decoded->{'geometry'}->{'location'}->lat;
$longitude = $decoded->{'geometry'}->{'location'}->lng;

foreach ($decoded->{'address_components'} as $component) {
if ($component->types && count($component->types) && $component->types[0] === 'country') {
$country_code = $component->short_name;
}
}

return [
'latitude' => $latitude,
'longitude' => $longitude,
'country_code' => $country_code,
];
}
$geocodeResponse = app('geocoder')->geocodeQuery(GeocodeQuery::create($location)->withData('location_type', [ Mapbox::TYPE_PLACE, Mapbox::TYPE_ADDRESS ]));
$addressCollection = $geocodeResponse->get();
$address = $addressCollection->get(0);

if ($address) {
// We are returned the name, but we want the code.
$countries = array_flip(\App\Helpers\Fixometer::getAllCountries('en'));

return [
'latitude' => $address->getCoordinates()->getLatitude(),
'longitude' => $address->getCoordinates()->getLongitude(),
'country_code' => $countries[$address->getCountry()->getName()]
];
}
}

return false;
}

public function reverseGeocode($lat, $lng)
{
$json = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=".$this->googleKey());

$decoded = json_decode($json)->results[0];

return $decoded;
}
}
29 changes: 14 additions & 15 deletions app/Http/Controllers/API/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,37 +866,36 @@ private function validateGroupParams(Request $request, $create): array {
$area = $request->input('area');
$postcode = $request->input('postcode', '');
$location = $request->input('location');
$latitude = $request->input('latitude', null);
$longitude = $request->input('longitude', null);
$phone = $request->input('phone');
$website = $request->input('website');
$description = $request->input('description');
$timezone = $request->input('timezone');
$network_data = $request->input('network_data');

$latitude = null;
$longitude = null;
$country_code = null;

if ($timezone && !in_array($timezone, \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC))) {
throw ValidationException::withMessages(['location ' => __('partials.validate_timezone')]);
}

if (!empty($location)) {
$geocoder = new \App\Helpers\Geocoder();
$geocoded = $geocoder->geocode($location);
// We need the country, which we get by geocoding the location..
$geocoder = new \App\Helpers\Geocoder();
$geocoded = $geocoder->geocode($location);

if (empty($geocoded))
{
throw ValidationException::withMessages(['location ' => __('groups.geocode_failed')]);
}
if (empty($geocoded)) {
throw ValidationException::withMessages(['location ' => __('groups.geocode_failed')]);
}

if ($latitude == null || $longitude == null) {
// If the client didn't pass these values then grab them from the geocoded location.
$latitude = $geocoded['latitude'];
$longitude = $geocoded['longitude'];

// Note that the country returned by the geocoder is already in English, which is what we need for the
// value in the database.
$country_code = $geocoded['country_code'];
}

// Note that the country returned by the geocoder is already in English, which is what we need for the
// value in the database.
$country_code = $geocoded['country_code'];

return array(
$name,
$area,
Expand Down
13 changes: 7 additions & 6 deletions database/factories/GroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class GroupFactory extends Factory
public function definition()
{
return [
'name' => $this->faker->unique()->company(),
'free_text' => $this->faker->sentence(),
'facebook' => '',
'postcode' => '',
'timezone' => 'Europe/London'
];
'name' => $this->faker->unique()->company(),
'free_text' => $this->faker->sentence(),
'facebook' => '',
'postcode' => '',
'timezone' => 'Europe/London',
'location' => 'International House, 3Space, 6 Canterbury Cres, London SW9 7QD',
];
}
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ services:
volumes:
# We share the current folder into /var/www. This means code changes on the host will get picked up
# by the client.
- ./:/var/www
- ./:/var/www:rw
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
Expand Down
7 changes: 6 additions & 1 deletion docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# We install composer dependencies in here rather than during the build step so that if we switch branches
# and restart the container, it works.
service ssh start

if [ ! -f .env ]
then
cp .env.example .env
Expand All @@ -28,17 +30,20 @@ sed -i 's/DISCOURSE_SECRET=.*$/DISCOURSE_SECRET=mustbetencharacters/g' .env
sed -i 's/SESSION_DOMAIN=.*$/SESSION_DOMAIN=/g' phpunit.xml
sed -i 's/DB_TEST_HOST=.*$/DB_TEST_HOST=restarters_db/g' phpunit.xml

mkdir storage/framework/cache/data
php artisan migrate
npm install --legacy-peer-deps
npm rebuild node-sass
php artisan lang:js --no-lib resources/js/translations.js
chmod -R 777 public

npm run watch&
php artisan key:generate
php artisan cache:clear
php artisan config:clear

# Ensure we have the admin user
echo "User::create(['name'=>'Jane Bloggs','email'=>'jane@bloggs.net','password'=>Hash::make('passw0rd'),'role'=>2]);" | php artisan tinker
echo "User::create(['name'=>'Jane Bloggs','email'=>'jane@bloggs.net','password'=>Hash::make('passw0rd'),'role'=>2,'consent_past_data'=>'2021-01-01','consent_future_data'=>'2021-01-01','consent_gdpr'=>'2021-01-01']);" | php artisan tinker

php artisan serve --host=0.0.0.0 --port=80

Expand Down
1 change: 1 addition & 0 deletions lang/en/partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@
'notification_greeting' => 'Hello!',
'confirm' => 'Confirm',
'validate_timezone' => 'Please select a valid timezone.',
'dragmap' => 'Map marker not quite right? Feel free to drag around to fix it.'
];
1 change: 1 addition & 0 deletions lang/fr-BE/partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@
'notification_greeting' => 'Bonjour !',
'notification_footer' => 'Si vous souhaitez ne plus recevoir ces courriels, veuillez consulter <a href=":url">vos préférences</a> sur votre compte.',
'validate_timezone' => 'Veuillez sélectionner un fuseau horaire valide.',
'dragmap' => 'Le marqueur de carte n\'est pas tout à fait correct ? N\'hésitez pas à faire glisser le marqueur pour le corriger.',
];
1 change: 1 addition & 0 deletions lang/fr/partials.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@
'notification_greeting' => 'Bonjour !',
'notification_footer' => 'Si vous souhaitez ne plus recevoir ces courriels, veuillez consulter <a href=":url">vos préférences</a> sur votre compte.',
'validate_timezone' => 'Veuillez sélectionner un fuseau horaire valide.',
'dragmap' => 'Le marqueur de carte n\'est pas tout à fait correct ? N\'hésitez pas à faire glisser le marqueur pour le corriger.',
];
Loading