Browse Source

[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
pull/978/merge
Dave Lasley 7 years ago
committed by Pedro M. Baeza
parent
commit
37968c3831
  1. 19
      user_threshold/README.rst
  2. 2
      user_threshold/__manifest__.py
  3. 31
      user_threshold/models/res_users.py

19
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: 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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
@ -60,11 +64,10 @@ Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues Bugs are tracked on `GitHub Issues
`<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first, check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback. help us smash it by providing detailed and welcomed feedback.
Credits Credits
======= =======
@ -77,7 +80,7 @@ Contributors
------------ ------------
* Ted Salmon <tsalmon@laslabs.com> * Ted Salmon <tsalmon@laslabs.com>
* Dave Lasley <dave@laslabs.com>
Maintainer Maintainer
---------- ----------

2
user_threshold/__manifest__.py

@ -4,7 +4,7 @@
{ {
"name": "User Threshold", "name": "User Threshold",
"summary": "Add Configurable User Threshold Support", "summary": "Add Configurable User Threshold Support",
"version": "10.0.1.0.0",
"version": "10.0.1.0.1",
"category": "Authentication", "category": "Authentication",
"website": "https://www.laslabs.com", "website": "https://www.laslabs.com",
"author": "LasLabs, Odoo Community Association (OCA)", "author": "LasLabs, Odoo Community Association (OCA)",

31
user_threshold/models/res_users.py

@ -6,7 +6,7 @@ import os
from csv import reader from csv import reader
from lxml import etree 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 odoo.exceptions import AccessError, ValidationError
from .ir_config_parameter import THRESHOLD_HIDE, MAX_DB_USER_PARAM 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', '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 Override to check if env var to hide threshold configuration and
reset the database state is set. If it is, run those actions reset the database state is set. If it is, run those actions
@ -28,24 +29,14 @@ class ResUsers(models.Model):
if THRESHOLD_HIDE: if THRESHOLD_HIDE:
exempt_users_var = os.environ.get('USER_THRESHOLD_USER', '') exempt_users_var = os.environ.get('USER_THRESHOLD_USER', '')
exempt_users = reader([exempt_users_var]) 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): def _check_thresholds(self):
""" """

Loading…
Cancel
Save