// Filter list of entities per shop in admin if employee is not super admin #PSCFV-2525

This commit is contained in:
rMalie
2012-05-30 08:22:48 +00:00
parent e6264ba698
commit a118eb7a5e
2 changed files with 16 additions and 6 deletions
+15 -5
View File
@@ -174,7 +174,7 @@ class EmployeeCore extends ObjectModel
$this->id = $result['id_employee']; $this->id = $result['id_employee'];
$this->id_profile = $result['id_profile']; $this->id_profile = $result['id_profile'];
foreach ($result as $key => $value) foreach ($result as $key => $value)
if (key_exists($key, $this)) if (property_exists($this, $key))
$this->{$key} = $value; $this->{$key} = $value;
return $this; return $this;
} }
@@ -220,7 +220,7 @@ class EmployeeCore extends ObjectModel
public function isLastAdmin() public function isLastAdmin()
{ {
return ($this->id_profile == _PS_ADMIN_PROFILE_ return ($this->isSuperAdmin()
&& Employee::countProfile($this->id_profile, true) == 1 && Employee::countProfile($this->id_profile, true) == 1
&& $this->active && $this->active
); );
@@ -272,7 +272,7 @@ class EmployeeCore extends ObjectModel
*/ */
public function hasAuthOnShop($id_shop) public function hasAuthOnShop($id_shop)
{ {
return $this->id_profile == _PS_ADMIN_PROFILE_ || in_array($id_shop, $this->associated_shops); return $this->isSuperAdmin() || in_array($id_shop, $this->associated_shops);
} }
/** /**
@@ -284,7 +284,7 @@ class EmployeeCore extends ObjectModel
*/ */
public function hasAuthOnShopGroup($id_shop_group) public function hasAuthOnShopGroup($id_shop_group)
{ {
if ($this->id_profile == _PS_ADMIN_PROFILE_) if ($this->isSuperAdmin())
return true; return true;
foreach ($this->associated_shops as $id_shop) foreach ($this->associated_shops as $id_shop)
@@ -301,7 +301,7 @@ class EmployeeCore extends ObjectModel
*/ */
public function getDefaultShopID() public function getDefaultShopID()
{ {
if ($this->id_profile == _PS_ADMIN_PROFILE_ || in_array(Configuration::get('PS_SHOP_DEFAULT'), $this->associated_shops)) if ($this->isSuperAdmin() || in_array(Configuration::get('PS_SHOP_DEFAULT'), $this->associated_shops))
return Configuration::get('PS_SHOP_DEFAULT'); return Configuration::get('PS_SHOP_DEFAULT');
return $this->associated_shops[0]; return $this->associated_shops[0];
} }
@@ -314,4 +314,14 @@ class EmployeeCore extends ObjectModel
WHERE `id_profile` = '.(int)$id_profile.' WHERE `id_profile` = '.(int)$id_profile.'
'.($active_only ? ' AND `active` = 1' : '')); '.($active_only ? ' AND `active` = 1' : ''));
} }
/**
* Check if current employee is super administrator
*
* @return bool
*/
public function isSuperAdmin()
{
return $this->id_profile == _PS_ADMIN_PROFILE_;
}
} }
+1 -1
View File
@@ -1988,7 +1988,7 @@ class AdminControllerCore extends Controller
if ($this->multishop_context && Shop::isTableAssociated($this->table) && !empty($this->className)) if ($this->multishop_context && Shop::isTableAssociated($this->table) && !empty($this->className))
{ {
$def = ObjectModel::getDefinition($this->className); $def = ObjectModel::getDefinition($this->className);
if (Shop::getContext() != Shop::CONTEXT_ALL || !empty($def['multishop'])) if (Shop::getContext() != Shop::CONTEXT_ALL || !empty($def['multishop']) || !$this->context->employee->isSuperAdmin())
{ {
$idenfier_shop = Shop::getContextListShopID(); $idenfier_shop = Shop::getContextListShopID();
if (!$this->_group) if (!$this->_group)