mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] auth_admin, [ADD] auth_admin_website: enable select website to get base url from company
H4905
This commit is contained in:
@@ -17,7 +17,6 @@ Out of the box, only allows you to generate a login for an 'External User', e.g.
|
|||||||
""",
|
""",
|
||||||
'depends': [
|
'depends': [
|
||||||
'base',
|
'base',
|
||||||
'website',
|
|
||||||
'portal',
|
'portal',
|
||||||
],
|
],
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from logging import getLogger
|
|||||||
_logger = getLogger(__name__)
|
_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.
|
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)
|
key = str(config.search([('key', '=', 'database.secret')], limit=1).value)
|
||||||
h = hmac.new(key.encode(), (u + e + o).encode(), sha256)
|
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)
|
_logger.warn('login url for user id: ' + u + ' original user id: ' + o)
|
||||||
|
|
||||||
|
|||||||
1
auth_admin_website/__init__.py
Normal file
1
auth_admin_website/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import wizard
|
||||||
21
auth_admin_website/__manifest__.py
Executable file
21
auth_admin_website/__manifest__.py
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
'name': 'Auth Admin Website',
|
||||||
|
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||||
|
'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',
|
||||||
|
],
|
||||||
|
}
|
||||||
1
auth_admin_website/wizard/__init__.py
Normal file
1
auth_admin_website/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import portal_wizard
|
||||||
20
auth_admin_website/wizard/portal_wizard.py
Executable file
20
auth_admin_website/wizard/portal_wizard.py
Executable file
@@ -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': ''})
|
||||||
13
auth_admin_website/wizard/portal_wizard_views.xml
Normal file
13
auth_admin_website/wizard/portal_wizard_views.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="portal_wizard" model="ir.ui.view">
|
||||||
|
<field name="name">Portal Access Management - Auth Admin Multi-Website</field>
|
||||||
|
<field name="model">portal.wizard</field>
|
||||||
|
<field name="inherit_id" ref="auth_admin.portal_wizard"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='force_login_url']" position="before">
|
||||||
|
<field name="website_id"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user