[IMP] website: add signup option in website settings
This commit duplicates the General settings' User Signup options in the Website configuration, with a clear description of the options. We also remove the unnecessary usage of safe_eval in auth_signup's res_config.py. As stored values are repr values of a boolean field just comparing the string values is sufficient. There is no need to use safe_eval as it should be used only when necessary.
This commit is contained in:
committed by
Thibault Delavallée
parent
5854bb7d12
commit
689d6d6829
@@ -2,24 +2,27 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class BaseConfigSettings(models.TransientModel):
|
||||
_inherit = 'base.config.settings'
|
||||
|
||||
auth_signup_reset_password = fields.Boolean(string='Enable password reset from Login page')
|
||||
auth_signup_uninvited = fields.Boolean(string='Allow external users to sign up')
|
||||
auth_signup_uninvited = fields.Selection([
|
||||
('b2b', 'On invitation (B2B)'),
|
||||
('b2c', 'Free sign up (B2C)'),
|
||||
], string='Customer Account')
|
||||
auth_signup_template_user_id = fields.Many2one('res.users', string='Template user for new users created through signup')
|
||||
|
||||
@api.model
|
||||
def get_values(self):
|
||||
res = super(BaseConfigSettings, self).get_values()
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
# we use safe_eval on the result, since the value of the parameter is a nonempty string
|
||||
# the value of the parameter is a nonempty string
|
||||
res.update(
|
||||
auth_signup_reset_password=safe_eval(get_param('auth_signup.reset_password', 'False')),
|
||||
auth_signup_uninvited=safe_eval(get_param('auth_signup.allow_uninvited', 'False')),
|
||||
auth_signup_template_user_id=safe_eval(get_param('auth_signup.template_user_id', 'False')),
|
||||
auth_signup_reset_password=get_param('auth_signup.reset_password', 'False').lower() == 'true',
|
||||
auth_signup_uninvited='b2c' if get_param('auth_signup.allow_uninvited', 'False').lower() == 'true' else 'b2b',
|
||||
auth_signup_template_user_id=get_param('auth_signup.template_user_id', 'False').lower() == 'true',
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -29,7 +32,7 @@ class BaseConfigSettings(models.TransientModel):
|
||||
set_param = self.env['ir.config_parameter'].sudo().set_param
|
||||
# we store the repr of the values, since the value of the parameter is a required string
|
||||
set_param('auth_signup.reset_password', repr(self.auth_signup_reset_password))
|
||||
set_param('auth_signup.allow_uninvited', repr(self.auth_signup_uninvited))
|
||||
set_param('auth_signup.allow_uninvited', repr(self.auth_signup_uninvited == 'b2c'))
|
||||
set_param('auth_signup.template_user_id', repr(self.auth_signup_template_user_id.id))
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
<xpath expr="//div[@id='access_rights']" position="after">
|
||||
<div class="col-xs-12 col-md-6 o_setting_box" title="If unchecked, only invited users may sign up.">
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="auth_signup_uninvited"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label string="User Signup" for="auth_signup_uninvited"/>
|
||||
<label for="auth_signup_uninvited"/>
|
||||
<div class="text-muted">
|
||||
Allow external users to sign up from Login page
|
||||
Let your customers log in to see their documents
|
||||
</div>
|
||||
<div class="content-group" attrs="{'invisible': [('auth_signup_uninvited','=',False)]}">
|
||||
<div class="mt8">
|
||||
<field name="auth_signup_uninvited" widget="radio" required="True"/>
|
||||
</div>
|
||||
<div class="content-group" attrs="{'invisible': [('auth_signup_uninvited','=','b2b')]}">
|
||||
<div class="mt16">
|
||||
<button type="object" name="open_template_user" string="Default Access Rights" icon="fa-arrow-right" class="btn-link"/>
|
||||
</div>
|
||||
|
||||
@@ -53,6 +53,10 @@ class WebsiteConfigSettings(models.TransientModel):
|
||||
has_google_analytics = fields.Boolean("Google Analytics")
|
||||
has_google_analytics_dashboard = fields.Boolean("Google Analytics in Dashboard")
|
||||
has_google_maps = fields.Boolean("Google Maps")
|
||||
auth_signup_uninvited = fields.Selection([
|
||||
('b2b', 'On invitation (B2B)'),
|
||||
('b2c', 'Free sign up (B2C)'),
|
||||
], string='Customer Account')
|
||||
|
||||
@api.onchange('has_google_analytics')
|
||||
def onchange_has_google_analytics(self):
|
||||
@@ -77,12 +81,13 @@ class WebsiteConfigSettings(models.TransientModel):
|
||||
if not self.user_has_groups('website.group_website_designer'):
|
||||
raise AccessDenied()
|
||||
res = super(WebsiteConfigSettings, self).get_values()
|
||||
params = self.env['ir.config_parameter'].sudo()
|
||||
get_param = self.env['ir.config_parameter'].sudo().get_param
|
||||
res.update(
|
||||
has_google_analytics=params.get_param('website.has_google_analytics'),
|
||||
has_google_analytics_dashboard=params.get_param('website.has_google_analytics_dashboard'),
|
||||
has_google_maps=params.get_param('website.has_google_maps'),
|
||||
google_maps_api_key=params.get_param('google_maps_api_key', default=''),
|
||||
auth_signup_uninvited='b2c' if get_param('auth_signup.allow_uninvited', 'False').lower() == 'true' else 'b2b',
|
||||
has_google_analytics=get_param('website.has_google_analytics'),
|
||||
has_google_analytics_dashboard=get_param('website.has_google_analytics_dashboard'),
|
||||
has_google_maps=get_param('website.has_google_maps'),
|
||||
google_maps_api_key=get_param('google_maps_api_key', default=''),
|
||||
)
|
||||
return res
|
||||
|
||||
@@ -90,7 +95,9 @@ class WebsiteConfigSettings(models.TransientModel):
|
||||
if not self.user_has_groups('website.group_website_designer'):
|
||||
raise AccessDenied()
|
||||
super(WebsiteConfigSettings, self).set_values()
|
||||
self.env['ir.config_parameter'].sudo().set_param('website.has_google_analytics', self.has_google_analytics)
|
||||
self.env['ir.config_parameter'].sudo().set_param('website.has_google_analytics_dashboard', self.has_google_analytics_dashboard)
|
||||
self.env['ir.config_parameter'].sudo().set_param('website.has_google_maps', self.has_google_maps)
|
||||
self.env['ir.config_parameter'].sudo().set_param('google_maps_api_key', (self.google_maps_api_key or '').strip())
|
||||
set_param = self.env['ir.config_parameter'].sudo().set_param
|
||||
set_param('auth_signup.allow_uninvited', repr(self.auth_signup_uninvited == 'b2c'))
|
||||
set_param('website.has_google_analytics', self.has_google_analytics)
|
||||
set_param('website.has_google_analytics_dashboard', self.has_google_analytics_dashboard)
|
||||
set_param('website.has_google_maps', self.has_google_maps)
|
||||
set_param('google_maps_api_key', (self.google_maps_api_key or '').strip())
|
||||
|
||||
@@ -147,6 +147,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_left_pane">
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="auth_signup_uninvited"/>
|
||||
<div class="text-muted">
|
||||
Let your customers log in to see their documents
|
||||
</div>
|
||||
<div class="mt8">
|
||||
<field name="auth_signup_uninvited" widget="radio" required="True"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Social Media</h2>
|
||||
|
||||
Reference in New Issue
Block a user