From 05e94bbfee14c0fd351967c56d56a75fe31987b7 Mon Sep 17 00:00:00 2001 From: Xu Date: Fri, 10 Jun 2022 23:03:25 +0200 Subject: [PATCH] add config option and permission for food voucher --- config/config.default.php | 5 ++++- includes/controller/users_controller.php | 5 ++++- includes/view/User_view.php | 16 +++++++++------- src/Middleware/LegacyMiddleware.php | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/config/config.default.php b/config/config.default.php index b2d9cfb1..066fa797 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -271,9 +271,12 @@ 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 + // Enables the goody configuration on signup and profile 'enable_goody' => (bool)env('ENABLE_GOODY', false), + // Enables the food voucher in the user profile + 'enable_voucher' => (bool)env('ENABLE_VOUCHER', true), + // Number of shifts to freeload until angel is locked for shift signup. 'max_freeloadable_shifts' => env('MAX_FREELOADABLE_SHIFTS', 2), diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index fc2a4884..fde7a2b2 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -146,7 +146,10 @@ function user_edit_vouchers_controller() $user_source = $user; } - if (!auth()->can('admin_user') && !auth()->can('voucher.edit')) { + if ( + (!auth()->can('admin_user') && !auth()->can('voucher.edit')) + || !config('enable_voucher') + ) { throw_redirect(page_link_to('')); } diff --git a/includes/view/User_view.php b/includes/view/User_view.php index d3b661b2..4bd17616 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -634,13 +634,15 @@ function User_view( form_hidden('user', $user_source->id), form_submit('submit', __('arrived'), '', false, 'primary') ], page_link_to('admin_arrive'), true) : '', - $admin_user_privilege || $auth->can('voucher.edit') ? button( - page_link_to( - 'users', - ['action' => 'edit_vouchers', 'user_id' => $user_source->id] - ), - icon('file-binary-fill') . __('Edit vouchers') - ) : '', + ($admin_user_privilege || $auth->can('voucher.edit')) && config('enable_voucher') ? + button( + page_link_to( + 'users', + ['action' => 'edit_vouchers', 'user_id' => $user_source->id] + ), + icon('file-binary-fill') . __('Edit vouchers') + ) + : '', $admin_user_worklog_privilege ? button( user_worklog_add_link($user_source), icon('list') . __('Add work log') diff --git a/src/Middleware/LegacyMiddleware.php b/src/Middleware/LegacyMiddleware.php index e86a818a..457d7590 100644 --- a/src/Middleware/LegacyMiddleware.php +++ b/src/Middleware/LegacyMiddleware.php @@ -201,7 +201,7 @@ class LegacyMiddleware implements MiddlewareInterface return response($content, (int)$page); } - if (strpos($content, '