add user info to user view

This commit is contained in:
Xu 2023-11-16 21:27:23 +01:00 committed by Igor Scheller
parent 9acd06cb04
commit e9b8977728
8 changed files with 116 additions and 4 deletions

View File

@ -22,6 +22,7 @@ class StateFactory extends Factory
'user_id' => User::factory(), 'user_id' => User::factory(),
'arrived' => (bool) $arrival, 'arrived' => (bool) $arrival,
'arrival_date' => $arrival ? Carbon::instance($arrival) : null, 'arrival_date' => $arrival ? Carbon::instance($arrival) : null,
'user_info' => $this->faker->optional(.1)->text(),
'active' => $this->faker->boolean(.3), 'active' => $this->faker->boolean(.3),
'force_active' => $this->faker->boolean(.1), 'force_active' => $this->faker->boolean(.1),
'got_shirt' => $this->faker->boolean(), 'got_shirt' => $this->faker->boolean(),

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddUserInfoToUsersState extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('users_state', function (Blueprint $table): void {
$table->string('user_info')->nullable()->default(null)->after('arrival_date');
});
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('users_state', function (Blueprint $table): void {
$table->dropColumn('user_info');
});
}
}

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
class AddUserInfoPermissions extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->insert([
['name' => 'user.info.show', 'description' => 'Show User Info'],
['name' => 'user.info.edit', 'description' => 'Edit User Info'],
]);
$showUserInfo = $db->table('privileges')
->where('name', 'user.info.show')
->get(['id'])
->first();
$editUserInfo = $db->table('privileges')
->where('name', 'user.info.edit')
->get(['id'])
->first();
$buerocrat = 80;
$shico = 60;
$db->table('group_privileges')
->insertOrIgnore([
['group_id' => $buerocrat, 'privilege_id' => $editUserInfo->id],
['group_id' => $shico, 'privilege_id' => $showUserInfo->id],
]);
}
/**
* Reverse the migration
*/
public function down(): void
{
$db = $this->schema->getConnection();
$db->table('privileges')
->whereIn('name', ['user.info.edit', 'user.info.show'])
->delete();
}
}

View File

@ -27,6 +27,7 @@ function admin_user()
$goodie = GoodieType::from(config('goodie_type')); $goodie = GoodieType::from(config('goodie_type'));
$goodie_enabled = $goodie !== GoodieType::None; $goodie_enabled = $goodie !== GoodieType::None;
$goodie_tshirt = $goodie === GoodieType::Tshirt; $goodie_tshirt = $goodie === GoodieType::Tshirt;
$user_info_edit = auth()->can('user.info.edit');
if (!$request->has('id')) { if (!$request->has('id')) {
throw_redirect(users_link()); throw_redirect(users_link());
@ -84,6 +85,14 @@ function admin_user()
. '</td></tr>' . "\n"; . '</td></tr>' . "\n";
} }
if ($user_info_edit) {
$html .= ' <tr><td>' . __('user.info') . '</td><td>'
. '<textarea cols="40" rows="" name="userInfo" class="form-control">'
. htmlspecialchars((string) $user_source->state->user_info)
. '</textarea>'
. '</td></tr>' . "\n";
}
$options = [ $options = [
'1' => __('Yes'), '1' => __('Yes'),
'0' => __('No'), '0' => __('No'),
@ -270,16 +279,21 @@ function admin_user()
if ($goodie_enabled) { if ($goodie_enabled) {
$user_source->state->got_shirt = $request->postData('eTshirt'); $user_source->state->got_shirt = $request->postData('eTshirt');
} }
if ($user_info_edit) {
$user_source->state->user_info = $request->postData('userInfo');
}
$user_source->state->active = $request->postData('eAktiv'); $user_source->state->active = $request->postData('eAktiv');
$user_source->state->force_active = $force_active; $user_source->state->force_active = $force_active;
$user_source->state->save(); $user_source->state->save();
engelsystem_log( engelsystem_log(
'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')' 'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')'
. ($goodie_tshirt ? ', t-shirt: ' : '' . $user_source->personalData->shirt_size) . ($goodie_tshirt ? ', t-shirt-size: ' . $user_source->personalData->shirt_size : '')
. ', active: ' . $user_source->state->active . ', active: ' . $user_source->state->active
. ', force-active: ' . $user_source->state->force_active . ', force-active: ' . $user_source->state->force_active
. ($goodie_tshirt ? ', tshirt: ' : ', goodie: ' . $user_source->state->got_shirt) . ($goodie_tshirt ? ', t-shirt: ' : ', goodie: ' . $user_source->state->got_shirt)
. ($user_info_edit ? ', user-info: ' . $user_source->state->user_info : '')
); );
$html .= success(__('Changes were saved.') . "\n", true); $html .= success(__('Changes were saved.') . "\n", true);
break; break;

View File

@ -387,7 +387,6 @@ function User_view_myshifts(
foreach ($shifts as $shift) { foreach ($shifts as $shift) {
$key = $shift->start->timestamp . '-shift-' . $shift->shift_entry_id . $shift->id; $key = $shift->start->timestamp . '-shift-' . $shift->shift_entry_id . $shift->id;
$myshifts_table[$key] = User_view_myshift($shift, $user_source, $its_me); $myshifts_table[$key] = User_view_myshift($shift, $user_source, $its_me);
if (!$shift->freeloaded) { if (!$shift->freeloaded) {
$timeSum += ($shift->end->timestamp - $shift->start->timestamp); $timeSum += ($shift->end->timestamp - $shift->start->timestamp);
} }
@ -543,7 +542,10 @@ function User_view(
: '' : ''
) )
. htmlspecialchars($user_source->name) . htmlspecialchars($user_source->name)
. (config('enable_user_name') ? ' <small>' . $user_name . '</small>' : ''), . (config('enable_user_name') ? ' <small>' . $user_name . '</small>' : '')
. ((auth()->can('user.info.show') && $user_source->state->user_info)
? (' <small><span class="bi bi-info-circle-fill text-info" data-bs-toggle="tooltip" title="'
. htmlspecialchars($user_source->state->user_info) . '"></span></small>') : ''),
[ [
msg(), msg(),
div('row', [ div('row', [

View File

@ -1995,3 +1995,6 @@ msgstr "Start"
msgid "shifts.end" msgid "shifts.end"
msgstr "Ende" msgstr "Ende"
msgid "user.info"
msgstr "Benutzer Info"

View File

@ -698,3 +698,6 @@ msgstr "Start"
msgid "shifts.end" msgid "shifts.end"
msgstr "End" msgstr "End"
msgid "user.info"
msgstr "User info"

View File

@ -11,6 +11,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
/** /**
* @property bool $arrived * @property bool $arrived
* @property Carbon|null $arrival_date * @property Carbon|null $arrival_date
* @property string|null $user_info
* @property bool $active * @property bool $active
* @property bool $force_active * @property bool $force_active
* @property bool $got_shirt * @property bool $got_shirt
@ -18,6 +19,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* *
* @method static QueryBuilder|State[] whereArrived($value) * @method static QueryBuilder|State[] whereArrived($value)
* @method static QueryBuilder|State[] whereArrivalDate($value) * @method static QueryBuilder|State[] whereArrivalDate($value)
* @method static QueryBuilder|State[] whereUserInfo($value)
* @method static QueryBuilder|State[] whereActive($value) * @method static QueryBuilder|State[] whereActive($value)
* @method static QueryBuilder|State[] whereForceActive($value) * @method static QueryBuilder|State[] whereForceActive($value)
* @method static QueryBuilder|State[] whereGotShirt($value) * @method static QueryBuilder|State[] whereGotShirt($value)
@ -34,6 +36,7 @@ class State extends HasUserModel
protected $attributes = [ // phpcs:ignore protected $attributes = [ // phpcs:ignore
'arrived' => false, 'arrived' => false,
'arrival_date' => null, 'arrival_date' => null,
'user_info' => null,
'active' => false, 'active' => false,
'force_active' => false, 'force_active' => false,
'got_shirt' => false, 'got_shirt' => false,
@ -60,6 +63,7 @@ class State extends HasUserModel
'user_id', 'user_id',
'arrived', 'arrived',
'arrival_date', 'arrival_date',
'user_info',
'active', 'active',
'force_active', 'force_active',
'got_shirt', 'got_shirt',