From de3907eabca7d3744dba13eadbbe2f45f4f1441d Mon Sep 17 00:00:00 2001 From: fipwmaqzufheoxq92ebc <29818044+fipwmaqzufheoxq92ebc@users.noreply.github.com> Date: Fri, 28 Aug 2020 16:18:21 +0200 Subject: [PATCH] Add default permissions for new users --- config-dist.php | 2 ++ services/UsersService.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config-dist.php b/config-dist.php index b8bc56c1..476eaa46 100644 --- a/config-dist.php +++ b/config-dist.php @@ -172,3 +172,5 @@ Setting('FEATURE_FLAG_CHORES_ASSIGNMENTS', true); # Feature settings Setting('FEATURE_SETTING_STOCK_COUNT_OPENED_PRODUCTS_AGAINST_MINIMUM_STOCK_AMOUNT', true); // When set to true opened items will be counted as missing from stock when calculating if a product is below its minimum. Setting('FEATURE_FLAG_AUTO_TORCH_ON_WITH_CAMERA', true); // Enables the torch automaticaly in every camera barcode scanner. + +Setting('DEFAULT_PERMISSIONS', ['ADMIN']); \ No newline at end of file diff --git a/services/UsersService.php b/services/UsersService.php index 42f298d2..b6b2face 100644 --- a/services/UsersService.php +++ b/services/UsersService.php @@ -12,7 +12,17 @@ class UsersService extends BaseService 'last_name' => $lastName, 'password' => password_hash($password, PASSWORD_DEFAULT) )); - return $newUserRow->save(); + $newUserRow = $newUserRow->save(); + $permList = array(); + foreach ($this->getDatabase()->permission_hierarchy()->where('name', GROCY_DEFAULT_PERMISSIONS)->fetchAll() as $perm) { + $permList[] = array( + 'user_id' => $newUserRow->id, + 'permission_id' => $perm->id + ); + } + $this->getDatabase()->user_permissions()->insert($permList); + + return $newUserRow; } public function EditUser(int $userId, string $username, string $firstName, string $lastName, string $password)