[IMP] base_remote: black, isort, prettier
parent
6ebdd21c87
commit
78b1c44c3a
|
@ -2,17 +2,14 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': "Remote Base",
|
||||
'version': '12.0.1.0.1',
|
||||
'category': 'Generic Modules/Base',
|
||||
'author': "Creu Blanca, Odoo Community Association (OCA)",
|
||||
'website': 'http://github.com/OCA/server-tools',
|
||||
'license': 'AGPL-3',
|
||||
"depends": ['web'],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'views/res_remote_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
"name": "Remote Base",
|
||||
"version": "13.0.1.0.1",
|
||||
"category": "Generic Modules/Base",
|
||||
"author": "Creu Blanca, Odoo Community Association (OCA)",
|
||||
"website": "http://github.com/OCA/server-tools",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["web"],
|
||||
"data": ["security/ir.model.access.csv", "views/res_remote_views.xml"],
|
||||
"installable": True,
|
||||
"application": True,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from . import base
|
||||
from . import res_remote
|
||||
from . import res_users
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
# Copyright 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
from threading import current_thread
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class Base(models.AbstractModel):
|
||||
_inherit = 'base'
|
||||
_inherit = "base"
|
||||
|
||||
@property
|
||||
def remote(self):
|
||||
try:
|
||||
remote_addr = current_thread().environ["REMOTE_ADDR"]
|
||||
except (KeyError, AttributeError):
|
||||
return self.env['res.remote']
|
||||
return self.env['res.remote']._get_remote(remote_addr)
|
||||
return self.env["res.remote"]
|
||||
return self.env["res.remote"]._get_remote(remote_addr)
|
||||
|
|
|
@ -1,36 +1,29 @@
|
|||
# Copyright 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import api, models, fields
|
||||
import socket
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResRemote(models.Model):
|
||||
_name = 'res.remote'
|
||||
_description = 'Remotes'
|
||||
_name = "res.remote"
|
||||
_description = "Remotes"
|
||||
|
||||
name = fields.Char(
|
||||
required=True,
|
||||
string='Hostname',
|
||||
index=True,
|
||||
readonly=True
|
||||
)
|
||||
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'
|
||||
required=True, help="Shows if the remote can be found through the socket"
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
('name_unique', 'unique(name)', 'Hostname must be unique')
|
||||
]
|
||||
_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),
|
||||
"name": hostname or addr,
|
||||
"ip": addr,
|
||||
"in_network": bool(hostname),
|
||||
}
|
||||
|
||||
@api.model
|
||||
|
@ -38,12 +31,12 @@ class ResRemote(models.Model):
|
|||
try:
|
||||
hostname, alias, ips = socket.gethostbyaddr(addr)
|
||||
except socket.herror:
|
||||
logging.warning('Remote with ip %s could not be found' % addr)
|
||||
logging.warning("Remote with ip %s could not be found" % addr)
|
||||
hostname = False
|
||||
remote = self.search([('name', '=ilike', hostname or addr)])
|
||||
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})
|
||||
remote.write({"ip": addr})
|
||||
return remote
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from threading import current_thread
|
||||
from odoo import api, models, SUPERUSER_ID
|
||||
|
||||
from odoo import SUPERUSER_ID, api, models
|
||||
from odoo.exceptions import AccessDenied
|
||||
from odoo.service import wsgi_server
|
||||
from odoo.tools import config
|
||||
|
@ -31,7 +32,7 @@ class ResUsers(models.Model):
|
|||
with cls.pool.cursor() as cr:
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
remote = env["res.users"].remote
|
||||
if not config['test_enable']:
|
||||
if not config["test_enable"]:
|
||||
remote.ensure_one()
|
||||
result = method()
|
||||
if not result:
|
||||
|
@ -43,8 +44,7 @@ class ResUsers(models.Model):
|
|||
@classmethod
|
||||
def _login(cls, db, login, password):
|
||||
return cls._auth_check_remote(
|
||||
login,
|
||||
lambda: super(ResUsers, cls)._login(db, login, password),
|
||||
login, lambda: super(ResUsers, cls)._login(db, login, password),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
@ -52,5 +52,6 @@ class ResUsers(models.Model):
|
|||
return cls._auth_check_remote(
|
||||
login,
|
||||
lambda: super(ResUsers, cls).authenticate(
|
||||
db, login, password, user_agent_env),
|
||||
db, login, password, user_agent_env
|
||||
),
|
||||
)
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
This module allows to store all the connected remotes (external ip addresses) to Odoo.
|
||||
It should be used with other modules in order to check remote's configurations.
|
||||
It should be used with other modules in order to check remote's configurations.
|
||||
|
|
|
@ -5,7 +5,7 @@ from mock import patch
|
|||
from werkzeug.utils import redirect
|
||||
|
||||
from odoo import http
|
||||
from odoo.tests.common import at_install, HttpCase, post_install
|
||||
from odoo.tests.common import HttpCase, at_install, post_install
|
||||
|
||||
|
||||
@at_install(False)
|
||||
|
@ -24,39 +24,39 @@ class TestRemote(HttpCase):
|
|||
"login": "demo",
|
||||
"password": "Demo%&/(908409**",
|
||||
}
|
||||
self.remote_addr = '127.0.0.1'
|
||||
self.remote_addr = "127.0.0.1"
|
||||
with self.cursor() as cr:
|
||||
env = self.env(cr)
|
||||
# Make sure involved users have good passwords
|
||||
env.user.password = self.good_password
|
||||
env["res.users"].search([
|
||||
("login", "=", self.data_demo["login"]),
|
||||
]).password = self.data_demo["password"]
|
||||
remote = self.env['res.remote'].search([
|
||||
('ip', '=', self.remote_addr)
|
||||
])
|
||||
env["res.users"].search(
|
||||
[("login", "=", self.data_demo["login"])]
|
||||
).password = self.data_demo["password"]
|
||||
remote = self.env["res.remote"].search([("ip", "=", self.remote_addr)])
|
||||
if remote:
|
||||
remote.unlink()
|
||||
|
||||
def test_xmlrpc_login_ok(self, *args):
|
||||
"""Test Login"""
|
||||
data1 = self.data_demo
|
||||
self.assertTrue(self.xmlrpc_common.authenticate(
|
||||
self.env.cr.dbname, data1["login"], data1["password"], {}))
|
||||
self.assertTrue(
|
||||
self.xmlrpc_common.authenticate(
|
||||
self.env.cr.dbname, data1["login"], data1["password"], {}
|
||||
)
|
||||
)
|
||||
with self.cursor() as cr:
|
||||
env = self.env(cr)
|
||||
self.assertTrue(
|
||||
env['res.remote'].search([('ip', '=', self.remote_addr)])
|
||||
)
|
||||
self.assertTrue(env["res.remote"].search([("ip", "=", self.remote_addr)]))
|
||||
|
||||
def test_xmlrpc_login_failure(self, *args):
|
||||
"""Test Login Failure"""
|
||||
data1 = self.data_demo
|
||||
data1['password'] = 'Failure!'
|
||||
self.assertFalse(self.xmlrpc_common.authenticate(
|
||||
self.env.cr.dbname, data1["login"], data1["password"], {}))
|
||||
data1["password"] = "Failure!"
|
||||
self.assertFalse(
|
||||
self.xmlrpc_common.authenticate(
|
||||
self.env.cr.dbname, data1["login"], data1["password"], {}
|
||||
)
|
||||
)
|
||||
with self.cursor() as cr:
|
||||
env = self.env(cr)
|
||||
self.assertTrue(
|
||||
env['res.remote'].search([('ip', '=', self.remote_addr)])
|
||||
)
|
||||
self.assertTrue(env["res.remote"].search([("ip", "=", self.remote_addr)]))
|
||||
|
|
|
@ -7,15 +7,17 @@
|
|||
<form string="Remote">
|
||||
<sheet>
|
||||
<div class="oe_title">
|
||||
<h1><field name="name"/></h1>
|
||||
<h1>
|
||||
<field name="name" />
|
||||
</h1>
|
||||
</div>
|
||||
<group name="technical">
|
||||
<group name="network">
|
||||
<field name="ip"/>
|
||||
<field name="in_network"/>
|
||||
<field name="ip" />
|
||||
<field name="in_network" />
|
||||
</group>
|
||||
</group>
|
||||
<notebook/>
|
||||
<notebook />
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -25,8 +27,8 @@
|
|||
<field name="model">res.remote</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Remotes">
|
||||
<field name="name"/>
|
||||
<field name="ip"/>
|
||||
<field name="name" />
|
||||
<field name="ip" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -37,10 +39,11 @@
|
|||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="res_remote_menu"
|
||||
name="Remotes"
|
||||
sequence="10"
|
||||
parent="base.menu_administration"
|
||||
action="res_remote_action"/>
|
||||
<menuitem
|
||||
id="res_remote_menu"
|
||||
name="Remotes"
|
||||
sequence="10"
|
||||
parent="base.menu_administration"
|
||||
action="res_remote_action"
|
||||
/>
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue