Skip to content

Commit

Permalink
[IMP] hr: flexible verification of access rights
Browse files Browse the repository at this point in the history
Allow to inherit state modification access right

Closes odoo#9145
  • Loading branch information
adrienpeiffer authored and mart-e committed Oct 22, 2015
1 parent fcd4d35 commit 2d4f062
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions addons/hr_holidays/hr_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ def onchange_date_to(self, cr, uid, ids, date_to, date_from):
result['value']['number_of_days_temp'] = 0
return result

def _check_state_access_right(self, cr, uid, vals, context=None):
if vals.get('state') and vals['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'):
return False
return True

def add_follower(self, cr, uid, ids, employee_id, context=None):
employee = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
if employee and employee.user_id:
Expand All @@ -348,7 +353,7 @@ def create(self, cr, uid, values, context=None):
context = {}
employee_id = values.get('employee_id', False)
context = dict(context, mail_create_nolog=True)
if values.get('state') and values['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'):
if not self._check_state_access_right(cr, uid, values, context):
raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state'))
if not values.get('name'):
employee_name = self.pool['hr.employee'].browse(cr, uid, employee_id, context=context).name
Expand All @@ -360,7 +365,7 @@ def create(self, cr, uid, values, context=None):

def write(self, cr, uid, ids, vals, context=None):
employee_id = vals.get('employee_id', False)
if vals.get('state') and vals['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'):
if not self._check_state_access_right(cr, uid, vals, context):
raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % vals.get('state'))
hr_holiday_id = super(hr_holidays, self).write(cr, uid, ids, vals, context=context)
self.add_follower(cr, uid, ids, employee_id, context=context)
Expand Down

0 comments on commit 2d4f062

Please sign in to comment.