refactor no self signup to shift self signup

This commit is contained in:
Xu 2023-08-26 14:55:19 +02:00 committed by Igor Scheller
parent 4cd7103121
commit 383f8ebde5
9 changed files with 106 additions and 25 deletions

View File

@ -24,7 +24,7 @@ class AngelTypeFactory extends Factory
'restricted' => $this->faker->boolean(), 'restricted' => $this->faker->boolean(),
'requires_driver_license' => $this->faker->boolean(), 'requires_driver_license' => $this->faker->boolean(),
'no_self_signup' => $this->faker->boolean(), 'shift_self_signup' => $this->faker->boolean(),
'show_on_dashboard' => $this->faker->boolean(), 'show_on_dashboard' => $this->faker->boolean(),
'hide_register' => $this->faker->boolean(), 'hide_register' => $this->faker->boolean(),
]; ];

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AngeltypesRenameNoSelfSignupToShiftSelfSignup extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->renameColumn('no_self_signup', 'shift_self_signup')->default(true);
$connection = $this->schema->getConnection();
$connection->table('angel_types')
->update(['no_self_signup' => $connection->raw('NOT no_self_signup'),
]);
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('angel_types', function (Blueprint $table): void {
$table->renameColumn('shift_self_signup', 'no_self_signup');
$connection = $this->schema->getConnection();
$connection->table('angel_types')
->update(['shift_self_signup' => $connection->raw('NOT shift_self_signup'),
]);
});
}
}

View File

@ -118,7 +118,7 @@ function angeltype_edit_controller()
} }
$angeltype->restricted = $request->has('restricted'); $angeltype->restricted = $request->has('restricted');
$angeltype->no_self_signup = $request->has('no_self_signup'); $angeltype->shift_self_signup = $request->has('shift_self_signup');
$angeltype->show_on_dashboard = $request->has('show_on_dashboard'); $angeltype->show_on_dashboard = $request->has('show_on_dashboard');
$angeltype->hide_register = $request->has('hide_register'); $angeltype->hide_register = $request->has('hide_register');
@ -138,7 +138,7 @@ function angeltype_edit_controller()
success('Angel type saved.'); success('Angel type saved.');
engelsystem_log( engelsystem_log(
'Saved angeltype: ' . $angeltype->name . ($angeltype->restricted ? ', restricted' : '') 'Saved angeltype: ' . $angeltype->name . ($angeltype->restricted ? ', restricted' : '')
. ($angeltype->no_self_signup ? ', no_self_signup' : '') . ($angeltype->shift_self_signup ? ', shift_self_signup' : '')
. ($angeltype->requires_driver_license ? ', requires driver license' : '') . ', ' . ($angeltype->requires_driver_license ? ', requires driver license' : '') . ', '
. ($angeltype->requires_ifsg_certificate ? ', requires ifsg certificate' : '') . ', ' . ($angeltype->requires_ifsg_certificate ? ', requires ifsg certificate' : '') . ', '
. $angeltype->contact_name . ', ' . $angeltype->contact_name . ', '
@ -318,7 +318,7 @@ function angeltypes_list_controller()
} }
$angeltype->is_restricted = $angeltype->restricted ? icon('mortarboard-fill') : ''; $angeltype->is_restricted = $angeltype->restricted ? icon('mortarboard-fill') : '';
$angeltype->no_self_signup_allowed = $angeltype->no_self_signup ? '' : icon('pencil-square'); $angeltype->shift_self_signup_allowed = $angeltype->shift_self_signup ? icon('pencil-square') : '';
$angeltype->name = '<a href="' $angeltype->name = '<a href="'
. page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id]) . page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype->id])

View File

@ -19,7 +19,7 @@ function NeededAngelTypes_by_shift($shiftId)
`angel_types`.`id`, `angel_types`.`id`,
`angel_types`.`name`, `angel_types`.`name`,
`angel_types`.`restricted`, `angel_types`.`restricted`,
`angel_types`.`no_self_signup` `angel_types`.`shift_self_signup`
FROM `needed_angel_types` FROM `needed_angel_types`
JOIN `angel_types` ON `angel_types`.`id` = `needed_angel_types`.`angel_type_id` JOIN `angel_types` ON `angel_types`.`id` = `needed_angel_types`.`angel_type_id`
WHERE `shift_id` = ? WHERE `shift_id` = ?

View File

