Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RES-1917 group email #677

Merged
merged 4 commits into from
Sep 4, 2023
Merged
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
78 changes: 78 additions & 0 deletions app/Console/Commands/ImportMRES.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

use function Symfony\Component\VarDumper\Dumper\esc;

class ImportMRES extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'import:mres {input}';


/**
* The console command description.
*
* @var string
*/
protected $description = 'Assign email addresses to MRES groups.';

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

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

$inputFile = fopen($input, 'r');

// First three lines are headers.
fgetcsv($inputFile);
fgetcsv($inputFile);
fgetcsv($inputFile);

while (!feof($inputFile))
{
$fields = fgetcsv($inputFile);

if ($fields) {
$fields = array_map("utf8_encode", $fields);
$groupname = trim($fields[0]);
$email = trim($fields[1]);

if ($email) {
// Find group with name
$group = \App\Group::where('name', 'like', $groupname)->first();

if ($group) {
$this->info("Set email for $groupname to $email");
$group->email = $email;
$group->save();
} else {
$this->error("No group found for $groupname");
}
}
}
}
}
}
1 change: 1 addition & 0 deletions app/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Group extends Model implements Auditable
'timezone',
'phone',
'network_data',
'email',
];

protected $appends = ['ShareableLink', 'auto_approve'];
Expand Down
16 changes: 14 additions & 2 deletions app/Http/Controllers/API/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ public function moderateGroupsv2(Request $request) {
* ref="#/components/schemas/Group/properties/website"
* ),
* @OA\Property(
* property="email",
* ref="#/components/schemas/Group/properties/email"
* ),
* @OA\Property(
* property="description",
* ref="#/components/schemas/Group/properties/description",
* ),
Expand Down Expand Up @@ -592,7 +596,7 @@ public function createGroupv2(Request $request) {
$user = $this->getUser();
$user->convertToHost();

list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country, $network_data) = $this->validateGroupParams(
list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country, $network_data, $email) = $this->validateGroupParams(
$request,
true
);
Expand All @@ -611,6 +615,7 @@ public function createGroupv2(Request $request) {
'timezone' => $timezone,
'phone' => $phone,
'network_data' => $network_data,
'email' => $email,
];

$group = Group::create($data);
Expand Down Expand Up @@ -692,6 +697,10 @@ public function createGroupv2(Request $request) {
* ref="#/components/schemas/Group/properties/website"
* ),
* @OA\Property(
* property="email",
* ref="#/components/schemas/Group/properties/email"
* ),
* @OA\Property(
* property="description",
* ref="#/components/schemas/Group/properties/description",
* ),
Expand Down Expand Up @@ -728,7 +737,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, $network_data) = $this->validateGroupParams(
list($name, $area, $postcode, $location, $phone, $website, $description, $timezone, $latitude, $longitude, $country, $network_data, $email) = $this->validateGroupParams(
$request,
false
);
Expand All @@ -754,6 +763,7 @@ public function updateGroupv2(Request $request, $idGroup) {
'timezone' => $timezone,
'phone' => $phone,
'network_data' => $network_data,
'email' => $email,
];

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

$latitude = null;
$longitude = null;
Expand Down Expand Up @@ -910,6 +921,7 @@ private function validateGroupParams(Request $request, $create): array {
$longitude,
$country_code,
$network_data,
$email,
);
}
}
10 changes: 9 additions & 1 deletion app/Http/Resources/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
* example="https://therestartproject.org"
* ),
* @OA\Property(
* property="email",
* title="email",
* description="Any email contact address for the group.",
* format="string",
* example="info@therestartproject.org"
* ),
* @OA\Property(
* property="description",
* title="description",
* description="HTML description of the group.",
Expand Down Expand Up @@ -280,7 +287,8 @@ public function toArray($request)
'timezone' => $this->timezone,
'approved' => $this->approved ? true : false,
'network_data' => gettype($this->network_data) == 'string' ? json_decode($this->network_data, true) : $this->network_data,
'full' => true
'full' => true,
'email' => $this->email,
];

$ret['hosts'] = $this->resource->all_confirmed_hosts_count;
Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2023_08_14_112539_group_email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('groups', function (Blueprint $table) {
$table->string('email', 255)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('groups', function (Blueprint $table) {
$table->dropColumn('email');
});
}
};
4 changes: 3 additions & 1 deletion lang/en/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
'groups_about_group' => 'Tell us about your group',
'groups_website' => 'Your website',
'groups_website_small' => 'Don\'t have a website? Feel free to add a Facebook group or similar',
'groups_group_small' => 'A couple of examples include \'Restarters Torino\' or \'Nottingham Fixers\'',
'groups_email' => 'Email address',
'groups_email_small' => 'A public contact email address for your group (optional)',
'groups_group_small' => 'e.g. \'Restarters Torino\' or \'Nottingham Fixers\'',
'groups_location' => 'Location',
'location' => 'Group location',
'area' => 'Area',
Expand Down
4 changes: 3 additions & 1 deletion lang/fr-BE/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
'groups_about_group' => 'Parlez-nous de votre Repair Café',
'groups_website' => 'Votre site web',
'groups_website_small' => 'Vous n\'avez pas de site web? Vous pouvez aussi ajouter une page Facebook ou autre',
'groups_group_small' => 'Quelques exemples tels que \'Restarters Torino\' ou \'Réparateurs de Paris\'',
'groups_email' => 'Adresse électronique',
'groups_email_small' => 'Une adresse électronique de contact public pour votre Repair Café (facultatif)',
'groups_group_small' => 'Par exemple \'Restarters Torino\' ou \'Réparateurs de Paris\'',
'groups_location' => 'Lieu',
'location' => 'Localisation du Repair Café',
'groups_approval_text' => 'L\'ajout de repair cafés doit être approuvé par un administrateur',
Expand Down
4 changes: 3 additions & 1 deletion lang/fr/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
'groups_about_group' => 'Parlez-nous de votre Repair Café',
'groups_website' => 'Votre site web',
'groups_website_small' => 'Vous n\'avez pas de site web? Vous pouvez aussi ajouter une page Facebook ou autre',
'groups_group_small' => 'Quelques exemples tels que \'Restarters Torino\' ou \'Réparateurs de Paris\'',
'groups_email' => 'Adresse électronique',
'groups_email_small' => 'Une adresse électronique de contact public pour votre Repair Café (facultatif)',
'groups_group_small' => 'Par exemple \'Restarters Torino\' ou \'Réparateurs de Paris\'',
'groups_location' => 'Lieu',
'location' => 'Localisation du Repair Café',
'groups_approval_text' => 'L\'ajout de repair cafés doit être approuvé par un administrateur',
Expand Down
Loading