// Fix bug on auths for sub employees #PSFV-849
This commit is contained in:
+18
-15
@@ -103,30 +103,33 @@ try
|
|||||||
|
|
||||||
$shop_id = '';
|
$shop_id = '';
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
if ($context->cookie->shopContext)
|
if ($this->context->cookie->shopContext)
|
||||||
{
|
{
|
||||||
$split = explode('-', $context->cookie->shopContext);
|
$split = explode('-', $this->context->cookie->shopContext);
|
||||||
if (count($split) == 2)
|
if (count($split) == 2)
|
||||||
{
|
{
|
||||||
if ($split[0] == 'g')
|
if ($split[0] == 'g')
|
||||||
Shop::setContext(Shop::CONTEXT_GROUP, $split[1]);
|
{
|
||||||
|
if ($this->context->employee->hasAuthOnShopGroup($split[1]))
|
||||||
|
Shop::setContext(Shop::CONTEXT_GROUP, $split[1]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$shop_id = $this->context->employee->getDefaultShopID();
|
||||||
|
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ($this->context->employee->hasAuthOnShop($split[1]))
|
||||||
|
{
|
||||||
|
$shop_id = $split[1];
|
||||||
|
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Shop::setContext(Shop::CONTEXT_SHOP, $split[1]);
|
$shop_id = $this->context->employee->getDefaultShopID();
|
||||||
$shop_id = $split[1];
|
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($context->employee->id_profile == _PS_ADMIN_PROFILE_)
|
|
||||||
$shop_id = '';
|
|
||||||
else if (Shop::getTotalShops(false) != Employee::getTotalEmployeeShopById((int)$context->employee->id))
|
|
||||||
{
|
|
||||||
$shops = Employee::getEmployeeShopById((int)$context->employee->id);
|
|
||||||
if (count($shops))
|
|
||||||
$shop_id = (int)$shops[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Employee::getEmployeeShopAccess((int)$context->employee->id);
|
|
||||||
|
|
||||||
// Replace existing shop if necessary
|
// Replace existing shop if necessary
|
||||||
if (!$shop_id)
|
if (!$shop_id)
|
||||||
|
|||||||
@@ -93,12 +93,13 @@
|
|||||||
function ifSuperAdmin(el)
|
function ifSuperAdmin(el)
|
||||||
{
|
{
|
||||||
var val = $(el).val();
|
var val = $(el).val();
|
||||||
if(val == {$smarty.const._PS_ADMIN_PROFILE_})
|
|
||||||
|
if (!val || val == {$smarty.const._PS_ADMIN_PROFILE_})
|
||||||
{
|
{
|
||||||
$('.assoShop input[type=checkbox]').attr('disabled', 'disabled');
|
$('.assoShop input[type=checkbox]').attr('disabled', true);
|
||||||
$('.assoShop input[type=checkbox]').attr('checked', 'checked');
|
$('.assoShop input[type=checkbox]').attr('checked', 'checked');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$('.assoShop input[type=checkbox]').attr('disabled', '');
|
$('.assoShop input[type=checkbox]').attr('disabled', false);
|
||||||
}
|
}
|
||||||
{/block}
|
{/block}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$().ready(function() {
|
$().ready(function() {
|
||||||
// Click on "all shop"
|
|
||||||
$('.input_all_shop').live('click', function() {
|
$('.input_all_shop').live('click', function() {
|
||||||
var checked = $(this).prop('checked');
|
var checked = $(this).prop('checked');
|
||||||
$('.input_shop_group:not(:disabled)').attr('checked', checked);
|
$('.input_shop_group:not(:disabled)').attr('checked', checked);
|
||||||
|
|||||||
+45
-45
@@ -97,7 +97,7 @@ class EmployeeCore extends ObjectModel
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $webserviceParameters = array(
|
protected $webserviceParameters = array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'id_lang' => array('xlink_resource' => 'languages'),
|
'id_lang' => array('xlink_resource' => 'languages'),
|
||||||
'last_passwd_gen' => array('setter' => null),
|
'last_passwd_gen' => array('setter' => null),
|
||||||
@@ -107,6 +107,16 @@ class EmployeeCore extends ObjectModel
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected $associated_shops = array();
|
||||||
|
|
||||||
|
public function __construct($id = null, $id_lang = null, $id_shop = null)
|
||||||
|
{
|
||||||
|
parent::__construct($id, $id_lang, $id_shop);
|
||||||
|
|
||||||
|
if ($this->id)
|
||||||
|
$this->associated_shops = $this->getAssociatedShops();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ObjectModel::getFields()
|
* @see ObjectModel::getFields()
|
||||||
* @return array
|
* @return array
|
||||||
@@ -253,57 +263,47 @@ class EmployeeCore extends ObjectModel
|
|||||||
$this->id = null;
|
$this->id = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEmployeeShopAccess($id_employee)
|
/**
|
||||||
|
* Check if the employee is associated to a specific shop
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
* @param int $id_shop
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasAuthOnShop($id_shop)
|
||||||
{
|
{
|
||||||
$context = Context::getContext();
|
return $this->id_profile == _PS_ADMIN_PROFILE_ || in_array($id_shop, $this->associated_shops);
|
||||||
|
|
||||||
switch (Shop::getContext())
|
|
||||||
{
|
|
||||||
case Shop::CONTEXT_SHOP:
|
|
||||||
if ($context->shop->checkIfShopExist(Shop::getContextShopID()))
|
|
||||||
{
|
|
||||||
if (!in_array($context->shop->id, Employee::getEmployeeShopById($id_employee)))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Shop::CONTEXT_GROUP:
|
|
||||||
if ($context->shop->checkIfShopGroupExist(Shop::getContextShopGroupID()))
|
|
||||||
{
|
|
||||||
$shops = Shop::getShops(false, Shop::getContextShopGroupID(), true);
|
|
||||||
foreach ($shops as $shop)
|
|
||||||
if (!in_array($shop, Employee::getEmployeeShopById($id_employee)))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Shop::CONTEXT_ALL:
|
|
||||||
if ($context->employee->id_profile == _PS_ADMIN_PROFILE_ ||
|
|
||||||
Shop::getTotalShops(false) == Employee::getTotalEmployeeShopById($id_employee))
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTotalEmployeeShopById($id)
|
/**
|
||||||
|
* Check if the employee is associated to a specific shop group
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
* @param int $id_shop_shop
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasAuthOnShopGroup($id_shop_group)
|
||||||
{
|
{
|
||||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'employee_shop` WHERE `id_employee` = '.(int)$id);
|
if ($this->id_profile == _PS_ADMIN_PROFILE_)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
foreach ($this->associated_shops as $id_shop)
|
||||||
|
if ($id_shop_group == Shop::getGroupFromShop($id_shop, true))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEmployeeShopById($id)
|
/**
|
||||||
|
* Get default id_shop with auth for current employee
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getDefaultShopID()
|
||||||
{
|
{
|
||||||
$result = Db::getInstance()->executeS('SELECT * FROM`'._DB_PREFIX_.'employee_shop` WHERE `id_employee` = '.(int)$id);
|
if ($this->id_profile == _PS_ADMIN_PROFILE_ || in_array(Configuration::get('PS_SHOP_DEFAULT'), $this->associated_shops))
|
||||||
$data = array();
|
return Configuration::get('PS_SHOP_DEFAULT');
|
||||||
foreach ($result as $group_data)
|
return $this->associated_shops[0];
|
||||||
$data[] = (int)$group_data['id_shop'];
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getEmployeesByProfile($id_profile, $active_only = false)
|
public static function getEmployeesByProfile($id_profile, $active_only = false)
|
||||||
|
|||||||
@@ -1076,6 +1076,24 @@ abstract class ObjectModelCore
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of associated id_shop
|
||||||
|
*
|
||||||
|
* @since 1.5.0
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAssociatedShops()
|
||||||
|
{
|
||||||
|
if (!Shop::isTableAssociated($this->def['table']))
|
||||||
|
return array();
|
||||||
|
|
||||||
|
$list = array();
|
||||||
|
$sql = 'SELECT id_shop FROM `'._DB_PREFIX_.$this->def['table'].'_shop` WHERE `'.$this->def['primary'].'` = '.(int)$this->id;
|
||||||
|
foreach (Db::getInstance()->executeS($sql) as $row)
|
||||||
|
$list[] = $row['id_shop'];
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1658,7 +1658,7 @@ class AdminControllerCore extends Controller
|
|||||||
$this->redirect_after = $url['path'].'?'.http_build_query($parse_query);
|
$this->redirect_after = $url['path'].'?'.http_build_query($parse_query);
|
||||||
}
|
}
|
||||||
elseif (!Shop::isFeatureActive())
|
elseif (!Shop::isFeatureActive())
|
||||||
$this->context->cookie->shopContext = 's-1';
|
$this->context->cookie->shopContext = 's-'.Configuration::get('PS_SHOP_DEFAULT');
|
||||||
|
|
||||||
$shop_id = '';
|
$shop_id = '';
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
@@ -1668,24 +1668,27 @@ class AdminControllerCore extends Controller
|
|||||||
if (count($split) == 2)
|
if (count($split) == 2)
|
||||||
{
|
{
|
||||||
if ($split[0] == 'g')
|
if ($split[0] == 'g')
|
||||||
Shop::setContext(Shop::CONTEXT_GROUP, $split[1]);
|
{
|
||||||
|
if ($this->context->employee->hasAuthOnShopGroup($split[1]))
|
||||||
|
Shop::setContext(Shop::CONTEXT_GROUP, $split[1]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$shop_id = $this->context->employee->getDefaultShopID();
|
||||||
|
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ($this->context->employee->hasAuthOnShop($split[1]))
|
||||||
|
{
|
||||||
|
$shop_id = $split[1];
|
||||||
|
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Shop::setContext(Shop::CONTEXT_SHOP, $split[1]);
|
$shop_id = $this->context->employee->getDefaultShopID();
|
||||||
$shop_id = $split[1];
|
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($this->context->employee->id_profile == _PS_ADMIN_PROFILE_)
|
|
||||||
$shop_id = '';
|
|
||||||
elseif (Shop::getTotalShops(false) != Employee::getTotalEmployeeShopById((int)$this->context->employee->id))
|
|
||||||
{
|
|
||||||
$shops = Employee::getEmployeeShopById((int)$this->context->employee->id);
|
|
||||||
if (count($shops))
|
|
||||||
$shop_id = (int)$shops[0];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Employee::getEmployeeShopAccess((int)$this->context->employee->id);
|
|
||||||
|
|
||||||
// Check multishop context and set right context if need
|
// Check multishop context and set right context if need
|
||||||
if (!($this->multishop_context & Shop::getContext()))
|
if (!($this->multishop_context & Shop::getContext()))
|
||||||
@@ -1963,7 +1966,7 @@ class AdminControllerCore extends Controller
|
|||||||
$filter_shop = '';
|
$filter_shop = '';
|
||||||
if ($this->multishop_context && Shop::isTableAssociated($this->table))
|
if ($this->multishop_context && Shop::isTableAssociated($this->table))
|
||||||
{
|
{
|
||||||
$idenfier_shop = Shop::getContextListShopID();
|
$idenfier_shop = Shop::getContextListShopID();
|
||||||
if (!$this->_group)
|
if (!$this->_group)
|
||||||
$this->_group = ' GROUP BY a.'.pSQL($this->identifier);
|
$this->_group = ' GROUP BY a.'.pSQL($this->identifier);
|
||||||
elseif (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
|
elseif (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
|
||||||
|
|||||||
@@ -757,7 +757,7 @@ class ShopCore extends ObjectModel
|
|||||||
static $total = null;
|
static $total = null;
|
||||||
|
|
||||||
if (is_null($total))
|
if (is_null($total))
|
||||||
$total = Shop::getTotalShops(true);
|
$total = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'shop');
|
||||||
return ($total > 1) ? true : false;
|
return ($total > 1) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user