Skip to content

Commit

Permalink
[ADD] read_only_user
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 committed Oct 16, 2024
1 parent 80e033f commit f490663
Show file tree
Hide file tree
Showing 14 changed files with 608 additions and 0 deletions.
73 changes: 73 additions & 0 deletions read_only_user/README.rst
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.
1 change: 1 addition & 0 deletions read_only_user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions read_only_user/__manifest__.py
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": [],
}
2 changes: 2 additions & 0 deletions read_only_user/migrations/17.0.0.1.0/post-migrate.py
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")
2 changes: 2 additions & 0 deletions read_only_user/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import res_users
from . import ir_model
34 changes: 34 additions & 0 deletions read_only_user/models/ir_model.py
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]
11 changes: 11 additions & 0 deletions read_only_user/models/res_users.py
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
3 changes: 3 additions & 0 deletions read_only_user/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions read_only_user/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Eugene Molotov (https://github.com/em230418)
1 change: 1 addition & 0 deletions read_only_user/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allows to set user as readonly
1 change: 1 addition & 0 deletions read_only_user/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix issues with Discuss (`mail`) and OdooBot (`mail_bot`) modules
4 changes: 4 additions & 0 deletions read_only_user/readme/USAGE.md
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
Loading

0 comments on commit f490663

Please sign in to comment.