Skip to content

Commit

Permalink
Allow admins to change member usernames
Browse files Browse the repository at this point in the history
rjackson committed Sep 5, 2024

Verified

This commit was signed with the committer’s verified signature.
rjackson Rob Jackson
1 parent 1e80837 commit 33b37da
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
@@ -340,6 +340,11 @@ public function update($id)
'suppress_real_name'
);

// TODO: Move to proper validators and 'validated' output?
if (!\Auth::user()->can('changeUsername', $user)) {
unset($input['display_name']);
}

$this->userForm->validate($input, $user->id);

$this->userRepository->updateMember($id, $input, \Auth::user()->hasRole('admin'));
5 changes: 5 additions & 0 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
@@ -25,4 +25,9 @@ public function unban(User $authedUser, User $user)
// Admins can ban others
return $authedUser->isAdmin();
}

public function changeUsername(User $authedUser, User $user)
{
return $authedUser->isAdmin();
}
}
2 changes: 1 addition & 1 deletion app/Validators/UserValidator.php
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ class UserValidator extends FormValidator
'email' => 'required|email|unique:users,email,{id}',
'secondary_email' => 'email|unique:users,secondary_email,{id}',
'password' => 'min:8',
'display_name' => '',
'display_name' => 'unique:users,display_name,{id}',
'monthly_subscription' => '',
'rules_agreed' => '',
];
2 changes: 1 addition & 1 deletion resources/views/account/edit.blade.php
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
<div class="col-xs-12 col-md-8">
<div class="form-group {{ FlashNotification::hasErrorDetail('display_name', 'has-error has-feedback') }}">
{!! Form::label('display_name', 'Username') !!}
{!! Form::text('display_name', null, ['class'=>'form-control', 'autocomplete'=>'off', 'readonly'=>'readonly']) !!}
{!! Form::text('display_name', null, ['class'=>'form-control', 'autocomplete'=>'off', 'readonly'=> !Auth::user()->can('changeUsername', $user) ]) !!}
<span class="help-block">Your Username will be used for display purposes on the members system, it cannot be changed once set without contacting the board </span>
{!! FlashNotification::getErrorDetail('display_name') !!}
</div>

0 comments on commit 33b37da

Please sign in to comment.