Fix delete group of a user

This commit is contained in:
Laurent Destailleur 2023-01-14 02:40:44 +01:00
parent b4702aee24
commit 09a0d579ce
2 changed files with 6 additions and 1 deletions

View File

@ -375,6 +375,7 @@ if (empty($reshook)) {
$editgroup->oldcopy = clone $editgroup; $editgroup->oldcopy = clone $editgroup;
$object->fetch($id); $object->fetch($id);
if ($action == 'addgroup') { if ($action == 'addgroup') {
$result = $object->SetInGroup($group, $editgroup->entity); $result = $object->SetInGroup($group, $editgroup->entity);
} }

View File

@ -2651,7 +2651,11 @@ class User extends CommonObject
$sql = "DELETE FROM ".$this->db->prefix()."usergroup_user"; $sql = "DELETE FROM ".$this->db->prefix()."usergroup_user";
$sql .= " WHERE fk_user = ".((int) $this->id); $sql .= " WHERE fk_user = ".((int) $this->id);
$sql .= " AND fk_usergroup = ".((int) $group); $sql .= " AND fk_usergroup = ".((int) $group);
$sql .= " AND entity = ".((int) $entity); if (empty($entity)) {
$sql .= " AND entity IN (0, 1)"; // group may be in entity 0 (so $entity=0) and link with user into entity 1.
} else {
$sql .= " AND entity = ".((int) $entity);
}
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {