Allow users to hand out admin rights.

This commit is contained in:
James Cole
2020-03-23 17:54:49 +01:00
parent 76c89a8efa
commit d6797b8428
7 changed files with 30 additions and 8 deletions

View File

@@ -106,6 +106,8 @@ class UserController extends Controller
$subTitle = (string) trans('firefly.edit_user', ['email' => $user->email]); $subTitle = (string) trans('firefly.edit_user', ['email' => $user->email]);
$subTitleIcon = 'fa-user-o'; $subTitleIcon = 'fa-user-o';
$currentUser = auth()->user();
$isAdmin = $this->repository->hasRole($user, 'owner');
$codes = [ $codes = [
'' => (string) trans('firefly.no_block_code'), '' => (string) trans('firefly.no_block_code'),
'bounced' => (string) trans('firefly.block_code_bounced'), 'bounced' => (string) trans('firefly.block_code_bounced'),
@@ -113,7 +115,7 @@ class UserController extends Controller
'email_changed' => (string) trans('firefly.block_code_email_changed'), 'email_changed' => (string) trans('firefly.block_code_email_changed'),
]; ];
return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon', 'codes')); return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon', 'codes', 'currentUser','isAdmin'));
} }
/** /**
@@ -183,6 +185,13 @@ class UserController extends Controller
if ('' !== $data['password']) { if ('' !== $data['password']) {
$this->repository->changePassword($user, $data['password']); $this->repository->changePassword($user, $data['password']);
} }
if (true === $data['is_owner']) {
$this->repository->attachRole($user, 'owner');
session()->flash('info', trans('firefly.give_admin_careful'));
}
if (false === $data['is_owner']) {
$this->repository->removeRole($user, 'owner');
}
$this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']); $this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
$this->repository->updateEmail($user, $data['email']); $this->repository->updateEmail($user, $data['email']);

View File

@@ -52,6 +52,7 @@ class UserFormRequest extends Request
'blocked' => 1 === $this->integer('blocked'), 'blocked' => 1 === $this->integer('blocked'),
'blocked_code' => $this->string('blocked_code'), 'blocked_code' => $this->string('blocked_code'),
'password' => $this->string('password'), 'password' => $this->string('password'),
'is_owner' => 1 === $this->integer('is_owner'),
]; ];
} }
@@ -68,6 +69,7 @@ class UserFormRequest extends Request
'password' => 'confirmed|secure_password', 'password' => 'confirmed|secure_password',
'blocked_code' => 'between:0,30|nullable', 'blocked_code' => 'between:0,30|nullable',
'blocked' => 'between:0,1|numeric', 'blocked' => 'between:0,1|numeric',
'is_owner' => 'between:0,1|numeric',
]; ];
} }
} }

View File

@@ -294,10 +294,15 @@ class UserRepository implements UserRepositoryInterface
* Remove any role the user has. * Remove any role the user has.
* *
* @param User $user * @param User $user
* @param string $role
*/ */
public function removeRole(User $user): void public function removeRole(User $user, string $role): void
{ {
$user->roles()->sync([]); $roleObj = $this->getRole($role);
if (null === $roleObj) {
return;
}
$user->roles()->detach($roleObj->id);
} }
/** /**
@@ -364,7 +369,8 @@ class UserRepository implements UserRepositoryInterface
$user->blocked_code = $data['blocked_code']; $user->blocked_code = $data['blocked_code'];
} }
if (isset($data['role']) && '' === $data['role']) { if (isset($data['role']) && '' === $data['role']) {
$this->removeRole($user); $this->removeRole($user, 'owner');
$this->removeRole($user, 'demo');
} }
$user->save(); $user->save();

View File

@@ -158,8 +158,9 @@ interface UserRepositoryInterface
* Remove any role the user has. * Remove any role the user has.
* *
* @param User $user * @param User $user
* @param string $role
*/ */
public function removeRole(User $user): void; public function removeRole(User $user, string $role): void;
/** /**
* Set MFA code. * Set MFA code.

View File

@@ -1351,6 +1351,7 @@ return [
'send_test_email_text' => 'To see if your installation is capable of sending email, please press this button. You will not see an error here (if any), <strong>the log files will reflect any errors</strong>. You can press this button as many times as you like. There is no spam control. The message will be sent to <code>:email</code> and should arrive shortly.', 'send_test_email_text' => 'To see if your installation is capable of sending email, please press this button. You will not see an error here (if any), <strong>the log files will reflect any errors</strong>. You can press this button as many times as you like. There is no spam control. The message will be sent to <code>:email</code> and should arrive shortly.',
'send_message' => 'Send message', 'send_message' => 'Send message',
'send_test_triggered' => 'Test was triggered. Check your inbox and the log files.', 'send_test_triggered' => 'Test was triggered. Check your inbox and the log files.',
'give_admin_careful' => 'Users who are given admin rights can take away yours. Be careful.',
'split_transaction_title' => 'Description of the split transaction', 'split_transaction_title' => 'Description of the split transaction',
'split_transaction_title_help' => 'If you create a split transaction, there must be a global description for all splits of the transaction.', 'split_transaction_title_help' => 'If you create a split transaction, there must be a global description for all splits of the transaction.',

View File

@@ -194,6 +194,7 @@ return [
'blocked' => 'Is blocked?', 'blocked' => 'Is blocked?',
'blocked_code' => 'Reason for block', 'blocked_code' => 'Reason for block',
'login_name' => 'Login', 'login_name' => 'Login',
'is_owner' => 'Is admin?',
// import // import
'apply_rules' => 'Apply rules', 'apply_rules' => 'Apply rules',

View File

@@ -22,7 +22,9 @@
{{ ExpandedForm.password('password_confirmation') }} {{ ExpandedForm.password('password_confirmation') }}
{{ ExpandedForm.checkbox('blocked') }} {{ ExpandedForm.checkbox('blocked') }}
{{ ExpandedForm.select('blocked_code', codes, user.blocked_code) }} {{ ExpandedForm.select('blocked_code', codes, user.blocked_code) }}
{% if user.id != currentUser.id %}
{{ ExpandedForm.checkbox('is_owner',1,isAdmin) }}
{% endif %}
</div> </div>
</div> </div>
</div> </div>