FIX Can't change the admin with default setup
This commit is contained in:
parent
c20296f963
commit
7b2fbdd638
@ -44,7 +44,8 @@ ListOfUsers=List of users
|
||||
Administrator=Administrator
|
||||
SuperAdministrator=Super Administrator
|
||||
SuperAdministratorDesc=Global administrator
|
||||
AdministratorDesc=Administrator's entity
|
||||
AdministratorDesc=Administrator
|
||||
AdministratorDescEntity=Administrator (for its company)
|
||||
DefaultRights=Default permissions
|
||||
DefaultRightsDesc=Define here <u>default</u> permissions that are automatically granted to a <u>new created</u> user (Go on user card to change permission of an existing user).
|
||||
DolibarrUsers=Dolibarr users
|
||||
|
||||
@ -1883,10 +1883,16 @@ else
|
||||
else
|
||||
{
|
||||
print '<td>';
|
||||
$nbSuperAdmin = $user->getNbOfUsers('superadmin');
|
||||
if ($user->admin
|
||||
&& ($user->id != $object->id) // Don't downgrade ourself
|
||||
&& ($object->entity > 0 || $nbSuperAdmin > 1) // Don't downgrade a superadmin if alone
|
||||
$nbAdmin = $user->getNbOfUsers('active','',1);
|
||||
$nbSuperAdmin = $user->getNbOfUsers('active','superadmin',1);
|
||||
//var_dump($nbAdmin);
|
||||
//var_dump($nbSuperAdmin);
|
||||
if ($user->admin // Need to be admin to allow downgrade of an admin
|
||||
&& ($user->id != $object->id) // Don't downgrade ourself
|
||||
&& (
|
||||
(empty($conf->multicompany->enabled) && $nbAdmin > 1)
|
||||
|| (! empty($conf->multicompany->enabled) && ($object->entity > 0 || $nbSuperAdmin > 1)) // Don't downgrade a superadmin if alone
|
||||
)
|
||||
)
|
||||
{
|
||||
print $form->selectyesno('admin',$object->admin,1);
|
||||
|
||||
@ -2195,25 +2195,27 @@ class User extends CommonObject
|
||||
/**
|
||||
* Return number of existing users
|
||||
*
|
||||
* @param string $limitTo Limit to 'active' or 'superadmin' users
|
||||
* @param bool $all Return for all entities
|
||||
* @param string $limitTo Limit to '' or 'active'
|
||||
* @param string $option 'superadmin' = return for entity 0 only
|
||||
* @param int $admin Filter on admin tag
|
||||
* @return int Number of users
|
||||
*/
|
||||
function getNbOfUsers($limitTo='active', $all=false)
|
||||
function getNbOfUsers($limitTo, $option='', $admin=-1)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT count(rowid) as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user";
|
||||
if ($limitTo == 'superadmin')
|
||||
if ($option == 'superadmin')
|
||||
{
|
||||
$sql.= " WHERE entity = 0";
|
||||
if ($admin >= 0) $sql.= " AND admin = ".$admin;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($all) $sql.= " WHERE entity > 0"; // all users except superadmins
|
||||
else $sql.= " WHERE entity = ".$conf->entity;
|
||||
$sql.=" WHERE entity IN (".getEntity('user',0).")";
|
||||
if ($limitTo == 'active') $sql.= " AND statut = 1";
|
||||
if ($admin >= 0) $sql.= " AND admin = ".$admin;
|
||||
}
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
@ -2227,7 +2229,7 @@ class User extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user