diff --git a/auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py b/auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py new file mode 100644 index 0000000000..e590eae6fa --- /dev/null +++ b/auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py @@ -0,0 +1,10 @@ +from odoo import SUPERUSER_ID, api + + +def migrate(cr, version): + env = api.Environment(cr, SUPERUSER_ID, {}) + keys = env["auth.api.key"].search( + [("tech_name", "=", False), ("name", "!=", False)] + ) + for key in keys: + key.write({"tech_name": key._normalize_tech_name(key.name)}) diff --git a/auth_api_key_server_env/models/auth_api_key.py b/auth_api_key_server_env/models/auth_api_key.py index baabfde16e..4e30d81011 100644 --- a/auth_api_key_server_env/models/auth_api_key.py +++ b/auth_api_key_server_env/models/auth_api_key.py @@ -10,20 +10,17 @@ class AuthApiKey(models.Model): _name = "auth.api.key" - _inherit = ["auth.api.key", "server.env.mixin"] + _inherit = ["auth.api.key", "server.env.techname.mixin", "server.env.mixin"] def _server_env_section_name(self): """Name of the section in the configuration files - We override the default implementation to keep the compatibility with the previous implementation of auth_api_key. The section name into the configuration file must be formatted as - 'api_key_{name}' - """ self.ensure_one() - return "api_key_{}".format(self.name) + return "api_key_{}".format(getattr(self, self._server_env_section_name_field)) @property def _server_env_fields(self): diff --git a/auth_api_key_server_env/readme/CONTRIBUTORS.rst b/auth_api_key_server_env/readme/CONTRIBUTORS.rst index f1c71bce18..bf905a1e0d 100644 --- a/auth_api_key_server_env/readme/CONTRIBUTORS.rst +++ b/auth_api_key_server_env/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * Simone Orsi +* Florian da Costa diff --git a/auth_api_key_server_env/readme/DESCRIPTION.rst b/auth_api_key_server_env/readme/DESCRIPTION.rst index 1dc7bf00af..a1f43f857e 100644 --- a/auth_api_key_server_env/readme/DESCRIPTION.rst +++ b/auth_api_key_server_env/readme/DESCRIPTION.rst @@ -6,5 +6,5 @@ section to your configuration file according to the following convention: .. code-block:: ini - [api_key_] + [api_key_] key=my_api_key diff --git a/auth_api_key_server_env/tests/test_auth_api_key.py b/auth_api_key_server_env/tests/test_auth_api_key.py index 4121cc3a5f..cded35ecd8 100644 --- a/auth_api_key_server_env/tests/test_auth_api_key.py +++ b/auth_api_key_server_env/tests/test_auth_api_key.py @@ -15,11 +15,16 @@ def setUpClass(cls, *args, **kwargs): cls.AuthApiKey = cls.env["auth.api.key"] cls.demo_user = cls.env.ref("base.user_demo") cls.api_key_from_env = cls.AuthApiKey.create( - {"name": "from_env", "key": "dummy", "user_id": cls.demo_user.id} + { + "name": "From Env", + "key": "dummy", + "user_id": cls.demo_user.id, + "tech_name": "test_env", + } ) cls.api_key_from_env.refresh() - serv_config.add_section("api_key_from_env") - serv_config.set("api_key_from_env", "key", "api_key_from_env") + serv_config.add_section("api_key_test_env") + serv_config.set("api_key_test_env", "key", "api_key_from_env") def test_lookup_key_from_env(self): self.assertEqual(