Commit Graph
1529 Commits
Author SHA1 Message Date
Romain Derie 985e49bdb5 [FIX] website: remove Google Analytics dashboard (deprecated)
==== Short version ====

Google is deprecating Universal Analytics in July 2023 and Google
Sign-In in March 2023. Google Analytics Embed API is based on Sign-In,
meaning it won't work anymore. It actually already doesn't work anymore
for accounts created somewhere after mid-2020 apparently.
There is no plan for now for Google to allow Analytics 4 dashboard to be
embed in external website.
We therefore can't do anything to keep the Google Analytics dashboard in
Odoo.
In previous stable version, it was kept but is displaying a warning
about it (as until mid 2023 old accounts can still embed it).
All this is about the embed dashboard, not the tracking in itself for
which Odoo is already adapted in Odoo 15.0 for Analytics 4.

==== Detailed version (following short version, read it first)  ====

- Universal Analytics EOL July 2023, see [1].
- It will be replaced by Analytics 4 for which Odoo is already ready and
  actually using it since version 15.0 with [2].
- Google Sign-In EOL March 2023, see [3]. Analytics Embed API was based
  on it, it won't work anymore.
- There is no plan (for now) for Google to allow Analytics 4 to be able
  to be embed in external websites. They seem to just have dropped the
  "feature".
  This was confirmed by Google here [4] and indirectly here [5] in the
  DOC:
  `Note: This API does not support Google Analytics 4 (GA4) properties`
- While the EOL is planed for 2023, the dashboard integration is already
  not working anymore for new accounts.
- Old projects/keys/accounts can still embed their analytics dashboard.
  The threshold seems to be somewhere mid-2020, according to [6].
  It seems to be accurate as my own key from 2018 still works, while my
  keys from 2021 do not.

==== Fix ====

- In stable, warn user about it in their Odoo Analytics dashboard (this
  PR) and also add a warning about that on the doc.
- In master, simply drop the whole google analytics dashboard
  integration and remove the doc about it, see [7].

==== Useful links ====

[1]: https://support.google.com/analytics/answer/11583528?hl=en
[2]: https://github.com/odoo/odoo/commit/78bc86cbeccfc5df16218aee2b0d7c501e5c05b5
[3]: https://developers.googleblog.com/2022/03/gis-jsweb-authz-migration.html
[4]: https://issuetracker.google.com/issues/233738709?pli=1
[5]: https://developers.google.com/analytics/devguides/reporting/embed/v1
[6]: https://support.google.com/analytics/answer/11583832
[7]: https://www.odoo.com/documentation/15.0/applications/websites/website/optimize/google_analytics_dashboard.html

Finally, note that it means that from July 2023 to Octobre 2023, while
Odoo 14.0 is still supported, Google Analytics won't work anymore in
that version as it will still be designed for Universal Analytics and
not Analytics 4.

opw-2710910
opw-2855405
opw-2881515
opw-2892370
task-2790245
task-2820890

closes odoo/odoo#96280

X-original-commit: d065595f77790fb5ab9480f6de5b88549352324b
Related: odoo/enterprise#29666
Related: odoo/upgrade#3698
Related: odoo/documentation#2499
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-07-26 15:48:43 +02:00
Benoit Socias b91fdd65f1 [FIX] website: write website-specific views before they get a new id
When both a specific inheriting view and a non-specific base view are
written simultaneously, the specific inheriting base view must be
updated even though its id will change during the COW of the base view.

This commit sorts the list of written views in order to first handle the
website-specific ones then the base ones which might change some of the
ids of the already updated view.

Steps to reproduce in 14.0+ (no scenario found in 13.0):
- Create a new website.
- Configure the language selector layout to "Inline".
- Configure the language selector layout to "None".
=> Error notification was displayed and change was not applied.

task-2885882

closes odoo/odoo#96248

X-original-commit: 317eea48186c948009399daedf70dd407f6a9ca8
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-07-18 21:03:12 +02:00
Raphael Collet fa49e347e9 [FIX] website: don't browse() a string
Part-of: odoo/odoo#95325
2022-07-14 22:45:44 +02:00
Julien Castiaux dce5dade01 [FIX] website: missing alternate URLs for pages
Install multiple langages, each time translating the website. In a
private browsing session access /contactus, show the page source, the
multiple alternate URL (`<link rel="alternative">` in the `<head>`) are
all pointing the canonical URL instead of the alternative.

closes odoo/odoo#95683

X-original-commit: 3d4b4d3dcff864613a9e7038137e21674425ed08
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-07-08 19:53:07 +02:00
Younn Olivier 1ff7f1e8b6 [FIX] website, *: restore theme/new content loader
*: test_website_modules

