[MERGE] base,res.users: cleanup uid cache when removing/disabling user (test incl.)...

+ fix regression with menu 
+ some minor cleanup

lp bug: https://launchpad.net/bugs/664379 fixed

bzr revid: odo@openerp.com-20101214193304-928za9xrkmt8yi9b
This commit is contained in:
P. Christeas 2010-12-14 20:33:04 +01:00 committed by Olivier Dony
commit 84a3e9da63
7 changed files with 109 additions and 14 deletions

View File

@ -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')
@ -354,12 +360,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):

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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']: