Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions user_threshold/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,11 +64,10 @@ Bug Tracker
===========

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,
help us smash it by providing detailed and welcomed feedback.


Credits
=======

Expand All @@ -77,7 +80,7 @@ Contributors
------------

* Ted Salmon <tsalmon@laslabs.com>

* Dave Lasley <dave@laslabs.com>

Maintainer
----------
Expand Down
2 changes: 1 addition & 1 deletion user_threshold/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
31 changes: 11 additions & 20 deletions user_threshold/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand All @@ -20,32 +20,23 @@ 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
"""
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):
"""
Expand Down