From b3a30d99f0fa54670dedde47bfb16dfd2f19bb11 Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 5 Jun 2023 09:42:16 +0100
Subject: [PATCH 01/19] Demote network coordinator.
---
app/Http/Controllers/UserController.php | 10 ++++-
.../Feature/Events/AddRemoveVolunteerTest.php | 2 +-
tests/Feature/Networks/NetworkTest.php | 40 ++++++++++++++++---
tests/TestCase.php | 2 +
4 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 7995c57cd2..51cbedd665 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -373,11 +373,19 @@ public function postAdminEdit(Request $request)
$user = User::find($user_id);
+ $oldRole = $user->role;
+
// Set role for User
$user->update([
- 'role' => $request->input('user_role'),
+ 'role' => $request->input('user_role'),
]);
+ // If we are demoting from NetworkCoordinator to host, remove them from the list of coordinators for
+ // any networks they are currently coordinating.
+ if ($oldRole == Role::NETWORK_COORDINATOR && $user->role == Role::HOST) {
+ $user->networks()->detach();
+ }
+
// The user may have previously been removed from the group, which will mean they have an entry in
// users_groups with deleted_at set. Zap that if present so that sync() then works. sync() doesn't
// handle soft deletes itself.
diff --git a/tests/Feature/Events/AddRemoveVolunteerTest.php b/tests/Feature/Events/AddRemoveVolunteerTest.php
index 88d34800f9..8f6588a0b3 100644
--- a/tests/Feature/Events/AddRemoveVolunteerTest.php
+++ b/tests/Feature/Events/AddRemoveVolunteerTest.php
@@ -198,7 +198,7 @@ public function testAdminRemoveReaddHost() {
$response = $this->post('/profile/edit-admin-settings', [
'_token' => $tokenValue,
'id' => $host->id,
- 'user_role' => 2,
+ 'user_role' => Role::ADMINISTRATOR,
'assigned_groups' => [
$idgroups
],
diff --git a/tests/Feature/Networks/NetworkTest.php b/tests/Feature/Networks/NetworkTest.php
index f563f4cd97..6aedc154cf 100644
--- a/tests/Feature/Networks/NetworkTest.php
+++ b/tests/Feature/Networks/NetworkTest.php
@@ -19,11 +19,6 @@ class NetworkTest extends TestCase
protected function setUp(): void
{
parent::setUp();
- DB::statement('SET foreign_key_checks=0');
- Network::truncate();
- DB::delete('delete from user_network');
- DB::statement('SET foreign_key_checks=1');
-
$this->networkService = new RepairNetworkService();
}
@@ -330,4 +325,39 @@ public function admins_can_edit()
$this->assertTrue($network->containsGroup($group));
$this->assertTrue($group->isMemberOf($network));
}
+
+ public function testRemoveNetworkCoordinatorByRole() {
+ $this->withoutExceptionHandling();
+
+ $network = Network::factory()->create();
+
+ $admin = User::factory()->administrator()->create();
+ $coordinator = User::factory()->networkCoordinator()->create();
+ $network->addCoordinator($coordinator);
+
+ $this->actingAs($admin);
+
+ $response = $this->get('/user/edit/' . $coordinator->id);
+ $response->assertStatus(200);
+
+ $crawler = new Crawler($response->getContent());
+
+ $tokens = $crawler->filter('input[name=_token]')->each(function (Crawler $node, $i) {
+ return $node;
+ });
+
+ $tokenValue = $tokens[0]->attr('value');
+
+ $response = $this->post('/profile/edit-admin-settings', [
+ '_token' => $tokenValue,
+ 'id' => $coordinator->id,
+ 'assigned_groups' => [],
+ 'user_role' => Role::HOST,
+ ]);
+ $response->assertSessionHas('message');
+ $this->assertTrue($response->isRedirection());
+
+ // Demoting to host should remove as a network coordinator.
+ $this->assertFalse($network->coordinators->contains($coordinator));
+ }
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index cb82ed3650..4fe386f7fd 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -94,6 +94,8 @@ protected function setUp(): void
$network->name = 'Restarters';
$network->shortname = 'restarters';
$network->save();
+ } else {
+ error_log("Got network");
}
$this->withoutExceptionHandling();
From 6c845be9a8f1a133caf83ec9de458fe98dc8f3cc Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 5 Jun 2023 09:43:33 +0100
Subject: [PATCH 02/19] Demote network coordinator.
---
app/Http/Controllers/UserController.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 51cbedd665..8b2ce89958 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -380,9 +380,9 @@ public function postAdminEdit(Request $request)
'role' => $request->input('user_role'),
]);
- // If we are demoting from NetworkCoordinator to host, remove them from the list of coordinators for
+ // If we are demoting from NetworkCoordinator, remove them from the list of coordinators for
// any networks they are currently coordinating.
- if ($oldRole == Role::NETWORK_COORDINATOR && $user->role == Role::HOST) {
+ if ($oldRole == Role::NETWORK_COORDINATOR && ($user->role == Role::HOST) || $user->role == Role::RESTARTER) {
$user->networks()->detach();
}
From 33e8166377a661925775759ebb43f63118d8d3f8 Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 5 Jun 2023 10:20:09 +0100
Subject: [PATCH 03/19] Test fixes.
---
tests/Feature/Events/AddRemoveVolunteerTest.php | 1 +
tests/Feature/Networks/NetworkTest.php | 5 +----
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/tests/Feature/Events/AddRemoveVolunteerTest.php b/tests/Feature/Events/AddRemoveVolunteerTest.php
index 8f6588a0b3..5a047e91bd 100644
--- a/tests/Feature/Events/AddRemoveVolunteerTest.php
+++ b/tests/Feature/Events/AddRemoveVolunteerTest.php
@@ -9,6 +9,7 @@
use App\Notifications\AdminModerationEvent;
use App\Notifications\NotifyRestartersOfNewEvent;
use App\Party;
+use App\Role;
use App\User;
use DB;
use Faker\Generator as Faker;
diff --git a/tests/Feature/Networks/NetworkTest.php b/tests/Feature/Networks/NetworkTest.php
index 6aedc154cf..9b31092927 100644
--- a/tests/Feature/Networks/NetworkTest.php
+++ b/tests/Feature/Networks/NetworkTest.php
@@ -300,10 +300,7 @@ public function admins_can_edit()
$admin = User::factory()->administrator()->create();
$this->actingAs($admin);
- $network = new Network();
- $network->name = 'Restarters';
- $network->shortname = 'restarters';
- $network->save();
+ $network = Network::where('shortname', 'restarters')->first();
$response = $this->get('/networks/' . $network->id . '/edit', $network->attributesToArray());
$response->assertSuccessful();
From e276705859e7729cfbbab14cb069fe310e05dd93 Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 5 Jun 2023 10:59:00 +0100
Subject: [PATCH 04/19] Test change to help debug intermittent test failure.
---
tests/Feature/Events/InviteEventTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/Feature/Events/InviteEventTest.php b/tests/Feature/Events/InviteEventTest.php
index cf8fe315e9..390f5e18f1 100644
--- a/tests/Feature/Events/InviteEventTest.php
+++ b/tests/Feature/Events/InviteEventTest.php
@@ -146,8 +146,8 @@ public function testInviteReal()
// ...should show up in the list of events with an invitation as we have not yet accepted.
$response3 = $this->get('/party');
$events = $this->getVueProperties($response3)[1][':initial-events'];
- $this->assertNotFalse(strpos($events, '"attending":false'));
- $this->assertNotFalse(strpos($events, '"invitation"'));
+ $this->assertStringContainsString('"attending":false', $events);
+ $this->assertStringContainsString('"invitation"', $events);
// Now accept the invitation.
$response4 = $this->get($invitation);
From 1968013f8c8fd5b31ec0b6f524516e0f07f00bd6 Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 12 Jun 2023 11:51:10 +0100
Subject: [PATCH 05/19] WIP Add varying message, handle weight mandatory.
---
lang/en/devices.php | 3 +-
lang/fr-BE/devices.php | 3 +-
lang/fr/devices.php | 3 +-
.../js/components/DeviceCategorySelect.vue | 22 +++----
resources/js/components/DeviceWeight.vue | 17 ++++-
resources/js/components/EventDevice.vue | 64 +++++++++----------
resources/js/constants.js | 3 +-
7 files changed, 62 insertions(+), 53 deletions(-)
diff --git a/lang/en/devices.php b/lang/en/devices.php
index c358aa2afe..c159235700 100644
--- a/lang/en/devices.php
+++ b/lang/en/devices.php
@@ -44,7 +44,8 @@
'powered_items' => 'powered items',
'unpowered_items' => 'unpowered items',
'weight' => 'Weight',
- 'required_impact' => 'kg - required for environmental impact calculation',
+ 'required_impact' => 'kg - used for environmental impact calculation (required)',
+ 'optional_impact' => 'kg - used for environmental impact calculation (optional)',
'age_approx' => 'years (approximate if unknown)',
'repair_source' => 'Source of repair information',
'tooltip_category' => 'Choose the category that best fits this item. More information about these categories...',
diff --git a/lang/fr-BE/devices.php b/lang/fr-BE/devices.php
index 77962e3747..044d8fac4d 100644
--- a/lang/fr-BE/devices.php
+++ b/lang/fr-BE/devices.php
@@ -47,7 +47,8 @@
'powered_items' => 'Appareils électriques',
'repair_outcome' => 'Résultat de la réparation?',
'repair_source' => 'Source d\'information de la réparation',
- 'required_impact' => 'kg - requis pour calcul de l\'impact environnemental',
+ 'required_impact' => 'kg - utilisé pour le calcul de l\'impact environnemental (obligatoire)',
+ 'optional_impact' => 'kg - utilisé pour le calcul de l\'impact environnemental (facultatif)',
'title_assessment' => 'Evaluation',
'title_items' => 'Objet',
'title_items_at_event' => 'Objets à cet événement',
diff --git a/lang/fr/devices.php b/lang/fr/devices.php
index 77962e3747..044d8fac4d 100644
--- a/lang/fr/devices.php
+++ b/lang/fr/devices.php
@@ -47,7 +47,8 @@
'powered_items' => 'Appareils électriques',
'repair_outcome' => 'Résultat de la réparation?',
'repair_source' => 'Source d\'information de la réparation',
- 'required_impact' => 'kg - requis pour calcul de l\'impact environnemental',
+ 'required_impact' => 'kg - utilisé pour le calcul de l\'impact environnemental (obligatoire)',
+ 'optional_impact' => 'kg - utilisé pour le calcul de l\'impact environnemental (facultatif)',
'title_assessment' => 'Evaluation',
'title_items' => 'Objet',
'title_items_at_event' => 'Objets à cet événement',
diff --git a/resources/js/components/DeviceCategorySelect.vue b/resources/js/components/DeviceCategorySelect.vue
index a0a563e8cc..51d08e0bc0 100644
--- a/resources/js/components/DeviceCategorySelect.vue
+++ b/resources/js/components/DeviceCategorySelect.vue
@@ -29,7 +29,7 @@
diff --git a/resources/js/components/EventDevice.vue b/resources/js/components/EventDevice.vue
index 4ce598ffa5..af6be5b287 100644
--- a/resources/js/components/EventDevice.vue
+++ b/resources/js/components/EventDevice.vue
@@ -25,7 +25,7 @@
:suppress-brand-warning="suppressBrandWarning"/>
-
+
@@ -378,7 +378,7 @@ export default {
},
async addDevice () {
try {
- if (this.weightRequired && this.currentDevice.weight == null) {
+ if (this.weightRequired && (isNaN(this.currentDevice.estimate) || this.currentDevice.estimate == null)) {
this.missingWeight = true
} else {
this.missingWeight = false
@@ -401,7 +401,7 @@ export default {
},
async saveDevice () {
try {
- if (this.weightRequired && this.currentDevice.weight == null) {
+ if (this.weightRequired && (isNaN(this.currentDevice.estimate) || this.currentDevice.estimate == null)) {
this.missingWeight = true
} else {
this.missingWeight = false
From 77120b0fce6751263d37d7cdf84191ebec6f4fc1 Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 12 Jun 2023 12:12:02 +0100
Subject: [PATCH 07/19] Review feedback.
---
app/Http/Controllers/UserController.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 8b2ce89958..d52114b66e 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -382,7 +382,7 @@ public function postAdminEdit(Request $request)
// If we are demoting from NetworkCoordinator, remove them from the list of coordinators for
// any networks they are currently coordinating.
- if ($oldRole == Role::NETWORK_COORDINATOR && ($user->role == Role::HOST) || $user->role == Role::RESTARTER) {
+ if ($oldRole == Role::NETWORK_COORDINATOR && ($user->role == Role::HOST || $user->role == Role::RESTARTER)) {
$user->networks()->detach();
}
From 9e644b202aa694bfb9fb4df83a81fec2c6ca1cd5 Mon Sep 17 00:00:00 2001
From: Edward Hibbert
Date: Mon, 12 Jun 2023 18:12:06 +0100
Subject: [PATCH 08/19] Change from storing country names in the DB to country
codes.
---
app/Console/Commands/CheckGroupLocations.php | 2 +-
app/Console/Commands/FixLatitudeLongitude.php | 45 --------------
app/Console/Commands/ImportGroups.php | 4 +-
app/Console/Commands/SyncEvents.php | 3 +-
app/Console/Commands/SyncGroups.php | 3 +-
app/Group.php | 2 +-
app/Helpers/Geocoder.php | 4 +-
app/Http/Controllers/API/GroupController.php | 12 ++--
.../Controllers/API/UserGroupsController.php | 3 +-
app/Http/Controllers/ExportController.php | 2 +-
app/Http/Controllers/GroupController.php | 2 +-
app/Http/Controllers/UserController.php | 12 ++--
app/Http/Resources/GroupLocation.php | 9 ++-
app/Listeners/CreateWordpressPostForEvent.php | 2 +-
app/Listeners/CreateWordpressPostForGroup.php | 2 +-
app/Listeners/EditWordpressPostForEvent.php | 2 +-
app/Listeners/EditWordpressPostForGroup.php | 2 +-
app/User.php | 2 +-
database/factories/UserFactory.php | 2 +-
.../2023_06_12_153317_country_codes.php | 58 +++++++++++++++++++
lang/en/countries.php | 2 +-
lang/fr-BE/countries.php | 2 +-
.../blocks/groups-near-you.blade.php | 2 +-
resources/views/user/all.blade.php | 2 +-
.../views/user/profile/profile.blade.php | 2 +-
tests/Feature/Dashboard/BasicTest.php | 6 +-
tests/Feature/Groups/APIv2GroupTest.php | 1 +
tests/Feature/Groups/GroupCommandsTest.php | 2 +-
tests/Feature/Microtasks/BattcatOraTest.php | 6 +-
tests/Feature/Microtasks/DustupOraTest.php | 6 +-
tests/Feature/Microtasks/MobifixOraTest.php | 2 +-
tests/Feature/Microtasks/PrintcatOraTest.php | 6 +-
tests/Feature/Microtasks/TabicatOraTest.php | 4 +-
tests/Feature/Networks/APIv2NetworkTest.php | 4 +-
tests/Feature/Users/EditProfileTest.php | 6 +-
.../Registration/AccountCreationTest.php | 2 +-
tests/TestCase.php | 2 +-
tests/Unit/{t => }/GeocoderTest.php | 3 +-
38 files changed, 128 insertions(+), 105 deletions(-)
delete mode 100644 app/Console/Commands/FixLatitudeLongitude.php
create mode 100644 database/migrations/2023_06_12_153317_country_codes.php
rename tests/Unit/{t => }/GeocoderTest.php (80%)
diff --git a/app/Console/Commands/CheckGroupLocations.php b/app/Console/Commands/CheckGroupLocations.php
index 7e0d23c910..7a44642e22 100644
--- a/app/Console/Commands/CheckGroupLocations.php
+++ b/app/Console/Commands/CheckGroupLocations.php
@@ -19,7 +19,7 @@ class CheckGroupLocations extends Command
*
* @var string
*/
- protected $description = 'Check that all gtroup locations are geocodeable';
+ protected $description = 'Check that all group locations are geocodeable';
/**
* Create a new command instance.
diff --git a/app/Console/Commands/FixLatitudeLongitude.php b/app/Console/Commands/FixLatitudeLongitude.php
deleted file mode 100644
index cf4a748c88..0000000000
--- a/app/Console/Commands/FixLatitudeLongitude.php
+++ /dev/null
@@ -1,45 +0,0 @@
- 99 OR longitude > 99) AND deleted_at IS NULL;'));
-
- foreach ($users as $user) {
- $this->info("User {$user->id} {$user->country}:{$user->location}");
- $geocoded = $geocoder->geocode($user->location.','.$user->country);
-
- if (! empty($geocoded)) {
- $this->info("...{$geocoded['latitude']}, {$geocoded['longitude']}");
- DB::update(DB::raw("UPDATE users SET latitude = {$geocoded['latitude']}, longitude={$geocoded['longitude']} WHERE id = {$user->id};"));
- }
- }
- }
-}
diff --git a/app/Console/Commands/ImportGroups.php b/app/Console/Commands/ImportGroups.php
index 18c8ddada8..bf4aa49532 100644
--- a/app/Console/Commands/ImportGroups.php
+++ b/app/Console/Commands/ImportGroups.php
@@ -61,7 +61,7 @@ public function handle()
return iconv( "iso-8859-15", "UTF-8", $str );
}, $fields);
- // Format is 'Name', 'Location', 'Postcode', 'Area', 'Country', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description'.
+ // Format is 'Name', 'Location', 'Postcode', 'Area', 'CountryCode', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description'.
$groupname = $fields[0];
$location = $fields[1];
@@ -122,7 +122,7 @@ public function handle()
$group->area = $area;
$group->latitude = $lat;
$group->longitude = $lng;
- $group->country = $country;
+ $group->country_code = $country;
$group->website = $website;
$group->phone = $phone;
$group->free_text = $description;
diff --git a/app/Console/Commands/SyncEvents.php b/app/Console/Commands/SyncEvents.php
index 182ea8aff3..9e6d3600a8 100644
--- a/app/Console/Commands/SyncEvents.php
+++ b/app/Console/Commands/SyncEvents.php
@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use App\Group;
+use App\Helpers\Fixometer;
use App\Party;
use DateTime;
use Illuminate\Console\Command;
@@ -77,7 +78,7 @@ public function handle()
$custom_fields = [
['key' => 'party_grouphash', 'value' => $event->group],
- ['key' => 'party_groupcountry', 'value' => $group->country],
+ ['key' => 'party_groupcountry', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'party_groupcity', 'value' => $group->area],
['key' => 'party_venue', 'value' => $event->venue],
['key' => 'party_location', 'value' => $event->location],
diff --git a/app/Console/Commands/SyncGroups.php b/app/Console/Commands/SyncGroups.php
index 8d00012056..051f7b4f9c 100644
--- a/app/Console/Commands/SyncGroups.php
+++ b/app/Console/Commands/SyncGroups.php
@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use App\Group;
+use App\Helpers\Fixometer;
use Illuminate\Console\Command;
class SyncGroups extends Command
@@ -54,7 +55,7 @@ public function handle()
try {
$custom_fields = [
['key' => 'group_city', 'value' => $group->area],
- ['key' => 'group_country', 'value' => $group->country],
+ ['key' => 'group_country', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'group_website', 'value' => $group->website],
['key' => 'group_hash', 'value' => $group->idgroups],
['key' => 'group_latitude', 'value' => $group->latitude],
diff --git a/app/Group.php b/app/Group.php
index 1ecf268740..1cb8c8d8f9 100644
--- a/app/Group.php
+++ b/app/Group.php
@@ -34,7 +34,7 @@ class Group extends Model implements Auditable
'postcode',
'latitude',
'longitude',
- 'country',
+ 'country_code',
'free_text',
'facebook',
'wordpress_post_id',
diff --git a/app/Helpers/Geocoder.php b/app/Helpers/Geocoder.php
index eb2178e52b..6dea4b0f96 100644
--- a/app/Helpers/Geocoder.php
+++ b/app/Helpers/Geocoder.php
@@ -30,14 +30,14 @@ public function geocode($location)
foreach ($decoded->{'address_components'} as $component) {
if ($component->types && count($component->types) && $component->types[0] === 'country') {
- $country = $component->long_name;
+ $country_code = $component->short_name;
}
}
return [
'latitude' => $latitude,
'longitude' => $longitude,
- 'country' => $country,
+ 'country_code' => $country_code,
];
}
}
diff --git a/app/Http/Controllers/API/GroupController.php b/app/Http/Controllers/API/GroupController.php
index eaddc820d0..d9219d574a 100644
--- a/app/Http/Controllers/API/GroupController.php
+++ b/app/Http/Controllers/API/GroupController.php
@@ -102,7 +102,7 @@ public static function getGroupsByUsersNetworks(Request $request)
'timezone' => $group->timezone,
'location' => [
'value' => $group->location,
- 'country' => Fixometer::translateCountry($group->country, $countries),
+ 'country' => Fixometer::translateCountry($group->country_code, $countries),
'latitude' => $group->latitude,
'longitude' => $group->longitude,
'area' => $group->area,
@@ -606,7 +606,7 @@ public function createGroupv2(Request $request) {
'postcode' => $postcode,
'latitude' => $latitude,
'longitude' => $longitude,
- 'country' => $country,
+ 'country_code' => $country,
'free_text' => $description,
'shareable_code' => Fixometer::generateUniqueShareableCode(\App\Group::class, 'shareable_code'),
'timezone' => $timezone,
@@ -750,7 +750,7 @@ public function updateGroupv2(Request $request, $idGroup) {
'location' => $location,
'latitude' => $latitude,
'longitude' => $longitude,
- 'country' => $country,
+ 'country_code' => $country,
'free_text' => $description,
'timezone' => $timezone,
'phone' => $phone,
@@ -875,7 +875,7 @@ private function validateGroupParams(Request $request, $create): array {
$latitude = null;
$longitude = null;
- $country = null;
+ $country_code = null;
if ($timezone && !in_array($timezone, \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC))) {
throw ValidationException::withMessages(['location ' => __('partials.validate_timezone')]);
@@ -895,7 +895,7 @@ private function validateGroupParams(Request $request, $create): array {
// Note that the country returned by the geocoder is already in English, which is what we need for the
// value in the database.
- $country = $geocoded['country'];
+ $country_code = $geocoded['country_code'];
}
return array(
@@ -909,7 +909,7 @@ private function validateGroupParams(Request $request, $create): array {
$timezone,
$latitude,
$longitude,
- $country,
+ $country_code,
$network_data,
);
}
diff --git a/app/Http/Controllers/API/UserGroupsController.php b/app/Http/Controllers/API/UserGroupsController.php
index a6fb3b12ae..b6194192dd 100644
--- a/app/Http/Controllers/API/UserGroupsController.php
+++ b/app/Http/Controllers/API/UserGroupsController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\API;
use App\Group;
+use App\Helpers\Fixometer;
use App\Http\Controllers\Controller;
use App\Role;
use App\User;
@@ -83,7 +84,7 @@ protected static function mapDetailsAndAuditToChange($userGroupAssociation, $aud
$group = Group::find($userGroupAssociation->group);
$userGroupChange['group_name'] = $group->name;
$userGroupChange['group_area'] = $group->area;
- $userGroupChange['group_country'] = $group->country;
+ $userGroupChange['group_country'] = Fixometer::getCountryFromCountryCode($group->country_code);
return $userGroupChange;
}
diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php
index 9006b809d0..9e606becc8 100644
--- a/app/Http/Controllers/ExportController.php
+++ b/app/Http/Controllers/ExportController.php
@@ -415,7 +415,7 @@ public function getTimeVolunteered(Request $request, $search = null, $export = f
//country hours completed
$country_hours_completed = clone $user_events;
- $country_hours_completed = $country_hours_completed->groupBy('users.country')->select('users.country', DB::raw('SUM(TIMEDIFF(event_start_utc, event_end_utc)) as event_hours'));
+ $country_hours_completed = $country_hours_completed->groupBy('users.country_code')->select('users.country_code', DB::raw('SUM(TIMEDIFF(event_start_utc, event_end_utc)) as event_hours'));
$all_country_hours_completed = $country_hours_completed->orderBy('event_hours', 'DESC')->get();
$country_hours_completed = $country_hours_completed->orderBy('event_hours', 'DESC')->take(5)->get();
diff --git a/app/Http/Controllers/GroupController.php b/app/Http/Controllers/GroupController.php
index 4ea4f8ac75..c2b30cbdc9 100644
--- a/app/Http/Controllers/GroupController.php
+++ b/app/Http/Controllers/GroupController.php
@@ -513,7 +513,7 @@ public static function expandGroups($groups, $your_groupids, $nearby_groupids)
asset('uploads/mid_'.$group_image->image->path) : null,
'location' => [
'location' => rtrim($group->location),
- 'country' => Fixometer::translateCountry($group->country, $countries),
+ 'country' => Fixometer::translateCountry($group->country_code, $countries),
'distance' => $distance,
],
'next_event' => $event ? $event->event_date_local : null,
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index d52114b66e..635e5e5251 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -157,7 +157,7 @@ public function postProfileInfoEdit(Request $request, App\Helpers\Geocoder $geoc
User::find($id)->update([
'email' => $request->input('email'),
'name' => $request->input('name'),
- 'country' => $request->input('country'),
+ 'country_code' => $request->input('country'),
'location' => $request->input('townCity'),
'age' => $request->input('age'),
'gender' => $request->input('gender'),
@@ -171,7 +171,7 @@ public function postProfileInfoEdit(Request $request, App\Helpers\Geocoder $geoc
}
if (! empty($user->location)) {
- $geocoded = $geocoder->geocode("{$user->location}, {$user->country}");
+ $geocoded = $geocoder->geocode("{$user->location}, " . Fixometer::getCountryFromCountryCode($user->country_code));
if (! empty($geocoded)) {
$user->latitude = $geocoded['latitude'];
$user->longitude = $geocoded['longitude'];
@@ -536,7 +536,7 @@ public function all()
$user['permissions'] = $User->getRolePermissions($user->role);
$user['groups'] = $user->groups;
$user['lastLogin'] = $user->lastLogin();
- $user['country'] = Fixometer::getCountryFromCountryCode($user->country);
+ $user['country'] = Fixometer::getCountryFromCountryCode($user->country_code);
return $user;
});
@@ -607,7 +607,7 @@ public function search(Request $request)
$user['permissions'] = $User->getRolePermissions($user->role);
$user['groups'] = $user->groups;
$user['lastLogin'] = $user->lastLogin();
- $user['country'] = Fixometer::getCountryFromCountryCode($user->country);
+ $user['country'] = Fixometer::getCountryFromCountryCode($user->country_code);
return $user;
});
@@ -920,7 +920,7 @@ public function postRegister(Request $request, $hash = null)
if (Auth::check()) { //Existing users are to update
$user = User::find(Auth::user()->id);
- $user->country = $request->input('country');
+ $user->country_code = $request->input('country');
$user->location = $request->input('city');
$user->gender = $request->input('gender');
$user->age = $request->input('age');
@@ -935,7 +935,7 @@ public function postRegister(Request $request, $hash = null)
'role' => $role,
'recovery' => substr(bin2hex(openssl_random_pseudo_bytes(32)), 0, 24),
'recovery_expires' => strftime('%Y-%m-%d %X', time() + (24 * 60 * 60)),
- 'country' => $request->input('country'),
+ 'country_code' => $request->input('country'),
'location' => $request->input('city'),
'gender' => $request->input('gender'),
'age' => $request->input('age'),
diff --git a/app/Http/Resources/GroupLocation.php b/app/Http/Resources/GroupLocation.php
index 2448761871..ec4f75d22d 100644
--- a/app/Http/Resources/GroupLocation.php
+++ b/app/Http/Resources/GroupLocation.php
@@ -30,6 +30,12 @@
* example="United Kingdom"
* ),
* @OA\Property(
+ * property="country_code",
+ * description="The two-letter ISO country code.",
+ * format="string",
+ * example="GB"
+ * ),
+ * @OA\Property(
* property="lat",
* title="lat",
* description="Latitude of the group.",
@@ -66,7 +72,8 @@ public function toArray($request)
'location' => $this->location,
'area' => $this->area,
'postcode' => $this->postcode,
- 'country' => \App\Helpers\Fixometer::translateCountry($this->country),
+ 'country' => \App\Helpers\Fixometer::getCountryFromCountryCode($this->country_code),
+ 'country_code' => $this->country_code,
'lat' => $this->latitude,
'lng' => $this->longitude,
];
diff --git a/app/Listeners/CreateWordpressPostForEvent.php b/app/Listeners/CreateWordpressPostForEvent.php
index 877a0a087e..1bf382cceb 100644
--- a/app/Listeners/CreateWordpressPostForEvent.php
+++ b/app/Listeners/CreateWordpressPostForEvent.php
@@ -80,7 +80,7 @@ public function createEventOnWordpress($theParty): void
['key' => 'party_venue', 'value' => $theParty->venue],
['key' => 'party_location', 'value' => $theParty->location],
['key' => 'party_time', 'value' => $theParty->getEventStartEndLocal()],
- ['key' => 'party_groupcountry', 'value' => $group->country],
+ ['key' => 'party_groupcountry', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'party_groupcity', 'value' => $group->area],
['key' => 'party_date', 'value' => $theParty->event_date_local],
['key' => 'party_timestamp', 'value' => $startTimestamp],
diff --git a/app/Listeners/CreateWordpressPostForGroup.php b/app/Listeners/CreateWordpressPostForGroup.php
index 3ecb87a679..12981061e6 100644
--- a/app/Listeners/CreateWordpressPostForGroup.php
+++ b/app/Listeners/CreateWordpressPostForGroup.php
@@ -72,7 +72,7 @@ public function createGroupOnWordpress($group): void
if (!$group->wordpress_post_id) {
$custom_fields = [
['key' => 'group_city', 'value' => $group->area],
- ['key' => 'group_country', 'value' => $group->country],
+ ['key' => 'group_country', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'group_website', 'value' => $group->website],
['key' => 'group_hash', 'value' => $group->idgroups],
['key' => 'group_avatar_url', 'value' => $group->groupImagePath()],
diff --git a/app/Listeners/EditWordpressPostForEvent.php b/app/Listeners/EditWordpressPostForEvent.php
index 83d51ac11a..b91dc035c4 100644
--- a/app/Listeners/EditWordpressPostForEvent.php
+++ b/app/Listeners/EditWordpressPostForEvent.php
@@ -53,7 +53,7 @@ public function handle(EditEvent $event)
$custom_fields = [
['key' => 'party_grouphash', 'value' => $data['group']],
- ['key' => 'party_groupcountry', 'value' => $group->country],
+ ['key' => 'party_groupcountry', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'party_groupcity', 'value' => $group->area],
['key' => 'party_venue', 'value' => $data['venue']],
['key' => 'party_location', 'value' => $data['location']],
diff --git a/app/Listeners/EditWordpressPostForGroup.php b/app/Listeners/EditWordpressPostForGroup.php
index 3226b73b9e..2985613ed1 100644
--- a/app/Listeners/EditWordpressPostForGroup.php
+++ b/app/Listeners/EditWordpressPostForGroup.php
@@ -45,7 +45,7 @@ public function handle(EditGroup $event)
if (is_numeric($group->wordpress_post_id)) {
$custom_fields = [
['key' => 'group_city', 'value' => $group->area],
- ['key' => 'group_country', 'value' => $group->country],
+ ['key' => 'group_country', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'group_website', 'value' => $data['website']],
['key' => 'group_hash', 'value' => $id],
['key' => 'group_avatar_url', 'value' => $data['group_avatar']],
diff --git a/app/User.php b/app/User.php
index 8c512a8e89..72651e4026 100644
--- a/app/User.php
+++ b/app/User.php
@@ -37,7 +37,7 @@ class User extends Authenticatable implements Auditable, HasLocalePreference
* @var array
*/
protected $fillable = [
- 'name', 'email', 'password', 'role', 'recovery', 'recovery_expires', 'language', 'repair_network', 'location', 'age', 'gender', 'country', 'newsletter', 'drip_subscriber_id', 'invites', 'biography', 'consent_future_data', 'consent_past_data', 'consent_gdpr', 'number_of_logins', 'latitude', 'longitude', 'last_login_at', 'api_token', 'access_group_tag_id', 'calendar_hash', 'repairdir_role', 'mediawiki', 'username',
+ 'name', 'email', 'password', 'role', 'recovery', 'recovery_expires', 'language', 'repair_network', 'location', 'age', 'gender', 'country_code', 'newsletter', 'drip_subscriber_id', 'invites', 'biography', 'consent_future_data', 'consent_past_data', 'consent_gdpr', 'number_of_logins', 'latitude', 'longitude', 'last_login_at', 'api_token', 'access_group_tag_id', 'calendar_hash', 'repairdir_role', 'mediawiki', 'username',
];
/**
diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php
index f413454394..c151ae195e 100644
--- a/database/factories/UserFactory.php
+++ b/database/factories/UserFactory.php
@@ -38,7 +38,7 @@ public function definition()
'consent_gdpr' => new \DateTime(),
'number_of_logins' => 1,
'age' => $this->faker->year(),
- 'country' => $this->faker->countryCode(),
+ 'country_code' => $this->faker->countryCode(),
'role' => Role::RESTARTER,
'invites' => 1,
'repairdir_role' => Role::REPAIR_DIRECTORY_NONE,
diff --git a/database/migrations/2023_06_12_153317_country_codes.php b/database/migrations/2023_06_12_153317_country_codes.php
new file mode 100644
index 0000000000..48311e598a
--- /dev/null
+++ b/database/migrations/2023_06_12_153317_country_codes.php
@@ -0,0 +1,58 @@
+renameColumn('country', 'country_code');
+ });
+
+ // Change the groups table to have country_code, not country.
+ Schema::table('groups', function (Blueprint $table) {
+ $table->string('country_code', 2)->after('area')->nullable();
+ });
+
+ $groups = DB::select(DB::raw('SELECT idgroups, country FROM groups'));
+
+ foreach ($groups as $g) {
+ // Countries are stored in English.
+ if ($g->country) {
+ $country = $g->country;
+ $group = Group::findOrFail($g->idgroups);
+ $group->country_code = $countries[$country];
+ Log::debug('Country: ' . $group->country . ' => ' . $group->country_code);
+ $group->save();
+ }
+ }
+
+ Schema::table('groups', function (Blueprint $table) {
+ $table->dropColumn('country');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ //
+ }
+};
diff --git a/lang/en/countries.php b/lang/en/countries.php
index 04059479bd..cd01f65f61 100644
--- a/lang/en/countries.php
+++ b/lang/en/countries.php
@@ -218,7 +218,7 @@
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syrian Arab Republic',
- 'TW' => 'Taiwan, Province of China',
+ 'TW' => 'Taiwan',
'TJ' => 'Tajikistan',
'TZ' => 'Tanzania, United Republic of',
'TH' => 'Thailand',
diff --git a/lang/fr-BE/countries.php b/lang/fr-BE/countries.php
index 137dbb9188..ccc369b13e 100644
--- a/lang/fr-BE/countries.php
+++ b/lang/fr-BE/countries.php
@@ -218,7 +218,7 @@
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syrian Arab Republic',
- 'TW' => 'Taiwan, Province of China',
+ 'TW' => 'Taiwan',
'TJ' => 'Tajikistan',
'TZ' => 'Tanzania, United Republic of',
'TH' => 'Thailand',
diff --git a/resources/views/dashboard/blocks/groups-near-you.blade.php b/resources/views/dashboard/blocks/groups-near-you.blade.php
index 1c85406446..aa232790ac 100644
--- a/resources/views/dashboard/blocks/groups-near-you.blade.php
+++ b/resources/views/dashboard/blocks/groups-near-you.blade.php
@@ -37,7 +37,7 @@
@if (is_null(Auth::user()->location))
@lang('dashboard.groups_near_you_set_location', ['profile_url' => '/profile/edit/'.Auth::user()->id])
@else
- @lang('dashboard.groups_near_you_your_location_is', ['location' => Auth::user()->location.', '.Auth::user()->country])
+ @lang('dashboard.groups_near_you_your_location_is', ['location' => Auth::user()->location.', '.\App\Helpers\Fixometer::getCountryFromCountryCode(Auth::user()->country_code)])
@endif
diff --git a/resources/views/user/all.blade.php b/resources/views/user/all.blade.php
index 52859b72c5..0a1592cdfc 100644
--- a/resources/views/user/all.blade.php
+++ b/resources/views/user/all.blade.php
@@ -194,7 +194,7 @@
N/A
@endif
-
{{ $u->country }} |
+ {{ \App\Helpers\Fixometer::getCountryFromCountryCode($u->country_code) }} |
@if (isset($u->groups) && $u->groups->count() > 0)
{{ $u->groups->count() }}
diff --git a/resources/views/user/profile/profile.blade.php b/resources/views/user/profile/profile.blade.php
index e35519cbc8..ba106d3590 100644
--- a/resources/views/user/profile/profile.blade.php
+++ b/resources/views/user/profile/profile.blade.php
@@ -28,7 +28,7 @@
|