Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11.0 saas portal signup separate server fix #784

Open
wants to merge 5 commits into
base: 11.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions saas_portal/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def add_new_client(self, redirect_to_signup=False, **post):
query = {'redirect': redirect}
return http.local_redirect(path=url, query=query)

dbname = self.get_full_dbname(post.get('dbname'))
dbname = self.get_full_dbname(post.get('dbname'), post.get('plan_id'))
user_id = request.session.uid
partner_id = None
if user_id:
Expand Down Expand Up @@ -78,10 +78,13 @@ def get_config_parameter(self, param):
full_param = 'saas_portal.%s' % param
return config.sudo().get_param(full_param)

def get_full_dbname(self, dbname):
if not dbname:
def get_full_dbname(self, dbname, plan_id):
if not dbname or not plan_id:
return None
full_dbname = '%s.%s' % (dbname, self.get_config_parameter('base_saas_domain'))
Plan = request.env['saas_portal.plan'].sudo()
plan = Plan.browse(int(plan_id))
base_saas_domain = plan.server_id.local_host
full_dbname = '%s.%s' % (dbname, base_saas_domain)
return full_dbname.replace('www.', '')

def get_plan(self, plan_id=None):
Expand Down
18 changes: 12 additions & 6 deletions saas_portal_signup/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ def get_auth_signup_qcontext(self):
if not qcontext.get('countries', False):
qcontext['countries'] = request.env['res.country'].search([])
if not qcontext.get('base_saas_domain', False):
qcontext['base_saas_domain'] = self.get_saas_domain()
qcontext['base_saas_domain'] = self.get_saas_domain(qcontext.get('plan_id'))
return qcontext

def get_saas_domain(self):
config = request.env['ir.config_parameter']
full_param = 'saas_portal.base_saas_domain'
base_saas_domain = config.sudo().get_param(full_param)
def get_saas_domain(self, plan_id):
# config = request.env['ir.config_parameter']
# full_param = 'saas_portal.base_saas_domain'
# base_saas_domain = config.sudo().get_param(full_param)
if plan_id:
Plan = request.env['saas_portal.plan'].sudo()
plan = Plan.browse(int(plan_id))
base_saas_domain = plan.server_id.local_host
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's localhost?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why - it should be the url of SaaS server (e.g. odoo-11.smb.ngalaba.com). It may be the name of saas_portal.server record either

else:
base_saas_domain = 'depends on the plan'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

return base_saas_domain

def do_signup(self, qcontext):
Expand All @@ -45,7 +51,7 @@ def do_signup(self, qcontext):
if qcontext.get('country_id', False):
values['country_id'] = qcontext['country_id']
if qcontext.get('dbname', False):
f_dbname = '%s.%s' % (qcontext['dbname'], self.get_saas_domain())
f_dbname = '%s.%s' % (qcontext['dbname'], self.get_saas_domain(qcontext['plan_id']))
full_dbname = f_dbname.replace('www.', '')
db_exists = odoo.service.db.exp_db_exist(full_dbname)
assert re.match('[a-zA-Z0-9_.-]+$', qcontext.get('dbname')
Expand Down