Skip to content

Commit

Permalink
[ADD] web_editor_media_dialog_dms: New module to allow to set dms fil…
Browse files Browse the repository at this point in the history
…es as media in web editor
  • Loading branch information
CarlosRoca13 committed Aug 23, 2024
1 parent 1e7dbb2 commit c408e9c
Show file tree
Hide file tree
Showing 17 changed files with 1,093 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/web_editor_media_dialog_dms/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
97 changes: 97 additions & 0 deletions web_editor_media_dialog_dms/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
===========================
Web Editor Media Dialog DMS
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:61e7939eaa7373b7c5114e669fe2cb623fba465e7f682708680aebee1ceddee2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fdms-lightgray.png?logo=github
:target: https://github.com/OCA/dms/tree/16.0/web_editor_media_dialog_dms
:alt: OCA/dms
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/dms-16-0/dms-16-0-web_editor_media_dialog_dms
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/dms&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the option in the web editor to include an image with the
corresponding link to open/download the linked files.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, we need:

#. Navigate to a model that has an HTML field
#. Edit the field
#. Type /image to open the media dialog
#. Select the DMS tab
#. Select the DMS file to be added

You can also edit the selected file making a double click on the image added to web
editor.

If you want to share the file to a public user, you can do it by selecting the option
**Allow open to public users** which is located on DMS tab of media dialog.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/dms/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/OCA/dms/issues/new?body=module:%20web_editor_media_dialog_dms%0Aversion:%2016.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
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`_:

* Pedro M. Baeza
* Carlos Roca

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/dms <https://github.com/OCA/dms/tree/16.0/web_editor_media_dialog_dms>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions web_editor_media_dialog_dms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions web_editor_media_dialog_dms/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Web Editor Media Dialog DMS",
"summary": "Integrate DMS with media dialog of web editor",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/dms",
"depends": ["dms", "web_editor"],
"assets": {
"web_editor.assets_media_dialog": [
"web_editor_media_dialog_dms/static/src/media_dialog/*",
]
},
}
70 changes: 70 additions & 0 deletions web_editor_media_dialog_dms/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_editor_media_dialog_dms
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-22 09:04+0000\n"
"PO-Revision-Date: 2024-08-22 11:05+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.0.1\n"

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "All DMS files have been loaded"
msgstr "Todos los archivos DMS han sido cargados"

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "Allow open to public users"
msgstr "Permitir abrir enlace a usuarios públicos"

#. module: web_editor_media_dialog_dms
#: model:ir.model,name:web_editor_media_dialog_dms.model_dms_file
msgid "File"
msgstr "Archivo"

#. module: web_editor_media_dialog_dms
#: model:ir.model,name:web_editor_media_dialog_dms.model_ir_binary
msgid "File streaming helper model for controllers"
msgstr "Modelo de ayuda para la transmisión de archivos para controladores"

#. module: web_editor_media_dialog_dms
#. odoo-python
#: code:addons/web_editor_media_dialog_dms/models/dms_file.py:0
#, python-format
msgid "Invalid access token"
msgstr "Token de acceso inválido"

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "Load more..."
msgstr "Cargar más..."

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "No DMS files found."
msgstr "No se encontraron archivos DMS."

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.esm.js:0
#, python-format
msgid "Search a dms file"
msgstr "Buscar un archivo DMS"
68 changes: 68 additions & 0 deletions web_editor_media_dialog_dms/i18n/web_editor_media_dialog_dms.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_editor_media_dialog_dms
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-22 09:04+0000\n"
"PO-Revision-Date: 2024-08-22 09:04+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: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "All DMS files have been loaded"
msgstr ""

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "Allow open to public users"
msgstr ""

#. module: web_editor_media_dialog_dms
#: model:ir.model,name:web_editor_media_dialog_dms.model_dms_file
msgid "File"
msgstr ""

#. module: web_editor_media_dialog_dms
#: model:ir.model,name:web_editor_media_dialog_dms.model_ir_binary
msgid "File streaming helper model for controllers"
msgstr ""

#. module: web_editor_media_dialog_dms
#. odoo-python
#: code:addons/web_editor_media_dialog_dms/models/dms_file.py:0
#, python-format
msgid "Invalid access token"
msgstr ""

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "Load more..."
msgstr ""

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.xml:0
#, python-format
msgid "No DMS files found."
msgstr ""

#. module: web_editor_media_dialog_dms
#. odoo-javascript
#: code:addons/web_editor_media_dialog_dms/static/src/media_dialog/dms_selector.esm.js:0
#, python-format
msgid "Search a dms file"
msgstr ""
2 changes: 2 additions & 0 deletions web_editor_media_dialog_dms/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import dms_file
from . import ir_binary
26 changes: 26 additions & 0 deletions web_editor_media_dialog_dms/models/dms_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Tecnativa - Carlos Roca
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import _, models
from odoo.exceptions import AccessError
from odoo.tools import consteq


class File(models.Model):
_inherit = "dms.file"

def get_access_token(self):
self.ensure_one()
return self._portal_ensure_token()

Check warning on line 14 in web_editor_media_dialog_dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

web_editor_media_dialog_dms/models/dms_file.py#L13-L14

Added lines #L13 - L14 were not covered by tests

def validate_access(self, access_token):
# Validate if token provided is correct for the record checked
self.ensure_one()
record_sudo = self.sudo()

Check warning on line 19 in web_editor_media_dialog_dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

web_editor_media_dialog_dms/models/dms_file.py#L18-L19

Added lines #L18 - L19 were not covered by tests
if access_token:
tok = record_sudo.with_context(prefetch_fields=False).access_token
valid_token = consteq(tok or "", access_token)

Check warning on line 22 in web_editor_media_dialog_dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

web_editor_media_dialog_dms/models/dms_file.py#L21-L22

Added lines #L21 - L22 were not covered by tests
if not valid_token:
raise AccessError(_("Invalid access token"))
return record_sudo
return self

Check warning on line 26 in web_editor_media_dialog_dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

web_editor_media_dialog_dms/models/dms_file.py#L24-L26

Added lines #L24 - L26 were not covered by tests
15 changes: 15 additions & 0 deletions web_editor_media_dialog_dms/models/ir_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Tecnativa - Carlos Roca
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import models


class IrBinary(models.AbstractModel):
_inherit = "ir.binary"

def _find_record_check_access(self, record, access_token):
# The method is overridden to allow access to the media attached to the
# dms.file records using an access_token.
if record._name == "dms.file":
return record.validate_access(access_token)

Check warning on line 14 in web_editor_media_dialog_dms/models/ir_binary.py

View check run for this annotation

Codecov / codecov/patch

web_editor_media_dialog_dms/models/ir_binary.py#L14

Added line #L14 was not covered by tests
return super()._find_record_check_access(record, access_token)
4 changes: 4 additions & 0 deletions web_editor_media_dialog_dms/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Pedro M. Baeza
* Carlos Roca
2 changes: 2 additions & 0 deletions web_editor_media_dialog_dms/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module adds the option in the web editor to include an image with the
corresponding link to open/download the linked files.
13 changes: 13 additions & 0 deletions web_editor_media_dialog_dms/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To use this module, we need:

#. Navigate to a model that has an HTML field
#. Edit the field
#. Type /image to open the media dialog
#. Select the DMS tab
#. Select the DMS file to be added

You can also edit the selected file making a double click on the image added to web
editor.

If you want to share the file to a public user, you can do it by selecting the option
**Allow open to public users** which is located on DMS tab of media dialog.
Loading

0 comments on commit c408e9c

Please sign in to comment.