mirror of
https://github.com/bringout/oca-website.git
synced 2026-04-22 20:51:59 +02:00
Initial commit: OCA Website packages (16 packages)
This commit is contained in:
commit
0578ef7638
660 changed files with 37334 additions and 0 deletions
|
|
@ -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
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
# 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, endpoint):
|
||||
res = cls._check_require_auth()
|
||||
if res:
|
||||
return res
|
||||
return super()._dispatch(endpoint)
|
||||
|
||||
@classmethod
|
||||
def _serve_fallback(cls):
|
||||
res = cls._check_require_auth()
|
||||
if res:
|
||||
return res
|
||||
return super()._serve_fallback()
|
||||
|
||||
@classmethod
|
||||
def _check_require_auth(cls):
|
||||
# if not website request - skip
|
||||
website = request.env["website"].sudo().get_current_website()
|
||||
if not website:
|
||||
return None
|
||||
if request.uid and (request.uid != website.user_id.id):
|
||||
return None
|
||||
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:
|
||||
redirect_path = "/web/login?redirect=%s" % path
|
||||
return request.redirect(redirect_path, code=302)
|
||||
|
|
@ -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!",
|
||||
)
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue