Skip to content
Open
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
8 changes: 3 additions & 5 deletions spreadsheet_dashboard_oca/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========================
Spreadsheet Dashboard Oca
=========================
Expand All @@ -17,7 +13,7 @@ Spreadsheet Dashboard Oca
.. |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/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github
Expand Down Expand Up @@ -70,6 +66,8 @@ Contributors

- Chris Mann

- Nimarosa <https://github.com/nimarosa>

Maintainers
-----------

Expand Down
3 changes: 2 additions & 1 deletion spreadsheet_dashboard_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Spreadsheet Dashboard Oca",
"summary": """
Use OCA Spreadsheets on dashboards configuration""",
"version": "18.0.1.1.0",
"version": "18.0.1.1.1",
"license": "AGPL-3",
"author": "CreuBlanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/spreadsheet",
Expand All @@ -15,6 +15,7 @@
],
"data": [
"security/ir.model.access.csv",
"security/security.xml",
"wizards/spreadsheet_spreadsheet_import.xml",
"wizards/spreadsheet_to_dashboard.xml",
"views/spreadsheet_dashboard_group_views.xml",
Expand Down
3 changes: 2 additions & 1 deletion spreadsheet_dashboard_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
- [Tecnativa](https://www.tecnativa.com):
- Carlos Roca
- [Open User Systems](https://www.openusersystems.com):
- Chris Mann
- Chris Mann
- Nimarosa \<<https://github.com/nimarosa>\>
10 changes: 10 additions & 0 deletions spreadsheet_dashboard_oca/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<!-- Transient records are not private to their creator in Odoo 18. -->
<record model="ir.rule" id="spreadsheet_to_dashboard_own_rule">
<field name="name">Spreadsheet to dashboard wizard: own records</field>
<field name="model_id" ref="model_spreadsheet_to_dashboard" />
<field name="domain_force">[('create_uid', '=', user.id)]</field>
</record>
</odoo>
25 changes: 10 additions & 15 deletions spreadsheet_dashboard_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Spreadsheet Dashboard Oca</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="spreadsheet-dashboard-oca">
<h1 class="title">Spreadsheet Dashboard Oca</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="spreadsheet-dashboard-oca">
<h1>Spreadsheet Dashboard Oca</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f2dd89e0742dd92768f13deebfcf0df75b55119ebe65a1c534295ed2382eee01
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/spreadsheet/tree/18.0/spreadsheet_dashboard_oca"><img alt="OCA/spreadsheet" src="https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/spreadsheet-18-0/spreadsheet-18-0-spreadsheet_dashboard_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/spreadsheet&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/spreadsheet/tree/18.0/spreadsheet_dashboard_oca"><img alt="OCA/spreadsheet" src="https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/spreadsheet-18-0/spreadsheet-18-0-spreadsheet_dashboard_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/spreadsheet&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to edit spreadsheet dashboards using OCA Spreadsheet
editor.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -390,23 +385,23 @@ <h1>Spreadsheet Dashboard Oca</h1>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/spreadsheet/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/spreadsheet/issues/new?body=module:%20spreadsheet_dashboard_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-2">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-3">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<ul class="simple">
<li>CreuBlanca</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Enric Tobella</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
Expand All @@ -417,10 +412,11 @@ <h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
<li>Chris Mann</li>
</ul>
</li>
<li>Nimarosa &lt;<a class="reference external" href="https://github.com/nimarosa">https://github.com/nimarosa</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -433,6 +429,5 @@ <h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions spreadsheet_dashboard_oca/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_dashboard_access
82 changes: 82 additions & 0 deletions spreadsheet_dashboard_oca/tests/test_dashboard_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.exceptions import AccessError
from odoo.tests import TransactionCase, new_test_user, tagged


@tagged("post_install", "-at_install")
class TestDashboardAccess(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.viewer = new_test_user(
cls.env, login="dash_viewer", groups="base.group_user"
)
cls.manager = new_test_user(
cls.env,
login="dash_manager",
groups="base.group_user,spreadsheet_dashboard.group_dashboard_manager,"
"spreadsheet_oca.group_user",
)
cls.section = cls.env["spreadsheet.dashboard.group"].create({"name": "S"})
cls.dashboard = cls.env["spreadsheet.dashboard"].create(
{"name": "Dashboard", "dashboard_group_id": cls.section.id}
)
cls.restricted = cls.env["spreadsheet.dashboard"].create(
{
"name": "Restricted",
"dashboard_group_id": cls.section.id,
"group_ids": [(6, 0, cls.env.ref("base.group_system").ids)],
}
)

def _message(self, server_revision_id):
return {
"type": "REMOTE_REVISION",
"serverRevisionId": server_revision_id,
"nextRevisionId": server_revision_id + "+",
"clientId": "client",
"commands": [],
}

def test_manager_edits_and_viewer_reads(self):
self.assertTrue(
self.dashboard.with_user(self.manager).send_spreadsheet_message(
self._message("a")
)
)
self.env.invalidate_all()
data = self.dashboard.with_user(self.viewer).get_spreadsheet_data()
self.assertEqual(data["mode"], "readonly")
self.assertEqual(len(data["revisions"]), 1)
revision = self.dashboard.spreadsheet_revision_ids
with self.assertRaises(AccessError):
revision.with_user(self.viewer).write({"commands": "{}"})
with self.assertRaises(AccessError):
revision.with_user(self.viewer).unlink()

def test_viewer_cannot_read_revisions_of_a_hidden_dashboard(self):
self.restricted.send_spreadsheet_message(self._message("a"))
revision = self.restricted.spreadsheet_revision_ids
self.assertTrue(revision)
Revision = self.env["spreadsheet.oca.revision"].with_user(self.viewer)
self.assertFalse(Revision.search([("id", "in", revision.ids)]))
with self.assertRaises(AccessError):
revision.with_user(self.viewer).read(["commands"])

def test_to_dashboard_wizard_is_private_to_its_creator(self):
sheet = (
self.env["spreadsheet.spreadsheet"]
.with_user(self.manager)
.create({"name": "Sheet"})
)
wizard = (
self.env["spreadsheet.to.dashboard"]
.with_user(self.manager)
.create({"spreadsheet_id": sheet.id, "dashboard_group_id": self.section.id})
)
Wizard = self.env["spreadsheet.to.dashboard"].with_user(self.viewer)
self.assertFalse(Wizard.search([("id", "=", wizard.id)]))
with self.assertRaises(AccessError):
wizard.with_user(self.viewer).read(["name"])
self.assertTrue(wizard.with_user(self.manager).name)
8 changes: 3 additions & 5 deletions spreadsheet_oca/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===============
Spreadsheet Oca
===============
Expand All @@ -17,7 +13,7 @@ Spreadsheet Oca
.. |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/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github
Expand Down Expand Up @@ -133,6 +129,8 @@ Contributors

- Florent THOMAS

- Nimarosa <https://github.com/nimarosa>

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion spreadsheet_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Spreadsheet Oca",
"summary": """
Allow to edit spreadsheets""",
"version": "18.0.1.3.3",
"version": "18.0.1.3.4",
"license": "AGPL-3",
"author": "CreuBlanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/spreadsheet",
Expand Down
101 changes: 100 additions & 1 deletion spreadsheet_oca/models/spreadsheet_oca_revision.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Copyright 2022 CreuBlanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
from collections import defaultdict

from odoo import _, api, fields, models
from odoo.exceptions import AccessError
from odoo.osv import expression


class SpreadsheetOcaRevision(models.Model):
"""Revisions have no access rules of their own: they follow the
spreadsheet they belong to (``model``/``res_id``), the way attachments and
messages follow their document. Reading a revision requires read access to
its spreadsheet; creating, changing or deleting one requires write access
to it."""

_name = "spreadsheet.oca.revision"
_description = "Spreadsheet Oca Revision" # TODO

Expand All @@ -15,3 +25,92 @@ class SpreadsheetOcaRevision(models.Model):
server_revision_id = fields.Char()
next_revision_id = fields.Char()
commands = fields.Char()

@api.model
def _get_spreadsheet_models(self):
"""Models whose records can own revisions."""
return [
name
for name in self.env.registry.descendants(
["spreadsheet.abstract"], "_inherit"
)
if not self.env[name]._abstract
]

@api.model
def _search(self, domain, offset=0, limit=None, order=None):
if self.env.su:
return super()._search(domain, offset=offset, limit=limit, order=order)
readable = []
for model_name in self._get_spreadsheet_models():
documents = self.env[model_name].with_context(active_test=False)
if not documents.has_access("read"):
continue
readable.append(
[
("model", "=", model_name),
("res_id", "in", documents._search([])),
]
)
domain = expression.AND(
[domain, expression.OR(readable) if readable else expression.FALSE_DOMAIN]
)
return super()._search(domain, offset=offset, limit=limit, order=order)

def _check_access(self, operation):
result = super()._check_access(operation)
if not self:
return result
revisions = self - result[0] if result else self
forbidden = revisions._get_forbidden_by_spreadsheet(operation)
if forbidden:
if result:
result = (result[0] + forbidden, result[1])
else:
result = (
forbidden,
lambda: forbidden._make_spreadsheet_access_error(operation),
)
return result

def _get_forbidden_by_spreadsheet(self, operation):
"""Return the revisions of ``self`` whose spreadsheet does not grant
the current user the access ``operation`` needs."""
document_operation = "read" if operation == "read" else "write"
spreadsheet_models = set(self._get_spreadsheet_models())
by_document = defaultdict(lambda: defaultdict(list))
for revision in self.sudo():
if revision.id:
by_document[revision.model][revision.res_id].append(revision.id)
forbidden_ids = []
for model_name, revision_ids_by_res_id in by_document.items():
if model_name not in spreadsheet_models:
forbidden_ids += sum(revision_ids_by_res_id.values(), [])
continue
documents = (
self.env[model_name]
.with_context(active_test=False)
.browse(revision_ids_by_res_id)
)
allowed = documents.exists()._filtered_access(document_operation)
for res_id, revision_ids in revision_ids_by_res_id.items():
if res_id not in allowed.ids:
forbidden_ids += revision_ids
return self.browse(forbidden_ids)

def _make_spreadsheet_access_error(self, operation):
return AccessError(
_(
"You are not allowed to %(operation)s the revisions of a "
"spreadsheet you cannot %(document_operation)s.",
operation=operation,
document_operation="read" if operation == "read" else "edit",
)
)

def write(self, vals):
result = super().write(vals)
if "model" in vals or "res_id" in vals:
# The check before the write was made on the former spreadsheet.
self.check_access("write")
return result
3 changes: 2 additions & 1 deletion spreadsheet_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- [Open User Systems](https://www.openusersystems.com):
- Chris Mann
- [Mind And Go](https://mind-and-go.com)
- Florent THOMAS
- Florent THOMAS
- Nimarosa \<<https://github.com/nimarosa>\>
6 changes: 6 additions & 0 deletions spreadsheet_oca/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@
<field name="model_id" ref="model_spreadsheet_spreadsheet_import_mode" />
<field name="domain_force">[('group_ids','in', user.groups_id.ids)]</field>
</record>
<!-- Transient records are not private to their creator in Odoo 18. -->
<record model="ir.rule" id="spreadsheet_import_own_rule">
<field name="name">Spreadsheet import wizard: own records</field>
<field name="model_id" ref="model_spreadsheet_spreadsheet_import" />
<field name="domain_force">[('create_uid', '=', user.id)]</field>
</record>
</odoo>
Loading
Loading