summaryrefslogtreecommitdiff
path: root/addons/website/controllers/main.py
AgeCommit message (Collapse)Author
2021-05-03[FIX] http_routing, website: prevent crash when using `fw` in urlRomain Derie
Before this commit, the routing map generated and used would be the one from the website the request is performed, instead of the one from the `fw` website ID which will be the one we redirect the user to. This issue was introduced with the routing map by website, be8fc2296b38 and is restricted to a single case: a publisher using the website switcher, and it won't happen on next page naviguation/refresh as the `fw` website id will be the same as the current website's ID. Thus there won't be any routing map mismatch. Step to reproduce: - Create a page on website 2, set it as homepage - Naviguate to website 1 on '/' url - Naviguate to website 2 on '/' url This will raise a werkzeug error about `EndPoint not iterable`. ----- Technical analysis ------ This is the current flow: 1. `_dispatch()` is setting `website_routing` to `get_current_website()` -> 2 2. `_dispatch()` is calling `_match()` 3. `_match()` is calling `routing_map()` with key = `website_routing`, which was set to 2 in step 1. 4. `routing_map()` is calling `_generate_routing_rules()` which generate the rules based on `website_routing`, which was set to 2 in step 1. 5. `_dispatch()` authenticate the user by calling `_authenticate()` 6. `_dispatch()` is calling `_add_dispatch_parameter()`, where URL param `fw` is forced in session, so `get_current_website()` now return the correct `website_id` -> 1 The issue: in order to handle the `fw` URL parameter (step 6.), we need to check the rights to ensure we can allow the website switch. To check rights, user need to be authenticated (step 5.), which is done after generating the routing map (2. & 3. & 4.). The routing map is generated based on the current website (step 1.) Step 6 depends of steps 5 which depends of steps 2/3/4 which depend of step 1, but step 1 should depend of step 6, which is an impossible cycle. closes odoo/odoo#70278 X-original-commit: 878e28f93a65756fa2002ef2af5b02a3e2c59b1b Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com> Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
2021-03-22[FIX] website: _handle_exception takes only two argumentsDenis Mudarisov
Before the commit, if an exception occurs there was an error saying: `TypeError: _handle_exception() takes 2 positional arguments but 3 were given` Impacted versions: - 12.0 - 13.0 - 14.0 X-original-commit: 47d6fa4ff6e78a33691c22b08504ce03e6796c9a
2020-11-20[FIX] website: only toggle view in toggle stateJeremy Kersten
Before this commit, we write on each record the value, whatever the current value. Now we check if it is necessary to avoid useless fork. The first change on header was slowly.
2020-11-17[FIX] website: adapt /website/action to v14 permsOlivier Dony
As of v14 and #53335 (6c97a6d), access to `ir.actions*` models has been restricted to admins, except in specific context such as via the `/web/action/load` route. This commit updates the `/website/action/` route to follow that logic, and allow custom server actions to be exposed as "custom controllers". The principle is that the action is located in a sudo environment, but executed using the request environment. Access will only be permitted if the model of the action is writable for the current user, or if any action "groups" are set and the user belongs to one of them (cfr f0d37c384b299e5f35cddda02d3f56c6ad37a9a7 for that part). closes odoo/odoo#61863 Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com>
2020-10-26[FIX] website: favicon use STATIC_CACHE_LONG that is a real yearJeremy Kersten
365 * 24 * 60 is not a year, but year/60 ;) While we fix it, it is the good time to change and use the dedicated http.STATIC_CACHE_LONG that exists for it. closes odoo/odoo#60768 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-10-13[FIX] website: filter filter_opt of dynamic snippet by website_idBenoit Socias
Add a filtering by the contextual website_id when looking up available website_snippet_filters via an rpc route limited to logged in users but relying on a sudo to actually obtain the list of available filters. Before this commit filters were visible on the editor for all websites. After this commit filters are only visible on the editor of the website that matches their website_id. https://github.com/odoo/odoo/pull/59341 task-2312878 closes odoo/odoo#59341 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-10-08[FIX] website: get visitor tz directly from cookieDavid Beguin
Since tz is now (from 6eb4762fee20a158023d774a90e7ee90c2cacec5) added to the client cookie, visitor timezone can directly be set when creating the visitor, using the request. Jstz can be removed as even for module in ENT that used this lib, we can get the timezone using Intl lib instead. This will also reduce the number of request made only to get visitor's timezone. This commit reverts part of 17e84025239ed78716ed5d5d92c0ee0e10fbfb29 Linked ENT PR: 12963 Task ID: 2333825 closes odoo/odoo#57103 Related: odoo/enterprise#12963 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-09-16[FIX] website: prevent /web/become route to crashRomain Derie
Since 9f82605df111, any call to `_login_redirect()` without previously going through `web_login()` method would crash, as `login_success` is set there. In this case, it was: Dispatch -> web_login -> redirect (new dispatch) -> _login_redirect() task-2340941 closes odoo/odoo#57839 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-08-28[FIX] website: check website_published exists before useJeremy Kersten
closes odoo/odoo#56734 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-08-18[IMP] website, website_sale: add dynamic snippetsLaurent Stukkens (LTU)
* Implement new snippets that allow the user to choose a filter and a template. Three snippets have been created: - Dynamic Snippet: Displays the data in a grid format - Dynamic Carousel: Displays the date in a carousel - Dynamic Products: Let the user pick a product category and displays the products in a carousel task-2276740 PR #53175 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-08-14[ADD] auth_totpXavier Morel
New module for supporting two-factor authentication via time-base one-time-password (TOTP). Users (including portal users) can choose to enable two-factor auth in their user account settings, by scanning a QR code and adding it to an authenticator app, such as Google Auth, 1Password, etc. When two-factor is enabled, password-based non-interactive RPC is only possible by using API keys. Co-authored-by: Olivier Dony <odo@odoo.com>
2020-08-14[FIX] portal, website: login redirectionXavier Morel
* migrate website to overriding web_login less (still needed to flag it as website-enabled) and use _login_redirect for its login redirection override needs * modify portal and website to not replace / shortcut the redirection workflow, so it's possible to override those properly if / as necessary
2020-07-28[MOV] website: move google map snippet from themes to communityThanh Dodeur
Improve the base code and adapt to new website features as well. Part of https://github.com/odoo/odoo/pull/49101 task-2091396 Co-authored-by: qsm-odoo <qsm@odoo.com>
2020-07-07[IMP] website: allow to have custom slug UxJeremy Kersten
Now, slug uses seo_name if field exists before to fallback on display_name. It allow to have a custom url without change the product name already used in backend e.g. or just because you want add some keywords for seo. task-2291676 closes odoo/odoo#54152 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-05-29[IMP] website: reintroduce a way to post from jsDramixDw
It was deleted in 11.0 as it was not used anymore. Now, it is reintroduce as it is a nice utility function for some external app or fixes. Here, it is use so that /website/add and /website/add/<path> work as a controller POST with a CSRF token. task-2241766
2020-05-14[REM] website: remove lazy template callMartin Trigaux
Was making a render_template on an arbitrary template Does not seem to be used anymore
2020-05-14[IMP] *: convert to private methodsMartin Trigaux
render, render_template, load, activity_schedule_with_view, get_website_pages should all be private: It should not be possible to render an aribtrary template only with its name or id Still need to render some qweb views from js so the method render_template is kept public. This explains why the website editor still need read access on ir.ui.view as we want to allow any snippet to be rendered.
2020-05-14[FIX] *: add sudo when accessing viewsMartin Trigaux
The method fields_view_get should be the only way to retrieve the view content. This method is executed in a super-user context. To avoid retrieving views for a model a user does not have access to (as it may reveal some informations like name of fields), add a verification of 'read' rights before retrieving the view content. Execute _postprocess_access_rights with sudo(False) as this method is used to evaluate which buttons should be displayed. Remove the su flag to avoid misleading the user and displaying a button they won't be able to use. Retrieving the database id from an view key is not considered as a sensitive information and get_view_id and viewref can be left as a public methods. Add missing sudo when needed Change _handle_visibility in website to avoid increasing the query count: Checking the visibility (to fail most of the time) to retry in sudo was making unecessary queries.
2020-05-01[IMP] website: simplify website menuDramixDw
Some apps, once installed, automatically create a menuitem in website. What complexify the UI and create useless menu withtout plusvalue. It is not because you install livechat to make support online, that you want a link in your menu to show stats e.g. Now we remove the default menu created, and help user to find it when he create a link. The autocomplete suggest most of the main App's controllers task-2189613 closes odoo/odoo#49081 Related: odoo/enterprise#9733 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-04-03[REF] base: replace toggle method by already-existing toggle_active for ↵Thibault Delavallée
ir.ui.view Toggle method defined on ir.ui.view does the same job of toggle_active that is the generic one available on all models. Task ID 2170708 Community PR odoo/odoo#46563
2020-03-31[IMP] website: add templates for footerBenjamin Vray
Also remove all t-fields from footers to have only static contents in footers. For social links, a controller is added so that a "static url" /website/social/xxx always redirect to the correct set URL for the given xxx social network. Part of https://github.com/odoo/odoo/pull/38950 task-2087641 Co-authored-by: qsm-odoo <qsm@odoo.com>
2020-03-30[IMP] website: improvement regarding social imageRomain Derie
This commit introduce multiple improvements regarding social image: - (perf) Don't read ir.attachment through `social_default_image` when it is not needed. Use a stored boolean to know if the field should be accessed. This will remove one SQL query in attachment for public user. - Show website logo, not the company logo since we now have a different logo for website. - Don't show images lower than 200 width or 200 height px. Logo will be shown regardless of his size. - Don't show website logo if there is a website social_default_image. Indeed, the spec was to prevent showing logo and social_default_image if they are the same image. Technically, this is hard to identify as they could be the same image uploaded with different resolutions (media dialog), especially if one of those was uploaded through the backend and one from the frontend. It is most likely we will never correctly identify duplicate as they won't be exactly the same. For this reason, it makes more sense to hide the website logo if the social_default_image is set. It avoids every issues while it makes sense since you won't want to use the logo over the social_default_image. If you really want to, you could reupload it through the SEO media dialog. closes odoo/odoo#47848 Related: odoo/upgrade#1012 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com> Co-authored-by: Romain Derie <rde@odoo.com> Co-authored-by: Jeremy Kersten <jke@odoo.com>
2020-03-26[IMP] website: perf - favicon.ico cached for 1 yearJeremy Kersten
Note that this route is only used when no icon is set in DOM, such as accessing a PDF after an order. task-2211013
2020-03-26[IMP] website: perf - prefetch menus when serving a pageRomain Derie
If we are rendering a page, the menus will most likely be rendered as well. Note that even in a 403 case when the page is found but is not visible, the menus will also be shown on the 403 page. Fetching the menus before accessing the requested page will prefetch that page as well in one go if that page is in the menus, without any costs for the pages not in the menus. There is a tradeoff for 'non-layout' pages, which only occurs in advanced technical cases: 1. Create a page with specific extension as name suffix (page.css) in which case the page will be bootstraped accordingly, without call to layout. 2. Remove the call to layout in HTML editor or backend 3. Remove the call to submenus template in HTML editor or backend For those cases, the menus will be prefetched for no reason. Note that homepage '/' is rendered through a controller, same logic is applied there. task-2211013
2020-02-07[FIX] website: restrict access to routeMartin Trigaux
This route was public by mistake, probably introduced to test during ddf32f4 but no reason to make it public, public user has not the write access on models anyway. Courtesy of Swapnesh Shah closes odoo/odoo#44915 X-original-commit: 66ac96b25aa4cf2b074f6c06b57ed8be72d6d647 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-02-05[IMP] website, *: make theme custo options act as simple snippet optionsqsm-odoo
* web_editor, theme_bootswatch Instead of having an entirely dedicated system for theme options in a third tab of the left panel, those theme options are now simple snippet options. See the customizeWebsite generic method. This allows to make any option available in the third tab or on any meaningful element like the header or the footer. This also allows to take advantage of all the features of the left panel: dependencies, visibility update, etc. Note: same as before, those changes do apply the color/size/layout immediately on the website, even if not saved. Changing that behavior is complex and might be the job of another task. Part of https://github.com/odoo/odoo/pull/41166 task-2088298
2020-02-05[REF] website, web_editor: move theme customization to edit modeSamuel Degueldre
Previously, theme customization was done through a modal dialog in the website module, this was not very user friendly since the rest of the customization for the website design was done from edit mode, meaning the user had to exit edit mode to customize things such as theme colors or fonts. It was also rather confusing to have these seemingly related things in completely unrelated places. This commit moves all of the options that used to be in the theme customization modal into a new tab in the editor's left panel. This commit is mainly just about rendering the old modal as a third left panel content. See next commit for deeper changes. Note: same as before, those changes do apply the color/size/layout immediately on the website, even if not saved. Changing that behavior is complex and might be the job of another task. Part of https://github.com/odoo/odoo/pull/41166 task-2088298
2020-02-04[FIX] *: deprecated access to url_ utilities through werkzeug rootXavier Morel
In 0.15 accessing werkzeug.urls functions directly through werkzeug is deprecated, the shortcut will be removed in the eventual werkzeug 1.0. Fix existing uses of these shortcuts. Also cleanup some imports when they're not far from a werkzeug* import being altered.
2019-12-17[IMP] website: redo res config settingsJeremy Kersten
task-2088625 closes odoo/odoo#40715 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-12-16[IMP] website: add edit robots.txt in settingsJeremy Kersten
task-2091358
2019-12-11[FIX] website: set correct value in frontend_lang cookieRomain Derie
Before this commit, the `url_code` field value was stored in the cookie instead of the `code` field. This was making the language selector in the frontend to not change the lang correctly when trying to access the website default lang, ONLY for the lang having an `url_code` different than its `code` value (typically the case for principal languages). Step to reproduce: - Add `fi_FI` as main lang on website - Visit frontend and change lang to `Suomi`, it won't change This behavior was only related to the language switcher. It did not affect dispatching (if correct lang in url) and nearest lang finder. Fixes #41522 closes odoo/odoo#41728 X-original-commit: b62b2828552abb38c8adc74c69cb427c3fd98605 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2019-11-26[IMP] website: allow to don't show specific view in nameJeremy Kersten
and uses it in customize_show. closes odoo/odoo#40887 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-11-19[FIX] website: set controller favicon.ico as nomultilangJeremy Kersten
Avoid redirect from /favicon.ico to /<lang>/facivon.ico at each request closes odoo/odoo#40535 X-original-commit: 94bcbc92e5e5a6fd3de7267e3c01f8c11fb045f4 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-28[IMP] website*: clean sitemapJeremy Kersten
From now, you need to explicitely add sitemap=True if you want your controller into the sitemap. It's the default value, but if you forgot it, it will raise a Warning on runbot. It will avoid wrong controller in sitemap and duplicate (empty) content. From now, if your model contains a field website_id, the modelConverter for sitemap will automatically add the domain: "[('website_id', 'in', (False, current_website_id))]" It avoid redundant declaration and ugly url in redirect/rewrite view. Migration: need to remove it from url_from in website.rewrite task-2065018 closes odoo/odoo#39427 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-22[FIX] website: clean sitemapJeremy Kersten
followup of 8a0fc6476c70a4126043de3b3efbd1096e41f968 task-2065018 closes odoo/odoo#39211 X-original-commit: bfa239b59c4d02c2b03ab8a84b52bc8f77704e41 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-22[IMP] website: connect with search google easilyJeremy Kersten
You need to provide a small part of the code, because to avoid fraud, google make several request to be sure that you don't allow all codes :) So the 'WPS' solution was dropped, now we take the first request from google that match the part provided, as the good one, and refuse all others requests. task-2086915 closes odoo/odoo#39186 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-18[FIX] website,*: remove useless route from sitemapJeremy Kersten
preparation for cleaning of v13 task-2065018 closes odoo/odoo#39051 X-original-commit: 8a0fc6476c70a4126043de3b3efbd1096e41f968 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-17[FIX] website: Missing module in AppsJeremy Kersten
closes odoo/odoo#38971 X-original-commit: 562a2ac270ef8aac3afde05625008cef64f62f89 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-08[FIX] website: prevent endless loop if homepage is unpublished..Romain Derie
.. and first menu is a container with # as url. There is a particular case where the / url would loop endlessly. 1. Unpublished the homepage / 2. Edit the menu so the first menu is a container. There is a hint telling you a container menu should have its URL set to `#` as a good practice. 3. This will lead to endless loop for public user as the code will check if the homepage can be accessed. Since it is unpublished, it will then fallback on the first menu which is not '/' and redirect to it. Sadly, the code was not expecting `#` to be handled as `/`. opw-2081969 closes odoo/odoo#38234 X-original-commit: cff11bdb66f1dda41cf333a28b67df7ef20a3de9 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2019-09-30[IMP] base, http_routing, website: allow custom routing ruleJeremy Kersten
After this commit, you will be able (in technical mode) to update the url for the python controllers. Eg. You can now rename /shop in /garden and /shop/product/ in /garden/vegetable/ Most of urls will be replaced at fly in the renderd qweb, with the function url_for but all old urls will keep available. So if you access url /shop you will be automatically redirected to /garden (308 Permanent Redirect). As for cdn and other post-process of att, the automatically replacement in the rendered qweb is only done when you will be not website editor. But the new dispatch of URL will be applied in all cases. For developper, since it is Permanent Redirect, don't forget to clear cache or open chrome debug tool (with option 'Disable cache while DevTools is Open) to see your lasts changes. closes odoo/odoo#36555 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-09-20[IMP] website : store visitor timezoneDavid Beguin
In order to be able to send push notifications using recipients timezone, the visitor timezone is now stored in DB. The visitor timezone is only updated once, when found_visitor_timezone cannot be found in localstorage. Once the timezone is updated, found_visitor_timezone is added to localstorage. Task ID : 1936643 PR #34973
2019-08-26[IMP] http_routing, website: allow to customize the lang in URLRomain Derie
With this commit it is now possible to change the lang displayed in the URL. Eg, you could use `/fr` instead of `/fr_BE`, or even a fancier `/french`. Task-32838 Courtesy of pla@odoo.com closes odoo/odoo#35135 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2019-07-30[IMP] website, *: use "auto" widget for font customizationAndrea Ulliana
* theme_bootswatch, theme_default, website_theme_install This commit makes use of the new 'auto' widget for font selection: instead of enabling a template which will enable a scss file which sets a font variable to a specific value... we directly allow to do a scss custo which sets that value. The code in charge of resetting font customizations on theme switching is also moved and refactored here in website (instead of being specific to each theme). Part of https://github.com/odoo/odoo/pull/33442 task-1974659 Co-authored-by: qsm-odoo <qsm@odoo.com>
2019-07-04[FIX] *: sudo() -> with_user()Raphael Collet
2019-06-18[MERGE] forward port branch saas-12.4 up to 618ea1ab675Christophe Simonis
2019-06-17[MERGE] forward port branch saas-12.3 up to 48a9f5a6335Christophe Simonis
2019-06-14[MERGE] forward port branch saas-12.2 up to 498b4b4350dChristophe Simonis
2019-06-11[MERGE] forward port branch 12.0 up to 7ef4ba03c4fChristophe Simonis
2019-06-07[MERGE] forward port branch saas-11.3 up to a2582c4252aChristophe Simonis
2019-06-04[FIX] website: redirect userRomain Derie
Before this commit, user would be redirect to / instead of /my after signup. That error was detected with task-1829827 which has a tour ensuring user is correctly redirected to /my after signup on the checkout summary after payment. Since 0229ef4c4a39, the `web_login()` super call order has been changed when called from the `/web/signup` route. See the commit for more details but basically, before the fix, it went only through: 1. web.web_login 2. portal._login_redirect Where now, it goes through: 1. website.web_login 2. auth_signup.web_login 3. web.web_login 4.portal._login_redirect Thus, portal._login_redirect is not returning `/my` as redirect anymore. Indeed, website.web_login will ignore its super() and force redirect to `/` With this commit, website's user are redirected to /my as expected. Side effect: website's user will also be redirected to /my on login instead of `/`, which is also prefered. closes odoo/odoo#33865 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>