From 25ca6582b2e971284ecc9fe2b6bda94ed4ff2971 Mon Sep 17 00:00:00 2001 From: yannis Date: Thu, 3 Jul 2025 12:10:19 +0200 Subject: [PATCH] feat: ungrant perm to tokens if lost in global --- htdocs/user/class/user.class.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 33599cebf80..4c3b33f56b8 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1269,6 +1269,38 @@ class User extends CommonObject $error++; dol_print_error($this->db); } + + if (!$error) { + $idtodelete = array(); + + $sqlusertokens = "SELECT oat.rowid, oat.state as rights"; + $sqlusertokens .= " FROM llx_oauth_token AS oat"; + $sqlusertokens .= " WHERE oat.fk_user = ".((int) $this->id); + + $idtodeletequery = $this->db->query($sql); + $resulttokens = $this->db->query($sqlusertokens); + if ($resulttokens && $idtodeletequery) { + while ($idobj = $this->db->fetch_object($idtodeletequery)) { + $idtodelete []= $idobj->id; + } + + while ($obj = $this->db->fetch_object($resulttokens)) { + if (!empty($obj->rights)) { + $newtokenrigths = array_diff(explode(',', $obj->rights), $idtodelete); + + $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."oauth_token"; + $sqlupdate.= " SET state = '".$this->db->escape(preg_replace('/\s+/', '', implode(',', $newtokenrigths)))."'"; + $sqlupdate.= " WHERE rowid = '".$obj->rowid."'"; + + $resupdate = $this->db->query($sqlupdate); + if (!$resupdate) { + $error++; + dol_print_error($this->db); + } + } + } + } + } } if (!$error && !$notrigger) {