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