From 4a637d277cbb28518c7b2b1934a0b8994a86b355 Mon Sep 17 00:00:00 2001 From: Cedric Collins Date: Thu, 18 Feb 2021 17:09:34 -0600 Subject: [PATCH] [IMP] auth_admin, [ADD] auth_admin_website: enable select website to get base url from company H4905 --- auth_admin/__manifest__.py | 1 - auth_admin/models/res_users.py | 4 ++-- auth_admin_website/__init__.py | 1 + auth_admin_website/__manifest__.py | 21 +++++++++++++++++++ auth_admin_website/wizard/__init__.py | 1 + auth_admin_website/wizard/portal_wizard.py | 20 ++++++++++++++++++ .../wizard/portal_wizard_views.xml | 13 ++++++++++++ 7 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 auth_admin_website/__init__.py create mode 100755 auth_admin_website/__manifest__.py create mode 100644 auth_admin_website/wizard/__init__.py create mode 100755 auth_admin_website/wizard/portal_wizard.py create mode 100644 auth_admin_website/wizard/portal_wizard_views.xml diff --git a/auth_admin/__manifest__.py b/auth_admin/__manifest__.py index 1420a7a3..a25e26f5 100755 --- a/auth_admin/__manifest__.py +++ b/auth_admin/__manifest__.py @@ -17,7 +17,6 @@ Out of the box, only allows you to generate a login for an 'External User', e.g. """, 'depends': [ 'base', - 'website', 'portal', ], 'auto_install': False, diff --git a/auth_admin/models/res_users.py b/auth_admin/models/res_users.py index 074abca0..2d5d16c6 100755 --- a/auth_admin/models/res_users.py +++ b/auth_admin/models/res_users.py @@ -9,7 +9,7 @@ from logging import getLogger _logger = getLogger(__name__) -def admin_auth_generate_login(env, user): +def admin_auth_generate_login(env, user, base_url=None): """ Generates a URL to allow the current user to login as the portal user. @@ -29,7 +29,7 @@ def admin_auth_generate_login(env, user): key = str(config.search([('key', '=', 'database.secret')], limit=1).value) h = hmac.new(key.encode(), (u + e + o).encode(), sha256) - base_url = str(config.search([('key', '=', 'web.base.url')], limit=1).value) + base_url = base_url or str(config.search([('key', '=', 'web.base.url')], limit=1).value) _logger.warn('login url for user id: ' + u + ' original user id: ' + o) diff --git a/auth_admin_website/__init__.py b/auth_admin_website/__init__.py new file mode 100644 index 00000000..40272379 --- /dev/null +++ b/auth_admin_website/__init__.py @@ -0,0 +1 @@ +from . import wizard diff --git a/auth_admin_website/__manifest__.py b/auth_admin_website/__manifest__.py new file mode 100755 index 00000000..03ea74a3 --- /dev/null +++ b/auth_admin_website/__manifest__.py @@ -0,0 +1,21 @@ +{ + 'name': 'Auth Admin Website', + 'author': 'Hibou Corp. ', + 'category': 'Hidden', + 'version': '13.0.1.0.0', + 'description': + """ +Login as other user +=================== + +Add support for multiple websites to Auth Admin + """, + 'depends': [ + 'auth_admin', + 'website', + ], + 'auto_install': True, + 'data': [ + 'wizard/portal_wizard_views.xml', + ], +} diff --git a/auth_admin_website/wizard/__init__.py b/auth_admin_website/wizard/__init__.py new file mode 100644 index 00000000..8bff21fa --- /dev/null +++ b/auth_admin_website/wizard/__init__.py @@ -0,0 +1 @@ +from . import portal_wizard diff --git a/auth_admin_website/wizard/portal_wizard.py b/auth_admin_website/wizard/portal_wizard.py new file mode 100755 index 00000000..2231543b --- /dev/null +++ b/auth_admin_website/wizard/portal_wizard.py @@ -0,0 +1,20 @@ +from odoo import fields, models +from odoo.addons.auth_admin.models.res_users import admin_auth_generate_login + + +class PortalWizardUser(models.TransientModel): + _inherit = 'portal.wizard.user' + + website_id = fields.Many2one('website', string='Website') + + def admin_auth_generate_login(self): + ir_model_access = self.env['ir.model.access'] + for row in self.filtered(lambda r: r.in_portal): + user = row.partner_id.user_ids[0] if row.partner_id.user_ids else None + if ir_model_access.check('res.partner', mode='unlink') and user: + if row.website_id: + base_url = row.website_id.get_base_url() + else: + base_url = None + row.force_login_url = admin_auth_generate_login(self.env, user, base_url=base_url) + self.filtered(lambda r: not r.in_portal).update({'force_login_url': ''}) diff --git a/auth_admin_website/wizard/portal_wizard_views.xml b/auth_admin_website/wizard/portal_wizard_views.xml new file mode 100644 index 00000000..a1e64b17 --- /dev/null +++ b/auth_admin_website/wizard/portal_wizard_views.xml @@ -0,0 +1,13 @@ + + + + Portal Access Management - Auth Admin Multi-Website + portal.wizard + + + + + + + +