diff --git a/portal_partner_data_no_edit/README.rst b/portal_partner_data_no_edit/README.rst new file mode 100644 index 000000000..272de2c4f --- /dev/null +++ b/portal_partner_data_no_edit/README.rst @@ -0,0 +1,103 @@ +============================== +Portal Partner Block Data Edit +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-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%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/12.0/portal_partner_data_no_edit + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-portal_partner_data_no_edit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/134/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to block portal users info editing to prevent unproper +changes. We can configure it on every partner. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To test this module, you need to: + +#. Block portal info editing for a partner: + + - Go to *Contacts* and choose the partner. + - In the the *Sales and Purchases* tab, *Misc* section there is a field named + *Block Portal Info Edit*. Enable or disable at your convenience. + +Usage +===== + +Once configured log in with that user and: + + - Go to `/my/account/` + - If the editing is blocked, you won't be able to edit any detail or submit + the form. + +Known issues / Roadmap +====================== + +- Add the `block_portal_data_edit` flag to the invite to portal popup. +- Add a text on the page highlighted (for example with info BS class), saying for those + blocked users that they should contact the company for any modification. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Other credits +~~~~~~~~~~~~~ + +* `Tecnativa `_: + + * David Vidal + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/portal_partner_data_no_edit/__init__.py b/portal_partner_data_no_edit/__init__.py new file mode 100644 index 000000000..91c5580fe --- /dev/null +++ b/portal_partner_data_no_edit/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/portal_partner_data_no_edit/__manifest__.py b/portal_partner_data_no_edit/__manifest__.py new file mode 100644 index 000000000..d1da845af --- /dev/null +++ b/portal_partner_data_no_edit/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Portal Partner Block Data Edit", + "version": "12.0.1.0.0", + "category": "Customer Relationship Management", + "author": "Tecnativa," + "Odoo Community Association (OCA)", + "website": "https://www.github.com/OCA/partner-contact", + "license": "AGPL-3", + "depends": [ + "portal", + ], + "data": [ + "views/res_partner_views.xml", + "views/portal_template.xml", + "views/assets.xml", + ], + "installable": True, +} diff --git a/portal_partner_data_no_edit/controllers/__init__.py b/portal_partner_data_no_edit/controllers/__init__.py new file mode 100644 index 000000000..8c3feb6f5 --- /dev/null +++ b/portal_partner_data_no_edit/controllers/__init__.py @@ -0,0 +1 @@ +from . import portal diff --git a/portal_partner_data_no_edit/controllers/portal.py b/portal_partner_data_no_edit/controllers/portal.py new file mode 100644 index 000000000..70f5e5ce8 --- /dev/null +++ b/portal_partner_data_no_edit/controllers/portal.py @@ -0,0 +1,22 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.http import request, route + + +class PortalBlockEdit(CustomerPortal): + + def _prepare_portal_layout_values(self): + """So we can change the edit link text in the view""" + values = super()._prepare_portal_layout_values() + values["block_portal_data_edit"] = ( + request.env.user.block_portal_data_edit) + return values + + @route() + def account(self, redirect=None, **post): + """Inject a context that we later we catch in the template `render`""" + if request.env.user.block_portal_data_edit: + context = dict(request.env.context, block_portal_data_edit=True) + request.env.context = context + return super().account(redirect, **post) diff --git a/portal_partner_data_no_edit/i18n/es.po b/portal_partner_data_no_edit/i18n/es.po new file mode 100644 index 000000000..98542cea6 --- /dev/null +++ b/portal_partner_data_no_edit/i18n/es.po @@ -0,0 +1,45 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * portal_partner_data_no_edit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-02-04 10:16+0000\n" +"PO-Revision-Date: 2021-02-04 11:18+0100\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: es\n" +"X-Generator: Poedit 2.3\n" + +#. module: portal_partner_data_no_edit +#: model_terms:ir.ui.view,arch_db:portal_partner_data_no_edit.o_portal_my_details +msgid " View" +msgstr " Ver" + +#. module: portal_partner_data_no_edit +#: model:ir.model.fields,help:portal_partner_data_no_edit.field_res_partner__block_portal_data_edit +#: model:ir.model.fields,help:portal_partner_data_no_edit.field_res_users__block_portal_data_edit +msgid "Block portal info editing for the portal user linked to this partner" +msgstr "Bloquea la edición de la información al usuario de portal vinculado a este contacto" + +#. module: portal_partner_data_no_edit +#: model:ir.model.fields,field_description:portal_partner_data_no_edit.field_res_partner__block_portal_data_edit +#: model:ir.model.fields,field_description:portal_partner_data_no_edit.field_res_users__block_portal_data_edit +msgid "Block Customer Info Edit" +msgstr "Bloquear edición de datos de portal" + +#. module: portal_partner_data_no_edit +#: model:ir.model,name:portal_partner_data_no_edit.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: portal_partner_data_no_edit +#: model:ir.model,name:portal_partner_data_no_edit.model_ir_ui_view +msgid "View" +msgstr "Ver" diff --git a/portal_partner_data_no_edit/i18n/portal_partner_data_no_edit.pot b/portal_partner_data_no_edit/i18n/portal_partner_data_no_edit.pot new file mode 100644 index 000000000..fb166a3ec --- /dev/null +++ b/portal_partner_data_no_edit/i18n/portal_partner_data_no_edit.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * portal_partner_data_no_edit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-02-04 10:11+0000\n" +"PO-Revision-Date: 2021-02-04 10:11+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: portal_partner_data_no_edit +#: model_terms:ir.ui.view,arch_db:portal_partner_data_no_edit.o_portal_my_details +msgid " View" +msgstr "" + +#. module: portal_partner_data_no_edit +#: model:ir.model.fields,help:portal_partner_data_no_edit.field_res_partner__block_portal_data_edit +#: model:ir.model.fields,help:portal_partner_data_no_edit.field_res_users__block_portal_data_edit +msgid "Block portal info editing for the portal user linked to this partner" +msgstr "" + +#. module: portal_partner_data_no_edit +#: model:ir.model.fields,field_description:portal_partner_data_no_edit.field_res_partner__block_portal_data_edit +#: model:ir.model.fields,field_description:portal_partner_data_no_edit.field_res_users__block_portal_data_edit +msgid "Block Customer Info Edit" +msgstr "" + +#. module: portal_partner_data_no_edit +#: model:ir.model,name:portal_partner_data_no_edit.model_res_partner +msgid "Contact" +msgstr "" + +#. module: portal_partner_data_no_edit +#: model:ir.model,name:portal_partner_data_no_edit.model_ir_ui_view +msgid "View" +msgstr "" + diff --git a/portal_partner_data_no_edit/models/__init__.py b/portal_partner_data_no_edit/models/__init__.py new file mode 100644 index 000000000..beb691b37 --- /dev/null +++ b/portal_partner_data_no_edit/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_ui_view +from . import res_partner diff --git a/portal_partner_data_no_edit/models/ir_ui_view.py b/portal_partner_data_no_edit/models/ir_ui_view.py new file mode 100644 index 000000000..8bf39cabb --- /dev/null +++ b/portal_partner_data_no_edit/models/ir_ui_view.py @@ -0,0 +1,52 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models +from lxml import html + + +class IrUiView(models.Model): + _inherit = "ir.ui.view" + + def render(self, values=None, engine='ir.qweb', minimal_qcontext=False): + """Disable inputs converting them into paragraphs and clear form + buttons. This way, we don't need to go input by input and we can + support any view extension without further patching""" + res = super().render( + values=values, engine=engine, minimal_qcontext=minimal_qcontext) + if not self.env.context.get("block_portal_data_edit"): + return res + fragments = html.fromstring(res.decode('utf-8')) + for fragment in fragments: + # The result is a page that looks the same way as the original form + # but with the input fields shadowed and not editable as they're + # just `

` paragraphs in `form-control` classes disguise. + for _input in fragment.iterfind( + ".//form[@action='/my/account']//input"): + if _input.type in ["text", "tel", "email"]: + attrs = _input.attrib + text = attrs.pop("value", "") + # We don't want this attribute in the `

` + del(attrs["type"]) + attrs["readonly"] = "1" + p_readonly = _input.makeelement("p", attrib=attrs) + p_readonly.text = text + _input.addprevious(p_readonly) + _input.getparent().remove(_input) + for _select in fragment.iterfind( + ".//form[@action='/my/account']//select"): + # Maybe there's a prettier way to extract the selected value + option = [ + x for x in _select.getchildren() + if x.attrib.get("value", "") == _select.value + ] + text = option and option[0].text or "" + attrs = _select.attrib + attrs["readonly"] = "1" + p_readonly = _select.makeelement("p", attrib=attrs) + p_readonly.text = text + _select.addprevious(p_readonly) + _select.getparent().remove(_select) + for _button in fragment.iterfind( + ".//form[@action='/my/account']//button"): + _button.getparent().remove(_button) + return b"".join(html.tostring(f) for f in fragments) diff --git a/portal_partner_data_no_edit/models/res_partner.py b/portal_partner_data_no_edit/models/res_partner.py new file mode 100644 index 000000000..aee44adc4 --- /dev/null +++ b/portal_partner_data_no_edit/models/res_partner.py @@ -0,0 +1,13 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + block_portal_data_edit = fields.Boolean( + string="Block Customer Info Edit", + help="Block portal info editing for the portal " + "user linked to this partner", + ) diff --git a/portal_partner_data_no_edit/readme/CONFIGURE.rst b/portal_partner_data_no_edit/readme/CONFIGURE.rst new file mode 100644 index 000000000..f4de8228d --- /dev/null +++ b/portal_partner_data_no_edit/readme/CONFIGURE.rst @@ -0,0 +1,7 @@ +To test this module, you need to: + +#. Block portal info editing for a partner: + + - Go to *Contacts* and choose the partner. + - In the the *Sales and Purchases* tab, *Misc* section there is a field named + *Block Portal Info Edit*. Enable or disable at your convenience. diff --git a/portal_partner_data_no_edit/readme/CREDITS.rst b/portal_partner_data_no_edit/readme/CREDITS.rst new file mode 100644 index 000000000..94b6ba953 --- /dev/null +++ b/portal_partner_data_no_edit/readme/CREDITS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * David Vidal diff --git a/portal_partner_data_no_edit/readme/DESCRIPTION.rst b/portal_partner_data_no_edit/readme/DESCRIPTION.rst new file mode 100644 index 000000000..ad85c7906 --- /dev/null +++ b/portal_partner_data_no_edit/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows to block portal users info editing to prevent unproper +changes. We can configure it on every partner. diff --git a/portal_partner_data_no_edit/readme/ROADMAP.rst b/portal_partner_data_no_edit/readme/ROADMAP.rst new file mode 100644 index 000000000..3d4156118 --- /dev/null +++ b/portal_partner_data_no_edit/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +- Add the `block_portal_data_edit` flag to the invite to portal popup. +- Add a text on the page highlighted (for example with info BS class), saying for those + blocked users that they should contact the company for any modification. diff --git a/portal_partner_data_no_edit/readme/USAGE.rst b/portal_partner_data_no_edit/readme/USAGE.rst new file mode 100644 index 000000000..40d89bc67 --- /dev/null +++ b/portal_partner_data_no_edit/readme/USAGE.rst @@ -0,0 +1,5 @@ +Once configured log in with that user and: + + - Go to `/my/account/` + - If the editing is blocked, you won't be able to edit any detail or submit + the form. diff --git a/portal_partner_data_no_edit/static/description/index.html b/portal_partner_data_no_edit/static/description/index.html new file mode 100644 index 000000000..c57f4af31 --- /dev/null +++ b/portal_partner_data_no_edit/static/description/index.html @@ -0,0 +1,459 @@ + + + + + + +Portal Partner Block Data Edit + + + +

+

Portal Partner Block Data Edit

+ + +

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

+

This module allows to block portal users info editing to prevent unproper +changes. We can configure it on every partner.

+

Table of contents

+ +
+

Configuration

+

To test this module, you need to:

+
    +
  1. Block portal info editing for a partner:
  2. +
+
+
    +
  • Go to Contacts and choose the partner.
  • +
  • In the the Sales and Purchases tab, Misc section there is a field named +Block Portal Info Edit. Enable or disable at your convenience.
  • +
+
+
+
+

Usage

+

Once configured log in with that user and:

+
+
    +
  • Go to /my/account/
  • +
  • If the editing is blocked, you won’t be able to edit any detail or submit +the form.
  • +
+
+
+
+

Known issues / Roadmap

+
    +
  • Add the block_portal_data_edit flag to the invite to portal popup.
  • +
  • Add a text on the page highlighted (for example with info BS class), saying for those +blocked users that they should contact the company for any modification.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Other credits

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/partner-contact project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/portal_partner_data_no_edit/static/src/js/portal_partner_data_no_edit_tour.js b/portal_partner_data_no_edit/static/src/js/portal_partner_data_no_edit_tour.js new file mode 100644 index 000000000..a2f834677 --- /dev/null +++ b/portal_partner_data_no_edit/static/src/js/portal_partner_data_no_edit_tour.js @@ -0,0 +1,60 @@ +/* Copyright 2021 Tecnativa - David Vidal + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ + +odoo.define("portal_partner_data_default.tour", function (require) { + "use strict"; + + var tour = require("web_tour.tour"); + var base = require("web_editor.base"); + + var steps = [ + { + trigger: "div.o_portal_my_details a:contains('Edit')", + }, + { + trigger: "input[name=name]", + run: 'Mr. Odoo', + }, + { + trigger: "button[type=submit]", + }, + ]; + tour.register("portal_partner_data_no_edit_default_tour", + { + url: "/my", + test: true, + wait_for: base.ready(), + }, + steps + ); + return { + steps: steps, + }; +}); + +odoo.define("portal_partner_data_block.tour", function (require) { + "use strict"; + + var tour = require("web_tour.tour"); + var base = require("web_editor.base"); + + var steps = [ + { + trigger: "div.o_portal_my_details a:contains('View')", + }, + { + trigger: "p[name=name]", + }, + ]; + tour.register("portal_partner_data_no_edit_block_tour", + { + url: "/my", + test: true, + wait_for: base.ready(), + }, + steps + ); + return { + steps: steps, + }; +}); diff --git a/portal_partner_data_no_edit/tests/__init__.py b/portal_partner_data_no_edit/tests/__init__.py new file mode 100644 index 000000000..5003f16c1 --- /dev/null +++ b/portal_partner_data_no_edit/tests/__init__.py @@ -0,0 +1 @@ +from . import test_portal_partner_data_no_edit diff --git a/portal_partner_data_no_edit/tests/test_portal_partner_data_no_edit.py b/portal_partner_data_no_edit/tests/test_portal_partner_data_no_edit.py new file mode 100644 index 000000000..f7862ebeb --- /dev/null +++ b/portal_partner_data_no_edit/tests/test_portal_partner_data_no_edit.py @@ -0,0 +1,38 @@ +# Copyright 2020 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import tagged, common + + +@tagged('post_install', '-at_install') +class PortalHttpCase(common.HttpCase): + + def setUp(self): + super().setUp() + self.partner = self.env.ref("base.partner_demo_portal") + + def test_portal_partner_default(self): + """The default standard behavior""" + tour = ( + "odoo.__DEBUG__.services['web_tour.tour']", + "portal_partner_data_no_edit_default_tour", + ) + self.browser_js( + url_path="/my", + code="%s.run('%s')" % tour, + ready="%s.tours.%s.ready" % tour, + login="portal", + ) + + def test_portal_partner_blocked(self): + """There's no form fields anymore""" + self.partner.block_portal_data_edit = True + tour = ( + "odoo.__DEBUG__.services['web_tour.tour']", + "portal_partner_data_no_edit_block_tour", + ) + self.browser_js( + url_path="/my", + code="%s.run('%s')" % tour, + ready="%s.tours.%s.ready" % tour, + login="portal", + ) diff --git a/portal_partner_data_no_edit/views/assets.xml b/portal_partner_data_no_edit/views/assets.xml new file mode 100644 index 000000000..dcd04c25e --- /dev/null +++ b/portal_partner_data_no_edit/views/assets.xml @@ -0,0 +1,9 @@ + + +