Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][MIG] document_page_portal #453

Open
wants to merge 13 commits into
base: 14.0
Choose a base branch
from
Open
103 changes: 103 additions & 0 deletions document_page_portal/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
====================
Document Page Portal
====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:83751d0dd805c839f85221e62ddf9569bc2555dda895792cc05bcc5cbc4ab377
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fknowledge-lightgray.png?logo=github
:target: https://github.com/OCA/knowledge/tree/13.0/document_page_portal
:alt: OCA/knowledge
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/knowledge-13-0/knowledge-13-0-document_page_portal
: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/knowledge&target_branch=13.0
:alt: Try me on Runboat

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

This module allows documents to be made available on the portal.

**Table of contents**

.. contents::
:local:

Configuration
=============

No configuration required.

Usage
=====

* Add a user as a follower of the document or configure the document as public so that it is visible through the user portal.

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

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

* Escodoo

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

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Escodoo <https://www.escodoo.com.br>

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.

.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px
:target: https://github.com/marcelsavegnago
:alt: marcelsavegnago

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-marcelsavegnago|

This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/13.0/document_page_portal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions document_page_portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
24 changes: 24 additions & 0 deletions document_page_portal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2020 - TODAY, Marcel Savegnago - Escodoo).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


{
"name": "Document Page Portal",
"summary": """
This module enables document page portal""",
"version": "14.0.1.0.0",
"category": "Knowledge Management",
"author": "Escodoo, Odoo Community Association (OCA)",
"maintainers": ["marcelsavegnago"],
"images": ["static/description/banner.png"],
"website": "https://github.com/OCA/knowledge",
"license": "AGPL-3",
"depends": ["base", "portal", "document_page"],
"data": [
"views/assets.xml",
"views/document_page.xml",
"security/document_page_portal_security.xml",
"security/ir.model.access.csv",
"views/document_page_portal_templates.xml",
],
}
1 change: 1 addition & 0 deletions document_page_portal/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import portal
147 changes: 147 additions & 0 deletions document_page_portal/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Copyright (C) 2020 - TODAY, Marcel Savegnago - Escodoo).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import http
from odoo.exceptions import AccessError, MissingError
from odoo.http import request
from odoo.osv.expression import OR
from odoo.tools.translate import _

from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager


class CustomerPortal(CustomerPortal):
def _prepare_portal_layout_values(self):
values = super(CustomerPortal, self)._prepare_portal_layout_values()
values["document_page_count"] = request.env["document.page"].search_count(
[("type", "=", "content")]
)
return values

def _document_page_get_page_view_values(
self, document_page, access_token, **kwargs
):
values = {

Check warning on line 25 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L25

Added line #L25 was not covered by tests
"page_name": "document_page",
"document_page": document_page,
}
return self._get_page_view_values(

Check warning on line 29 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L29

Added line #L29 was not covered by tests
document_page,
access_token,
values,
"my_document_pages_history",
False,
**kwargs
)

