add user info to user view
This commit is contained in:
parent
9acd06cb04
commit
e9b8977728
|
@ -22,6 +22,7 @@ class StateFactory extends Factory
|
|||
'user_id' => User::factory(),
|
||||
'arrived' => (bool) $arrival,
|
||||
'arrival_date' => $arrival ? Carbon::instance($arrival) : null,
|
||||
'user_info' => $this->faker->optional(.1)->text(),
|
||||
'active' => $this->faker->boolean(.3),
|
||||
'force_active' => $this->faker->boolean(.1),
|
||||
'got_shirt' => $this->faker->boolean(),
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ function admin_user()
|
|||
$goodie = GoodieType::from(config('goodie_type'));
|
||||
$goodie_enabled = $goodie !== GoodieType::None;
|
||||
$goodie_tshirt = $goodie === GoodieType::Tshirt;
|
||||
$user_info_edit = auth()->can('user.info.edit');
|
||||
|
||||
if (!$request->has('id')) {
|
||||
throw_redirect(users_link());
|
||||
|
@ -84,6 +85,14 @@ function admin_user()
|
|||
. '</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 = [
|
||||
'1' => __('Yes'),
|
||||
'0' => __('No'),
|
||||
|
@ -270,16 +279,21 @@ function admin_user()
|
|||
if ($goodie_enabled) {
|
||||
$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->force_active = $force_active;
|
||||
$user_source->state->save();
|
||||
|
||||
engelsystem_log(
|
||||
'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
|
||||
. ', 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);
|
||||
break;
|
||||
|
|
|
@ -387,7 +387,6 @@ function User_view_myshifts(
|
|||
foreach ($shifts as $shift) {
|
||||
$key = $shift->start->timestamp . '-shift-' . $shift->shift_entry_id . $shift->id;
|
||||
$myshifts_table[$key] = User_view_myshift($shift, $user_source, $its_me);
|
||||
|
||||
if (!$shift->freeloaded) {
|
||||
$timeSum += ($shift->end->timestamp - $shift->start->timestamp);
|
||||
}
|
||||
|
@ -543,7 +542,10 @@ function User_view(
|
|||
: ''
|
||||
)
|
||||
. 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(),
|
||||
div('row', [
|
||||
|
|
|
@ -1995,3 +1995,6 @@ msgstr "Start"
|
|||
|
||||
msgid "shifts.end"
|
||||
msgstr "Ende"
|
||||
|
||||
msgid "user.info"
|
||||
msgstr "Benutzer Info"
|
||||
|
|
|
@ -698,3 +698,6 @@ msgstr "Start"
|
|||
|
||||
msgid "shifts.end"
|
||||
msgstr "End"
|
||||
|
||||
msgid "user.info"
|
||||
msgstr "User info"
|
||||
|
|
|
@ -11,6 +11,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
|
|||
/**
|
||||
* @property bool $arrived
|
||||
* @property Carbon|null $arrival_date
|
||||
* @property string|null $user_info
|
||||
* @property bool $active
|
||||
* @property bool $force_active
|
||||
* @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[] whereArrivalDate($value)
|
||||
* @method static QueryBuilder|State[] whereUserInfo($value)
|
||||
* @method static QueryBuilder|State[] whereActive($value)
|
||||
* @method static QueryBuilder|State[] whereForceActive($value)
|
||||
* @method static QueryBuilder|State[] whereGotShirt($value)
|
||||
|
@ -34,6 +36,7 @@ class State extends HasUserModel
|
|||
protected $attributes = [ // phpcs:ignore
|
||||
'arrived' => false,
|
||||
'arrival_date' => null,
|
||||
'user_info' => null,
|
||||
'active' => false,
|
||||
'force_active' => false,
|
||||
'got_shirt' => false,
|
||||
|
@ -60,6 +63,7 @@ class State extends HasUserModel
|
|||
'user_id',
|
||||
'arrived',
|
||||
'arrival_date',
|
||||
'user_info',
|
||||
'active',
|
||||
'force_active',
|
||||
'got_shirt',
|
||||
|
|
Loading…
Reference in New Issue