[*] BO : Rights verification for multi-shop

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9198 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
lLefevre
2011-10-10 16:10:57 +00:00
parent 5fe22693dd
commit a8a11c0ece
8 changed files with 155 additions and 51 deletions
+84 -28
View File
@@ -27,60 +27,60 @@
class EmployeeCore extends ObjectModel
{
public $id;
public $id;
/** @var string Determine employee profile */
public $id_profile;
public $id_profile;
/** @var string employee language */
public $id_lang;
public $id_lang;
/** @var string Lastname */
public $lastname;
public $lastname;
/** @var string Firstname */
public $firstname;
public $firstname;
/** @var string e-mail */
public $email;
public $email;
/** @var string Password */
public $passwd;
public $passwd;
/** @var datetime Password */
public $last_passwd_gen;
public $last_passwd_gen;
public $stats_date_from;
public $stats_date_to;
/** @var string Display back office background in the specified color */
public $bo_color;
public $bo_color;
/** @var string employee's chosen theme */
public $bo_theme;
public $bo_theme;
/** @var string / enum hover or click mode */
public $bo_uimode;
public $bo_uimode;
/** @var bool, true */
public $bo_show_screencast;
public $bo_show_screencast;
/** @var boolean Status */
public $active = 1;
public $active = 1;
/** @var boolean show screencast */
public $show_screencast = 1;
public $show_screencast = 1;
public $remote_addr;
public $remote_addr;
protected $fieldsRequired = array('lastname', 'firstname', 'email', 'passwd', 'id_profile', 'id_lang');
protected $fieldsSize = array('lastname' => 32, 'firstname' => 32, 'email' => 128, 'passwd' => 32, 'bo_color' => 32, 'bo_theme' => 32);
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
protected $fieldsRequired = array('lastname', 'firstname', 'email', 'passwd', 'id_profile', 'id_lang');
protected $fieldsSize = array('lastname' => 32, 'firstname' => 32, 'email' => 128, 'passwd' => 32, 'bo_color' => 32, 'bo_theme' => 32);
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
'passwd' => 'isPasswdAdmin', 'active' => 'isBool', 'id_profile' => 'isInt', 'bo_color' => 'isColor', 'bo_theme' => 'isGenericName',
'bo_uimode' => 'isGenericName', 'show_screencast' => 'isBool', 'bo_show_screencast' => 'isBool');
protected $table = 'employee';
protected $identifier = 'id_employee';
protected $table = 'employee';
protected $identifier = 'id_employee';
protected $webserviceParameters = array(
'fields' => array(
@@ -123,10 +123,10 @@ class EmployeeCore extends ObjectModel
return $fields;
}
public function add($autodate = true, $nullValues = true)
public function add($autodate = true, $null_values = true)
{
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_BACK').'minutes'));
return parent::add($autodate, $nullValues);
return parent::add($autodate, $null_values);
}
/**
@@ -136,9 +136,9 @@ class EmployeeCore extends ObjectModel
* @param string $passwd Password is also checked if specified
* @return Employee instance
*/
public function getByEmail($email, $passwd = NULL)
public function getByEmail($email, $passwd = null)
{
if (!Validate::isEmail($email) OR ($passwd != NULL AND !Validate::isPasswd($passwd)))
if (!Validate::isEmail($email) || ($passwd != null && !Validate::isPasswd($passwd)))
die(Tools::displayError());
$result = Db::getInstance()->getRow('
@@ -151,7 +151,7 @@ class EmployeeCore extends ObjectModel
return false;
$this->id = $result['id_employee'];
$this->id_profile = $result['id_profile'];
foreach ($result AS $key => $value)
foreach ($result as $key => $value)
if (key_exists($key, $this))
$this->{$key} = $value;
return $this;
@@ -176,7 +176,7 @@ class EmployeeCore extends ObjectModel
*/
public static function checkPassword($id_employee, $passwd)
{
if (!Validate::isUnsignedId($id_employee) OR !Validate::isPasswd($passwd, 8))
if (!Validate::isUnsignedId($id_employee) || !Validate::isPasswd($passwd, 8))
die (Tools::displayError());
return Db::getInstance()->getValue('
@@ -187,13 +187,13 @@ class EmployeeCore extends ObjectModel
AND active = 1');
}
public static function countProfile($id_profile, $activeOnly = false)
public static function countProfile($id_profile, $active_only = false)
{
return Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'employee`
WHERE `id_profile` = '.(int)$id_profile.'
'.($activeOnly ? ' AND `active` = 1' : ''));
'.($active_only ? ' AND `active` = 1' : ''));
}
public function isLastAdmin()
@@ -240,4 +240,60 @@ class EmployeeCore extends ObjectModel
Context::getContext()->cookie->logout();
$this->id = null;
}
public static function getEmployeeShopAccess($id_employee)
{
$context = Context::getContext();
switch ($type = $context->shop->getContextType())
{
case 1:
info('context shop');
if ($context->shop->checkIfShopExist($context->shop->id))
{
if (!in_array($context->shop->id, self::getEmployeeShopById($id_employee)))
return false;
}
else
return false;
break;
case 2:
info('context group');
if ($context->shop->checkIfGroupShopExist($context->shop->getGroupID()))
{
$shops = $context->shop->getIdShopsByIdGroupShop($context->shop->getGroupID());
foreach ($shops as $shop)
if (!in_array($shop, self::getEmployeeShopById($id_employee)))
return false;
}
else
return false;
break;
case 3:
info('context all');
if ($context->employee->id_profile == _PS_ADMIN_PROFILE_ ||
$context->shop->getTotalShopsWhoExists() == self::getTotalEmployeeShopById($id_employee))
return true;
else
return false;
break;
}
return true;
}
public static function getTotalEmployeeShopById($id)
{
return (int)Db::getInstance()->getValue(sprintf('SELECT COUNT(*) FROM`'._DB_PREFIX_.'employee_shop` WHERE `id_employee` = %d', (int)$id));
}
public static function getEmployeeShopById($id)
{
$result = Db::getInstance()->executeS(sprintf('SELECT * FROM`'._DB_PREFIX_.'employee_shop` WHERE `id_employee` = %d', (int)$id));
$data = array();
foreach ($result as $group_data)
$data[] = (int)$group_data['id_shop'];
return $data;
}
}