From 8c72f30aeb0ab7bdab666de26ae7bb04bf542f50 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Tue, 29 Aug 2017 09:02:33 -0700 Subject: [PATCH 1/6] [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 | 1 + user_threshold/__manifest__.py | 2 +- user_threshold/models/res_users.py | 32 ++++++++++++++---------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/user_threshold/README.rst b/user_threshold/README.rst index 28cf6f40ec2..518c4e89f43 100644 --- a/user_threshold/README.rst +++ b/user_threshold/README.rst @@ -77,6 +77,7 @@ Contributors ------------ * Ted Salmon +* Dave Lasley Maintainer diff --git a/user_threshold/__manifest__.py b/user_threshold/__manifest__.py index 4ab471a07aa..7dfa1bca670 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 b26151215b2..dc85427ac5b 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -6,7 +6,7 @@ from csv import reader from lxml import etree -from odoo import SUPERUSER_ID, _, api, fields, models, registry +from odoo import SUPERUSER_ID, _, api, fields, models from odoo.exceptions import AccessError, ValidationError from .ir_config_parameter import THRESHOLD_HIDE, MAX_DB_USER_PARAM @@ -29,23 +29,21 @@ def __init__(self, pool, cr): 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'), + env = api.Environment(cr, SUPERUSER_ID, {}) + installed = env['ir.module.module'].search_count([ + ('name', '=', 'user_threshold'), + ('state', '=', 'installed'), + ]) + if installed: + users = env['res.users'].search([ + ('share', '=', False), + ('threshold_exempt', '=', True), ]) - 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() + 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): """ From 60d1d3e7952559b128652d70386d4977d31181c6 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Fri, 1 Sep 2017 19:07:49 -0700 Subject: [PATCH 2/6] Switch to _register_hook --- user_threshold/models/res_users.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py index dc85427ac5b..fe98bdb8434 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -6,7 +6,7 @@ from csv import reader from lxml import etree -from odoo import SUPERUSER_ID, _, api, fields, models +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,7 @@ class ResUsers(models.Model): 'Exempt User From User Count Thresholds', ) - def __init__(self, pool, cr): + def _register_hook(self, pool, cr): """ Override to check if env var to hide threshold configuration and reset the database state is set. If it is, run those actions @@ -28,22 +28,15 @@ def __init__(self, pool, cr): if THRESHOLD_HIDE: exempt_users_var = os.environ.get('USER_THRESHOLD_USER', '') exempt_users = reader([exempt_users_var]) - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - installed = env['ir.module.module'].search_count([ - ('name', '=', 'user_threshold'), - ('state', '=', 'installed'), - ]) - if installed: - users = 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 + users = 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): """ From 3b4f9b7ee462b928150fd8747845cb353460a556 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Mon, 4 Sep 2017 08:54:00 -0700 Subject: [PATCH 3/6] Fix decorator --- user_threshold/models/res_users.py | 1 + 1 file changed, 1 insertion(+) diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py index fe98bdb8434..ed9c839eb5a 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -20,6 +20,7 @@ class ResUsers(models.Model): 'Exempt User From User Count Thresholds', ) + @api.model_cr def _register_hook(self, pool, cr): """ Override to check if env var to hide threshold configuration and From 87cfa1492e301c438e7682611ac08a66f18f9be9 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Mon, 4 Sep 2017 09:22:50 -0700 Subject: [PATCH 4/6] New api! --- user_threshold/models/res_users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py index ed9c839eb5a..71375b376a7 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -21,7 +21,7 @@ class ResUsers(models.Model): ) @api.model_cr - def _register_hook(self, pool, 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 From 3734e991660949deae1368ebd281dfbb280c08b3 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Mon, 4 Sep 2017 09:55:55 -0700 Subject: [PATCH 5/6] Apply diff correctly :derp: --- user_threshold/models/res_users.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py index 71375b376a7..d608a8a7b7d 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -29,16 +29,15 @@ def _register_hook(self): if THRESHOLD_HIDE: exempt_users_var = os.environ.get('USER_THRESHOLD_USER', '') exempt_users = reader([exempt_users_var]) - users = env['res.users'].search([ + users = self.env['res.users'].search([ ('share', '=', False), ('threshold_exempt', '=', True), ]) - non_ex = users.filtered( - lambda r: r.login not in exempt_users - ) + 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): """ Check to see if any user thresholds are met From a3117d49b663e262ffbebefea9cc7c2cd7037c6b Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Tue, 19 Sep 2017 12:55:52 -0700 Subject: [PATCH 6/6] Lint fixes --- user_threshold/README.rst | 18 ++++++++++-------- user_threshold/models/res_users.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/user_threshold/README.rst b/user_threshold/README.rst index 518c4e89f43..07e0ec46363 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 ======= @@ -79,7 +82,6 @@ Contributors * Ted Salmon * Dave Lasley - Maintainer ---------- diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py index d608a8a7b7d..d57d74dd84b 100644 --- a/user_threshold/models/res_users.py +++ b/user_threshold/models/res_users.py @@ -37,7 +37,7 @@ def _register_hook(self): for user in non_ex: user.threshold_exempt = False - + def _check_thresholds(self): """ Check to see if any user thresholds are met