@http.route(
["/my/knowledge/documents/", "/my/knowledge/documents/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_knowledge_document_pages(
self,
page=1,
date_begin=None,
date_end=None,
sortby=None,
search=None,
search_in="content",
**kw
):
values = self._prepare_portal_layout_values()
domain = [("type", "=", "content")]

searchbar_sortings = {
"date": {"label": _("Newest"), "order": "create_date desc"},
"name": {"label": _("Name"), "order": "name"},
"parent": {"label": _("Category"), "order": "parent_id"},
}
searchbar_inputs = {
"content": {
"input": "content",
"label": _('Search <span class="nolabel"> (in Content)</span>'),
},
"all": {"input": "all", "label": _("Search in All")},
}

# default sort by value
if not sortby:
sortby = "date"
order = searchbar_sortings[sortby]["order"]

if date_begin and date_end:
domain += [

Check warning on line 76 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L76

Added line #L76 was not covered by tests
("create_date", ">", date_begin),
("create_date", "<=", date_end),
]

# search
if search and search_in:
search_domain = []

Check warning on line 83 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L83

Added line #L83 was not covered by tests
if search_in in ("content", "all"):
search_domain = OR(

Check warning on line 85 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L85

Added line #L85 was not covered by tests
[
search_domain,
["|", ("name", "ilike", search), ("content", "ilike", search)],
]
)
domain += search_domain

Check warning on line 91 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L91

Added line #L91 was not covered by tests

# pager
document_pages_count = request.env["document.page"].search_count(domain)
pager = portal_pager(
url="/my/knowledge/documents",
url_args={"date_begin": date_begin, "date_end": date_end, "sortby": sortby},
total=document_pages_count,
page=page,
step=self._items_per_page,
)

document_pages = request.env["document.page"].search(
domain, order=order, limit=self._items_per_page, offset=pager["offset"]
)
request.session["my_document_pages_history"] = document_pages.ids[:100]

values.update(
{
"date": date_begin,
"document_pages": document_pages,
"page_name": "document_page",
"default_url": "/my/knowledge/s",
"pager": pager,
"searchbar_sortings": searchbar_sortings,
"searchbar_inputs": searchbar_inputs,
"sortby": sortby,
"search_in": search_in,
"search": search,
}
)
return request.render(
"document_page_portal.portal_my_knowledge_document_pages", values
)

@http.route(
[
"/knowledge/document/<int:document_page_id>",
"/knowledge/document/<int:document_page_id>/<token>",
"/my/knowledge/document/<int:document_page_id>",
],
type="http",
auth="public",
website=True,
)
def document_pages_followup(self, document_page_id=None, access_token=None, **kw):
try:
document_page_sudo = self._document_check_access(

Check warning on line 138 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L137-L138

Added lines #L137 - L138 were not covered by tests
"document.page", document_page_id, access_token
)
except (AccessError, MissingError):
return request.redirect("/my")

Check warning on line 142 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L141-L142

Added lines #L141 - L142 were not covered by tests

values = self._document_page_get_page_view_values(

Check warning on line 144 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L144

Added line #L144 was not covered by tests
document_page_sudo, access_token, **kw
)
return request.render("document_page_portal.document_pages_followup", values)

Check warning on line 147 in document_page_portal/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

document_page_portal/controllers/portal.py#L147

Added line #L147 was not covered by tests
94 changes: 94 additions & 0 deletions document_page_portal/i18n/document_page_portal.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * document_page_portal
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \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: document_page_portal
#: model_terms:ir.ui.view,arch_db:document_page_portal.document_pages_followup
msgid "<em class=\"text-muted\"><small>No content</small></em>"
msgstr ""

#. module: document_page_portal
#: model_terms:ir.ui.view,arch_db:document_page_portal.document_pages_followup
msgid "<small class=\"text-right\">Category:</small>"
msgstr ""

#. module: document_page_portal
#: code:addons/document_page_portal/controllers/portal.py:0
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_knowledge_document_pages
#, python-format
msgid "Category"
msgstr ""

#. module: document_page_portal
#: model_terms:ir.ui.view,arch_db:document_page_portal.document_pages_followup
msgid "Current Category of this document"
msgstr ""

#. module: document_page_portal
#: model:ir.model,name:document_page_portal.model_document_page
msgid "Document Page"
msgstr ""

#. module: document_page_portal
#: model:ir.model.fields,help:document_page_portal.field_document_page__is_public
msgid ""
"If true it allows any user of the portal to have access to this document."
msgstr ""

#. module: document_page_portal
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_home_Knowledge_document_page
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_home_menu_Knowledge
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_knowledge_document_pages
msgid "Knowledge Documents"
msgstr ""

#. module: document_page_portal
#: code:addons/document_page_portal/controllers/portal.py:0
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_knowledge_document_pages
#, python-format
msgid "Name"
msgstr ""

#. module: document_page_portal
#: code:addons/document_page_portal/controllers/portal.py:0
#, python-format
msgid "Newest"
msgstr ""

#. module: document_page_portal
#: model:ir.model.fields,field_description:document_page_portal.field_document_page__is_public
msgid "Public Page"
msgstr ""

#. module: document_page_portal
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_knowledge_document_pages
msgid "Ref"
msgstr ""

#. module: document_page_portal
#: code:addons/document_page_portal/controllers/portal.py:0
#, python-format
msgid "Search <span class=\"nolabel\"> (in Content)</span>"
msgstr ""

#. module: document_page_portal
#: code:addons/document_page_portal/controllers/portal.py:0
#, python-format
msgid "Search in All"
msgstr ""

#. module: document_page_portal
#: model_terms:ir.ui.view,arch_db:document_page_portal.portal_my_knowledge_document_pages
msgid "There are currently no Knowledge Document for your account."
msgstr ""
Loading
Loading