diff --git a/db/migrations/2024_04_06_000000_add_user_fa_edit_permission.php b/db/migrations/2024_04_06_000000_add_user_fa_edit_permission.php new file mode 100644 index 00000000..3f7c8ab5 --- /dev/null +++ b/db/migrations/2024_04_06_000000_add_user_fa_edit_permission.php @@ -0,0 +1,44 @@ +schema->getConnection(); + $db->table('privileges') + ->insert([ + 'name' => 'user.fa.edit', 'description' => 'Edit User Force Active State', + ]); + + $editFa = $db->table('privileges') + ->where('name', 'user.fa.edit') + ->get(['id']) + ->first(); + + $bureaucrat = 80; + $db->table('group_privileges') + ->insertOrIgnore([ + ['group_id' => $bureaucrat, 'privilege_id' => $editFa->id], + ]); + } + + /** + * Reverse the migration + */ + public function down(): void + { + $db = $this->schema->getConnection(); + $db->table('privileges') + ->where('name', 'user.fa.edit') + ->delete(); + } +} diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 7e8259f7..4a588933 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -271,7 +271,7 @@ function user_controller() $shifts, $user->id == $user_source->id, $tshirt_score, - auth()->can('admin_active'), + auth()->can('user.edit.shirt'), auth()->can('admin_user_worklog'), $worklogs, auth()->can('user.ifsg.edit') diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index c2a629c6..c2e3ec00 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -255,9 +255,9 @@ function admin_active() $userData['work_time'] = sprintf('%.2f', round($timeSum / 3600, 2)) . ' h'; $userData['score'] = round($usr['shift_length'] / 60) . ' min (' . sprintf('%.2f', $usr['shift_length'] / 3600) . ' h)'; - $userData['active'] = icon_bool($usr->state->active == 1); - $userData['force_active'] = icon_bool($usr->state->force_active == 1); - $userData['tshirt'] = icon_bool($usr->state->got_shirt == 1); + $userData['active'] = icon_bool($usr->state->active); + $userData['force_active'] = icon_bool($usr->state->force_active); + $userData['tshirt'] = icon_bool($usr->state->got_shirt); $userData['shift_count'] = $usr['shift_count']; $actions = []; diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index c9cfbe64..8d67b733 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -140,9 +140,14 @@ function admin_user() } // Forced active? - if (auth()->can('admin_active') && config('enable_force_active')) { + if (config('enable_force_active')) { $html .= ' ' . __('Force active') . '' . "\n"; - $html .= html_options('force_active', $options, $user_source->state->force_active) . '' . "\n"; + if (auth()->can('user.fa.edit')) { + $html .= html_options('force_active', $options, $user_source->state->force_active); + } else { + $html .= ($user_source->state->force_active ? __('Yes') : __('No')); + } + $html .= '' . "\n"; } if ($goodie_enabled && $user_edit_shirt) { @@ -341,7 +346,7 @@ function admin_user() if ($user_edit_shirt) { $user_source->state->active = $request->postData('eAktiv'); } - if (auth()->can('admin_active') && config('enable_force_active')) { + if (auth()->can('user.fa.edit') && config('enable_force_active')) { $user_source->state->force_active = $request->input('force_active'); } $user_source->state->save();