diff --git a/config-dist.php b/config-dist.php index 3f914c31..b8bc56c1 100644 --- a/config-dist.php +++ b/config-dist.php @@ -172,7 +172,3 @@ 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('USER_CLASS', '\Grocy\Controllers\Users\DefaultUser'); \ No newline at end of file diff --git a/controllers/Users/AllowedUser.php b/controllers/Users/AllowedUser.php deleted file mode 100644 index 88e76ca3..00000000 --- a/controllers/Users/AllowedUser.php +++ /dev/null @@ -1,14 +0,0 @@ -db = DatabaseService::getInstance()->GetDbConnection(); - - } - - protected function getPermissions(): Result - { - return $this->db->permission_check()->where('user_id', GROCY_USER_ID); - } - - public function hasPermission(string $permission): bool - { - return $this->getPermissions()->where('permission_name', $permission)->fetch() != null; - } -} \ No newline at end of file diff --git a/controllers/Users/LockedUser.php b/controllers/Users/LockedUser.php deleted file mode 100644 index f325d24c..00000000 --- a/controllers/Users/LockedUser.php +++ /dev/null @@ -1,14 +0,0 @@ -db = DatabaseService::getInstance()->GetDbConnection(); + + } + + protected function getPermissions(): Result + { + return $this->db->permission_check()->where('user_id', GROCY_USER_ID); + } + + public function hasPermission(string $permission): bool + { + // global $PERMISSION_CACHE; + // if(isset($PERMISSION_CACHE[$permission])) + // return $PERMISSION_CACHE[$permission]; + return $this->getPermissions()->where('permission_name', $permission)->fetch() !== null; + } public static function checkPermission($request, string ...$permissions): void { - $user_class = GROCY_USER_CLASS; - $user = new $user_class(); - assert($user instanceof User, 'Please check the Setting USER_CLASS: It should be an implementation of User'); + $user = new User(); foreach ($permissions as $permission) { if (!$user->hasPermission($permission)) { throw new PermissionMissingException($request, $permission); } } + } + public function getPermissionList() + { + return $this->db->uihelper_permission()->where('user_id', GROCY_USER_ID); + } + + public static function hasPermissions(string ...$permissions) + { + $user = new User(); + foreach ($permissions as $permission) { + if (!$user->hasPermission($permission)) { + return false; + } + } + return true; + } + + public static function PermissionList() + { + $user = new User(); + return $user->getPermissionList(); + } } +