from odoo import models


class IrHttp(models.AbstractModel):
    _inherit = 'ir.http'

    def session_info(self):
        """Expose, synchronously to the web client, whether the Templates
        button should be rendered in the chatter for the current user.

        The composer action's ``condition`` callback is synchronous, so the
        flag is surfaced here (rather than via a runtime RPC) to avoid a
        button flicker. It combines the company-specific feature flag
        (Section 2.9) with the user's group membership (Section 2.3 / 5.1).
        """
        result = super().session_info()
        user = self.env.user
        enabled = self.env['mail.quick.template']._is_feature_enabled()
        has_group = user.has_group('do_mail_quick_templates.group_template_user')
        result['do_mail_quick_templates_enabled'] = bool(enabled and has_group)
        result['do_mail_quick_templates_is_manager'] = user.has_group(
            'do_mail_quick_templates.group_template_manager'
        )
        return result
