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

12.0 ports #846

Open
wants to merge 9 commits into
base: 11.0
Choose a base branch
from
Empty file modified auth_oauth_check_client_id/__init__.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion auth_oauth_check_client_id/__manifest__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'name': 'auth_oauth - check client_id',
'version': '11.0.1.0.0',
'version': '12.0.1.0.0',
'author': 'Ivan Yelizariev, Nicolas JEUDY',
'license': 'LGPL-3',
'category': 'SaaS',
Expand Down
Empty file modified auth_oauth_check_client_id/models/__init__.py
100644 → 100755
Empty file.
Empty file modified auth_oauth_check_client_id/models/res_users.py
100644 → 100755
Empty file.
Empty file modified auth_oauth_check_client_id/static/description/icon.png
100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified auth_oauth_ip/README.rst
100644 → 100755
Empty file.
Empty file modified auth_oauth_ip/__init__.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion auth_oauth_ip/__manifest__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"summary": """Allows to check access_token by requests in local network""",
"category": "Extra Tools",
"images": [],
"version": "11.0.1.0.0",
"version": "12.0.1.0.0",
"author": "IT-Projects LLC, Ivan Yelizariev, Nicolas JEUDY",
"support": "apps@it-projects.info",
"website": "https://it-projects.info",
Expand Down
Empty file modified auth_oauth_ip/doc/changelog.rst
100644 → 100755
Empty file.
Empty file modified auth_oauth_ip/doc/index.rst
100644 → 100755
Empty file.
15 changes: 4 additions & 11 deletions auth_oauth_ip/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class res_users(models.Model):
_inherit = 'res.users'

def _auth_oauth_rpc(self, endpoint, access_token, local_host=None, local_port=None):
local_host = local_host or self.env.context.get('local_host')
local_port = local_port or self.env.context.get('local_port')
params = werkzeug.url_encode({'access_token': access_token})
host = None
try:
Expand All @@ -39,22 +41,13 @@ def _auth_oauth_rpc(self, endpoint, access_token, local_host=None, local_port=No
else:
url = endpoint + '?' + params
req = urllib.request.Request(url, headers={'host': host})
print(('url', url))

with urllib.request.urlopen(req) as response:
html = response.read()
return json.loads(html.decode("utf-8"))

@api.model
def _auth_oauth_validate(self, provider, access_token):
""" return the validation data corresponding to the access token """
p = self.env['auth.oauth.provider'].browse(provider)
validation = self._auth_oauth_rpc(
p.validation_endpoint, access_token, local_host=p.local_host, local_port=p.local_port)
if validation.get("error"):
raise Exception(validation['error'])
if p.data_endpoint:
data = self._auth_oauth_rpc(
p.data_endpoint, access_token, local_host=p.local_host, local_port=p.local_port)
validation.update(data)
return validation
self = self.with_context(local_host=p.local_host, local_port=p.local_port)
return super(res_users, self)._auth_oauth_validate(provider, access_token)
Empty file modified auth_oauth_ip/static/description/icon.png
100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 15 additions & 17 deletions auth_oauth_ip/views.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_oauth_provider_form">
<field name="name">auth.oauth.provider.form</field>
<field name="model">auth.oauth.provider</field>
<field name="inherit_id" ref="auth_oauth.view_oauth_provider_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<group>
<field name="local_host"/>
<field name="local_port"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
<odoo>
<record model="ir.ui.view" id="view_oauth_provider_form">
<field name="name">auth.oauth.provider.form</field>
<field name="model">auth.oauth.provider</field>
<field name="inherit_id" ref="auth_oauth.view_oauth_provider_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<group>
<field name="local_host"/>
<field name="local_port"/>
</group>
</xpath>
</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion saas_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'category': 'SaaS',
"support": "apps@it-projects.info",
'website': 'https://it-projects.info',
'depends': ['saas_utils'],
'depends': ['base'],
'data': [],
'installable': True,
}
3 changes: 1 addition & 2 deletions saas_client/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
'auth_oauth',
'auth_oauth_ip',
'auth_oauth_check_client_id',
'saas_utils',
'mail',
'web_settings_dashboard',
'access_limit_records_number',
],
'data': [
'views/saas_client.xml',
'views/res_config.xml',
# 'views/res_config.xml',
'security/rules.xml',
'security/groups.xml',
'data/ir_cron.xml',
Expand Down
1 change: 1 addition & 0 deletions saas_client/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ def web_login(self, redirect=None, **kw):
suspended = param_model.sudo().get_param('saas_client.suspended', '0')
page_for_suspended = param_model.sudo().get_param('saas_client.page_for_suspended', '/')
if suspended == '1':
request.params['login_success'] = False
return werkzeug.utils.redirect(page_for_suspended, 303)
return super(SaaSClientLogin, self).web_login(redirect, **kw)
21 changes: 9 additions & 12 deletions saas_client/models/res_config.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from odoo import models, fields, api


class BaseConfigSettings(models.TransientModel):
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

base_saas_domain = fields.Char('Base SaaS domain')

current_domain = fields.Char(readonly=True)
domain_change_link = fields.Html(readonly=True)

# current_domain
@api.model
def get_default_current_domain(self, fields):
def get_values(self):
res = super(ResConfigSettings, self).get_values()
current_domain = self.env["ir.config_parameter"].sudo().get_param('web.base.url', default=None)
return {'current_domain': current_domain or False}

# domain_change_link
@api.model
def get_default_domain_change_link(self, fields):
link = self.env["ir.config_parameter"].sudo().get_param('saas_client.saas_dashboard', default=None)
html = link and '<a href=' + link + '>' + 'You can change your domain name here' + '</a>' or False
return {'domain_change_link': html}
html = link and '<a href="' + link + '" target="_blank" class="oe_link"><i class="fa fa-fw fa-arrow-right"/>' + 'You can change your domain name here' + '</a>' or False
res.update(
current_domain=current_domain or False,
domain_change_link=html,
)
return res
34 changes: 34 additions & 0 deletions saas_client/translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Copyright 2018 PlanetaTIC <info@planetatic.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.addons.base_sparse_field.models.fields import monkey_patch
from odoo.tools.translate import GettextAlias


@monkey_patch(GettextAlias)
def _get_cr(self, frame, allow_create=True):
# try, in order: cr, cursor, self.env.cr, self.cr,
# request.env.cr
if 'cr' in frame.f_locals:
return frame.f_locals['cr'], False
if 'cursor' in frame.f_locals:
return frame.f_locals['cursor'], False
s = frame.f_locals.get('self')
if hasattr(s, 'env'):
return s.env.cr, False
if hasattr(s, 'cr'):
return s.cr, False
# Don't get cursor from request as its database can be different from the
# one in the thread!
# try:
# from odoo.http import request
# return request.env.cr, False
# except RuntimeError:
# pass
if allow_create:
# create a new cursor
db = self._get_db()
if db is not None:
return db.cursor(), True
return None, False
2 changes: 1 addition & 1 deletion saas_client/views/res_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<field name="current_domain" class="oe_inline"/>
</div>
<div class="content-group">
<div class="mt16 row">
<div class="mt16">
<field name="domain_change_link" class="oe_inline"/>
</div>
</div>
Expand Down
11 changes: 6 additions & 5 deletions saas_portal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
'category': 'SaaS',
"support": "apps@it-projects.info",
'website': 'https://it-projects.info',
'depends': ['oauth_provider',
'website',
'auth_signup',
'saas_base',
'saas_utils'],
'depends': [
'oauth_provider',
'website',
'auth_signup',
'saas_base',
],
'data': [
'data/mail_template_data.xml',
'data/plan_sequence.xml',
Expand Down
25 changes: 21 additions & 4 deletions saas_portal/models/saas_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from odoo import api, exceptions, fields, models
from odoo.tools import scan_languages
from odoo.tools.translate import _
from odoo.addons.base.res.res_partner import _tz_get
from odoo.addons.base.models.res_partner import _tz_get
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT

from odoo.addons.saas_base.exceptions import MaximumTrialDBException
Expand Down Expand Up @@ -74,18 +74,24 @@ def _request_params(self, path='/web', scheme=None,
if not state:
state = {}
scheme = scheme or self.request_scheme
print ("scheme ", scheme)
port = port or self.request_port
print ("port", port)
scope = scope or ['userinfo', 'force_login', 'trial', 'skiptheuse']
print ("scope 1 ", scope)
scope = ' '.join(scope)
print ("scope 2", scope)
client_id = client_id or self.env['oauth.application'].generate_client_id(
)
print ("client id ", client_id)
params = {
'scope': scope,
'state': simplejson.dumps(state),
'redirect_uri': '{scheme}://{saas_server}:{port}{path}'.format(scheme=scheme, port=port, saas_server=self.host, path=path),
'response_type': 'token',
'client_id': client_id,
}
print ("paramas ______________", params)
return params

@api.multi
Expand All @@ -99,20 +105,29 @@ def _request(self, **kwargs):
def _request_server(self, path=None, scheme=None, port=None, **kwargs):
self.ensure_one()
scheme = scheme or self.local_request_scheme or self.request_scheme
print("scheme ", scheme)
host = self.local_host or self.host
print ("host ", host)
port = port or self.local_port or self.request_port
print ("port", port)
params = self._request_params(**kwargs)
print ("params", params)
access_token = self.oauth_application_id.sudo()._get_access_token(create=True)
print ("access_token", access_token)
params.update({
'token_type': 'Bearer',
'access_token': access_token,
'expires_in': 3600,
})
url = '{scheme}://{host}:{port}{path}'.format(
scheme=scheme, host=host, port=port, path=path)
print ("url", url)
req = requests.Request('GET', url, data=params,
headers={'host': self.host})
print ("req", req)
req_kwargs = {'verify': self.verify_ssl}
print ("req_kwargs", req_kwargs)
print ("req.prepare() ", req.prepare())
return req.prepare(), req_kwargs

@api.multi
Expand Down Expand Up @@ -142,10 +157,12 @@ def action_sync_server(self, updating_client_ID=None):
'client_id': server.client_id,
'updating_client_ID': updating_client_ID,
}
req, req_kwargs = server._request_server(
path='/saas_server/sync_server', state=state, client_id=server.client_id)
req, req_kwargs = server._request_server(path='/saas_server/sync_server', state=state, client_id=server.client_id)
res = requests.Session().send(req, **req_kwargs)

print ("state ", state)
print ("req", req)
print ("req_kwargs", req_kwargs);
print ("res ", res)
if not res.ok:
raise Warning(_('Reason: %s \n Message: %s') %
(res.reason, res.content))
Expand Down
2 changes: 1 addition & 1 deletion saas_portal/views/saas_portal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<separator/>
<field name="partner_id" string="Contact" filter_domain="[('partner_id', 'child_of', self)]"/>
<group expand="0" string="Group By">
<filter string="Plan" domain="[]" context="{'group_by':'plan_id'}"/>
<filter string="Plan" name="plan" domain="[]" context="{'group_by':'plan_id'}"/>
</group>
</search>
</field>
Expand Down
2 changes: 1 addition & 1 deletion saas_portal_demo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"installable": True,
"installable": False,
"auto_install": False,
}
2 changes: 1 addition & 1 deletion saas_portal_portal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
'data': [
'views/website_instance_templates.xml',
],
'installable': True,
'installable': False,
}
2 changes: 1 addition & 1 deletion saas_portal_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'depends': [
'sale',
'saas_portal',
'product_price_factor',
# 'product_price_factor',
'saas_portal_start',
'contract',
],
Expand Down
2 changes: 1 addition & 1 deletion saas_portal_start/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'website': 'https://it-projects.info',
'depends': ['website', 'saas_portal'],
'data': [
'views/website.xml',
# 'views/website.xml',
],
'installable': True,
}
3 changes: 1 addition & 2 deletions saas_server/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
'auth_oauth',
'auth_oauth_ip',
'saas_base',
'saas_utils',
'website',
],
'data': [
'views/saas_server.xml',
'views/res_config_settings_views.xml',
'data/auth_oauth_data.xml',
'data/ir_config_parameter.xml',
'data/pre_install.yml',
# 'data/pre_install.yml',
],
'installable': True,
}
7 changes: 7 additions & 0 deletions saas_server/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,16 @@ def stats(self, **post):
_logger.info('sync_server post: %s', post)

state = simplejson.loads(post.get('state'))
print("state ", state)
updating_client_ID = state.get('updating_client_ID')
print ("updating_client_ID ", updating_client_ID)
access_token = post['access_token']
print ("access_token ", access_token)
saas_oauth_provider = request.env.ref('saas_server.saas_oauth_provider').sudo()
print ("saas_oauth_provider ", saas_oauth_provider)

user_data = request.env['res.users'].sudo()._auth_oauth_rpc(saas_oauth_provider.validation_endpoint, access_token, local_host=saas_oauth_provider.local_host, local_port=saas_oauth_provider.local_port)
print ("user_data ", user_data)
if user_data.get("error"):
raise Exception(user_data['error'])

Expand All @@ -286,6 +291,8 @@ def stats(self, **post):
'db_storage': client.db_storage,
'total_storage_limit': client.total_storage_limit,
})
print ("res ", res)
print ("simplejson.dumps(res) ",simplejson.dumps(res))
return simplejson.dumps(res)

def _get_message(self, dbuuid):
Expand Down
6 changes: 6 additions & 0 deletions saas_server/data/pre_install.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2018 PlanetaTIC <info@planetatic.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<function model="res.users" name="_saas_server_config_oauth"/>
</odoo>