From f4b9811702742da74fc865555e6e210fb6c121d6 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Mon, 26 Jun 2023 14:12:15 +0200 Subject: [PATCH 1/9] [14.0] auth_api_key: allow to update api key from form view and hide keys in UI --- auth_api_key/views/auth_api_key.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth_api_key/views/auth_api_key.xml b/auth_api_key/views/auth_api_key.xml index c2305274ae..209e74a410 100644 --- a/auth_api_key/views/auth_api_key.xml +++ b/auth_api_key/views/auth_api_key.xml @@ -6,7 +6,7 @@ auth.api.key.form (in auth_api_key) auth.api.key -
+
From fecda7c1e3cf3153708fba2be2ec626b85bdd32d Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 21 Jan 2022 11:41:19 +0100 Subject: [PATCH 2/9] auth_api_key_group: dev status -> Beta --- auth_api_key_group/__manifest__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/auth_api_key_group/__manifest__.py b/auth_api_key_group/__manifest__.py index bd3f4e82db..2e328fe854 100644 --- a/auth_api_key_group/__manifest__.py +++ b/auth_api_key_group/__manifest__.py @@ -11,6 +11,7 @@ to limit access to services or records based on groups of keys. """, "version": "17.0.1.0.0", + "development_status": "Beta", "license": "LGPL-3", "website": "https://github.com/OCA/server-auth", "author": "Camptcamp,Odoo Community Association (OCA)", From 2d605f471cf7ef19ade07566336bac23d32ed1c7 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 14 Jan 2022 07:28:34 +0100 Subject: [PATCH 3/9] auth_api_key_group: fix author name --- auth_api_key_group/README.rst | 2 +- auth_api_key_group/__manifest__.py | 4 ++-- auth_api_key_group/models/auth_api_key.py | 2 +- auth_api_key_group/models/auth_api_key_group.py | 2 +- auth_api_key_group/static/description/index.html | 2 +- auth_api_key_group/tests/test_auth_api_key_group.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/auth_api_key_group/README.rst b/auth_api_key_group/README.rst index 52ecabd066..690721b41e 100644 --- a/auth_api_key_group/README.rst +++ b/auth_api_key_group/README.rst @@ -55,7 +55,7 @@ Credits Authors ------- -* Camptcamp +* Camptocamp Contributors ------------ diff --git a/auth_api_key_group/__manifest__.py b/auth_api_key_group/__manifest__.py index 2e328fe854..59560b965f 100644 --- a/auth_api_key_group/__manifest__.py +++ b/auth_api_key_group/__manifest__.py @@ -1,4 +1,4 @@ -# Copyright 2021 Camptcamp SA +# Copyright 2021 Camptocamp SA # @author: Simone Orsi # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). @@ -14,7 +14,7 @@ "development_status": "Beta", "license": "LGPL-3", "website": "https://github.com/OCA/server-auth", - "author": "Camptcamp,Odoo Community Association (OCA)", + "author": "Camptocamp,Odoo Community Association (OCA)", "maintainers": ["simahawk"], "depends": ["auth_api_key"], "data": [ diff --git a/auth_api_key_group/models/auth_api_key.py b/auth_api_key_group/models/auth_api_key.py index 5743900ce0..46ff9ae907 100644 --- a/auth_api_key_group/models/auth_api_key.py +++ b/auth_api_key_group/models/auth_api_key.py @@ -1,4 +1,4 @@ -# Copyright 2021 Camptcamp SA +# Copyright 2021 Camptocamp SA # @author: Simone Orsi # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). diff --git a/auth_api_key_group/models/auth_api_key_group.py b/auth_api_key_group/models/auth_api_key_group.py index 28f34f5e85..1887287a9b 100644 --- a/auth_api_key_group/models/auth_api_key_group.py +++ b/auth_api_key_group/models/auth_api_key_group.py @@ -1,4 +1,4 @@ -# Copyright 2021 Camptcamp SA +# Copyright 2021 Camptocamp SA # @author: Simone Orsi # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). diff --git a/auth_api_key_group/static/description/index.html b/auth_api_key_group/static/description/index.html index 006a7a198c..bb14cb3f09 100644 --- a/auth_api_key_group/static/description/index.html +++ b/auth_api_key_group/static/description/index.html @@ -400,7 +400,7 @@

Credits

Authors

    -
  • Camptcamp
  • +
  • Camptocamp
diff --git a/auth_api_key_group/tests/test_auth_api_key_group.py b/auth_api_key_group/tests/test_auth_api_key_group.py index 75581bbf16..846bc9750b 100644 --- a/auth_api_key_group/tests/test_auth_api_key_group.py +++ b/auth_api_key_group/tests/test_auth_api_key_group.py @@ -1,4 +1,4 @@ -# Copyright 2021 Camptcamp SA +# Copyright 2021 Camptocamp SA # @author: Simone Orsi # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). From cc5c249d407b7be93fe53309106d3ee48a85b417 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Tue, 21 Mar 2023 15:30:58 +0100 Subject: [PATCH 4/9] auth_api_key: archive key when user is archived An archived user should not have an active api key anymore. But to stay backward compatible the migration script will keep all key active. --- auth_api_key/models/auth_api_key.py | 8 ++++++++ auth_api_key/tests/test_auth_api_key.py | 13 +++++++++++++ auth_api_key/views/auth_api_key.xml | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/auth_api_key/models/auth_api_key.py b/auth_api_key/models/auth_api_key.py index 416cd4ab7f..04381e5c3e 100644 --- a/auth_api_key/models/auth_api_key.py +++ b/auth_api_key/models/auth_api_key.py @@ -23,6 +23,9 @@ class AuthApiKey(models.Model): help="""The user used to process the requests authenticated by the api key""", ) + # Not using related to stay backward compatible with having active key + # for an archived user (no need to be charged on active user for the api) + active = fields.Boolean(compute="_compute_active", readonly=False, store=True) _sql_constraints = [("name_uniq", "unique(name)", "Api Key name must be unique.")] @@ -48,6 +51,11 @@ def _retrieve_uid_from_api_key(self, key): def _clear_key_cache(self): self.env.registry.clear_cache() + @api.depends("user_id.active") + def _compute_active(self): + for record in self: + record.active = record.user_id.active + @api.model_create_multi def create(self, vals_list): records = super().create(vals_list) diff --git a/auth_api_key/tests/test_auth_api_key.py b/auth_api_key/tests/test_auth_api_key.py index b8e0804097..067fec3e9d 100644 --- a/auth_api_key/tests/test_auth_api_key.py +++ b/auth_api_key/tests/test_auth_api_key.py @@ -43,3 +43,16 @@ def test_cache_invalidation(self): ) with self.assertRaises(ValidationError): self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key") + + def test_user_archived_unarchived(self): + demo_user = self.env.ref("base.user_demo") + self.assertEqual( + self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key"), demo_user.id + ) + demo_user.active = False + with self.assertRaises(ValidationError): + self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key") + demo_user.active = True + self.assertEqual( + self.env["auth.api.key"]._retrieve_uid_from_api_key("api_key"), demo_user.id + ) diff --git a/auth_api_key/views/auth_api_key.xml b/auth_api_key/views/auth_api_key.xml index 209e74a410..d0543249a2 100644 --- a/auth_api_key/views/auth_api_key.xml +++ b/auth_api_key/views/auth_api_key.xml @@ -8,6 +8,13 @@
+ +