diff --git a/config/config.default.php b/config/config.default.php index 79d3518b..e7f8957d 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -246,6 +246,9 @@ return [ // Enables the T-Shirt configuration on signup and profile 'enable_tshirt_size' => (bool)env('ENABLE_TSHIRT_SIZE', true), + // Enables the goody/voucher configuration on signup and profile + 'enable_goody' => (bool)env('ENABLE_GOODY', false), + // Number of shifts to freeload until angel is locked for shift signup. 'max_freeloadable_shifts' => env('MAX_FREELOADABLE_SHIFTS', 2), diff --git a/db/factories/User/SettingsFactory.php b/db/factories/User/SettingsFactory.php index 14df359f..4ef37a57 100644 --- a/db/factories/User/SettingsFactory.php +++ b/db/factories/User/SettingsFactory.php @@ -19,6 +19,7 @@ class SettingsFactory extends Factory 'language' => $this->faker->locale(), 'theme' => $this->faker->numberBetween(1, 20), 'email_human' => $this->faker->boolean(), + 'email_goody' => $this->faker->boolean(), 'email_shiftinfo' => $this->faker->boolean(), 'email_news' => $this->faker->boolean(), ]; diff --git a/db/migrations/2021_12_29_000000_users_settings_add_email_goody.php b/db/migrations/2021_12_29_000000_users_settings_add_email_goody.php new file mode 100644 index 00000000..88924a85 --- /dev/null +++ b/db/migrations/2021_12_29_000000_users_settings_add_email_goody.php @@ -0,0 +1,42 @@ +schema->table( + 'users_settings', + function (Blueprint $table) { + $table->boolean('email_goody')->default(false)->after('email_human'); + } + ); + + $connection = $this->schema->getConnection(); + $connection + ->table('users_settings') + ->update(['email_goody' => $connection->raw('email_human')]); + } + + /** + * Reverse the migration + */ + public function down() + { + $this->schema->table( + 'users_settings', + function (Blueprint $table) { + $table->dropColumn('email_goody'); + } + ); + } +} diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index f01d152d..7deb4619 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -47,6 +47,7 @@ function guest_register() $email_shiftinfo = false; $email_by_human_allowed = false; $email_news = false; + $email_goody = false; $tshirt_size = ''; $password_hash = ''; $selected_angel_types = []; @@ -118,6 +119,10 @@ function guest_register() $email_news = true; } + if ($request->has('email_goody')) { + $email_goody = true; + } + if ($enable_tshirt_size) { if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) { $tshirt_size = $request->input('tshirt_size'); @@ -215,6 +220,7 @@ function guest_register() 'language' => $session->get('locale'), 'theme' => config('theme'), 'email_human' => $email_by_human_allowed, + 'email_goody' => $email_goody, 'email_shiftinfo' => $email_shiftinfo, 'email_news' => $email_news, ]); @@ -365,9 +371,16 @@ function guest_register() ), form_checkbox( 'email_by_human_allowed', - __('To receive vouchers, agree that nick, email address, worked hours and shirt size will be stored until the next similar event. To withdraw your approval, send an email to %1$s.', [config('privacy_email')]), + __('Allow heaven angels to contact you by e-mail.'), $email_by_human_allowed ), + config('enable_goody') ? + form_checkbox( + 'email_goody', + __('To receive vouchers, give consent that nick, email address, worked hours and shirt size will be stored until the next similar event.') + . (config('privacy_email') ? ' ' . __('To withdraw your approval, send an email to %1$s.', [config('privacy_email')]) : ''), + $email_goody + ) : '', ]) ]), div('row', [ diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index 32302af7..0323fdd0 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -39,6 +39,9 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) $user_source->settings->email_shiftinfo = $request->has('email_shiftinfo'); $user_source->settings->email_human = $request->has('email_by_human_allowed'); $user_source->settings->email_news = $request->has('email_news'); + if (config('enable_goody')) { + $user_source->settings->email_goody = $request->has('email_goody'); + } if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) { $user_source->personalData->shirt_size = $request->input('tshirt_size'); @@ -180,7 +183,6 @@ function user_settings() $enable_tshirt_size = config('enable_tshirt_size'); $tshirt_sizes = config('tshirt_sizes'); $locales = config('locales'); - $oauth2_providers = config('oauth'); $buildup_start_date = null; $teardown_end_date = null; @@ -211,7 +213,6 @@ function user_settings() $buildup_start_date, $teardown_end_date, $enable_tshirt_size, - $tshirt_sizes, - $oauth2_providers + $tshirt_sizes ); } diff --git a/includes/view/User_view.php b/includes/view/User_view.php index 0bfbe3b3..9d2df1ef 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -19,7 +19,6 @@ use Engelsystem\Controllers\SettingsController; * @param int $teardown_end_date Unix timestamp * @param bool $enable_tshirt_size * @param array $tshirt_sizes - * @param array $oauth2_providers * * @return string */ @@ -30,14 +29,14 @@ function User_settings_view( $buildup_start_date, $teardown_end_date, $enable_tshirt_size, - $tshirt_sizes, - $oauth2_providers + $tshirt_sizes ) { $personalData = $user_source->personalData; $enable_user_name = config('enable_user_name'); $enable_pronoun = config('enable_pronoun'); $enable_dect = config('enable_dect'); $enable_planned_arrival = config('enable_planned_arrival'); + $enable_goody = config('enable_goody'); /** @var Renderer $renderer */ $renderer = app(Renderer::class); @@ -100,9 +99,15 @@ function User_settings_view( ), form_checkbox( 'email_by_human_allowed', - __('To receive vouchers, agree that nick, email address, worked hours and shirt size will be stored until the next similar event. To withdraw your approval, send an email to %1$s.', [config('privacy_email')]), + __('Allow heaven angels to contact you by e-mail.'), $user_source->settings->email_human ), + $enable_goody ? form_checkbox( + 'email_goody', + __('To receive vouchers, give consent that nick, email address, worked hours and shirt size will be stored until the next similar event.') + . (config('privacy_email') ? ' ' . __('To withdraw your approval, send an email to %1$s.', [config('privacy_email')]) : ''), + $user_source->settings->email_goody + ) : '', $enable_tshirt_size ? form_select( 'tshirt_size', __('Shirt size'), diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 98c6f3b7..95716c8b 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -1627,8 +1627,14 @@ msgid "Notify me of new news" msgstr "Benachrichtige mich bei neuen News" #: includes/pages/guest_login.php:291 includes/view/User_view.php:73 -msgid "To receive vouchers, agree that nick, email address, worked hours and shirt size will be stored until the next similar event. To withdraw your approval, send an email to %1$s." -msgstr "Um Voucher zu erhalten, stimme zu, dass Nick, E-Mail-Adresse, geleistete Arbeit und Shirtgröße bis zum nächsten gleichartigen Event gespeichert werden. Dies kann jederzeit durch eine Email an %1$s widerrufen werden." +msgid "Allow heaven angels to contact you by e-mail." +msgstr "Erlaube Himmel-Engeln dich per Mail zu kontaktieren." + +msgid "To receive vouchers, give consent that nick, email address, worked hours and shirt size will be stored until the next similar event." +msgstr "Um Voucher zu erhalten, stimme zu, dass Nick, E-Mail-Adresse, geleistete Arbeit und Shirtgröße bis zum nächsten gleichartigen Event gespeichert werden." + +msgid "To withdraw your approval, send an email to %1$s." +msgstr "Dies kann jederzeit durch eine E-Mail an %1$s widerrufen werden." #: includes/pages/guest_login.php:300 includes/view/User_view.php:48 msgid "Planned date of arrival" diff --git a/resources/lang/pt_BR/default.po b/resources/lang/pt_BR/default.po index 9fce4a2d..55ea1126 100644 --- a/resources/lang/pt_BR/default.po +++ b/resources/lang/pt_BR/default.po @@ -1354,8 +1354,8 @@ msgstr "" "mudam)" #: includes/pages/guest_login.php:230 includes/view/User_view.php:51 -msgid "To receive vouchers, agree that nick, email address, worked hours and shirt size will be stored until the next similar event. To withdraw your approval, send an email to %1$s." -msgstr "Permito que humanos me enviem emails (por exemplo, para um voucher)" +msgid "Allow heaven angels to contact you by e-mail." +msgstr "Permito que humanos me enviem emails" #: includes/pages/guest_login.php:235 includes/view/User_view.php:43 msgid "Planned date of arrival" diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index 158ab017..73c2d242 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -120,6 +120,7 @@ class Controller extends BaseController 'type' => 'gauge', ['labels' => ['type' => 'system'], 'value' => $this->stats->email('system')], ['labels' => ['type' => 'humans'], 'value' => $this->stats->email('humans')], + ['labels' => ['type' => 'goody'], 'value' => $this->stats->email('goody')], ['labels' => ['type' => 'news'], 'value' => $this->stats->email('news')], ], 'users_working' => [ diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index 2733ba0c..620724c8 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -115,6 +115,9 @@ class Stats case 'humans': $query = Settings::whereEmailHuman(true); break; + case 'goody': + $query = Settings::whereEmailGoody(true); + break; case 'news': $query = Settings::whereEmailNews(true); break; diff --git a/src/Models/User/Settings.php b/src/Models/User/Settings.php index 1ad4a85b..263564f9 100644 --- a/src/Models/User/Settings.php +++ b/src/Models/User/Settings.php @@ -9,12 +9,14 @@ use Illuminate\Database\Query\Builder as QueryBuilder; * @property string $language * @property int $theme * @property bool $email_human + * @property bool $email_goody * @property bool $email_shiftinfo * @property bool $email_news * * @method static QueryBuilder|Settings[] whereLanguage($value) * @method static QueryBuilder|Settings[] whereTheme($value) * @method static QueryBuilder|Settings[] whereEmailHuman($value) + * @method static QueryBuilder|Settings[] whereEmailGoody($value) * @method static QueryBuilder|Settings[] whereEmailShiftinfo($value) * @method static QueryBuilder|Settings[] whereEmailNews($value) */ @@ -25,13 +27,32 @@ class Settings extends HasUserModel /** @var string The table associated with the model */ protected $table = 'users_settings'; + /** @var array Default attributes */ + protected $attributes = [ + 'email_human' => false, + 'email_goody' => false, + 'email_shiftinfo' => false, + 'email_news' => false, + ]; + /** The attributes that are mass assignable */ protected $fillable = [ 'user_id', 'language', 'theme', 'email_human', + 'email_goody', 'email_shiftinfo', 'email_news', ]; + + /** @var string[] */ + protected $casts = [ + 'user_id' => 'integer', + 'theme' => 'integer', + 'email_human' => 'boolean', + 'email_goody' => 'boolean', + 'email_shiftinfo' => 'boolean', + 'email_news' => 'boolean', + ]; } diff --git a/tests/Unit/Controllers/Metrics/StatsTest.php b/tests/Unit/Controllers/Metrics/StatsTest.php index 0fb44813..e20d8286 100644 --- a/tests/Unit/Controllers/Metrics/StatsTest.php +++ b/tests/Unit/Controllers/Metrics/StatsTest.php @@ -260,6 +260,7 @@ class StatsTest extends TestCase $this->assertEquals(0, $stats->email('not-available-option')); $this->assertEquals(2, $stats->email('system')); $this->assertEquals(3, $stats->email('humans')); + $this->assertEquals(1, $stats->email('goody')); $this->assertEquals(1, $stats->email('news')); } @@ -390,7 +391,7 @@ class StatsTest extends TestCase { $this->addUser(); $this->addUser([], ['shirt_size' => 'L'], ['email_human' => true, 'email_shiftinfo' => true]); - $this->addUser(['arrived' => 1], [], ['email_human' => true, 'email_news' => true]); + $this->addUser(['arrived' => 1], [], ['email_human' => true, 'email_goody' => true, 'email_news' => true]); $this->addUser(['arrived' => 1], ['pronoun' => 'unicorn'], ['language' => 'lo_RM', 'email_shiftinfo' => true]); $this->addUser(['arrived' => 1, 'got_voucher' => 2], ['shirt_size' => 'XXL'], ['language' => 'lo_RM']); $this->addUser(['arrived' => 1, 'got_voucher' => 9, 'force_active' => true], [], ['theme' => 1]);