No method was readily available to know if a user is `internal` (has
group `base.group_user`), which was inconsistent with other base groups.
_is_internal is now used in the codebase where it is clear that
`.has_group('base.group_user')` is called on a single record.
Part-of: odoo/odoo#85703
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import registry, SUPERUSER_ID
|
|
from odoo.api import Environment
|
|
from odoo.addons.bus.controllers import main
|
|
from odoo.fields import Datetime
|
|
from odoo.http import Controller, request, route
|
|
|
|
|
|
class BusController(main.BusController):
|
|
|
|
@route('/longpolling/poll', type="json", auth="public")
|
|
def poll(self, channels, last, options=None):
|
|
if request.env.user._is_internal():
|
|
ip_address = request.httprequest.remote_addr
|
|
users_log = request.env['res.users.log'].search_count([
|
|
('create_uid', '=', request.env.user.id),
|
|
('ip', '=', ip_address),
|
|
('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))])
|
|
if not users_log:
|
|
with registry(request.env.cr.dbname).cursor() as cr:
|
|
env = Environment(cr, request.env.user.id, {})
|
|
env['res.users.log'].create({'ip': ip_address})
|
|
return super(BusController, self).poll(channels, last, options=options)
|