|
@ -153,24 +153,33 @@ def _create(self, data_list): |
|
|
[('model', '=', self._name)]).id |
|
|
[('model', '=', self._name)]).id |
|
|
access_right_rec = self.env['access.right'].sudo().search_read( |
|
|
access_right_rec = self.env['access.right'].sudo().search_read( |
|
|
[('model_id', '=', current_model_id)], |
|
|
[('model_id', '=', current_model_id)], |
|
|
['model_id', 'is_create_or_update', |
|
|
['model_id', 'is_create_or_update','restriction_type','user_id', |
|
|
'groups_id']) |
|
|
'groups_id']) |
|
|
if access_right_rec and not self.env.is_admin(): |
|
|
if access_right_rec and not self.env.is_admin(): |
|
|
for rec in access_right_rec: |
|
|
for rec in access_right_rec: |
|
|
group_name = self.env['ir.model.data'].sudo().search([ |
|
|
if rec['restriction_type']=='group': |
|
|
('model', '=', 'res.groups'), |
|
|
group_name = self.env['ir.model.data'].sudo().search([ |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
('model', '=', 'res.groups'), |
|
|
]).name |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
module_name = self.env['ir.model.data'].sudo().search([ |
|
|
]).name |
|
|
('model', '=', 'res.groups'), |
|
|
module_name = self.env['ir.model.data'].sudo().search([ |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
('model', '=', 'res.groups'), |
|
|
]).module |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
group = module_name + "." + group_name |
|
|
]).module |
|
|
if self.env.user.has_group(group): |
|
|
group = module_name + "." + group_name |
|
|
if rec['is_create_or_update']: |
|
|
if self.env.user.has_group(group): |
|
|
raise UserError('You are restricted from performing this' |
|
|
if rec['is_create_or_update']: |
|
|
' operation. Please contact the' |
|
|
raise UserError( |
|
|
' administrator.') |
|
|
'You are restricted from performing this' |
|
|
|
|
|
' operation. Please contact the' |
|
|
|
|
|
' administrator.') |
|
|
|
|
|
if rec['restriction_type']=='user': |
|
|
|
|
|
if self.env.user.id == rec['user_id'][0]: |
|
|
|
|
|
if rec['is_create_or_update']: |
|
|
|
|
|
raise UserError( |
|
|
|
|
|
'You are restricted from performing this' |
|
|
|
|
|
' operation. Please contact the' |
|
|
|
|
|
' administrator.') |
|
|
return records |
|
|
return records |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -283,25 +292,34 @@ def unlink(self): |
|
|
[('model', '=', self._name)]).id |
|
|
[('model', '=', self._name)]).id |
|
|
access_right_rec = self.env['access.right'].sudo().search_read( |
|
|
access_right_rec = self.env['access.right'].sudo().search_read( |
|
|
[('model_id', '=', current_model_id)], ['model_id', 'is_delete', |
|
|
[('model_id', '=', current_model_id)], ['model_id', 'is_delete', |
|
|
|
|
|
'restriction_type','user_id', |
|
|
'groups_id']) |
|
|
'groups_id']) |
|
|
if access_right_rec and not self.env.is_admin(): |
|
|
if access_right_rec and not self.env.is_admin(): |
|
|
for rec in access_right_rec: |
|
|
for rec in access_right_rec: |
|
|
group_name = self.env['ir.model.data'].sudo().search([ |
|
|
if rec['restriction_type'] == 'group': |
|
|
('model', '=', 'res.groups'), |
|
|
group_name = self.env['ir.model.data'].sudo().search([ |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
('model', '=', 'res.groups'), |
|
|
]).name |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
module_name = self.env['ir.model.data'].sudo().search([ |
|
|
]).name |
|
|
('model', '=', 'res.groups'), |
|
|
module_name = self.env['ir.model.data'].sudo().search([ |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
('model', '=', 'res.groups'), |
|
|
]).module |
|
|
('res_id', '=', rec['groups_id'][0]) |
|
|
group = module_name + "." + group_name |
|
|
]).module |
|
|
if self.env.user.has_group(group): |
|
|
group = module_name + "." + group_name |
|
|
if rec['is_delete']: |
|
|
if self.env.user.has_group(group): |
|
|
raise UserError(_('You are restricted from performing this' |
|
|
if rec['is_delete']: |
|
|
' operation. Please contact the' |
|
|
raise UserError( |
|
|
' administrator.')) |
|
|
_('You are restricted from performing this' |
|
|
|
|
|
' operation. Please contact the' |
|
|
|
|
|
' administrator.')) |
|
|
|
|
|
if rec['restriction_type']=='user': |
|
|
|
|
|
if self.env.user.id == rec['user_id'][0]: |
|
|
|
|
|
if rec['is_delete']: |
|
|
|
|
|
raise UserError( |
|
|
|
|
|
'You are restricted from performing this' |
|
|
|
|
|
' operation. Please contact the' |
|
|
|
|
|
' administrator.') |
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BaseModel._create = _create |
|
|
BaseModel._create = _create |
|
|
BaseModel.unlink = unlink |
|
|
BaseModel.unlink = unlink |
|
|