Files
odoo_source/addons/hr_presence/controllers/bus_controller.py
T
Florian Charlier dae28c4b46 [IMP] base: add _is_internal method to res.users
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
2022-06-14 09:35:57 +02:00

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)