-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
608 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
============== | ||
Read Only User | ||
============== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:2780a8fae20a31a6f9db586ddd263331485f24162bd54e8dbbbf2d8648a07d64 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-it--projects--llc%2Faccess--addons-lightgray.png?logo=github | ||
:target: https://github.com/it-projects-llc/access-addons/tree/17.0/read_only_user | ||
:alt: it-projects-llc/access-addons | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Allows to set user as readonly | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
- Open ``Settings -> Users & Companies -> Users`` | ||
- Choose any user except yourself | ||
- ``Actions -> Toggle readonly`` | ||
- RESULT: user is now readonly user | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
- Fix issues with Discuss (``mail``) and OdooBot (``mail_bot``) modules | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/it-projects-llc/access-addons/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/it-projects-llc/access-addons/issues/new?body=module:%20read_only_user%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* IT-Projects LLC | ||
|
||
Contributors | ||
------------ | ||
|
||
- Eugene Molotov (https://github.com/em230418) | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is part of the `it-projects-llc/access-addons <https://github.com/it-projects-llc/access-addons/tree/17.0/read_only_user>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": """Read Only User""", | ||
"version": "17.0.0.1.0", | ||
"author": "IT-Projects LLC", | ||
"support": "[email protected]", | ||
"website": "https://github.com/it-projects-llc/access-addons", | ||
"license": "LGPL-3", | ||
"depends": ["base"], | ||
"data": [ | ||
"views/res_users_views.xml", | ||
], | ||
"demo": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def migrate(cr, installed_version): | ||
cr.execute("UPDATE res_users SET is_readonly = NOT is_regular_user") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import res_users | ||
from . import ir_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from odoo import _, api, models, tools | ||
from odoo.exceptions import AccessError | ||
|
||
|
||
class IrModelAccess(models.Model): | ||
_inherit = "ir.model.access" | ||
|
||
@api.model | ||
def check(self, model, mode="read", raise_exception=True): | ||
if self.env.su: | ||
# User root have all accesses | ||
return True | ||
|
||
assert isinstance(model, str), "Not a model name: %s" % (model,) # noqa: UP031 | ||
|
||
if mode != "read" and model != "res.users.log": | ||
if self._is_readonly_user(): | ||
if raise_exception: | ||
raise AccessError(_("Sorry, you are read-only user.")) | ||
else: | ||
return False | ||
|
||
return super().check(model, mode, raise_exception) | ||
|
||
@tools.ormcache("self.env.uid") | ||
def _is_readonly_user(self): | ||
self.env.cr.execute( | ||
""" | ||
SELECT is_readonly | ||
FROM res_users | ||
WHERE id = %s""", | ||
(self.env.uid,), | ||
) | ||
return self.env.cr.fetchone()[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class Users(models.Model): | ||
_inherit = "res.users" | ||
|
||
is_readonly = fields.Boolean() | ||
|
||
def toggle_readonly(self): | ||
for user in self: | ||
user.is_readonly = not user.is_readonly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Eugene Molotov (https://github.com/em230418) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allows to set user as readonly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Fix issues with Discuss (`mail`) and OdooBot (`mail_bot`) modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- Open `Settings -> Users & Companies -> Users` | ||
- Choose any user except yourself | ||
- `Actions -> Toggle readonly` | ||
- RESULT: user is now readonly user |
Oops, something went wrong.