'mail.message check permission rules for related document. This method is
meant to be inherited in order to implement addons-specific behavior.
A common behavior would be to allow creating messages when having read
access rule on the document, for portal document such as issues.'

@api.model
def check_mail_message_access(self, res_ids, operation, model_name=None):

    if model_name:
        DocModel = self.env[model_name]
    else:
        DocModel = self
    if hasattr(DocModel, '_mail_post_access'):
        create_allow = DocModel._mail_post_access
    else:
        create_allow = 'write'
    if (operation in ['write', 'unlink']):
        check_operation = 'write'
    elif ((operation == 'create') and (create_allow in ['create', 'read', 'write', 'unlink'])):
        check_operation = create_allow
    elif (operation == 'create'):
        check_operation = 'write'
    else:
        check_operation = operation
    DocModel.check_access_rights(check_operation)
    DocModel.browse(res_ids).check_access_rule(check_operation)
