[CLEAN] hr: check_related_document now located in hr_employee instead of a mail_message override.

bzr revid: tde@openerp.com-20130612095507-1ksx759e8hkk323h
This commit is contained in:
Thibault Delavallée 2013-06-12 11:55:07 +02:00
parent adb84380e2
commit 4f7a2419fe
4 changed files with 35 additions and 71 deletions

View File

@ -24,6 +24,5 @@ import hr
import res_config
import res_users
import mail_message
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -152,6 +152,7 @@ class hr_job(osv.osv):
class hr_employee(osv.osv):
_name = "hr.employee"
_description = "Employee"
_order = 'name_related'
_inherits = {'resource.resource': "resource_id"}
_inherit = ['mail.thread']
@ -216,7 +217,15 @@ class hr_employee(osv.osv):
'last_login': fields.related('user_id', 'date', type='datetime', string='Latest Connection', readonly=1),
}
_order = 'name_related'
def _get_default_image(self, cr, uid, context=None):
image_path = get_module_resource('hr', 'static/src/img', 'default_image.png')
return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
defaults = {
'active': 1,
'image': _get_default_image,
'color': 0,
}
def create(self, cr, uid, data, context=None):
if context is None:
@ -272,10 +281,6 @@ class hr_employee(osv.osv):
work_email = self.pool.get('res.users').browse(cr, uid, user_id, context=context).email
return {'value': {'work_email': work_email}}
def _get_default_image(self, cr, uid, context=None):
image_path = get_module_resource('hr', 'static/src/img', 'default_image.png')
return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
def action_follow(self, cr, uid, ids, context=None):
""" Wrapper because message_subscribe_users take a user_ids=None
that receive the context without the wrapper. """
@ -305,13 +310,6 @@ class hr_employee(osv.osv):
user_field_lst.append(name)
return user_field_lst
_defaults = {
'active': 1,
'image': _get_default_image,
'color': 0,
}
def _check_recursion(self, cr, uid, ids, context=None):
level = 100
while len(ids):
@ -326,6 +324,22 @@ class hr_employee(osv.osv):
(_check_recursion, 'Error! You cannot create recursive hierarchy of Employee(s).', ['parent_id']),
]
# ---------------------------------------------------
# Mail gateway
# ---------------------------------------------------
def check_mail_message_access(self, cr, uid, mids, operation, model_obj=None, context=None):
""" mail.message document permission rule: can post a new message if can read
because of portal document. """
if not model_obj:
model_obj = self
employee_ids = model_obj.search(cr, uid, [('user_id', '=', uid)], context=context)
if employee_ids and operation == 'create':
model_obj.check_access_rights(cr, uid, 'read')
model_obj.check_access_rule(cr, uid, mids, 'read', context=context)
else:
return super(hr_employee, self).check_mail_message_access(cr, uid, mids, operation, model_obj=model_obj, context=context)
class hr_department(osv.osv):
_description = "Department"

View File

@ -1,40 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
from openerp.osv import osv
class mail_message(osv.Model):
_name = 'mail.message'
_inherit = 'mail.message'
def check_related_document(self, cr, uid, model_obj, mids, operation, context=None):
"""If the user posting the message to an employee is an employee, only
the read access are checked"""
if model_obj._name == 'hr.employee':
employee_ids = model_obj.search(cr, uid, [('user_id', '=', uid)], context=context)
if employee_ids:
model_obj.check_access_rights(cr, uid, 'read')
model_obj.check_access_rule(cr, uid, mids, 'read', context=context)
return
super(mail_message, self).check_related_document(cr, uid, model_obj, mids, operation, context)

View File

@ -755,15 +755,6 @@ class mail_message(osv.Model):
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % \
(self._description, operation))
def check_related_document(self, cr, uid, model_obj, mids, operation, context=None):
"""Concrete check permission rules for related document"""
if operation in ['create', 'write', 'unlink']:
model_obj.check_access_rights(cr, uid, 'write')
model_obj.check_access_rule(cr, uid, mids, 'write', context=context)
else:
model_obj.check_access_rights(cr, uid, operation)
model_obj.check_access_rule(cr, uid, mids, operation, context=context)
def create(self, cr, uid, values, context=None):
if context is None:
context = {}