edit user nick needs buerocrat
This commit is contained in:
parent
ac73489aed
commit
162116998c
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Engelsystem\Migrations;
|
||||||
|
|
||||||
|
use Engelsystem\Database\Migration\Migration;
|
||||||
|
|
||||||
|
class AddUserEditPermission extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migration
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$db = $this->schema->getConnection();
|
||||||
|
$db->table('privileges')
|
||||||
|
->insert([
|
||||||
|
'name' => 'user.edit', 'description' => 'Edit user',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$editUser = $db->table('privileges')
|
||||||
|
->where('name', 'user.edit')
|
||||||
|
->get(['id'])
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$buerocrat = 80;
|
||||||
|
$db->table('group_privileges')
|
||||||
|
->insertOrIgnore([
|
||||||
|
'group_id' => $buerocrat, 'privilege_id' => $editUser->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migration
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$db = $this->schema->getConnection();
|
||||||
|
$db->table('privileges')
|
||||||
|
->where('name', 'user.edit')
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ function admin_user()
|
||||||
$goodie_tshirt = $goodie === GoodieType::Tshirt;
|
$goodie_tshirt = $goodie === GoodieType::Tshirt;
|
||||||
$user_info_edit = auth()->can('user.info.edit');
|
$user_info_edit = auth()->can('user.info.edit');
|
||||||
$user_edit_shirt = auth()->can('user.edit.shirt');
|
$user_edit_shirt = auth()->can('user.edit.shirt');
|
||||||
|
$user_edit = auth()->can('user.edit');
|
||||||
|
|
||||||
if (!$request->has('id')) {
|
if (!$request->has('id')) {
|
||||||
throw_redirect(users_link());
|
throw_redirect(users_link());
|
||||||
|
@ -60,7 +61,8 @@ function admin_user()
|
||||||
$html .= '<tr><td>' . "\n";
|
$html .= '<tr><td>' . "\n";
|
||||||
$html .= '<table>' . "\n";
|
$html .= '<table>' . "\n";
|
||||||
$html .= ' <tr><td>' . __('general.nick') . '</td><td>'
|
$html .= ' <tr><td>' . __('general.nick') . '</td><td>'
|
||||||
. '<input size="40" name="eNick" value="' . htmlspecialchars($user_source->name) . '" class="form-control" maxlength="24">'
|
. '<input size="40" name="eNick" value="' . htmlspecialchars($user_source->name)
|
||||||
|
. '" class="form-control" maxlength="24" ' . ($user_edit ? '' : 'disabled') . '>'
|
||||||
. '</td></tr>' . "\n";
|
. '</td></tr>' . "\n";
|
||||||
$html .= ' <tr><td>' . __('Last login') . '</td><td><p class="help-block">'
|
$html .= ' <tr><td>' . __('Last login') . '</td><td><p class="help-block">'
|
||||||
. ($user_source->last_login_at ? $user_source->last_login_at->format(__('general.datetime')) : '-')
|
. ($user_source->last_login_at ? $user_source->last_login_at->format(__('general.datetime')) : '-')
|
||||||
|
@ -281,14 +283,19 @@ function admin_user()
|
||||||
case 'save':
|
case 'save':
|
||||||
$user_source = User::find($user_id);
|
$user_source = User::find($user_id);
|
||||||
|
|
||||||
|
$changed_email = false;
|
||||||
if ($user_source->settings->email_human) {
|
if ($user_source->settings->email_human) {
|
||||||
|
$changed_email = $user_source->email !== $request->postData('eemail');
|
||||||
$user_source->email = $request->postData('eemail');
|
$user_source->email = $request->postData('eemail');
|
||||||
}
|
}
|
||||||
|
|
||||||
$nick = trim($request->get('eNick'));
|
$nick = trim($request->get('eNick'));
|
||||||
$nickValid = (new Username())->validate($nick);
|
$nickValid = (new Username())->validate($nick);
|
||||||
|
|
||||||
if ($nickValid) {
|
$changed_nick = false;
|
||||||
|
$old_nick = $user_source->name;
|
||||||
|
if ($nickValid && $user_edit) {
|
||||||
|
$changed_nick = $user_source->name !== $nick;
|
||||||
$user_source->name = $nick;
|
$user_source->name = $nick;
|
||||||
}
|
}
|
||||||
$user_source->save();
|
$user_source->save();
|
||||||
|
@ -324,7 +331,11 @@ function admin_user()
|
||||||
$user_source->state->save();
|
$user_source->state->save();
|
||||||
|
|
||||||
engelsystem_log(
|
engelsystem_log(
|
||||||
'Updated user: ' . $user_source->name . ' (' . $user_source->id . ')'
|
'Updated user: ' . ($changed_nick
|
||||||
|
? ('nick modified form ' . $old_nick . ' to ' . $user_source->name)
|
||||||
|
: $user_source->name)
|
||||||
|
. ' (' . $user_source->id . ')'
|
||||||
|
. ($changed_email ? ', email modified' : '')
|
||||||
. ($goodie_tshirt ? ', t-shirt-size: ' . $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
|
||||||
|
|
Loading…
Reference in New Issue