Files
odoo_source/odoo/service/common.py
T
jev-odoo 5a2e675f14 [FIX] service: rpc call with empty array (php)
Before this fix, trying to authenticate via
xml-rpc call from PHP following the documentation at
odoo.com/documentation/14.0/webservices/odoo.html#logging-in
raised an error:

    > $uid = $common->authenticate($db, $username, $password, array());
    TypeError: 'list' object is not a mapping

Because PHP doesn't have separate array and mapping types, the
XML-RPC encoder disambiguates based on the existence of
key => value pairs, such disambiguation yields an empty xmlrpc
array for an empty PHP array, which is unexpected on the Python
side.

Relax the check on the Python side:

* fixing this on the client side requires adding arbitrary and
  meaningless key => value to the empty array to force the
  correct disambiguation which is ugly and weird
* the example code has been there for a long time, so there's
  probably lots of such PHP code in the wild

opw-2388141

closes odoo/odoo#62101

X-original-commit: 9f97b7435977c81a079004b7c2186ce75526490c
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-11-20 14:21:36 +00:00

59 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import logging
import odoo.release
import odoo.tools
from odoo.exceptions import AccessDenied
from odoo.tools.translate import _
_logger = logging.getLogger(__name__)
RPC_VERSION_1 = {
'server_version': odoo.release.version,
'server_version_info': odoo.release.version_info,
'server_serie': odoo.release.serie,
'protocol_version': 1,
}
def exp_login(db, login, password):
return exp_authenticate(db, login, password, None)
def exp_authenticate(db, login, password, user_agent_env):
if not user_agent_env:
user_agent_env = {}
res_users = odoo.registry(db)['res.users']
try:
return res_users.authenticate(db, login, password, {**user_agent_env, 'interactive': False})
except AccessDenied:
return False
def exp_version():
return RPC_VERSION_1
def exp_about(extended=False):
"""Return information about the OpenERP Server.
@param extended: if True then return version info
@return string if extended is False else tuple
"""
info = _('See http://openerp.com')
if extended:
return info, odoo.release.version
return info
def exp_set_loglevel(loglevel, logger=None):
# TODO Previously, the level was set on the now deprecated
# `odoo.netsvc.Logger` class.
return True
def dispatch(method, params):
g = globals()
exp_method_name = 'exp_' + method
if exp_method_name in g:
return g[exp_method_name](*params)
else:
raise Exception("Method not found: %s" % method)