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

[4405][ADD] website_require_login #6

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
6 changes: 6 additions & 0 deletions setup/website_require_login/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,
)
85 changes: 85 additions & 0 deletions website_require_login/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
======================
Website Login Required
======================

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

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

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

This module allows to restrict access to specific website pages to logged users.

**Table of contents**

.. contents::
:local:

Usage
=====

Website > Configuration > Authorization required URLs: select a website and enter a relative path, eg: /shop

When public user will try to access mywebsite.com/shop or any of its child pages, they will be requested to login.

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

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

* Advitus MB
* Ooops

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

* Ooops404 <https://ooops404.com>
* Nils Coenen <[email protected]>

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/website <https://github.com/OCA/website/tree/15.0/website_require_login>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions website_require_login/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2020 Advitus MB
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).

from . import models
21 changes: 21 additions & 0 deletions website_require_login/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2020 Advitus MB
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).

{
"name": "Website Login Required",
"category": "Website",
"version": "15.0.1.0.0",
"author": "Advitus MB, Ooops, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/website",
"license": "LGPL-3",
"depends": [
"website",
],
"data": [
"security/ir.model.access.csv",
"views/website_auth_url.xml",
"data/ir_actions.xml",
"data/ir_ui_menu.xml",
],
"installable": True,
}
12 changes: 12 additions & 0 deletions website_require_login/data/ir_actions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="action_website_auth_url" model="ir.actions.act_window">
<field name="name">Authorization required URLs</field>
<field name="res_model">website.auth.url</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="website_auth_url_tree_view" />
<field name="target">current</field>
</record>

</odoo>
12 changes: 12 additions & 0 deletions website_require_login/data/ir_ui_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<menuitem
name="Authorization required URLs"
id="menu_website_auth_url"
action="action_website_auth_url"
parent="website.menu_website_global_configuration"
sequence="60"
/>

</odoo>
88 changes: 88 additions & 0 deletions website_require_login/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_require_login
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-03-07 19:22+0000\n"
"Last-Translator: Francesco Foresti <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.14.1\n"

#. module: website_require_login
#: model:ir.actions.act_window,name:website_require_login.action_website_auth_url
#: model:ir.model,name:website_require_login.model_website_auth_url
#: model:ir.ui.menu,name:website_require_login.menu_website_auth_url
msgid "Authorization required URLs"
msgstr "URL che richiedono il login"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__create_uid
msgid "Created by"
msgstr "Creato da"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__create_date
msgid "Created on"
msgstr "Creato il"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: website_require_login
#: model:ir.model,name:website_require_login.model_ir_http
msgid "HTTP Routing"
msgstr "Instradamento HTTP"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__id
msgid "ID"
msgstr "ID"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__write_uid
msgid "Last Updated by"
msgstr "Ultimo aggiornamento di"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__write_date
msgid "Last Updated on"
msgstr "Ultimo aggiornamento il"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__path
msgid "Path"
msgstr "Percorso"

#. module: website_require_login
#: model:ir.model.fields,help:website_require_login.field_website_auth_url__path
msgid ""
"Relative URL path and subpath. Ex.: /shop will restrict /shop, /shop/"
"product, etc."
msgstr ""
"Percorso e sotto-percorso relativo all'URL, es: /shop limiterà l'accesso sia "
"a /shop che a /shop/product, etc."

#. module: website_require_login
#: model:ir.model.constraint,message:website_require_login.constraint_website_auth_url_path_unique
msgid "The path must be unique per website!"
msgstr "Il percorso deve essere univoco per sito web!"

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__website_id
msgid "Website"
msgstr "Sito web"
83 changes: 83 additions & 0 deletions website_require_login/i18n/website_require_login.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_require_login
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.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: website_require_login
#: model:ir.actions.act_window,name:website_require_login.action_website_auth_url
#: model:ir.model,name:website_require_login.model_website_auth_url
#: model:ir.ui.menu,name:website_require_login.menu_website_auth_url
msgid "Authorization required URLs"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__create_uid
msgid "Created by"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__create_date
msgid "Created on"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__display_name
msgid "Display Name"
msgstr ""

#. module: website_require_login
#: model:ir.model,name:website_require_login.model_ir_http
msgid "HTTP Routing"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__id
msgid "ID"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url____last_update
msgid "Last Modified on"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__write_uid
msgid "Last Updated by"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__write_date
msgid "Last Updated on"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__path
msgid "Path"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,help:website_require_login.field_website_auth_url__path
msgid ""
"Relative URL path and subpath. Ex.: /shop will restrict /shop, "
"/shop/product, etc."
msgstr ""

#. module: website_require_login
#: model:ir.model.constraint,message:website_require_login.constraint_website_auth_url_path_unique
msgid "The path must be unique per website!"
msgstr ""

#. module: website_require_login
#: model:ir.model.fields,field_description:website_require_login.field_website_auth_url__website_id
msgid "Website"
msgstr ""
5 changes: 5 additions & 0 deletions website_require_login/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2020 Advitus MB
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).

from . import ir_http
from . import website_auth_url
36 changes: 36 additions & 0 deletions website_require_login/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2020 Advitus MB
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from pathlib import Path

from odoo import models
from odoo.http import request


class IrHttp(models.AbstractModel):
_inherit = "ir.http"

@classmethod
def _dispatch(cls):
res = super(IrHttp, cls)._dispatch()

# if not website request - skip

website = request.env["website"].sudo().get_current_website()
if not website:
return res
if request.uid == website.user_id.id:
auth_paths = (
request.env["website.auth.url"]
.sudo()
.search(
[
("website_id", "=", website.id),
]
)
.mapped("path")
)
path = request.httprequest.path
for auth_path in auth_paths:
if auth_path == path or Path(auth_path) in Path(path).parents:
return request.redirect("/web/login?redirect=%s" % path)
return res
30 changes: 30 additions & 0 deletions website_require_login/models/website_auth_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2020 Advitus MB
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).

from odoo import fields, models


class WebsiteAuthURL(models.Model):
_name = "website.auth.url"
_description = "Authorization required URLs"

website_id = fields.Many2one(
comodel_name="website",
required=True,
)

path = fields.Char(
required=True,
help=(
"Relative URL path and subpath. "
"Ex.: /shop will restrict /shop, /shop/product, etc."
),
)

_sql_constraints = [
(
"path_unique",
"unique (website_id, path)",
"The path must be unique per website!",
)
]
2 changes: 2 additions & 0 deletions website_require_login/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Ooops404 <https://ooops404.com>
* Nils Coenen <[email protected]>
Loading
Loading