Impacted versions:

8.0

Steps to reproduce:

To reproduce this one, you have to configure outgoing and incoming server and mail aliases

see https://youtu.be/-HzDGh9C9Jc

Current behavior:

If you add a user which has no acces on a object (purchase.order in this case) as follower on a record of this object **AFTER someone has responded by email on this record**, and if you send an message on this record, an exception is raised at the connection of the user added as a follower.

Expected behavior:

No exceptions should be raised at the connection of the user added as a follower.

Video/Screenshot link (optional):

https://youtu.be/-HzDGh9C9Jc

addons/mail/mail_message.py
""" Set messages as (un)read. Technically, the notifications related
            to uid are set to (un)read. If for some msg_ids there are missing
            notifications (i.e. due to load more or thread parent fetching),
            they are created.
            :param bool read: set notification as (un)read
            :param bool create_missing: create notifications for missing entries
                (i.e. when acting on displayed messages not notified)
            :return number of message mark as read
        """
        notification_obj = self.pool.get('mail.notification')
        user_pid = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id.id
        domain = [('partner_id', '=', user_pid), ('message_id', 'in', msg_ids)]
        if not create_missing:
            domain += [('is_read', '=', not read)]
        notif_ids = notification_obj.search(cr, uid, domain, context=context)
        
        if len(notif_ids) == len(msg_ids) or not create_missing:
            notification_obj.write(cr, uid, notif_ids, {'is_read': read}, context=context)
            return len(notif_ids)
        
        notified_msg_ids = [notification.message_id.id for notification in notification_obj.browse(cr, uid, notif_ids, context=context)]
        to_create_msg_ids = list(set(msg_ids) - set(notified_msg_ids))
        for msg_id in to_create_msg_ids:
            notification_obj.create(cr, uid, {'partner_id': user_pid, 'is_read': read, 'message_id': msg_id}, context=context)
        notification_obj.write(cr, uid, notif_ids, {'is_read': read}, context=context)
        return len(notif_ids)
    @api.cr_uid_ids_context
    def set_message_starred(self, cr, uid, msg_ids, starred, create_missing=True, context=None):
        """ Set messages as (un)starred. Technically, the notifications related
            to uid are set to (un)starred.