[FIX] note: copy default stages as SUPERUSER_ID to avoid access error. Only do it for employees

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

bzr revid: chs@openerp.com-20131009162920-lg56wwmtg8qm1kuf
This commit is contained in:
Christophe Simonis 2013-10-09 18:29:20 +02:00
parent 6bd70af1de
commit e701169ac6
3 changed files with 79 additions and 11 deletions

View File

@ -19,6 +19,7 @@
#
##############################################################################
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
from openerp.tools import html2plaintext
@ -188,18 +189,15 @@ class res_users(osv.Model):
_inherit = ['res.users']
def create(self, cr, uid, data, context=None):
user_id = super(res_users, self).create(cr, uid, data, context=context)
user = self.browse(cr, uid, uid, context=context)
note_obj = self.pool.get('note.stage')
data_obj = self.pool.get('ir.model.data')
model_id = data_obj.get_object_reference(cr, uid, 'base', 'group_user') #Employee Group
group_id = model_id and model_id[1] or False
if group_id in [x.id for x in user.groups_id]:
for note_xml_id in ['note_stage_00','note_stage_01','note_stage_02','note_stage_03','note_stage_04']:
note_obj = self.pool['note.stage']
data_obj = self.pool['ir.model.data']
is_employee = self.has_group(cr, user_id, 'base.group_user')
if is_employee:
for n in range(5):
xmlid = 'note_stage_%02d' % (n,)
try:
data_id = data_obj._get_id(cr, uid, 'note', note_xml_id)
_model, stage_id = data_obj.get_object_reference(cr, SUPERUSER_ID, 'note', xmlid)
except ValueError:
continue
stage_id = data_obj.browse(cr, uid, data_id, context=context).res_id
note_obj.copy(cr, uid, stage_id, default = {
'user_id': user_id}, context=context)
note_obj.copy(cr, SUPERUSER_ID, stage_id, default={'user_id': user_id}, context=context)
return user_id

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2013-TODAY OpenERP S.A. <http://openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_note
checks = [
test_note,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (c) 2013-TODAY OpenERP S.A. <http://openerp.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests import common
class TestNote(common.TransactionCase):
def test_bug_lp_1156215(self):
"""ensure any users can create new users"""
cr, uid = self.cr, self.uid
IMD = self.registry('ir.model.data')
Users = self.registry('res.users')
_, demo_user = IMD.get_object_reference(cr, uid, 'base', 'user_demo')
_, group_id = IMD.get_object_reference(cr, uid, 'base', 'group_erp_manager')
Users.write(cr, uid, [demo_user], {
'groups_id': [(4, group_id)],
})
# must not fail
Users.create(cr, demo_user, {
'name': 'test bug lp:1156215',
'login': 'lp_1156215',
})