@ -156,7 +156,7 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
`angel_types`.`id`, `angel_types`.`id`,
`angel_types`.`name`, `angel_types`.`name`,
`angel_types`.`restricted`, `angel_types`.`restricted`,
`angel_types`.`no_self_signup` `angel_types`.`shift_self_signup`
FROM `shifts` FROM `shifts`
JOIN `needed_angel_types` ON `needed_angel_types`.`shift_id`=`shifts`.`id` JOIN `needed_angel_types` ON `needed_angel_types`.`shift_id`=`shifts`.`id`
JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id` JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id`
@ -173,7 +173,7 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter)
`angel_types`.`id`, `angel_types`.`id`,
`angel_types`.`name`, `angel_types`.`name`,
`angel_types`.`restricted`, `angel_types`.`restricted`,
`angel_types`.`no_self_signup` `angel_types`.`shift_self_signup`
FROM `shifts` FROM `shifts`
JOIN `needed_angel_types` ON `needed_angel_types`.`room_id`=`shifts`.`room_id` JOIN `needed_angel_types` ON `needed_angel_types`.`room_id`=`shifts`.`room_id`
JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id` JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id`
@ -209,7 +209,7 @@ function NeededAngeltype_by_Shift_and_Angeltype(Shift $shift, AngelType $angelty
`angel_types`.`id`, `angel_types`.`id`,
`angel_types`.`name`, `angel_types`.`name`,
`angel_types`.`restricted`, `angel_types`.`restricted`,
`angel_types`.`no_self_signup` `angel_types`.`shift_self_signup`
FROM `shifts` FROM `shifts`
JOIN `needed_angel_types` ON `needed_angel_types`.`shift_id`=`shifts`.`id` JOIN `needed_angel_types` ON `needed_angel_types`.`shift_id`=`shifts`.`id`
JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id` JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id`
@ -226,7 +226,7 @@ function NeededAngeltype_by_Shift_and_Angeltype(Shift $shift, AngelType $angelty
`angel_types`.`id`, `angel_types`.`id`,
`angel_types`.`name`, `angel_types`.`name`,
`angel_types`.`restricted`, `angel_types`.`restricted`,
`angel_types`.`no_self_signup` `angel_types`.`shift_self_signup`
FROM `shifts` FROM `shifts`
JOIN `needed_angel_types` ON `needed_angel_types`.`room_id`=`shifts`.`room_id` JOIN `needed_angel_types` ON `needed_angel_types`.`room_id`=`shifts`.`room_id`
JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id` JOIN `angel_types` ON `angel_types`.`id`= `needed_angel_types`.`angel_type_id`
@ -368,12 +368,12 @@ function Shift_signup_allowed_angel(
if ( if (
empty($user_angeltype) empty($user_angeltype)
|| $angeltype->no_self_signup == 1 || !$angeltype->shift_self_signup
|| ($angeltype->restricted == 1 && !isset($user_angeltype['confirm_user_id'])) || ($angeltype->restricted && !isset($user_angeltype['confirm_user_id']))
) { ) {
// you cannot join if user is not of this angel type // you cannot join if user is not of this angel type
// you cannot join if angeltype has shift self signup disabled
// you cannot join if you are not confirmed // you cannot join if you are not confirmed
// you cannot join if angeltype has no self signup
return new ShiftSignupState(ShiftSignupStatus::ANGELTYPE, $free_entries); return new ShiftSignupState(ShiftSignupStatus::ANGELTYPE, $free_entries);
} }

View File

@ -97,8 +97,14 @@ function AngelType_edit_view(AngelType $angeltype, bool $supporter_mode)
__('Angel types which require introduction can only be used by an angel if enabled by a supporter (double opt-in).') __('Angel types which require introduction can only be used by an angel if enabled by a supporter (double opt-in).')
), ),
$supporter_mode $supporter_mode
? form_info(__('No Self Sign Up allowed'), $angeltype->no_self_signup ? __('Yes') : __('No')) ? form_info(__('shift.self_signup'), $angeltype->shift_self_signup ? __('Yes') : __('No'))
: form_checkbox('no_self_signup', __('No Self Sign Up allowed'), $angeltype->no_self_signup), : form_checkbox(
'shift_self_signup',
__('shift.self_signup') .
' <span class="bi bi-info-circle-fill text-info" data-bs-toggle="tooltip" title="' .
__('angeltypes.shift.self_signup.info') . '"></span>',
$angeltype->shift_self_signup
),
$supporter_mode ? $supporter_mode ?
form_info( form_info(
__('Requires driver license'), __('Requires driver license'),
@ -571,11 +577,11 @@ function AngelTypes_list_view($angeltypes, bool $admin_angeltypes)
button(url('/angeltypes/about'), __('angeltypes.about')), button(url('/angeltypes/about'), __('angeltypes.about')),
]), ]),
table([ table([
'name' => __('Name'), 'name' => __('Name'),
'is_restricted' => icon('mortarboard-fill') . __('Requires introduction'), 'is_restricted' => icon('mortarboard-fill') . __('Requires introduction'),
'no_self_signup_allowed' => icon('pencil-square') . __('Self Sign Up Allowed'), 'shift_self_signup_allowed' => icon('pencil-square') . __('shift.self_signup.allowed'),
'membership' => __('Membership'), 'membership' => __('Membership'),
'actions' => '', 'actions' => '',
], $angeltypes), ], $angeltypes),
], true); ], true);
} }

View File

@ -1303,8 +1303,18 @@ msgstr ""
"Engeltypen, welche eine Einführung benötigen, müssen von einem Supporter freigeschaltet werden " "Engeltypen, welche eine Einführung benötigen, müssen von einem Supporter freigeschaltet werden "
"(double-opt-in)." "(double-opt-in)."
msgid "No Self Sign Up allowed" msgid "shift.self_signup"
msgstr "Kein Selbst-Eintragen erlaubt" msgstr "Schichten selbst eintragen"
msgid "shift.self_signup.allowed"
msgstr "Schichten selbst eintragen erlaubt"
msgid "angeltypes.shift.self_signup.info"
msgstr "Engeltypen, welche Schichten selbst eintragen erlaubt haben, "
"erlauben Engeln sich selbst in ihre Schichten einzutragen, "
"ist Schichten selbst eintragen nicht erlaubt können nur Supporter "
"oder Admins Engel in die Schichten des Engeltyps eintragen."
msgid "Requires driver license" msgid "Requires driver license"
msgstr "Benötigt Führerschein" msgstr "Benötigt Führerschein"

View File

@ -531,6 +531,16 @@ msgstr "DECT"
msgid "angeltypes.email" msgid "angeltypes.email"
msgstr "E-Mail" msgstr "E-Mail"
msgid "angeltypes.shift.self_signup.info"
msgstr "Angel types which have shift self signup enabled allow angels to self sign up for there shifts, "
"if shift self signup is disabled only supporters and admins can sign angels into shifts of these angel types."
msgid "shift.self_signup"
msgstr "Shift self signup"
msgid "shift.self_signup.allowed"
msgstr "Shift self signup allowed"
msgid "registration.register" msgid "registration.register"
msgstr "Register" msgstr "Register"

View File

@ -24,7 +24,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* @property boolean $restricted # If users need an introduction * @property boolean $restricted # If users need an introduction
* @property boolean $requires_driver_license # If users must have a driver license * @property boolean $requires_driver_license # If users must have a driver license
* @property boolean $requires_ifsg_certificate # If users must have a ifsg certificate * @property boolean $requires_ifsg_certificate # If users must have a ifsg certificate
* @property boolean $no_self_signup # Users can sign up for shifts * @property boolean $shift_self_signup # Users can sign up for shifts
* @property boolean $show_on_dashboard # Show on public dashboard * @property boolean $show_on_dashboard # Show on public dashboard
* @property boolean $hide_register # Hide from registration page * @property boolean $hide_register # Hide from registration page
* *
@ -49,7 +49,21 @@ class AngelType extends BaseModel
{ {
use HasFactory; use HasFactory;
/** @var array<string> */ /** @var array Default attributes */
protected $attributes = [ // phpcs:ignore
'restricted' => false,
'requires_driver_license' => false,
'requires_ifsg_certificate' => false,
'shift_self_signup' => true,
'show_on_dashboard' => false,
'hide_register' => false,
];
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
protected $fillable = [ // phpcs:ignore protected $fillable = [ // phpcs:ignore
'name', 'name',
'description', 'description',
@ -61,7 +75,7 @@ class AngelType extends BaseModel
'restricted', 'restricted',
'requires_driver_license', 'requires_driver_license',
'requires_ifsg_certificate', 'requires_ifsg_certificate',
'no_self_signup', 'shift_self_signup',
'show_on_dashboard', 'show_on_dashboard',
'hide_register', 'hide_register',
]; ];
@ -71,7 +85,7 @@ class AngelType extends BaseModel
'restricted' => 'boolean', 'restricted' => 'boolean',
'requires_driver_license' => 'boolean', 'requires_driver_license' => 'boolean',
'requires_ifsg_certificate' => 'boolean', 'requires_ifsg_certificate' => 'boolean',
'no_self_signup' => 'boolean', 'shift_self_signup' => 'boolean',
'show_on_dashboard' => 'boolean', 'show_on_dashboard' => 'boolean',
'hide_register' => 'boolean', 'hide_register' => 'boolean',
]; ];