supporters can freeload

This commit is contained in:
Xu 2024-01-23 15:06:31 +01:00 committed by Igor Scheller
parent 7e26e20608
commit e7ff3b657a
4 changed files with 30 additions and 17 deletions

View File

@ -20,10 +20,18 @@ function user_myshifts()
{ {
$user = auth()->user(); $user = auth()->user();
$request = request(); $request = request();
$is_angeltype_supporter = false;
if ($request->has('edit')) {
$id = $request->input('edit');
$shiftEntry = ShiftEntry::where('id', $id)
->where('user_id', User::find($request->input('id'))->id)
->first();
$is_angeltype_supporter = $shiftEntry && auth()->user()->isAngelTypeSupporter($shiftEntry->angelType);
}
if ( if (
$request->has('id') $request->has('id')
&& auth()->can('user_shifts_admin') && (auth()->can('user_shifts_admin') || $is_angeltype_supporter)
&& preg_match('/^\d+$/', $request->input('id')) && preg_match('/^\d+$/', $request->input('id'))
&& User::find($request->input('id')) && User::find($request->input('id'))
) { ) {
@ -61,7 +69,10 @@ function user_myshifts()
if ($request->hasPostData('submit')) { if ($request->hasPostData('submit')) {
$valid = true; $valid = true;
if (auth()->can('user_shifts_admin')) { if (
auth()->can('user_shifts_admin')
|| $is_angeltype_supporter
) {
$freeloaded = $request->has('freeloaded'); $freeloaded = $request->has('freeloaded');
$freeloaded_comment = strip_request_item_nl('freeloaded_comment'); $freeloaded_comment = strip_request_item_nl('freeloaded_comment');
if ($freeloaded && $freeloaded_comment == '') { if ($freeloaded && $freeloaded_comment == '') {
@ -91,6 +102,9 @@ function user_myshifts()
. '. Freeloaded: ' . ($freeloaded ? 'YES Comment: ' . $freeloaded_comment : 'NO') . '. Freeloaded: ' . ($freeloaded ? 'YES Comment: ' . $freeloaded_comment : 'NO')
); );
success(__('Shift saved.')); success(__('Shift saved.'));
if ($is_angeltype_supporter) {
throw_redirect(url('/shifts', ['action' => 'view', 'shift_id' => $shiftEntry->shift_id]));
}
throw_redirect(url('/users', ['action' => 'view', 'user_id' => $shifts_user->id])); throw_redirect(url('/users', ['action' => 'view', 'user_id' => $shifts_user->id]));
} }
} }
@ -104,13 +118,13 @@ function user_myshifts()
$shiftEntry->user_comment, $shiftEntry->user_comment,
$shiftEntry->freeloaded, $shiftEntry->freeloaded,
$shiftEntry->freeloaded_comment, $shiftEntry->freeloaded_comment,
auth()->can('user_shifts_admin') auth()->can('user_shifts_admin'),
$is_angeltype_supporter
); );
} else { } else {
throw_redirect(url('/user-myshifts')); throw_redirect(url('/user-myshifts'));
} }
} }
throw_redirect(url('/users', ['action' => 'view', 'user_id' => $shifts_user->id])); throw_redirect(url('/users', ['action' => 'view', 'user_id' => $shifts_user->id]));
return ''; return '';
} }

View File

@ -205,15 +205,16 @@ function ShiftEntry_edit_view(
$comment, $comment,
$freeloaded, $freeloaded,
$freeloaded_comment, $freeloaded_comment,
$user_admin_shifts = false $user_admin_shifts = false,
$angeltype_supporter = false
) { ) {
$freeload_form = []; $freeload_form = [];
if ($user_admin_shifts) { if ($user_admin_shifts || $angeltype_supporter) {
$freeload_form = [ $freeload_form = [
form_checkbox('freeloaded', __('Freeloaded'), $freeloaded), form_checkbox('freeloaded', __('Freeloaded'), $freeloaded),
form_textarea( form_textarea(
'freeloaded_comment', 'freeloaded_comment',
__('Freeload comment (Only for shift coordination):'), __('Freeload comment (Only for shift coordination and supporters):'),
$freeloaded_comment $freeloaded_comment
), ),
]; ];

View File

@ -319,14 +319,12 @@ function Shift_view_render_shift_entry(ShiftEntry $shift_entry, $user_shift_admi
$isUser = $shift_entry->user_id == auth()->user()->id; $isUser = $shift_entry->user_id == auth()->user()->id;
if ($user_shift_admin || $angeltype_supporter || $isUser) { if ($user_shift_admin || $angeltype_supporter || $isUser) {
$entry .= ' <div class="btn-group m-1">'; $entry .= ' <div class="btn-group m-1">';
if ($user_shift_admin || $isUser) { $entry .= button_icon(
$entry .= button_icon( url('/user-myshifts', ['edit' => $shift_entry->id, 'id' => $shift_entry->user_id]),
url('/user-myshifts', ['edit' => $shift_entry->id, 'id' => $shift_entry->user_id]), 'pencil',
'pencil', 'btn-sm',
'btn-sm', __('form.edit')
__('form.edit') );
);
}
$angeltype = $shift_entry->angelType; $angeltype = $shift_entry->angelType;
$disabled = Shift_signout_allowed($shift, $angeltype, $shift_entry->user_id) ? '' : ' btn-disabled'; $disabled = Shift_signout_allowed($shift, $angeltype, $shift_entry->user_id) ? '' : ' btn-disabled';
$entry .= button_icon( $entry .= button_icon(

View File

@ -1077,8 +1077,8 @@ msgstr "Schicht Anmeldung"
msgid "Freeloaded" msgid "Freeloaded"
msgstr "Geschwänzt" msgstr "Geschwänzt"
msgid "Freeload comment (Only for shift coordination):" msgid "Freeload comment (Only for shift coordination and supporters):"
msgstr "Schwänzer Kommentar (Nur für die Schicht-Koordination):" msgstr "Schwänzer Kommentar (Nur für Supporter und die Schicht-Koordination):"
msgid "Edit shift entry" msgid "Edit shift entry"
msgstr "Schichteintrag bearbeiten" msgstr "Schichteintrag bearbeiten"