make force active a config option

This commit is contained in:
Xu 2024-01-23 17:11:32 +01:00 committed by Igor Scheller
parent e7ff3b657a
commit cf570502f4
6 changed files with 23 additions and 12 deletions

View File

@ -318,6 +318,9 @@ return [
// Enables the planned arrival/leave date // Enables the planned arrival/leave date
'enable_planned_arrival' => (bool) env('ENABLE_PLANNED_ARRIVAL', true), 'enable_planned_arrival' => (bool) env('ENABLE_PLANNED_ARRIVAL', true),
// Whether force active should be enabled
'enable_force_active' => (bool) env('ENABLE_FORCE_ACTIVE', true),
// Resembles the Goodie Type. There are three options: // Resembles the Goodie Type. There are three options:
// 'none' => no goodie at all // 'none' => no goodie at all
// 'goodie' => a goodie which has no sizing options // 'goodie' => a goodie which has no sizing options

View File

@ -238,7 +238,7 @@ function user_controller()
auth()->resetApiKey($user_source); auth()->resetApiKey($user_source);
} }
if ($user_source->state->force_active) { if ($user_source->state->force_active && config('enable_force_active')) {
$tshirt_score = __('Enough'); $tshirt_score = __('Enough');
} else { } else {
$tshirt_score = sprintf('%.2f', User_tshirt_score($user_source->id)) . ' h'; $tshirt_score = sprintf('%.2f', User_tshirt_score($user_source->id)) . ' h';

View File

@ -43,7 +43,7 @@ function admin_active()
if ($request->has('set_active')) { if ($request->has('set_active')) {
if ($request->has('count') && preg_match('/^\d+$/', $request->input('count'))) { if ($request->has('count') && preg_match('/^\d+$/', $request->input('count'))) {
$count = strip_request_item('count'); $count = strip_request_item('count');
if ($count < $forced_count) { if ($count < $forced_count && config('enable_force_active')) {
error(sprintf( error(sprintf(
__('At least %s angels are forced to be active. The number has to be greater.'), __('At least %s angels are forced to be active. The number has to be greater.'),
$forced_count $forced_count
@ -85,11 +85,14 @@ function admin_active()
->whereNot('users_state.user_info', ''); ->whereNot('users_state.user_info', '');
}) })
->groupBy('users.id') ->groupBy('users.id')
->orderByDesc('force_active')
->orderByDesc('shift_length') ->orderByDesc('shift_length')
->orderByDesc('name') ->orderByDesc('name')
->limit($count); ->limit($count);
if (config('enable_force_active')) {
$query->orderByDesc('force_active');
}
$users = $query->get(); $users = $query->get();
$user_nicks = []; $user_nicks = [];
foreach ($users as $usr) { foreach ($users as $usr) {
@ -192,10 +195,13 @@ function admin_active()
->whereNot('users_state.user_info', ''); ->whereNot('users_state.user_info', '');
}) })
->groupBy('users.id') ->groupBy('users.id')
->orderByDesc('force_active')
->orderByDesc('shift_length') ->orderByDesc('shift_length')
->orderByDesc('name'); ->orderByDesc('name');
if (config('enable_force_active')) {
$query->orderByDesc('force_active');
}
if (!is_null($count)) { if (!is_null($count)) {
$query->limit($count); $query->limit($count);
} }
@ -357,8 +363,8 @@ function admin_active()
'shift_count' => __('Shifts'), 'shift_count' => __('Shifts'),
'work_time' => __('Length'), 'work_time' => __('Length'),
'active' => __('Active?'), 'active' => __('Active?'),
'force_active' => __('Forced'),
], ],
(config('enable_force_active') ? ['force_active' => __('Forced'),] : []),
($goodie_enabled ? ['tshirt' => ($goodie_tshirt ? __('T-shirt?') : __('Goodie?'))] : []), ($goodie_enabled ? ['tshirt' => ($goodie_tshirt ? __('T-shirt?') : __('Goodie?'))] : []),
[ [
'actions' => __('general.actions'), 'actions' => __('general.actions'),

View File

@ -140,7 +140,7 @@ function admin_user()
} }
// Forced active? // Forced active?
if (auth()->can('admin_active')) { if (auth()->can('admin_active') && config('enable_force_active')) {
$html .= ' <tr><td>' . __('Force active') . '</td><td>' . "\n"; $html .= ' <tr><td>' . __('Force active') . '</td><td>' . "\n";
$html .= html_options('force_active', $options, $user_source->state->force_active) . '</td></tr>' . "\n"; $html .= html_options('force_active', $options, $user_source->state->force_active) . '</td></tr>' . "\n";
} }
@ -341,7 +341,7 @@ function admin_user()
if ($user_edit_shirt) { if ($user_edit_shirt) {
$user_source->state->active = $request->postData('eAktiv'); $user_source->state->active = $request->postData('eAktiv');
} }
if (auth()->can('admin_active')) { if (auth()->can('admin_active') && config('enable_force_active')) {
$user_source->state->force_active = $request->input('force_active'); $user_source->state->force_active = $request->input('force_active');
} }
$user_source->state->save(); $user_source->state->save();

View File

@ -47,7 +47,7 @@ function User_edit_vouchers_view($user)
[ [
msg(), msg(),
info(sprintf( info(sprintf(
$user->state->force_active $user->state->force_active && config('enable_force_active')
? __('Angel can receive another %d vouchers and is FA.') ? __('Angel can receive another %d vouchers and is FA.')
: __('Angel can receive another %d vouchers.'), : __('Angel can receive another %d vouchers.'),
User_get_eligable_voucher_count($user) User_get_eligable_voucher_count($user)
@ -157,7 +157,9 @@ function Users_view(
} }
$user_table_headers['freeloads'] = Users_table_header_link('freeloads', __('Freeloads'), $order_by); $user_table_headers['freeloads'] = Users_table_header_link('freeloads', __('Freeloads'), $order_by);
$user_table_headers['active'] = Users_table_header_link('active', __('user.active'), $order_by); $user_table_headers['active'] = Users_table_header_link('active', __('user.active'), $order_by);
if (config('enable_force_active')) {
$user_table_headers['force_active'] = Users_table_header_link('force_active', __('Forced'), $order_by); $user_table_headers['force_active'] = Users_table_header_link('force_active', __('Forced'), $order_by);
}
if ($goodie_enabled) { if ($goodie_enabled) {
if ($goodie_tshirt) { if ($goodie_tshirt) {
$user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by); $user_table_headers['got_shirt'] = Users_table_header_link('got_shirt', __('T-Shirt'), $order_by);
@ -560,7 +562,7 @@ function User_view(
'comment' => __('worklog.comment'), 'comment' => __('worklog.comment'),
'actions' => __('general.actions'), 'actions' => __('general.actions'),
], $my_shifts)); ], $my_shifts));
} elseif ($user_source->state->force_active) { } elseif ($user_source->state->force_active && config('enable_force_active')) {
$myshifts_table = success( $myshifts_table = success(
($its_me ? __('You have done enough.') : (__('%s has done enough.', [$user_source->name]))), ($its_me ? __('You have done enough.') : (__('%s has done enough.', [$user_source->name]))),
true true
@ -771,7 +773,7 @@ function User_view_state_admin($freeloader, $user_source)
) )
. '</span>'; . '</span>';
if ($user_source->state->force_active) { if ($user_source->state->force_active && config('enable_force_active')) {
$state[] = '<span class="text-success">' . __('user.force_active') . '</span>'; $state[] = '<span class="text-success">' . __('user.force_active') . '</span>';
} elseif ($user_source->state->active) { } elseif ($user_source->state->active) {
$state[] = '<span class="text-success">' . __('user.active') . '</span>'; $state[] = '<span class="text-success">' . __('user.active') . '</span>';

View File

@ -35,7 +35,7 @@
'disabled': not has_permission_to('admin_arrive'), 'disabled': not has_permission_to('admin_arrive'),
}) }} }) }}
{% if userdata.state.force_active %} {% if userdata.state.force_active and config('enable_force_active') %}
{{ f.switch('force_active', __('user.force_active'), { {{ f.switch('force_active', __('user.force_active'), {
'checked': true, 'checked': true,
'disabled': true, 'disabled': true,