Skip to content

Commit 39dbeb4

Browse files
authored
Merge pull request #300 from em230418/14.0
[14.0] access_limit_max_users
2 parents da5319a + c59eb97 commit 39dbeb4

File tree

12 files changed

+225
-0
lines changed

12 files changed

+225
-0
lines changed

access_limit_max_users/README.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. image:: https://itpp.dev/images/infinity-readme.png
2+
:alt: Tested and maintained by IT Projects Labs
3+
:target: https://itpp.dev
4+
5+
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
6+
:target: https://opensource.org/licenses/MIT
7+
:alt: License: MIT
8+
9+
=======================
10+
Limit number of users
11+
=======================
12+
13+
With this module you can limit number of users.
14+
15+
This module creates record with external id `access_limit_max_users.max_users_limit`
16+
that defines max amount of users can have current database. By default it is
17+
number of active users at moment of installation of this module.
18+
19+
In order to make user to be ignoring the limit, you can use field ``is_excluded_from_limiting`` in one of the following ways:
20+
21+
* Create or set ``is_excluded_from_limiting`` to True in supersuper (sudo) mode. See `<tests/test_excluded_users.py>`_
22+
* Define user record in `data files <https://www.odoo.com/documentation/14.0/reference/data.html>`__ with ``is_excluded_from_limiting`` set to True.
23+
24+
Questions?
25+
==========
26+
27+
To get an assistance on this module contact us by email :arrow_right: help@itpp.dev
28+
29+
Contributors
30+
============
31+
* `Eugene Molotov <https://it-projects.info/team/em230418>`__:
32+
33+
34+
Further information
35+
===================
36+
37+
Odoo Apps Store: https://apps.odoo.com/apps/modules/14.0/access_limit_max_users/
38+
39+
40+
Tested on `Odoo 14.0 <https://github.com/odoo/odoo/commit/05c373a99a6064f08fc9eb0662ab2ccdb1978cd7>`_

access_limit_max_users/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from . import models
2+
from odoo.api import Environment, SUPERUSER_ID
3+
from odoo.tools.safe_eval import safe_eval
4+
5+
6+
def post_init_hook(cr, registry):
7+
env = Environment(cr, SUPERUSER_ID, {})
8+
ref_record = env.ref("access_limit_max_users.max_users_limit")
9+
ref_record.max_records = env["res.users"].search_count(safe_eval(ref_record.domain))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
2+
# License MIT (https://opensource.org/licenses/MIT).
3+
4+
{
5+
"name": """Limit number of users""",
6+
"summary": """With this module you can limit number of users""",
7+
"category": "Hidden",
8+
# "live_test_url": "http://apps.it-projects.info/shop/product/DEMO-URL?version=14.0",
9+
"images": [],
10+
"version": "14.0.1.1.1",
11+
"application": False,
12+
"author": "IT-Projects LLC, Eugene Molotov",
13+
"support": "apps@it-projects.info",
14+
"website": "https://apps.odoo.com/apps/modules/14.0/access_limit_max_users/",
15+
"license": "Other OSI approved licence", # MIT
16+
# "price": 9.00,
17+
# "currency": "EUR",
18+
"depends": ["access_limit_records_number"],
19+
"external_dependencies": {"python": [], "bin": []},
20+
"data": ["data/base_limit_records_number.xml"],
21+
"demo": [],
22+
"qweb": [],
23+
"post_load": None,
24+
"pre_init_hook": None,
25+
"post_init_hook": "post_init_hook",
26+
"uninstall_hook": None,
27+
"auto_install": False,
28+
"installable": True,
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!-- Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
3+
License MIT (https://opensource.org/licenses/MIT). -->
4+
<odoo>
5+
<record id="max_users_limit" model="base.limit.records_number">
6+
<field name="name">Limit number of users</field>
7+
<field name="model_id" ref="base.model_res_users" />
8+
<field name="max_records" eval="1" />
9+
<field name="domain">[("is_excluded_from_limiting", "=", False)]</field>
10+
</record>
11+
</odoo>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
`1.1.1`
2+
-------
3+
4+
- **Fix**: Fixed impossibility to successfully edit any user
5+
6+
`1.1.0`
7+
-------
8+
9+
- **Improvement**: Added field `is_excluded_from_limiting` to Users model to exclude certain records, when limiting number of users
10+
11+
`1.0.0`
12+
-------
13+
14+
- **Init version**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=======================
2+
Limit number of users
3+
=======================
4+
5+
Installation
6+
============
7+
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way
8+
9+
Usage
10+
=====
11+
12+
* Open menu ``[[ Settings ]] >> Users & Companies >> Users``
13+
* Click ``[Create]``
14+
* Fill in required fields. Usually they are `Name` and `Email Address`
15+
* RESULT: you will see exception message, that says that you cannot create more records.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_users
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from odoo import _, api, fields, models
2+
from odoo.exceptions import ValidationError
3+
4+
5+
class ResUsers(models.Model):
6+
_inherit = "res.users"
7+
8+
is_excluded_from_limiting = fields.Boolean(default=False)
9+
10+
@api.model
11+
def create(self, vals):
12+
if vals.get("is_excluded_from_limiting") and not self.env.is_superuser():
13+
raise ValidationError(
14+
_(
15+
"Only superuser can create user with positive is_excluded_from_limiting value"
16+
)
17+
)
18+
return super(ResUsers, self).create(vals)
19+
20+
def write(self, vals):
21+
if vals.get("is_excluded_from_limiting") and not self.env.is_superuser():
22+
raise ValidationError(
23+
_(
24+
"Only superuser can set user with positive is_excluded_from_limiting value"
25+
)
26+
)
27+
return super(ResUsers, self).write(vals)
4.84 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import test_base
2+
from . import test_excluded_users

0 commit comments

Comments
 (0)