From 5c6bd686abf73b4d8deb2ce2646d0f47dbdb237d Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 14 Dec 2010 18:28:26 +0200 Subject: [PATCH 1/5] reports: fix some default args, import message, empty translations bzr revid: p_christ@hol.gr-20101214162826-79ppx7qw23ag3qx0 --- bin/report/interface.py | 2 ++ bin/report/render/__init__.py | 5 +++-- bin/report/render/rml.py | 13 ++++++------- bin/report/render/rml2pdf/trml2pdf.py | 6 +++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/report/interface.py b/bin/report/interface.py index ec9ed7ddef1..16dfafe0a18 100644 --- a/bin/report/interface.py +++ b/bin/report/interface.py @@ -164,6 +164,8 @@ class report_rml(report_int): def translate(doc, lang): for node in doc.xpath('//*[@t]'): + if not node.text: + continue translation = ir_translation_obj._get_source(cr, uid, self.name2, 'xsl', lang, node.text) if translation: node.text = translation diff --git a/bin/report/render/__init__.py b/bin/report/render/__init__.py index 1a888e18b75..1d0a4464e0b 100644 --- a/bin/report/render/__init__.py +++ b/bin/report/render/__init__.py @@ -25,8 +25,9 @@ from render import render try: import Image -except: - print 'WARNING; Python Imaging not installed, you can use only .JPG pictures !' +except ImportError: + import logging + logging.getLogger('init').warning('Python Imaging not installed, you can use only .JPG pictures !') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/report/render/rml.py b/bin/report/render/rml.py index 0bc78f95555..568e83641ea 100644 --- a/bin/report/render/rml.py +++ b/bin/report/render/rml.py @@ -29,12 +29,11 @@ import makohtml2html as makohtml class rml(render.render): - def __init__(self, rml, localcontext = None, datas={}, path='.', title=None): - render.render.__init__(self, datas) + def __init__(self, rml, localcontext = None, datas=None, path='.', title=None): + render.render.__init__(self, datas, path) self.localcontext = localcontext self.rml = rml self.output_type = 'pdf' - self.path = path self.title=title @@ -42,7 +41,7 @@ class rml(render.render): return rml2pdf.parseNode(self.rml, self.localcontext, images=self.bin_datas, path=self.path,title=self.title) class rml2html(render.render): - def __init__(self, rml,localcontext = None, datas = {}): + def __init__(self, rml,localcontext = None, datas=None): super(rml2html, self).__init__(datas) self.rml = rml self.localcontext = localcontext @@ -52,7 +51,7 @@ class rml2html(render.render): return htmlizer.parseString(self.rml,self.localcontext) class rml2txt(render.render): - def __init__(self, rml, localcontext= None, datas={}): + def __init__(self, rml, localcontext= None, datas=None): super(rml2txt, self).__init__(datas) self.rml = rml self.localcontext = localcontext @@ -62,7 +61,7 @@ class rml2txt(render.render): return txtizer.parseString(self.rml, self.localcontext) class odt2odt(render.render): - def __init__(self, rml, localcontext = None, datas = {}): + def __init__(self, rml, localcontext=None, datas=None): render.render.__init__(self, datas) self.rml_dom = rml self.localcontext = localcontext @@ -72,7 +71,7 @@ class odt2odt(render.render): return odt.parseNode(self.rml_dom,self.localcontext) class html2html(render.render): - def __init__(self, rml, localcontext = None, datas = {}): + def __init__(self, rml, localcontext=None, datas=None): render.render.__init__(self, datas) self.rml_dom = rml self.localcontext = localcontext diff --git a/bin/report/render/rml2pdf/trml2pdf.py b/bin/report/render/rml2pdf/trml2pdf.py index b609528177e..d01317f8257 100644 --- a/bin/report/render/rml2pdf/trml2pdf.py +++ b/bin/report/render/rml2pdf/trml2pdf.py @@ -942,8 +942,12 @@ class _rml_template(object): fis.append(PageCount()) self.doc_tmpl.build(fis) -def parseNode(rml, localcontext = {},fout=None, images={}, path='.',title=None): +def parseNode(rml, localcontext=None,fout=None, images=None, path='.',title=None): node = etree.XML(rml) + if localcontext is None: + localcontext = {} + if images is None: + images = {} r = _rml_doc(node, localcontext, images, path, title=title) #try to override some font mappings try: From ef39bbb95522d3aca83ddd610d6baf5327122c50 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 14 Dec 2010 18:28:56 +0200 Subject: [PATCH 2/5] base tests: yaml test for res.users logic Code inspired from Xavier ALT's example. bzr revid: p_christ@hol.gr-20101214162856-oskw0ohg8hx9hoc3 --- bin/addons/base/test/test_auth.yml | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 bin/addons/base/test/test_auth.yml diff --git a/bin/addons/base/test/test_auth.yml b/bin/addons/base/test/test_auth.yml new file mode 100644 index 00000000000..90dc1602f0b --- /dev/null +++ b/bin/addons/base/test/test_auth.yml @@ -0,0 +1,73 @@ +- + I will now stress the authentication layer of the ORM +- + I create a test user. +- + !record {model: res.users, id: res_user_test_a1}: + name: Test Auth User 1 + login: test_base_a1 + password: 'base-test-passwd' + active: True +- + I will prepare the context +- + !python {model: res.users }: | + from tools import config + host = config.get_misc('httpd', 'interface') + port = config.get_misc('httpd', 'port', 8069) + if not host: + host = config.get('xmlrpc_interface') + port = config.get('xmlrpc_port') or self.port + if host == '0.0.0.0' or not host: + host = '127.0.0.1' + port = int(port) + context['test_xmlrpc_url'] = 'http://%s:%d/xmlrpc/' % (host, port) +- + I will commit the cursor and try to login. +- + !python {model: res.users }: | + from xmlrpclib import ServerProxy + cr.commit() + try: + logsock = ServerProxy(context['test_xmlrpc_url']+'common') + luid = logsock.login(cr.dbname, 'test_base_a1', 'base-test-passwd') + assert luid, "User is not activated after res.users commit!" + except Exception: + raise +- + I will just try to read something as that user +- + !python {model: res.users }: | + from xmlrpclib import ServerProxy + cr.commit() + try: + logsock = ServerProxy(context['test_xmlrpc_url']+'object') + luid = ref('res_user_test_a1') + res = logsock.execute(cr.dbname, luid, 'base-test-passwd', 'res.users', 'read', luid, ['name',]) + assert res and res['name'], "User cannot read its name!" + except Exception: + raise +- + I will now disable the user. +- + !record {model: res.users, id: res_user_test_a1}: + active: False +- + I will commit the cursor. +- + !python {model: res.users }: | + cr.commit() +- + I will try to read again, connecting as the disabled user. +- + !python {model: res.users }: | + from xmlrpclib import ServerProxy + cr.commit() + try: + logsock = ServerProxy(context['test_xmlrpc_url']+'object') + luid = ref('res_user_test_a1') + res = logsock.execute(cr.dbname, luid, 'base-test-passwd', 'res.users', 'read', luid, ['name',]) + raise AssertionError("User should not be enabled!") + except Fault, e: + if e.faultCode != 'AccessDenied': + raise \ No newline at end of file From 66564a93fc6ae8aded844cc2b8122f5cc9958230 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 14 Dec 2010 18:29:05 +0200 Subject: [PATCH 3/5] res.users: invalidate cache when a user is modified. [Bug 664379] Original description, by Xavier ALT: > The server is using a variable name "_uid_cache" for authentication > caching, but this variable is never clear when user informations change, > that means if we disable a user or change it's password their requests > are still allowed (cached auth check ok). > > This affects OpenERP v5 (server/bin/service/security.py) and OpenERP v6 > (server/bin/addons/base/res/res_users.py, class users). > > The only workaround is to restart the server. > bzr revid: p_christ@hol.gr-20101214162905-716i3ra12xvdtc2l --- bin/addons/base/res/res_user.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/addons/base/res/res_user.py b/bin/addons/base/res/res_user.py index 4cd80b7db5f..95c4d8def42 100644 --- a/bin/addons/base/res/res_user.py +++ b/bin/addons/base/res/res_user.py @@ -354,12 +354,22 @@ class users(osv.osv): self.pool.get('ir.model.access').call_cache_clearing_methods(cr) clear = partial(self.pool.get('ir.rule').clear_cache, cr) map(clear, ids) + db = cr.dbname + if db in self._uid_cache: + for id in ids: + if id in self._uid_cache[db]: + del self._uid_cache[db][id] return res def unlink(self, cr, uid, ids, context=None): if 1 in ids: raise osv.except_osv(_('Can not remove root user!'), _('You can not remove the admin user as it is used internally for resources created by OpenERP (updates, module installation, ...)')) + db = cr.dbname + if db in self._uid_cache: + for id in ids: + if id in self._uid_cache[db]: + del self._uid_cache[db][id] return super(users, self).unlink(cr, uid, ids, context=context) def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100): From 40cf6eac7a41306959c7d68d5241da13a10721cc Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 14 Dec 2010 18:29:19 +0200 Subject: [PATCH 4/5] res.users: fix default menu_id, after models got sorted by name. With the old sorting behavior, id=1 would be the first menu to appear. But, after sorting, the alphabetically first ("accounting dashboard") replaced the main menu! bzr revid: p_christ@hol.gr-20101214162919-o9xflsed4ap6hn2z --- bin/addons/base/res/res_user.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/addons/base/res/res_user.py b/bin/addons/base/res/res_user.py index 95c4d8def42..e7f881c1c9d 100644 --- a/bin/addons/base/res/res_user.py +++ b/bin/addons/base/res/res_user.py @@ -299,8 +299,14 @@ class users(osv.osv): return False def _get_menu(self,cr, uid, context=None): - ids = self.pool.get('ir.actions.act_window').search(cr, uid, [('usage','=','menu')], context=context) - return ids and ids[0] or False + dataobj = self.pool.get('ir.model.data') + try: + model, res_id = dataobj.get_object_reference(cr, uid, 'base', 'action_menu_admin') + if model != 'ir.actions.act_window': + return False + return res_id + except ValueError: + return False def _get_group(self,cr, uid, context=None): dataobj = self.pool.get('ir.model.data') From 56cdbc05a96bc2d691341c8e7fa347dd19393193 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 14 Dec 2010 18:30:03 +0200 Subject: [PATCH 5/5] web_services: use pg_dump in batch mode. bzr revid: p_christ@hol.gr-20101214163003-tmdtxaxul5n1wybe --- bin/service/web_services.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/service/web_services.py b/bin/service/web_services.py index 7cdcd040d88..3c21202780a 100644 --- a/bin/service/web_services.py +++ b/bin/service/web_services.py @@ -186,7 +186,7 @@ class db(netsvc.ExportService): self._set_pg_psw_env_var() - cmd = ['pg_dump', '--format=c', '--no-owner'] + cmd = ['pg_dump', '--format=c', '--no-owner' , '-w'] if tools.config['db_user']: cmd.append('--username=' + tools.config['db_user']) if tools.config['db_host']: @@ -222,7 +222,7 @@ class db(netsvc.ExportService): self._create_empty_database(db_name) - cmd = ['pg_restore', '--no-owner'] + cmd = ['pg_restore', '--no-owner', '-w'] if tools.config['db_user']: cmd.append('--username=' + tools.config['db_user']) if tools.config['db_host']: