mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Fixed some localization strings Reviewed/optimized product deletion handling Add option to hide products from the stock overview page (closes #906) Prefill default_due_days also on the inventory page (closes #591) Added DataTables accent chinese-string plugin (closes #872) Show costs and calories per recipe ingredient (closes #1072) Fixed user permission saving (fixes #1099) User permissions should not have an effect for demo mode (closes #972) Handle QU conversion when consuming a substituation (child) product (fixes #1118) Consume/open any child product when the parent product is not in stock (closes #899) Added a retry camera barcode scanning button to product picker workflow (closes #736)
110 lines
2.8 KiB
PHP
110 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Grocy\Controllers\Users;
|
|
|
|
use Grocy\Services\DatabaseService;
|
|
use LessQL\Result;
|
|
|
|
class User
|
|
{
|
|
const PERMISSION_ADMIN = 'ADMIN';
|
|
|
|
const PERMISSION_BATTERIES = 'BATTERIES';
|
|
const PERMISSION_BATTERIES_TRACK_CHARGE_CYCLE = 'BATTERIES_TRACK_CHARGE_CYCLE';
|
|
const PERMISSION_BATTERIES_UNDO_CHARGE_CYCLE = 'BATTERIES_UNDO_CHARGE_CYCLE';
|
|
|
|
const PERMISSION_CALENDAR = 'CALENDAR';
|
|
|
|
const PERMISSION_CHORES = 'CHORES';
|
|
const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION';
|
|
const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION';
|
|
|
|
const PERMISSION_EQUIPMENT = 'EQUIPMENT';
|
|
|
|
const PERMISSION_MASTER_DATA_EDIT = 'MASTER_DATA_EDIT';
|
|
|
|
const PERMISSION_RECIPES = 'RECIPES';
|
|
const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN';
|
|
|
|
const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST';
|
|
const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD';
|
|
const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE';
|
|
|
|
const PERMISSION_STOCK = 'STOCK';
|
|
const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME';
|
|
const PERMISSION_STOCK_EDIT = 'STOCK_EDIT';
|
|
const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY';
|
|
const PERMISSION_STOCK_OPEN = 'STOCK_OPEN';
|
|
const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE';
|
|
const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER';
|
|
|
|
const PERMISSION_TASKS = 'TASKS';
|
|
const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED';
|
|
const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION';
|
|
|
|
const PERMISSION_USERS = 'USERS';
|
|
const PERMISSION_USERS_CREATE = 'USERS_CREATE';
|
|
const PERMISSION_USERS_EDIT = 'USERS_EDIT';
|
|
const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF';
|
|
const PERMISSION_USERS_READ = 'USERS_READ';
|
|
|
|
/**
|
|
* @var \LessQL\Database|null
|
|
*/
|
|
protected $db;
|
|
|
|
public static function PermissionList()
|
|
{
|
|
$user = new self();
|
|
return $user->getPermissionList();
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
$this->db = DatabaseService::getInstance()->GetDbConnection();
|
|
}
|
|
|
|
public static function checkPermission($request, string ...$permissions): void
|
|
{
|
|
$user = new self();
|
|
|
|
foreach ($permissions as $permission)
|
|
{
|
|
if (!$user->hasPermission($permission))
|
|
{
|
|
throw new PermissionMissingException($request, $permission);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getPermissionList()
|
|
{
|
|
return $this->db->uihelper_user_permissions()->where('user_id', GROCY_USER_ID);
|
|
}
|
|
|
|
public function hasPermission(string $permission): bool
|
|
{
|
|
return $this->getPermissions()->where('permission_name', $permission)->fetch() !== null;
|
|
}
|
|
|
|
public static function hasPermissions(string ...$permissions)
|
|
{
|
|
$user = new self();
|
|
|
|
foreach ($permissions as $permission)
|
|
{
|
|
if (!$user->hasPermission($permission))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected function getPermissions(): Result
|
|
{
|
|
return $this->db->user_permissions_resolved()->where('user_id', GROCY_USER_ID);
|
|
}
|
|
}
|