743 lines
17 KiB
PHP
743 lines
17 KiB
PHP
<?php
|
|
|
|
use KupShop\AdminBundle\AdminRegister\AdminRegisterLocator;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
|
|
class UserRights
|
|
{
|
|
private static $adminRegisterLocator;
|
|
|
|
public static function getAdminRegisterLocator(): AdminRegisterLocator
|
|
{
|
|
if (!isset(self::$adminRegisterLocator)) {
|
|
self::$adminRegisterLocator = ServiceContainer::getService(AdminRegisterLocator::class);
|
|
}
|
|
|
|
return self::$adminRegisterLocator;
|
|
}
|
|
|
|
public static function hasRights($type, $specific = '')
|
|
{
|
|
$item = self::getAdminRegisterLocator()->getPermissions($type) ?? getVal($type, self::$rights);
|
|
|
|
if (!$item) {
|
|
// logError(__FILE__, __LINE__, "Nonexisting user right: $type");
|
|
return true;
|
|
}
|
|
|
|
if (!empty($item['superadmin']) && !isSuperuser()) {
|
|
return false;
|
|
}
|
|
|
|
if (!empty($item['modules']) || !empty($item['submodules'])) {
|
|
$allow = false;
|
|
foreach ($item['modules'] ?? [] as $module) {
|
|
if (findModule($module)) {
|
|
$allow |= true;
|
|
}
|
|
}
|
|
|
|
foreach ($item['submodules'] ?? [] as $module => $submodule) {
|
|
if (findModule($module, $submodule)) {
|
|
$allow |= true;
|
|
}
|
|
}
|
|
|
|
if (!$allow) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (empty($item['rights'])) {
|
|
return true;
|
|
}
|
|
|
|
foreach ($item['rights'] as $right) {
|
|
if (substr($right, -1) == '_') {
|
|
if (findRight($right.$specific)) {
|
|
return true;
|
|
}
|
|
} elseif (findRight($right)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static function isOnlySuperadmin($type)
|
|
{
|
|
$item = self::getAdminRegisterLocator()->getPermissions($type) ?? getVal($type, self::$rights);
|
|
if (!$item) {
|
|
return false;
|
|
}
|
|
|
|
if (!empty($item['superadmin']) && $item['superadmin'] === true) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function addRights($list, $rights = [])
|
|
{
|
|
self::$rights[$list] = $rights;
|
|
}
|
|
|
|
protected static $rights = [
|
|
'productsRelatedTypes' => [
|
|
'submodules' => [
|
|
Modules::PRODUCTS_RELATED => Modules::SUB_TYPES,
|
|
],
|
|
'superadmin' => true,
|
|
],
|
|
'products' => [
|
|
'modules' => [
|
|
'products',
|
|
],
|
|
'rights' => [
|
|
'PROD_',
|
|
],
|
|
],
|
|
'productsMassModification' => [
|
|
'modules' => [
|
|
'products',
|
|
],
|
|
'rights' => [
|
|
'PROD_EDIT',
|
|
'PROD_ERASE',
|
|
],
|
|
],
|
|
'parameters' => [
|
|
'modules' => [
|
|
'products_parameters',
|
|
],
|
|
'rights' => [
|
|
'PARAM',
|
|
],
|
|
],
|
|
'productsVarLabels' => [
|
|
'modules' => [
|
|
'products_variations',
|
|
],
|
|
'rights' => [
|
|
'VARIANT_LABELS',
|
|
],
|
|
],
|
|
'sections' => [
|
|
'modules' => [
|
|
'products_sections',
|
|
],
|
|
'rights' => [
|
|
'SEC_',
|
|
],
|
|
],
|
|
'producers' => [
|
|
'modules' => [
|
|
'producers',
|
|
],
|
|
'rights' => [
|
|
'PRODCR',
|
|
],
|
|
],
|
|
'orders' => [
|
|
'modules' => [
|
|
'orders',
|
|
],
|
|
'rights' => [
|
|
'ORDER_',
|
|
],
|
|
],
|
|
'ProductsSerialNumbers' => [
|
|
'modules' => [
|
|
'products_serial_numbers',
|
|
'stock_in',
|
|
],
|
|
'rights' => [
|
|
'PSERNUM',
|
|
],
|
|
],
|
|
'ProductsBatches' => [
|
|
'modules' => [
|
|
Modules::PRODUCTS_BATCHES,
|
|
Modules::WAREHOUSE,
|
|
],
|
|
'rights' => [
|
|
'PBATCHES',
|
|
],
|
|
],
|
|
'users' => [
|
|
'modules' => [
|
|
'eshop_users',
|
|
],
|
|
'rights' => [
|
|
'USR_',
|
|
],
|
|
],
|
|
|
|
'discounts' => [
|
|
'modules' => [
|
|
'order_discount',
|
|
],
|
|
'rights' => [
|
|
'DISCNT',
|
|
],
|
|
],
|
|
'ordersMassProcess' => [
|
|
'modules' => [
|
|
'orders_mass_process',
|
|
],
|
|
'rights' => [
|
|
'ORDER',
|
|
],
|
|
],
|
|
'photos' => [
|
|
'modules' => [
|
|
'photos',
|
|
],
|
|
'rights' => [
|
|
'PHOTOS_',
|
|
],
|
|
],
|
|
'fileBrowser' => [
|
|
'rights' => [
|
|
'FILE_BROWSER_USE',
|
|
],
|
|
],
|
|
'stockIn' => [
|
|
'modules' => [
|
|
'stock_in',
|
|
],
|
|
'rights' => [
|
|
'INSTORE_STOCKIN',
|
|
],
|
|
],
|
|
'suppliers' => [
|
|
'modules' => [
|
|
'products_suppliers',
|
|
'automatic_import',
|
|
'suppliers',
|
|
],
|
|
'rights' => [
|
|
'INSTORE_STOCKIN',
|
|
],
|
|
],
|
|
'stockInMissing' => [
|
|
'modules' => [
|
|
'missing_products',
|
|
],
|
|
'rights' => [
|
|
'INSTORE_MISSING',
|
|
],
|
|
],
|
|
'InfoPanelList' => [
|
|
'modules' => [
|
|
],
|
|
'rights' => [
|
|
'INFOPANEL',
|
|
],
|
|
],
|
|
'shopStore' => [
|
|
'modules' => [
|
|
],
|
|
'rights' => [
|
|
'MODULOVNA',
|
|
],
|
|
],
|
|
'ReturnDelivery' => [
|
|
'modules' => [
|
|
],
|
|
'rights' => [
|
|
'RETURNS',
|
|
],
|
|
],
|
|
'LabelsList' => [
|
|
'modules' => [
|
|
Modules::LABELS,
|
|
],
|
|
'rights' => [
|
|
'LABELS',
|
|
],
|
|
],
|
|
|
|
'templatesMenu' => [
|
|
'modules' => [
|
|
'templates',
|
|
],
|
|
'rights' => [
|
|
'PRODUCT_TEMPLATES',
|
|
],
|
|
],
|
|
'BonusProgramExchange' => [
|
|
'submodules' => [
|
|
Modules::BONUS_PROGRAM => Modules::SUB_POINTS_EXCHANGE,
|
|
],
|
|
'rights' => [
|
|
'BONUS_PROGRAM_EXCHANGE',
|
|
],
|
|
],
|
|
|
|
'Sales' => [
|
|
'modules' => [
|
|
Modules::SALES,
|
|
],
|
|
'rights' => [
|
|
'SALES',
|
|
],
|
|
],
|
|
|
|
'productsOfSuppliers' => [
|
|
'modules' => [
|
|
'stock_in',
|
|
'products_suppliers',
|
|
'suppliers',
|
|
],
|
|
'rights' => [
|
|
'INSTORE_STOCKIN',
|
|
],
|
|
],
|
|
'inventory' => [
|
|
'modules' => [
|
|
'inventory',
|
|
],
|
|
'rights' => [
|
|
'INVENTORY',
|
|
],
|
|
],
|
|
'productsPrices' => [
|
|
'submodules' => [
|
|
Modules::PRODUCTS => Modules::SUB_PRICE_BUY,
|
|
],
|
|
'rights' => [
|
|
'INVENTORY',
|
|
],
|
|
],
|
|
'stockManual' => [
|
|
'modules' => [
|
|
'stock_in',
|
|
],
|
|
'rights' => [
|
|
'INSTORE_STOCKIN',
|
|
],
|
|
],
|
|
'pages' => [
|
|
'modules' => [
|
|
'menulinks',
|
|
],
|
|
'rights' => [
|
|
'MENU_LINKS',
|
|
],
|
|
],
|
|
'menu' => [
|
|
'modules' => [
|
|
'menulinks',
|
|
],
|
|
'rights' => [
|
|
'MENU_LINKS',
|
|
],
|
|
],
|
|
'sliders' => [
|
|
'modules' => [
|
|
'sliders',
|
|
],
|
|
'rights' => [
|
|
'SLIDERS',
|
|
],
|
|
],
|
|
'articles' => [
|
|
'modules' => [
|
|
'articles',
|
|
],
|
|
'rights' => [
|
|
'ART_',
|
|
],
|
|
],
|
|
'artsections' => [
|
|
'modules' => [
|
|
'articles_sections',
|
|
],
|
|
'rights' => [
|
|
'ART_SEC_',
|
|
],
|
|
],
|
|
'articlesTags' => [
|
|
'modules' => [
|
|
'articles',
|
|
],
|
|
'rights' => [
|
|
'ART_',
|
|
],
|
|
],
|
|
'artauthors' => [
|
|
'modules' => [
|
|
Modules::ARTICLES_AUTHORS,
|
|
],
|
|
'rights' => [
|
|
'ART_AUTH_',
|
|
],
|
|
],
|
|
'dbbackup' => [
|
|
'modules' => [
|
|
'dbbackup',
|
|
],
|
|
'rights' => [
|
|
'OTH_BACKUP_',
|
|
],
|
|
],
|
|
'stats' => [
|
|
'modules' => [
|
|
'stats',
|
|
],
|
|
'rights' => [
|
|
'STAT',
|
|
],
|
|
],
|
|
'import-generic' => [
|
|
'modules' => [
|
|
'products',
|
|
],
|
|
'rights' => [
|
|
'IMPRT',
|
|
],
|
|
],
|
|
'import_automatic' => [
|
|
'modules' => [
|
|
'automatic_import',
|
|
],
|
|
'rights' => [
|
|
'IMPRT',
|
|
],
|
|
],
|
|
'import-xml_feed' => [
|
|
'modules' => [
|
|
'products',
|
|
],
|
|
'rights' => [
|
|
'IMPRT',
|
|
],
|
|
'superadmin' => true,
|
|
],
|
|
'import-xml_feed_new' => [
|
|
'modules' => [
|
|
'products',
|
|
],
|
|
'rights' => [
|
|
'IMPRT',
|
|
],
|
|
// 'superadmin' => true,
|
|
],
|
|
'orderPayment' => [
|
|
'modules' => [
|
|
'order_payment',
|
|
],
|
|
'rights' => [
|
|
'ORDER_PAYMENT',
|
|
'POS_',
|
|
],
|
|
],
|
|
'admins' => [
|
|
'modules' => [
|
|
],
|
|
'rights' => [
|
|
'OTH_ADM_',
|
|
],
|
|
],
|
|
'settings' => [
|
|
'modules' => [
|
|
],
|
|
'rights' => [
|
|
'OTH_SET_',
|
|
],
|
|
],
|
|
'delivery_type' => [
|
|
'modules' => [
|
|
'eshop_delivery',
|
|
],
|
|
'rights' => [
|
|
'DELVR',
|
|
],
|
|
],
|
|
'deliveryDelivery' => [
|
|
'modules' => [
|
|
'eshop_delivery',
|
|
],
|
|
'rights' => [
|
|
'DELVR',
|
|
],
|
|
],
|
|
'deliveryPayment' => [
|
|
'modules' => [
|
|
'eshop_delivery',
|
|
],
|
|
'rights' => [
|
|
'DELVR',
|
|
],
|
|
],
|
|
'vats' => [
|
|
'modules' => [
|
|
'products',
|
|
],
|
|
'rights' => [
|
|
'VAT',
|
|
],
|
|
],
|
|
'priceLevels' => [
|
|
'modules' => [
|
|
'price_levels',
|
|
],
|
|
'rights' => [
|
|
'PRICELEVELS',
|
|
],
|
|
],
|
|
'currencies' => [
|
|
'modules' => [
|
|
'currencies',
|
|
],
|
|
'rights' => [
|
|
'CURRENCY',
|
|
],
|
|
],
|
|
'automatic_import' => [
|
|
'modules' => [
|
|
'automatic_import',
|
|
],
|
|
'rights' => [
|
|
'IMPRT',
|
|
],
|
|
],
|
|
'export_orders' => [
|
|
'modules' => [
|
|
'orders',
|
|
],
|
|
'rights' => [
|
|
'EXPRT',
|
|
],
|
|
],
|
|
'export_products' => [
|
|
'modules' => [
|
|
'export',
|
|
],
|
|
'rights' => [
|
|
'EXPRT',
|
|
],
|
|
],
|
|
'export_selling_products' => [
|
|
'modules' => [
|
|
'orders',
|
|
],
|
|
'rights' => [
|
|
'EXPRT',
|
|
],
|
|
],
|
|
'export_users' => [
|
|
'modules' => [
|
|
'eshop_users',
|
|
],
|
|
'rights' => [
|
|
'EXPRT',
|
|
],
|
|
],
|
|
'ordersOfSuppliers' => [
|
|
'modules' => [
|
|
'orders_of_suppliers',
|
|
],
|
|
'rights' => [
|
|
'INSTORE_STOCKIN',
|
|
],
|
|
// 'superadmin' => true,
|
|
],
|
|
'replacement' => [
|
|
'modules' => [
|
|
'replacement',
|
|
],
|
|
'rights' => [
|
|
'ORDER_',
|
|
],
|
|
],
|
|
'templates' => [
|
|
'modules' => [
|
|
'templates',
|
|
],
|
|
'rights' => [
|
|
'PROD_',
|
|
],
|
|
],
|
|
'templatesCategories' => [
|
|
'modules' => [
|
|
'templates',
|
|
],
|
|
'rights' => [
|
|
'PROD_',
|
|
],
|
|
],
|
|
'templatesProducts' => [
|
|
'modules' => [
|
|
'templates',
|
|
],
|
|
'rights' => [
|
|
'PROD_',
|
|
],
|
|
],
|
|
'pos' => [
|
|
'rights' => [
|
|
'POS_',
|
|
],
|
|
'modules' => [
|
|
'new_pos',
|
|
],
|
|
],
|
|
'old_pos' => [
|
|
'rights' => [
|
|
'POS_',
|
|
],
|
|
'modules' => [
|
|
'pos',
|
|
],
|
|
],
|
|
'usersGroups' => [
|
|
'modules' => [
|
|
'eshop_users',
|
|
],
|
|
'rights' => [
|
|
'USER_GROUPS',
|
|
],
|
|
],
|
|
'cleaning' => [
|
|
'superadmin' => true,
|
|
],
|
|
'htmlComponents' => [
|
|
'superadmin' => true,
|
|
],
|
|
'languageCheckAdmin' => [
|
|
'superadmin' => true,
|
|
],
|
|
'balikonos' => [
|
|
'rights' => [
|
|
'ORDER_',
|
|
],
|
|
'modules' => [
|
|
'balikonos',
|
|
],
|
|
],
|
|
'balikobot' => [
|
|
'rights' => [
|
|
'BALIKOBOT',
|
|
],
|
|
],
|
|
'BalikonosOrders' => [
|
|
'rights' => [
|
|
'ORDER_',
|
|
],
|
|
'modules' => [
|
|
'balikonos',
|
|
],
|
|
],
|
|
'restrictions' => [
|
|
'rights' => [
|
|
'RESTR',
|
|
],
|
|
'modules' => [
|
|
'restrictions',
|
|
],
|
|
],
|
|
'reviews' => [
|
|
'rights' => [
|
|
'REVIEWS',
|
|
],
|
|
'modules' => [
|
|
'reviews',
|
|
],
|
|
],
|
|
'sellers' => [
|
|
'rights' => [
|
|
'SELLERS',
|
|
],
|
|
'modules' => [
|
|
'sellers',
|
|
'sellers_old',
|
|
],
|
|
],
|
|
'margins' => [
|
|
'rights' => [
|
|
'MARGINS',
|
|
],
|
|
'modules' => [
|
|
'margins',
|
|
],
|
|
],
|
|
'preOrders' => [
|
|
'rights' => [
|
|
'ORDER_',
|
|
],
|
|
],
|
|
'emails' => [
|
|
'modules' => [
|
|
'orders',
|
|
'forms',
|
|
],
|
|
'rights' => [
|
|
'OTH_EMAILS_',
|
|
],
|
|
],
|
|
'fulltext' => [
|
|
'modules' => [
|
|
'eshop_search',
|
|
],
|
|
'rights' => [
|
|
'FULLTEXT_SEARCH',
|
|
],
|
|
],
|
|
'translate' => [
|
|
'rights' => [
|
|
'TRANSLATE_',
|
|
],
|
|
],
|
|
'translationsStats' => [
|
|
'rights' => [
|
|
'TRANSLATE_',
|
|
],
|
|
],
|
|
'countries' => [
|
|
'rights' => [
|
|
'COUNTRY',
|
|
],
|
|
],
|
|
'languages' => [
|
|
'superadmin' => true,
|
|
'rights' => [
|
|
'LANGUAGE',
|
|
],
|
|
],
|
|
'feeds' => [
|
|
'modules' => [
|
|
'feeds',
|
|
],
|
|
'rights' => [
|
|
'FEEDS',
|
|
],
|
|
],
|
|
'pricelist' => [
|
|
'rights' => [
|
|
'PRICELISTS',
|
|
],
|
|
],
|
|
'invoices' => [
|
|
'modules' => [
|
|
'invoices',
|
|
],
|
|
'rights' => [
|
|
'ORDER_INVOICE', // fakturovat objednavky
|
|
'INVOICE', // spravovat fakturacni rady
|
|
],
|
|
],
|
|
'LlmPrompt' => [
|
|
'modules' => [
|
|
'llm',
|
|
],
|
|
'rights' => [
|
|
'LLM_',
|
|
],
|
|
],
|
|
];
|
|
}
|