From c6e30a34b5de0ce02205efd2f2804b773bac08cb Mon Sep 17 00:00:00 2001 From: Nicolas JEUDY Date: Mon, 22 Jun 2020 13:57:42 +0200 Subject: [PATCH] [MIG] 13.0 initial working version for openid_connect --- .../models/ext_module.py | 1 - galicea_openid_connect/__init__.py | 1 + galicea_openid_connect/__manifest__.py | 3 +- .../{security/__init__.py => hooks.py} | 20 +++++------ galicea_openid_connect/models/client.py | 2 -- galicea_openid_connect/security/init.xml | 8 ----- galicea_openid_connect/security/init.yml | 4 --- galicea_openid_connect/views/views.xml | 35 ++++++------------- 8 files changed, 22 insertions(+), 52 deletions(-) rename galicea_openid_connect/{security/__init__.py => hooks.py} (56%) delete mode 100644 galicea_openid_connect/security/init.xml delete mode 100644 galicea_openid_connect/security/init.yml diff --git a/galicea_environment_checkup/models/ext_module.py b/galicea_environment_checkup/models/ext_module.py index caedbea..66a0b95 100644 --- a/galicea_environment_checkup/models/ext_module.py +++ b/galicea_environment_checkup/models/ext_module.py @@ -10,7 +10,6 @@ class Module(models.Model): dependency_checks = fields.Text(compute="_compute_dependency_checks") - @api.one def _compute_dependency_checks(self): checks = dependencies.get_checks_for_module_recursive(self) self.dependency_checks = json.dumps(display_data(self.env, checks)) diff --git a/galicea_openid_connect/__init__.py b/galicea_openid_connect/__init__.py index d32de84..c72d346 100644 --- a/galicea_openid_connect/__init__.py +++ b/galicea_openid_connect/__init__.py @@ -3,3 +3,4 @@ from . import models from . import system_checks from . import api +from .hooks import init_keys diff --git a/galicea_openid_connect/__manifest__.py b/galicea_openid_connect/__manifest__.py index 35008a1..ee6510a 100644 --- a/galicea_openid_connect/__manifest__.py +++ b/galicea_openid_connect/__manifest__.py @@ -12,7 +12,7 @@ "security/security.xml", "security/ir.model.access.csv", # 'security/init.yml', - "security/init.xml", + # "security/init.xml", "views/views.xml", "views/templates.xml", ], @@ -28,6 +28,7 @@ ] } }, + "post_init_hook": "init_keys", "images": [ "static/description/images/master_screenshot.png", "static/description/images/client_screenshot.png", diff --git a/galicea_openid_connect/security/__init__.py b/galicea_openid_connect/hooks.py similarity index 56% rename from galicea_openid_connect/security/__init__.py rename to galicea_openid_connect/hooks.py index 58da460..5784ab5 100644 --- a/galicea_openid_connect/security/__init__.py +++ b/galicea_openid_connect/hooks.py @@ -1,4 +1,5 @@ -from .. import random_tokens +from odoo import api, SUPERUSER_ID +from . import random_tokens try: from jwcrypto import jwk @@ -6,7 +7,8 @@ except ImportError: pass -def init_keys(IrConfigParameter): +def init_keys(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) keys = { "galicea_openid_connect.authorization_code_jwk": lambda: jwk.JWK.generate( kty="oct", @@ -24,14 +26,8 @@ def init_keys(IrConfigParameter): ).export(), } - for key, gen in keys.iteritems(): - if not IrConfigParameter.search([("key", "=", key)]): - IrConfigParameter.create( - { - "key": key, - "value": gen(), - "group_ids": [ - (4, IrConfigParameter.env.ref("base.group_erp_manager").id) - ], - } + for key, gen in keys.items(): + if not env["ir.config_parameter"].search([("key", "=", key)]): + env["ir.config_parameter"].create( + {"key": key, "value": gen(),} ) diff --git a/galicea_openid_connect/models/client.py b/galicea_openid_connect/models/client.py index 520655f..5dc246c 100644 --- a/galicea_openid_connect/models/client.py +++ b/galicea_openid_connect/models/client.py @@ -54,7 +54,6 @@ class Client(models.Model): values["system_user_id"] = system_user.id return super(Client, self).create(values) - @api.multi def write(selfs, values): super(Client, selfs).write(values) if "name" in values: @@ -63,7 +62,6 @@ class Client(models.Model): ) return True - @api.multi def unlink(selfs): users_to_unlink = selfs.mapped(lambda client: client.system_user_id) ret = super(Client, selfs).unlink() diff --git a/galicea_openid_connect/security/init.xml b/galicea_openid_connect/security/init.xml deleted file mode 100644 index 6a8285d..0000000 --- a/galicea_openid_connect/security/init.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/galicea_openid_connect/security/init.yml b/galicea_openid_connect/security/init.yml deleted file mode 100644 index e827682..0000000 --- a/galicea_openid_connect/security/init.yml +++ /dev/null @@ -1,4 +0,0 @@ -- - !python {model: ir.config_parameter}: | - from odoo.addons.galicea_openid_connect.security import init_keys - init_keys(self) diff --git a/galicea_openid_connect/views/views.xml b/galicea_openid_connect/views/views.xml index 5fd28fc..4c1ed4b 100644 --- a/galicea_openid_connect/views/views.xml +++ b/galicea_openid_connect/views/views.xml @@ -5,11 +5,11 @@ action = { - "type": "ir.actions.act_window", - "view_mode": "form", - "view_id": obj.env.ref('galicea_openid_connect.client_view_form_secret').id, - "res_model": "galicea_openid_connect.client", - "res_id": obj.id + "type": "ir.actions.act_window", + "view_mode": "form", + "view_id": obj.env.ref('galicea_openid_connect.client_view_form_secret').id, + "res_model": "galicea_openid_connect.client", + "res_id": obj.id } @@ -23,9 +23,8 @@ - - - galicea_openid_connect.client @@ -57,10 +44,10 @@ + name="OpenID Clients" + res_model="galicea_openid_connect.client" /> - +