it-projects-llc / odoo-saas-tools

Odoo SaaS Tools — tools for SaaS Businesses. Sale and manage Odoo databases.
https://saas.it-projects.info
GNU Lesser General Public License v3.0
559 stars 577 forks source link

Client suspended invalid with odoo11 commit da1f153d61d747d9357694382fe04f96c0ca886a #762

Open l327253678 opened 6 years ago

l327253678 commented 6 years ago

Hi guys, the security.check(self.db, self.uid, self.password) has removed in this commit.So the check method in saas_client won't be called.

@classmethod
def check(cls, db, uid, passwd):
    res = super(ResUsers, cls).check(db, uid, passwd)
    cr = cls.pool.cursor()
    try:
        self = api.Environment(cr, uid, {})[cls._name]
        suspended = self.env['ir.config_parameter'].sudo().get_param('saas_client.suspended', '0')
        if suspended == "1" and uid != SI:
            raise SuspendedDBException
    finally:
        cr.close()
    return res

Here is my solution:

import odoo
from odoo.http import OpenERPSession
from odoo.addons.base_sparse_field.models.fields import monkey_patch

_logger = logging.getLogger(__name__)

class SuspendedDBException(Exception):
    pass

@monkey_patch(OpenERPSession)
def check_security(self):
    with odoo.registry(self.db).cursor() as cr:
        uid = self.uid
        env = odoo.api.Environment(cr, uid, {})
        suspended = env['ir.config_parameter'].sudo().get_param('saas_client.suspended', '0')
        if suspended == "1" and uid != odoo.SUPERUSER_ID:
            raise SuspendedDBException
    return check_security.super(self)
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/58474703-client-suspended-invalid-with-odoo11-commit-da1f153d61d747d9357694382fe04f96c0ca886a?utm_campaign=plugin&utm_content=tracker%2F3643037&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F3643037&utm_medium=issues&utm_source=github).
njeudy commented 6 years ago

Hello, can you provide a PR that we can review ?