From 37968c383144d6886c59017802dddf933bc3921e Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Tue, 19 Sep 2017 15:39:20 -0700 Subject: [PATCH] [FIX] user_threshold: Don't create or commit new cursor (#955) * [FIX] user_threshold: Don't create or commit new cursor * Remove new cursor creation/commit in favor of using current cursor --- user_threshold/README.rst | 19 ++++++++++-------- user_threshold/__manifest__.py | 2 +- user_threshold/models/res_users.py | 31 +++++++++++------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/user_threshold/README.rst b/user_threshold/README.rst index 28cf6f40e..07e0ec463 100644 --- a/user_threshold/README.rst +++ b/user_threshold/README.rst @@ -46,11 +46,15 @@ number of users that the company can have. The following environment variables are available for your configuration ease: -| Name | Description | -|------|-------------| -| USER_THRESHOLD_HIDE | Hide all threshold settings and default the exempt users to those defined by the USER_THRESHOLD_USERS variable -| USER_THRESHOLD_USER | White list of users who are exempt from the threshold. - ++---------------------+--------------------------------------------------------+ +| Name | Description | ++=====================+========================================================+ +| USER_THRESHOLD_HIDE | Hide all threshold settings and default the exempt | +| | users to those defined by the ``USER_THRESHOLD_USERS`` | +| | variable. | ++---------------------+--------------------------------------------------------+ +| USER_THRESHOLD_USER | White list of users who are exempt from the threshold. | ++---------------------+--------------------------------------------------------+ .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot @@ -60,11 +64,10 @@ Bug Tracker =========== Bugs are tracked on `GitHub Issues -``_. In case of trouble, please +`_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smash it by providing detailed and welcomed feedback. - Credits ======= @@ -77,7 +80,7 @@ Contributors ------------ * Ted Salmon - +* Dave Lasley Maintainer ---------- diff --git a/user_threshold/__manifest__.py b/user_threshold/__manifest__.py index 4ab471a07..7dfa1bca6 100644 --- a/user_threshold/__manifest__.py +++ b/user_threshold/__manifest__.py @@ -4,7 +4,7 @@ { "name": "User Threshold", "summary": "Add Configurable User Threshold Support", - "version": "10.0.1.0.0", + "version": "10.0.1.0.1", "category": "Authentication", "website": "https://www.laslabs.com", "author": "LasLabs, Odoo Community Association (OCA)", diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py index b26151215..d57d74dd8 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -6,7 +6,7 @@ import os from csv import reader from lxml import etree -from odoo import SUPERUSER_ID, _, api, fields, models, registry +from odoo import api, fields, models, _ from odoo.exceptions import AccessError, ValidationError from .ir_config_parameter import THRESHOLD_HIDE, MAX_DB_USER_PARAM @@ -20,7 +20,8 @@ class ResUsers(models.Model): 'Exempt User From User Count Thresholds', ) - def __init__(self, pool, cr): + @api.model_cr + def _register_hook(self): """ Override to check if env var to hide threshold configuration and reset the database state is set. If it is, run those actions @@ -28,24 +29,14 @@ class ResUsers(models.Model): if THRESHOLD_HIDE: exempt_users_var = os.environ.get('USER_THRESHOLD_USER', '') exempt_users = reader([exempt_users_var]) - with api.Environment.manage(): - with registry(cr.dbname).cursor() as new_cr: - new_env = api.Environment(new_cr, SUPERUSER_ID, {}) - installed = new_env['ir.module.module'].search_count([ - ('name', '=', 'user_threshold'), - ('state', '=', 'installed'), - ]) - if installed: - users = new_env['res.users'].search([ - ('share', '=', False), - ('threshold_exempt', '=', True), - ]) - non_ex = users.filtered( - lambda r: r.login not in exempt_users - ) - for user in non_ex: - user.threshold_exempt = False - new_cr.commit() + users = self.env['res.users'].search([ + ('share', '=', False), + ('threshold_exempt', '=', True), + ]) + non_ex = users.filtered(lambda r: r.login not in exempt_users) + + for user in non_ex: + user.threshold_exempt = False def _check_thresholds(self): """