Initial commit: Odoo 18.0-20251222 extra-addons
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled

This commit is contained in:
tocmo0nlord
2026-03-13 20:43:25 +00:00
parent 36e847a7df
commit adbe430761
9472 changed files with 1265727 additions and 0 deletions

3
base_remote/models/__init__.py Executable file
View File

@@ -0,0 +1,3 @@
from . import base
from . import res_remote
from . import res_users

18
base_remote/models/base.py Executable file
View File

@@ -0,0 +1,18 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
# from threading import current_thread
from odoo import http, models
class Base(models.AbstractModel):
_inherit = "base"
@property
def remote(self):
try:
remote_addr = http.request.httprequest.remote_addr
except (KeyError, AttributeError, RuntimeError):
return self.env["res.remote"]
return self.env["res.remote"]._get_remote(remote_addr)

View File

@@ -0,0 +1,42 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
import socket
from odoo import api, fields, models
class ResRemote(models.Model):
_name = "res.remote"
_description = "Remotes"
name = fields.Char(required=True, string="Hostname", index=True, readonly=True)
ip = fields.Char(required=True)
in_network = fields.Boolean(
required=True, help="Shows if the remote can be found through the socket"
)
_sql_constraints = [("name_unique", "unique(name)", "Hostname must be unique")]
@api.model
def _create_vals(self, addr, hostname):
return {
"name": hostname or addr,
"ip": addr,
"in_network": bool(hostname),
}
@api.model
def _get_remote(self, addr):
try:
hostname, alias, ips = socket.gethostbyaddr(addr)
except socket.herror:
logging.warning(f"Remote with ip {addr} could not be found")
hostname = False
remote = self.search([("name", "=ilike", hostname or addr)])
if not remote:
remote = self.create(self._create_vals(addr, hostname))
if remote.ip != addr:
# IPs can change through time, but hostname should not change
remote.write({"ip": addr})
return remote

40
base_remote/models/res_users.py Executable file
View File

@@ -0,0 +1,40 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api, models
from odoo.exceptions import AccessDenied
from odoo.tools import config
class ResUsers(models.Model):
_inherit = "res.users"
@classmethod
def _auth_check_remote(cls, credential, method):
"""Force a method to raise an AccessDenied on falsey return."""
with cls.pool.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
remote = env["res.users"].remote
if not config["test_enable"]:
remote.ensure_one()
result = method()
if not result:
# Force exception to record auth failure
raise AccessDenied()
return result
# Override all auth-related core methods
@classmethod
def _login(cls, db, credential, user_agent_env):
return cls._auth_check_remote(
credential,
lambda: super(ResUsers, cls)._login(db, credential, user_agent_env),
)
@classmethod
def authenticate(cls, db, credential, user_agent_env):
return cls._auth_check_remote(
credential,
lambda: super(ResUsers, cls).authenticate(db, credential, user_agent_env),
)