From 6f60b165f86e64f802d0e7bdf3a8e9d7250f86b8 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 4 Feb 2009 15:36:29 +0100 Subject: [PATCH] [IMP] automatically add new groups to admin user bzr revid: christophe@tinyerp.com-20090204143629-3nb99mmzlf380fjp --- bin/addons/base/res/res_user.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bin/addons/base/res/res_user.py b/bin/addons/base/res/res_user.py index 27810c8ac07..e2d438ea6a3 100644 --- a/bin/addons/base/res/res_user.py +++ b/bin/addons/base/res/res_user.py @@ -56,7 +56,15 @@ class groups(osv.osv): if vals['name'].startswith('-'): raise osv.except_osv(_('Error'), _('The name of the group can not start with "-"')) - return super(groups, self).create(cr, uid, vals, context=context) + gid = super(groups, self).create(cr, uid, vals, context=context) + + # assign this new group to user_root + user_obj = self.pool.get('res.users') + aid = user_obj.browse(cr, 1, user_obj._get_admin_id(cr)) + if aid: + aid.write({'groups_id': [(4, gid)]}) + + return gid groups() @@ -91,6 +99,7 @@ def _tz_get(self,cr,uid, context={}): return [(x, x) for x in pytz.all_timezones] class users(osv.osv): + __admin_ids = {} _name = "res.users" #_log_access = False _columns = { @@ -127,6 +136,14 @@ class users(osv.osv): _sql_constraints = [ ('login_key', 'UNIQUE (login)', 'You can not have two users with the same login !') ] + + def _get_admin_id(self, cr): + if self.__admin_ids.get(cr.dbname) is None: + ir_model_data_obj = self.pool.get('ir.model.data') + mdid = ir_model_data_obj._get_id(cr, 1, 'base', 'user_root') + self.__admin_ids[cr.dbname] = ir_model_data_obj.read(cr, 1, [mdid], ['res_id'])[0]['res_id'] + return self.__admin_ids[cr.dbname] + def _get_action(self,cr, uid, context={}): ids = self.pool.get('ir.ui.menu').search(cr, uid, [('usage','=','menu')]) return ids and ids[0] or False