Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions user_threshold/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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
32 changes: 12 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,24 @@ class ResUsers(models.Model):
'Exempt User From User Count Thresholds',
)

def __init__(self, pool, cr):
@api.model_cr
def _register_hook(self, pool, cr):
Copy link
Copy Markdown
Contributor

@MiquelRForgeFlow MiquelRForgeFlow Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply def _register_hook(self):? We are in v10 api!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annnnnnd now I have actually RTFM. This is why blindly copying code is probably a bad idea lmao

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have copy-pasted my patch :D

"""
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 = 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