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
|
Administrator=Administrator
|
||||||
SuperAdministrator=Super Administrator
|
SuperAdministrator=Super Administrator
|
||||||
SuperAdministratorDesc=Global administrator
|
SuperAdministratorDesc=Global administrator
|
||||||
AdministratorDesc=Administrator's entity
|
AdministratorDesc=Administrator
|
||||||
|
AdministratorDescEntity=Administrator (for its company)
|
||||||
DefaultRights=Default permissions
|
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).
|
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
|
DolibarrUsers=Dolibarr users
|
||||||
|
|||||||
@ -1883,10 +1883,16 @@ else
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$nbSuperAdmin = $user->getNbOfUsers('superadmin');
|
$nbAdmin = $user->getNbOfUsers('active','',1);
|
||||||
if ($user->admin
|
$nbSuperAdmin = $user->getNbOfUsers('active','superadmin',1);
|
||||||
&& ($user->id != $object->id) // Don't downgrade ourself
|
//var_dump($nbAdmin);
|
||||||
&& ($object->entity > 0 || $nbSuperAdmin > 1) // Don't downgrade a superadmin if alone
|
//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);
|
print $form->selectyesno('admin',$object->admin,1);
|
||||||
|
|||||||
@ -2195,25 +2195,27 @@ class User extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Return number of existing users
|
* Return number of existing users
|
||||||
*
|
*
|
||||||
* @param string $limitTo Limit to 'active' or 'superadmin' users
|
* @param string $limitTo Limit to '' or 'active'
|
||||||
* @param bool $all Return for all entities
|
* @param string $option 'superadmin' = return for entity 0 only
|
||||||
|
* @param int $admin Filter on admin tag
|
||||||
* @return int Number of users
|
* @return int Number of users
|
||||||
*/
|
*/
|
||||||
function getNbOfUsers($limitTo='active', $all=false)
|
function getNbOfUsers($limitTo, $option='', $admin=-1)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT count(rowid) as nb";
|
$sql = "SELECT count(rowid) as nb";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."user";
|
$sql.= " FROM ".MAIN_DB_PREFIX."user";
|
||||||
if ($limitTo == 'superadmin')
|
if ($option == 'superadmin')
|
||||||
{
|
{
|
||||||
$sql.= " WHERE entity = 0";
|
$sql.= " WHERE entity = 0";
|
||||||
|
if ($admin >= 0) $sql.= " AND admin = ".$admin;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($all) $sql.= " WHERE entity > 0"; // all users except superadmins
|
$sql.=" WHERE entity IN (".getEntity('user',0).")";
|
||||||
else $sql.= " WHERE entity = ".$conf->entity;
|
|
||||||
if ($limitTo == 'active') $sql.= " AND statut = 1";
|
if ($limitTo == 'active') $sql.= " AND statut = 1";
|
||||||
|
if ($admin >= 0) $sql.= " AND admin = ".$admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
@ -2227,7 +2229,7 @@ class User extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->lasterror();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user