[IMP] base: do not load actions when can not read target models
As neither fields_view_get, nor default_get actually verify you have access to a specific model (this is likely to be changed in the future), it was possible to execute an action to a model, even if the user does not have access to the corresponding model. Before this commit, launching an action to a wizard with no access was opening a new record view with all fields in readonly and clicking on any button raised an access error. To avoid the frustrating of seeing an action but getting an unusable screen when clicking on it, just hide the action in the first place.
This commit is contained in:
@@ -109,6 +109,7 @@ class IrActions(models.Model):
|
||||
WHERE a.binding_model_id=m.id AND m.model=%s
|
||||
ORDER BY a.id """
|
||||
cr.execute(query, [model_name])
|
||||
IrModelAccess = self.env['ir.model.access']
|
||||
|
||||
# discard unauthorized actions, and read action definitions
|
||||
result = defaultdict(list)
|
||||
@@ -117,9 +118,13 @@ class IrActions(models.Model):
|
||||
try:
|
||||
action = self.env[action_model].browse(action_id)
|
||||
action_groups = getattr(action, 'groups_id', ())
|
||||
action_model = getattr(action, 'res_model', False)
|
||||
if action_groups and not action_groups & user_groups:
|
||||
# the user may not perform this action
|
||||
continue
|
||||
if action_model and not IrModelAccess.check(action_model, mode='read', raise_exception=False):
|
||||
# the user won't be able to read records
|
||||
continue
|
||||
result[binding_type].append(action.read()[0])
|
||||
except (AccessError, MissingError):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user