This commit restores the display of the website loader (the "Building
your website" GIF) during the installation of a module from the new
content modal, or after completing the configurator flow.

Follows the merge of the "website in backend" task at [1].

[1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b

task-2687506

Part-of: odoo/odoo#81485
2022-07-08 19:52:09 +02:00
Younn Olivier fed0e69c27 [FIX] website: fix multi website redirections
Before this commit, switching websites with custom domains was not
properly done: the client action should redirect to the custom domain if
there is one, instead of only redirecting the iframe.

The redirection was not correct for the "go to website" buttons either:
in that case, the url was incorrectly generated for the redirection (the
custom domain was passed in the path parameter of the client action).

See merge commit for more information.

task-2687506
2022-06-24 10:28:07 +02:00
Younn Olivier b85c2a4cb1 [IMP] website, *: redirect to the client action when needed
*: website_blog, website_hr_recruitment, website_sale, website_slides

This commit changes the redirections from the controllers, that were
always redirecting to the frontend before.

Now, we want to open the website in its backend client action most of
the time (for example, when clicking on the "go to website" buttons on
the form views).

For that, a new get_client_action_url is introduced on the website
model.

See merge commit for more information.

task-2687506
2022-06-24 10:28:07 +02:00
xO-Tx 0db19449d0 [IMP] website: add options on page list view
The goal of this commit is to add options to manage website pages as in
frontend page manager using list view.

- The click on list view item will redirect iframe to the targeted page.
- The Page Properties dialogs (DuplicatePageDialog, DeletePageDialog)
  are used to clone/remove pages.
- The pages listView is loaded using the current website domain.

See merge commit for more information.

task-2687506
2022-06-24 10:28:06 +02:00
xO-Tx 2ef7e78826 [IMP] website: add page properties dialog
The goal of this commit is to add the 'Page Properties' dialog using
the 'website.page' form view.

The PagePropertiesDialogWrapper was updated to work on pages listView
(to clone/remove pages).

A boolean field 'is_in_menu' was added to control if page is in menu on
page properties dialog. This should be refactored later as a wizard.

See merge commit for more information.

task-2687506
2022-06-24 10:28:06 +02:00
Younn Olivier caefcb8590 [IMP] website: convert configurator to client action
Before this commit, the configurator was its own frontend application.

With the website edition UI moved to the backend, it makes also sense to
move the configurator to the backend, as a client action, so that it is
easy to trigger it after installing a website (or the website module),
and returning to the website_preview client action after having
completed it.

This commit adds a new color_palettes.scss file, added in the
assets_backend, that will print the values of the color palettes (so
that some js can handle it). For now, it is needed for the configurator
and the editor. It will probably need to be reviewed later to not put
everything in backend assets.

See merge commit for more information.

task-2687506
2022-06-24 10:28:06 +02:00
Benjamin Vray 9b1f4a84e3 [IMP] website: remove _cache_customize_show_views method
Remove _cache_customize_show_views method added by [1].
As the customize show options have been moved to edit mode. The
"customize_show" attributes will be less used.

[1]: https://github.com/odoo/odoo/commit/697f6007847e0cf209610acd533c5cd4d2c83296

See merge commit for more information.

task-2710582
2022-06-24 10:28:05 +02:00
Jeremy Kersten a6a83b6d62 [FIX] website: fix / optimize canonical url
Homepage was never considered as canonical due to the trailing /
domain.com/fr/ != domain.com/fr

Now _get_canonical_url_localized for homepage is fixed.

Remove all computation related to canonical that is usless for connected
user. It is mainly used for SEO tools/bots/crawler.

Initially planed for 13.0 with [1] but reverted with [2].

[1]: https://github.com/odoo/odoo/commit/33167b3928c767a08fdc7eedc3e6204aac9cac08
[2]: https://github.com/odoo/odoo/commit/deb23450f18196c7f8d9e819db603fccd407b82a

closes odoo/odoo#94289

X-original-commit: 375abe5e369b59a57b352d68d4835f2ef275b560
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
2022-06-23 10:14:58 +02:00
Huy Le 414d4f98a1 [FIX] website: og:url should be localized
Before this commit, with a website using multiple languages, when sharing
any links with a language other than the original language on Facebook,
the content of Optimize SEO always receives the value of the default
language.

The reason is that `og:url` does not change according to the
language of the website because it's using `http.httprequest.url`.

Note that `http.httprequest.url` doesn't contain the lang part since we
already went through the dispatch's rerouting.
So we need to localize `og:url` to fix this.

Steps to reproduce:
1. Set up 2 different languages for your website (e.g. English, Vietnamese).
 Set the default language for the website to English.
2. Create any page, promote seo page for both languages.
3. Share this link on Facebook with Vietnamese language, see the title
and description on preview are still in English.

closes odoo/odoo#93998

X-original-commit: d47a2e4d08110df380c0060eebb1e9c2924b523e
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-06-21 17:58:07 +02:00
Jeremy Kersten af8b192327 [FIX] website: fix twitter image format and use it
Twitter image was wrongly computed, appending /300x300 after the unique
parameters.

Twitter image was always overwrite by `website_meta_og_img` or
`opengraph_meta['og:image']`

closes odoo/odoo#94158

X-original-commit: 086724929bd8d21537b626a79d12f8739933f5a5
Signed-off-by: Jérémy Kersten <jke@odoo.com>
2022-06-21 15:41:53 +02:00
Jeremy Kersten 6ee8ee2183 [FIX] web_unsplash, website: fix deps between website and web_unsplash
Website has no dependency to web_unsplash, we cannot warranty the order
of the execution of the overwrite done in 5ef8300.
So to avoid to create a new module bridge, with a lot of code, we prefer
to make a check for website user directly in unsplash module.
It is 'safe' since if you don't have website, the group
`group_website_designer` doesn't exists and so it will do a `or False`.

closes odoo/odoo#93885

X-original-commit: 05f9f5db372b1a3644f85cb1de3c443b722ef309
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-06-17 14:14:38 +02:00
Romain Derie bed3cd54a5 [FIX] website: stop calling theme _post_copy() on theme update
Before this commit, both the theme install* and upgrade flow would end
up calling the theme's `_post_copy()`.
The `_post_copy()` is in charge of enabling or disabling some website
options as ripple effect, language in footer, changing header template
etc.

From there, the user could later fine-tune its website and change those
options, altering what the theme chose during the install.

We don't want a later theme update to reapply the theme pre-selected
options and erase/revert the changes the user made after the theme
install.

This commit is then removing the call to `_post_copy()` on theme update.

Note that the `_post_copy()` is encapsulating the theme python code
which is supposed to only do some visual stuff like enabling a view or a
theme option.

Also, note that calling `_post_copy()` in a theme update will not only
re-enable/disable some views but that will create a de-sync between the
activated view and the scss value.
Indeed, for instance, enabling the hamburger menu view is not enough, it
should also be coming with a scss value change.
The mismatch between the template and the scss will lead to some visual
glitches / ugly result.
Calling `_post_copy()` when applying the theme for the first time
through the UI (the only way possible) will not create that de-sync
issue as that flow is resetting the scss value:
`_reset_default_config()` will be called through `_theme_remove()`.

* `theme install` does not refer to the module install
  but the moment the theme is applied on a website, which is not the
  same as themes modules behaves in their own manner. When a theme is
  installed on the DB, it does nothing except creating fake records in
  "standalone" tables, which will then be converted to real records and
  applied on the selected website.

opw-2824045

closes odoo/odoo#93109

X-original-commit: 14387f36438b731753e2e7169f54865b123cdcfa
Related: odoo/design-themes#571
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-06-08 16:50:56 +02:00
qsm-odoo 5fb94f6b79 [FIX] website, *: properly translate website filters names
*: website_blog, website_event, website_sale

The "website.snippet.filter" model introduced at [1] was not marked to
have its "name" field to be translated. As those names are shown in the
website editor panel to be able to select a filter, they have to be
translated.

[1]: https://github.com/odoo/odoo/commit/0e7640b5f22d2bea04bbe22d3189cff7e03af545

opw-2852416

closes odoo/odoo#93074

X-original-commit: fc9e5619331cf22f8605a72907153f9431ca6b15
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-06-08 15:45:49 +02:00
Romain Derie d348bed1ad [IMP] website, *: use upsert to improve visitor perf
* im_livechat, test_event_full, website_blog, website_crm,
  website_event, website_event_track, website_event_track_quiz,
  webite_livechat, website_sale

There is 6 main changes in this commit:

1. Using raw SQL Upsert instead of the ORM methods. While raw SQL should
generally be avoided, it makes sense for such a low level behavior which
is impacting every flows.
Indeed, tracking visitors is a generic behavior done on all pages and
controllers. It is important to optimize it to reduce processing time
and SQL Queries.
Benchmark of that change alone:
> Rendering a tracked page improves from ~19.5ms to ~17ms (using `ab`
  with 1000 loop) and the requests involved in the tracking process are
  reduced from 8 SQL Queries to 3:
  - 1 request to upsert the visitor
  - 1 request to fetch the visitor data
  - 1 request to add the tracking record

2. Adding in that upsert query the `visitor.track` insert, creating both
records in one go, bringing the query count from 3 to 2.

3. Refactoring of the `parent_id` behavior that was introduced in stable
with [1]. The purpose was to keep track of multiple visitor linked to a
same user to merge the tracking together. Especially useful for tracking
a same visitor on different devices (when logged in).
Only one visitor was kept as active, others would be archived and their
tracks would be set/moved to the main partner.
Removing those duplicate visitor was not possible because those archived
duplicated visitor were holding the devices notification push token.
Since [2], those token were moved to their own table, all related to the
main visitor.
We can then now safely remove those duplicate visitors after merging
their track to the main visitor. Thus, the `parent_id` field is no more
useful. Removing it removes a layer of complexity.
Note that thanks to this part, the `active` field can also be removed.

4. Deeper functionnal change, inspired from Plausible: The access_token
is no more stored in a cookie but is the result of a hashing method
based on <IP Adress, User Agent>.
The reason behind that change is that, in an upcoming refactoring,
sessions won't be stored anymore unless absolutely needed (login, add to
cart..). It will also ship a no cookies policy, trying to get rid of all
cookies.
This change is bringing some functional changes:
- Since the IP is included in the hash to generate the token, it means
  that:
  A. If an anonymous user switch IP (eg from 4G to wifi), it is
     considered as a new visitor.
  B. If 2 anonymous users with the exact same user agent (same browser,
     same browser version, same exact os or phone) are on the same IP,
     those will be considered as the same visitor.
- Since the request host is not included in the hash, it means that
  visiting a DB from 2 differents URLs (domain and/or ip) on the same
  device and same browser will result in a shared visitor.
  It shouldn't imply any issue as this is A. not wrong and B. mostly
  used for tests.
As all this is only related to non logged in user, it shouldn't be a
real issue as anonymous visitors are not supposed to be meant to be
business critical, even if we use them for "a bit more" than simple
analytics data.

5. The access_token is now replaced by the partner_id once the user logs
in, so:
- We don't need to either search on the partner_id field or the
access_token field (depending if the user is logged in or not), we can
only use the access_token row/field to do both.
- On logout, everything works out of the box as the access_token will be
regenerated since there is no partner_id anymore.
- On login, if an access_token matches the user's partner_id, that
visitor is returned.
If there is no such token, a new visitor is created for that partner_id.
In both 2 cases, tracks are moved to that visitor and the anonymous
visitor is removed.
- We can remove the code that was in charge of checking if the
access_token / visitor cookie was wrong (coming from another user eg,
different user login on same device). Indeed, such collision is not
possible anymore as the access_token automatically match the logged in
user.
- We can remove the code that was in charge of checking if the
access_token / visitor cookie was wrong (coming from a logged in user
while the current visitor is not loggedin). Such collision is not
possible anymore as the access_token is (re)generated as an anonymous
token (hash) when not logged in.

6. There is no more check to prevent a track to be created if there was
already a track for that URL in the last 30 minutes.
While this can easily be re-introduced (one CTE on the upsert), it was
adding ~100ms (from ~20 to ~110ms) to the request on a big database as
Odoo where there is ~100 millions tracks and ~100 millions visitors.
It has been validated that it was not a real issue as it is not
fundamentally wrong. If a visitor visited 20 times a product or a
specific page in that short amount of time, you might want to know that
because the user is most likely interested by it.

Changes (1+2), 3, (4+5) and 6 are all independant from each other and
could have existed on their own.

[1]: https://github.com/odoo/odoo/commit/c6b8a44b970a46dcd87a4e2cb1ad52fa340b209f
[2]: https://github.com/odoo/enterprise/pull/16781/commits/f75090fe8b42484e89e933976e8441d2f5eb9415

task-2867045

closes odoo/odoo#87857

Related: odoo/enterprise#28004
Related: odoo/upgrade#3566
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-06-07 16:31:20 +02:00
Romain Derie 92feb6a67f [FIX] website: ensure request.env and env.uid are set
Some cases might lead to undefined `env` on request or undefined `uid`
on request.env:
1. Mobile app: no uid is set on the jsonRequest env
2. Multi db: _env is None on request, and request.env unbound

1. Was checked with [1]
2. Was checked with [2] but by doing so, it actually broke the check
   done for 1.

[1]: https://github.com/odoo/odoo/commit/245ef4b0fddc7e5da3ebe841438c2d2902933f14
[2]: https://github.com/odoo/odoo/commit/3a7033463ea98def2e3fb85333c4f00f7c7d6925

task-2867045

Part-of: odoo/odoo#87857
2022-06-07 16:31:19 +02:00
Romain Derie 124c65b6a1 [IMP] website: stop creating visitors and tracks for bots/crawlers
Before this commit, every visit on the website would create a visitor
and tracks, including visits from bots and crawlers (e.g. google bot).

Now, we prevent that as it doesn't bring any value to track those bots.

Note that it means there won't be any track created if you are using
tools like `ab` for perf investigation or `curl` commands.

task-2867045

Part-of: odoo/odoo#87857
2022-06-07 16:31:19 +02:00
Gorash 0452d0701f [IMP] website: remove cache from website.page
The cache placed on the pages is no longer useful thanks to the use of
the new directive t-cache.

closes odoo/odoo#88276

Related: odoo/enterprise#27582
Related: odoo/documentation#2056
Related: odoo/upgrade#3451
Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
2022-06-03 16:40:40 +02:00
Gorash b0a2a41d78 [IMP] all/website: using lazy values and t-cache in templates
Using lazy values allows you to not do query when the content is not
displayed or if it is already cached. Adding `t-cache` only reduces
render time, but combining it with lazy values saves browses, computes
and query.
Thus for the `/shop` page the page is displayed in 60ms (before: 250ms).

Part-of: odoo/odoo#88276
2022-06-03 16:40:40 +02:00
Gorash 9af92b7374 [IMP] base: Qweb add t-cache and t-nocache directive
The `t-cache` directive allows you to keep the rendered result
of a template part. The supplied key must be a tuple. This tuple
can contain recordset in this case the zone will be invalidated
each time the write_date of these records changes.

The `t-nocache` directive makes it possible to force rendering
of a part even if it is in a `t-cache`. The values available in
the `t-nocache` are the one provided when calling the template
(and therefore ignores any t-set that could have been done).

Part-of: odoo/odoo#88276
2022-06-03 16:40:40 +02:00
Gorash 8c869769e9 [IMP] base: add a cache for company_ids on res.user
Part-of: odoo/odoo#88276
2022-06-03 16:40:39 +02:00
Julien Castiaux da8def8e41 [IMP] core, web: Delegate delivery of static files
Rationnals
----------

Web servers can serve some resources (e.g. static files) right away
without any interaction with the web application. The network model of
most web servers makes them capable of handling thousands of
simultaneous requests when it comes to intensive IO operations such as
streaming data from a file. The network model of Odoo is different: it
is capable of a lot of processing power but can only serve a handful of
requests at a time, i.e. Odoo (with some help from postgres) is
optimized for CPU operations, not IO.

Some users don't configure their web server, they use a basic
configuration that relay all requests to Odoo. The result is that many
Odoo HTTP Workers can be busy streaming static files instead of
processing other requests. This can lead to a worker starvation, i.e.
all workers are busy streaming files and cannot process new requests.

X-Sendfile
----------

In this work, we add the support for the [X-Sendfile] header family,
they are multiples http headers that can be used by the web application
to communicate with the web server in order to delegate the delivery of
files stored on the file system. Odoo still receives the request but it
does no more stream the file content from within its HTTP worker,
instead it skips the response body altogether and sets the `X-Sendfile`
special header with the path of the file on the filesystem. The web
server intercepts that special header, open the file and stream it.

Using those headers, we can use the best of both the web application and
the web server. The web application is still responsible to locate the
resource and verify the access rights, the web server is still
responsible of streaming the content.

Using X-Sendfile is opt-in via the `--x-sendfile` CLI flag. We set both
`X-Sendfile` (apache) and `X-Accel-Redirect` (nginx). If you are using
apache, make sure `mod_xsendfile` is enabled. If you are using NGINX
you have to add the following location block:

    location /web/filestore {  # custom path, hardcoded within Odoo
        # Prevent access from the outside world, i.e. makes this
        # route only accessible via X-Accel. MANDATORY!!!
        internal;

        # Give access to the filestore using this server's
        # permissions. Odoo is in charge of verifying the access
        # rights.
        alias /path/to/odoo/data-dir/filestore;
    }

The Odoo [deployment documentation] has been updated accordingly.

[X-Sendfile]: https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/
[deployment documentation]: https://www.odoo.com/documentation/master/administration/install/deploy.html#serving-static-files-and-attachments

Changes to the API
------------------

To benefit most from X-Sendfile, all APIs related to streaming content
over HTTP has to be adapted. They are: (1) `request._serve_static`,
(2) `ir.http._serve_fallback`, (3) `/web/content` and (4) `/web/image`.

Each used it own way to deliver content: (1) `_serve_static` was using
`send_file` (flask's send_file that as been vendored with odoo 10
years ago and not maintenained since then), (2) _serve_fallback was
handcrafting a `werkzeug.wrappers.Response`, (3) /web/content-image were
using the "binary server" `ir.http.binary_content` API.

I has been decided to remove all 3 APIs and to merge the code inside of
the new `http.Stream` object and the `ir.binary` helper model.

A Stream wraps what is going to be sent to the browser, it can be a path
to a file on the locale filesystem, a blob of raw data or an URL to an
external resource. The Stream also holds various metadata that are
mainly used for caching. The preferred way to create a Stream is via one
of its three factories so that all the metadata are set. The factories
are: `from_path`, `from_attachment` and `from_binary_field`. A stream
instance exposes a single method `get_response()` used to create the
corresponding HTTP response object out of the stream.

Inside of `ir.http` were a few methods that were not related to the http
routing and formed what was called the "binary server". All those
methods have been removed and the feature have been refactored inside of
the new `ir.binary` model. The removed methods are:

- `_xmlid_to_obj`
- `_get_record_and_check`
- `_binary_ir_attachment_redirect_content`
- `_binary_record_content`
- `_binary_set_headers`
- `binary_content`
- `_response_by_status`
- `_get_content_common`
- `_content_image`
- `_content_image_get_response`
- `_placeholder_image_get_response`

The new `ir.binary` abstract model exposes the following utilities:

**`_find_record`**

Find an attachment or a record with a binary-field out of an xmlid or
out of a pair record-model/record-id. Check the access rights and the
access token.

**`_get_stream_from`**

Create a Stream from an attachment or a record with a binary-field.

**`_get_image_stream_from`**

Same as `_get_stream_from` but adapted for images. It sets a sensible
ETag on the stream and has image resizing support.

**`_placeholder`**

Get the image placeholder blob.

Testing
-------

It is possible to test the web server configuration using the
`test_http` module. Install the module then run the unittest using the
`webserver` test-tag. By default it attempts to connect to a web-server
running on `http://localhost:80`, you can change this URL by setting the
`WEB_SERVER_URL` environment variable.

    odoo-bin -i test_http --stop-after-init
    WEB_SERVER_URL='http://localhost:80' odoo-bin --test-tags webserver --stop-after-init

closes odoo/odoo#88134

Task: 2801675
Related: odoo/documentation#2083
Related: odoo/enterprise#26191
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-06-01 02:53:59 +02:00
Raphael Collet 6cf8db906f [REF] *: adapt code to new flush API
closes odoo/odoo#87527

Related: odoo/upgrade#3497
Related: odoo/enterprise#26939
Signed-off-by: Raphael Collet <rco@odoo.com>
2022-05-25 18:00:47 +02:00
Huy Le 504ff2a674 [FIX] website: exclude non installable theme on configurator
Exclude non installable theme from the configurator suggested themes.
Also, exclude themes which are found in the database (sql) but not in
the manifest (files/sources). This was reported after migration where
`theme_beauty_sale` was still in the database but did not exists
anymore.

Note that in prior versions, this was causing a `KeyError`.

closes odoo/odoo#92167

X-original-commit: 6e4faeb136e123e09d74cde06c47f7c822b1fd19
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-05-24 16:00:14 +02:00
Christophe Monniez 65c8814a2f [FIX] various: replace deprecated currentThread method
CurrentThread is now really deprecated in Python 3.10 ... Time to
change.

Part-of: odoo/odoo#91927
2022-05-23 08:29:52 +02:00
Ivan Yelizariev 08605c506e [FIX] website: make search by "Visited Pages" work again
Field `website.visitor::page_ids` was storable initially [1], but then it was
refactored [2] and hence the search by "Visited Pages" [3] became broken.

Fix it by adding `search=` attribute

[1]: https://github.com/odoo/odoo/commit/6bec0e4d29e6b33b74962b2893a7a405667ef58c
[2]: https://github.com/odoo/odoo/commit/e33172e83210a5e0044a6fb92e315b84deefc440
[3]: https://github.com/odoo/odoo/blob/c6c7605cdae803aca4f441ef4e622a1b79f17019/addons/website/views/website_visitor_views.xml#L248-L257

opw-2622141

closes odoo/odoo#91829

X-original-commit: 792e07b8ff43ecb0499f4add27f5465c28e716cf
Signed-off-by: Ivan Elizaryev (iel) <iel@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-05-19 19:04:55 +02:00
Jeremy Kersten cccd6eb01d [IMP] website[_event,_sale]: add plausible as Analytics solution
This commit add the way to specify the Plausible shared key auth token and
the plausible domain on your website to have the Plausible Dashboard integrated
in your Website > Dashboard > Analytics menu.

Some custom event are already pre-configured as:

Push an event 'Shop' on confirmation on ecommerce (with amount bucket +/- 50)
Push an event 'Lead Generation' on:
    'Thank you' page of contactus
    Confirmation of subscription for an event

From this way, the end user can just add a goal 'Lead Generation'
or 'Shop' on Plausible to have the Goal values visible.

closes odoo/odoo#91058

Related: odoo/documentation#2007
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-05-18 20:33:34 +02:00
Huy 6768e77f9b [FIX] website: allow editor users to edit theme views
Currently, "Editor and Designer" can't edit the views which originate
from a theme (which are copies from the theme `theme.ir.ui.view`
records).

This error is caused by [1], which is preventing the `arch_updated`
field to be set to `True`, as this field is supposed to be set to `True`
only on manual user change, not during module update.

Indeed, restricted users don't have access to the themes records, making
the overide raising an error.

But there were actually no reason for this code to be executed outside
module operation.

Steps to reproduce:
- Create any view in a theme module.
  For example: create a custom footer view.
- As a "Editor and Designer" user, edit this view through the website
  builder.
- An access right error is raised.

[1]: https://github.com/odoo/odoo/commit/1eb7c577ecb31c2f0876b6dd76769e2b47802cb0

closes odoo/odoo#91255

X-original-commit: d2be8dc99eb99321be1172af447d5f2536c17364
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-05-13 13:18:53 +02:00
Julien Castiaux 1de40dd85e [FIX] website: wrong canonical URL after reroute
A reroute in an internal redirection, the URL on the current request is
changed. The actual changes occurs on the "WSGI environment", a
dictionnary that is populated with the request information by the WSGI
server (werkzeug in our case). Among all the properties there are
PATH_INFO, RAW_URI and REQUEST_URI.

* PATH_INFO is the standard value, it contains a RFC-3986 path.
  `request.httprequest.path` is based on that value.
* RAW_URI and REQUEST_PATH are two custom values set by werkzeug to
  mimic other popular wsgi servers (gunicorn, uwsgi, mod_wsgi), they
  also only contain a RFC-3986 path.

When rerouting only PATH_INFO and RAW_URI are updated. REQUEST_URI is
left as-is in order to keep the original path somewhere. When building
the cannonical path, one must use the original path instead of the
rerouted one.

X-original-commit: 779486c4dff23b946b4b14e3dca164ecca4f85a8
Part-of: odoo/odoo#91034
2022-05-12 13:42:57 +02:00
Denis Ledoux b03c227e88 [REF] models: refactor fields_view_get, load_views
Refactor the `load_views` API so it no longer sends multiple times the same
fields description.

e.g.
When `load_views` is called to get the kanban, tree and form views,
the list of fields of the model was sent 4 times:
- Once for each view, with only the fields used in the view,
  in `['fields_views']['kanban']['fields']` for instance
- Once globally, with all the fields of the model, in `['fields']`

The goal of this revision is to change that so it sends the list of all fields
only once.

In addition, if a view contains x2many fields,
the fields description of the comodel is also sent.
It was sent in the `views` key of the view fields dict.
e.g.
When calling `load_views` of `res.partner` to get the kanban,
tree and form views,
the `res.partner` fields description was actually sent 6 times:
- Once for each view
- Once globally
- Once for each view of the many2many field `child_ids` of the form view, in
  - `['fields_views']['form']['fields']['child_ids']['views']['kanban']['fields']`
  - `['fields_views']['form']['fields']['child_ids']['views']['form']['fields']`

The change suggested in this revision is to:
- Remove the fields description for each view in `['fields_views']`.
  As it no longer contains the fields,
  the key becomes `['views']` instead of `['fields_views']`.
- Replace the dict key `['fields']` by `['models']`,
  which is a dict with as key the model name and as values
  the model fields description. It contains the fields description
  for all models implied in the view:
  the model of the main view and the model of all one2many and many2many fields.

With this change, the fields description will only be sent once by model
implied in the view.

In addition, the web client was getting the information about the fields
sometimes in the global fields description list (e.g. `['fields']`),
sometimes in the fields description list of the view type
(e.g. `['fields_views']['form']['fields']`),
making it a pain to try to make changes / performance gain
in these field description dictionaries, because you never knew in which dict
the web client was getting its info.
Now, as there is only one place to get the fields description from,
it's clearer and cleaner.

- one2many and many2many fields views are passed directly in the main view
  architecture rather than being put in the `views` key
  of the field description.
  This is actually easier to treat by the web client,
  and this will allow in a future work to cache an entire view in one block
  of text rather than having to combine multiple cached blocks of text
  to return one view.
- one2many and many2many fields which do not have directly embedded views
  have their views directly injected in the architecture,
  so the web client doesn't have to do RPC calls to `load_views`
  for each one2many and many2many fields not having embedded views.
  For instance, this allow to reduce the number of RPC calls to `load_views`
  from 8 to 1 when loading the form of `product.product`.
  Currently, this behavior is limited to 1 level deep but we consider making it
  go all the way down in future works. We did not do it for the moment because
  in certain cases it rises the processing time and the size (bytes) too much.
  e.g. the sale.order view can be 5 levels deep,
  meaning you can reach 4 dialogs on top the main view.
  ```
  sale.order form > order_line > sale.order.line form > invoice_lines >
  account.move.line form > asset_ids > account.asset form >
  depreciation_move_ids > account.move form.
  ```
  This will also benefit in future works to cache an entire view in one block
  of text rather to having to combine multiple cached block of text
  to get one view.
- `fields_view_get` becomes `get_view`.
  As it no longer returns the fields description,
  keeping the `fields` in the name `fields_view_get` no longer makes sense.
  Hence removing `fields` from the method name, it becomes `view_get`.
  As it gets renamed anyway, we take the opportunity to rename it `get_view`,
  which is more in line with the general getter/setter guidelines
  in the model object world.
- `_fields_view_get` becomes `_get_view`. For the same reasons than above.
- `load_views` becomes `get_views`.
  This is not mandatory, there is no technical reason to rename `load_views` as
  it practically sends the same info as before,
  the view architectures and their fields description. Just in another way.
  We just take the opportunity of this pull request to suggest a cleaner API:
  `_get_view`, `get_view` and `get_views`.
- Arguments `toolbar=False, submenu=False` fo the methods
  `_fields_view_get` and `fields_view_get` are converted to a kwargs `**options`
  in `_get_view` and `get_view`.
  The rationale is that submenu was already no longer used (deprecated)
  and the mobile options is introduced.
  The mobile options is necessary to tell the server to send the mobile views
  for x2many fields (kanban instead of tree).
  Instead of adding a new argument each time we add a new option to
  `fields_view_get`, it seems wiser to have a kwargs `**options` to avoid
  to re-write all overrides each time a new option is introduced.
- `_fields_view_get` returned a dict containing the arch in text and some of the
  view information. Now, `get_view` returns a tuple with the view architecture
  as an `etree` node, and the view as a browse record. The rationale is that all
  overrides of `_fields_view_get` were about modifying the arch only
  (e.g. changing the address format/re-organizing the address related field
  nodes of the partner according to the company country).
  To do so, all these overrides were doing `etree.fromstring` to parse the arch
  which was sent in text to convert it to an `etree`,
  then operations were done on the `etree`,
  and then `etree.tostring` was called to convert back the arch to string.
  With this change of signature to send the arch as an `etree`,
  all these back and forth `etree.fromstring` -> `etree.tostring` are avoided,
  allowing some performance gain and less code in the end.
- A cleanup of the keys returned in the dict of `fields_view_get`
  has been performed in `get_view`:
  - `fields` is removed, as explained above,
  - `view_id` is renamed `id`,
  - `name` is removed, it was unused by the web client,
  - `type` is removed, it was unused by the web client,
  - `field_parent` is removed, it was unused by the web client,
  - `base_model` is removed, it was unused by the web client.
- `filters` is moved from the global dict returned by `load_views`
  (now `get_views`) to the dict returned by `fields_view_get` (now `get_view`)
  as it applies only to the `search` view type.
- Retro-compatible methods for the 3 methods
  `fields_view_get`, `_fields_view_get` and `load_views` are provided,
  with deprecation warnings in them.

- The web client could cache the model fields description
  (as it already caches the views),
  so it doesn't need to fetch them again if it asks for another view of a model
  for which he already has the fields description.
  If we do so, `get_views` could return only the list of models used by
  the views, without the fields description as of now,
  and the web client would then call `fields_get` independently only for
  the models for which it doesn't have yet the fields description.
  This would avoid the server to return the fields description
  and to call `fields_get`, which is costly, for each `get_views`,
  therefore gaining performances.
- Inject the views of the one2many and many2many fields all the way down,
  unlimited depth level, as explained above.
- Cache with `ormcache` the architecture of back-end views.
  This is already done for qweb views, it's not done for back-end views.
  Therefore the postprocessing of the views is performed for each `get_views`,
  which is costly, while the view architecture doesn't change for users
  belonging to the same groups, according to the groups implied by the view.

This pull request is co-authored by
Aaron Bohy (aab) for the web client part and
Denis Ledoux (dle) for the server part.

Part-of: odoo/odoo#87522
2022-04-29 09:57:44 +02:00
Pierre-Yves Dufays aef2d27053 [IMP] website: add X-Disable-Tracking header to improve tracking
In this commit we add a request header X-Disable-Tracking that enables the
client to ask the server not to track a request.

This is useful for example when the client prefetches pages to be able to work
offline. In that case, the prefetched pages must not be considered as viewed
by the user. In such scenario and without such header, it is not possible to
get an accurate page tracking.

Task-2476513

Part-of: odoo/odoo#86031
2022-04-29 08:09:58 +02:00
William Braeckman fb86ae3371 [FIX] website,website_sale: fix unable to save in multi company settings
This commit is a follow-up to https://github.com/odoo/odoo/pull/89707
The above PR fixed most issues with the configuration but since the
default value was not set anymore for `auth_signup_uninvited` a
configuration with no website attached would make the config not
saveable (required field not set).

closes odoo/odoo#89938

X-original-commit: 5fab73f7730a10636642ba96b1fdd7a7455fe6f9
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
2022-04-27 21:28:32 +02:00
William Braeckman 7e945db634 [FIX] website,website_sale: fix user sign up config
This commit aims to fix multiple issues with the "Customer Account"
parameter in the backend config.

 - Hide the parameter from general and sales settings if website is
   installed.
 - Properly compute the right value once website is installed, as it was
   not using the website's value.
 - Fix a traceback when clicking on "Default Access Rights".

TaskId-2825096

closes odoo/odoo#89806

X-original-commit: 8b162f507f881619061d61530cc03b4b4654c1fe
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
2022-04-27 12:16:28 +02:00
Victor Feyens 7d422a2cd4 [FIX] *: unnecessary semicolon (W0301)
+ empty spaces removal
+ added space after comma (C0326 - bad-whitespace)

Part-of: odoo/odoo#86332
2022-04-27 07:51:23 +02:00
Romain Derie 346360cc27 [FIX] website: give unlink access right on assets to website editor
Commit [1] was not enough, expecting that the unlink right was not
needed. But it is.

A recent test highlighted that issue.

[1]: https://github.com/odoo/odoo/commit/e3515a7b73c3e173a3ddf0bc48e4a888024c8817

closes odoo/odoo#89211

X-original-commit: 19a97fcaf1fd2f762522d171e98d9942fb45e9d1
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-20 22:56:12 +02:00
Romain Derieandroen-odoo b8bd897fe4 [FIX] website: allow user to access HTML/CSS editor
Current behavior:
When an admin user modified a file with the HTML/CSS/JS editor in a
website, users that had "editor and designer" right couldn't access
the HTML/CSS/JS editor anymore.

Steps to reproduce:
- Have user 1 (U1) admin
- Have user 2 (U2) with website access set to "Editor and Designer"
- U1 modify the css user_custom_rules.scss with the HTML/CSS Editor
- U2 can't open the editor of that website because he is not in the
setting groups or the one that created it

opw-2733109

X-original-commit: d20468c3463927a54c34688769a22b3949c5c465
Part-of: odoo/odoo#89211
Co-authored-by: roen-odoo <roen@odoo.com>
2022-04-20 22:56:11 +02:00
Benoit Socias 998dc0bbe2 [FIX] website: avoid traceback during edition of menu missing URL
Before this commit if a menu had been saved without URL, a string +
boolean concatenation error could happen when updating the menu.

After this commit the False boolean is replaced by an empty string to
avoid the problem.

task-2781260

closes odoo/odoo#89147

X-original-commit: 0288e0e91a071c7ec4b8adb0474d82a46dea9c9c
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-20 18:49:07 +02:00
Benoit Socias 38872576e5 [FIX] website, web_tour: send parent menu id as integer in menu update
Since [1] nested menus were not saved anymore because model ids do not
support `str` anymore.

After this commit the menus update data contain an integer `parent_id`
making them understood again by the model.
The `parent_id`s returned by `nestedSortable()` are the ones obtained
through a regex match, and therefore are strings.

Steps to reproduce:
- go to the 'Home' web page
- click on 'Edit Menu' in the 'Pages' menu
- drag and drop a menu item to nest it (e.g. put 'Contact Us' inside
'Home')
- click on 'Save'
=> nested entry disappeared from the menu instead of being nested under
its parent

[1]: https://github.com/odoo/odoo/commit/534087fa8d3c9947a918aa109f4030b5628a80d1

task-2781260

X-original-commit: d7bfb935580d6cc70dc213657c1a6dbc85dfa756
Part-of: odoo/odoo#89147
2022-04-20 18:49:07 +02:00
roen-odoo d8568944b4 [FIX] website, website_blog: remove stars from blog description
Current behavior:
When adding a "Heading" in the first 200 characters of a blog with
/Heading, the short description of the blog preview would have
unwanted stars (*) around the heading

Steps to reproduce:
- Create a blog article
- In the first 200 characters of the blog use a heading (e.g. /Heading1)
- Go back to the blog list, the description of the new article contains
  unwanted stars (*)

opw-2798595

closes odoo/odoo#88352

X-original-commit: 6cb57d2f1ffb0adceaa3199cc0bf5140589d9328
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-14 14:07:05 +02:00
Benoit Socias e9ea0692bb [FIX] website: not split fuzzy matching candidates on hyphen
Since [1] when the fuzzy search was introduced, the candidate words used
for the fuzzy matching were split on non-'\w' (all non alphanumeric
characters + underscore).

This commit adds '-' (hyphen) to the list of characters that should be
considered part of the same word.

Steps to reproduce:
- Specify a product with name 'micro-vis'
- search for 'micro-vis' or 'microvis'
=> Was not returning any match
=> Now returns fuzzy match even for 'micro-vs'

opw-2801704

[1]: https://github.com/odoo/odoo/commit/c6ba756e4b4704089d02434871788a82d90cb195

closes odoo/odoo#88591

X-original-commit: 10d54d3c6ba46afa86abac5275a02c4b5ec7d5a1
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-13 11:55:37 +02:00
Benoit Socias 768db8390d [FIX] website, website_payment: exclude Donation snippet from cache
Since [1] the CSRF token used by the donation snippet's form did end up
being cached for new visitors that did not have a session id yet.
This made the validation of the token fail when using the form because
the token from the very first new visitor on the worker was reused.

After this commit pages that contain a Donation snippet are not cached
anymore in order to always get a fresh CSRF token - similarly to what is
done for the form snippet.

When using incognito mode the csrf token is sometimes not recognized
during navigation to the donation payment page.
Simple sequence to reproduce it:
- drop a Donation snippet on the Home page
- use Firefox and do not log in
- in normal browser, select 25 then press Donate Now
- open an incognito browser, select 50 then press Donate Now
=> 400 Bad Request
Alternative (any browser):
- open page with Donation snippet in incognito window
- remove session id from cookies using developer tools
- close window
- reopen page in a new incognito window
- try to donate
=> 400 Bad Request

[1]: https://github.com/odoo/odoo/commit/7fccbac004628093da49016f75370a84bba49465

opw-2774065

closes odoo/odoo#88184

X-original-commit: 16c9b103195f342f8bcca928a53121dbe4480d58
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-07 13:24:20 +02:00
Romain Derie 5a8d6c351b [IMP] website, test_website: avoid a query on res_company_user_rel
Manual forward port, commit was lost from 15.2 to master. Either it
seemed not needed after the httpocalypse refactoring, or was simply
lost during the rebase.

-----

We can remove an useless SQL Query for public user on every single page
serve, if we directly set the website's company_id in the available
company_ids of the public user.

Indeed, the public user from a website always have the same company_id
as the website.

We can then do that directly and bypass the next line which will
always be true in the case of the public user, making a read for
nothing.

task-2774979

closes #85419

X-original-commit: c95ab6f

[1]: https://github.com/odoo/odoo/commit/728ade674cb12c64718efda56b0d5d542e319cba

closes odoo/odoo#87856

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-06 19:32:44 +02:00
Mathieu Walravens 1ba130a4aa [FIX] website: published link redirect does not check if domain exists
Since commit [1], we should use domain instead of _get_http_domain().
However _get_http_domain() checks if the domain exists which is not the
case in commit [2]. It only impacts databases having multiple websites.

[1]: https://github.com/odoo/odoo/commit/7d8a8ddea0b363732f2177ad589a3e0e10e2fb6c
[2]: https://github.com/odoo/odoo/commit/ee71cdff0786d5c41fbcc50894cd06811d3d8d5b

Steps to reproduce:
  1. Install the eCommerce app
  2. Add a second website
  3. Keep the domain field of the website empty
  4. Set the website field of a product to the website.
  4. Click 'Go to Website'

Current behavior before PR:
  - RPC_ERROR: Odoo Server Error

Desired behavior after PR is merged:
  - Redirected to the product's page

closes odoo/odoo#88067

X-original-commit: 18c8a97ac986753728462b374a1c327bc9597a37
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-06 15:30:51 +02:00
Julien Castiaux c46f4b908a [IMP] *: request.session.geoip -> request.geoip
Commit "[IMP] core: don't save visitor default session" moved the geoip
from the session to the request with a deprecation warning. This commit
adapts the remaining modules to use `request.geoip` instead of
`request.session.geoip`.

Geoip is always set on the request but it can be an empty dictionnary in
case the geolocalization failed.

closes odoo/odoo#86015

Task: 2789035
Related: odoo/enterprise#25192
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-04-05 14:13:54 +02:00
Martin Trigaux f41ec39abe [IMP] base: get_view_id becomes private
Add new helper get_view
Remove dangerous documented comment

Part-of: odoo/odoo#85110
2022-03-29 10:56:16 +02:00
Gorash 880954ebfc [IMP] *: remove _render from ir.ui.view and simplify report
There were inconsistencies in the calls to `_render`.
* the view context could contain information that misled developers.
Indeed, the context and value of the view are not supposed to be found
in the rendering. Thus by calling `ir.qweb` with the name of the
template, we ensure that there is no unwanted information and in
addition the cache key is that of the name of the template which saves
a query.
* the context used for rendering was modified by a method on
`ir.ui.view`, except this is not information used by this model. There
is now a `_prepare_environment` method residing on `ir.qweb`. This
method allows to modify the value dictionary as well as the context in
which the rendering will be done. This preparation of the data as well
as my security check is done only once per rendering. This also saves
some queries
* Freeze options for rendering were inconsistent. It could be that
options on which rendering depends were not part of the cache key. Thus,
depending on the user who generated the generation of the rendering
function, there was or was not information in the template. For example
for automatic branding. This is no longer possible, because it is the
context that is used. The options serving as a cache key are only
recorded for information (for the profiling system for example). A
simplification of the `ir.qweb.field` models could be made.

The report rendering and call `ir.qweb` instead of `ir.ui.view`.

Part-of: odoo/odoo#85110
2022-03-29 10:56:15 +02:00
Fabio Barbero 47041f2d45 [IMP] base: allow user to activate multiple languages at once
Purpose
=======
Add "Activate" button when selecting multiple languages, select multiple
languages when clicking on "Add languages" in settings.

Specifications
=============
`lang` variable in `base.language.install` changed from Selection to
Many2many to allow multiple languages being activated at once.
Hide globe icon for language fields from view mode (only visible when
editing). Remove state in base.language.install since it's no longer
need to keep track of the installation step.

Task-2662548

closes odoo/odoo#78287

Related: odoo/upgrade#2921
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-03-14 08:42:58 +00:00