summaryrefslogtreecommitdiff
path: root/addons/website/static/src
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2019-02-06 09:50:38 +0000
committerSébastien Theys <seb@odoo.com>2019-02-06 09:50:38 +0000
commitc1be1993f9bcd11f3fdff78e81ea71e518c15779 (patch)
tree72045b536b781e963e4e6354b9ff84ceb20a5fbf /addons/website/static/src
parent3b256ba487df8ed3ef28eddec25af75ce3be4677 (diff)
[FIX] *: share URL on the correct website if possible
* = base, auth_signup, mail, portal, sale, website, website_sale Before this commit, sending an object by email would always link to web.base.url even if the object was created from a specific website. Now if the object has a website, we use the URL of that website if it is set. The fallback will always be on the web.base.url. opw-1921030 PR: #30000
Diffstat (limited to 'addons/website/static/src')
-rw-r--r--addons/website/static/src/js/tours/website_tour_reset_password.js181
1 files changed, 181 insertions, 0 deletions
diff --git a/addons/website/static/src/js/tours/website_tour_reset_password.js b/addons/website/static/src/js/tours/website_tour_reset_password.js
new file mode 100644
index 00000000000..2b304bb0103
--- /dev/null
+++ b/addons/website/static/src/js/tours/website_tour_reset_password.js
@@ -0,0 +1,181 @@
+odoo.define('website.tour_reset_password', function (require) {
+'use strict';
+
+var base = require('web_editor.base');
+var localStorage = require('web.local_storage');
+var rpc = require('web.rpc');
+var tour = require('web_tour.tour');
+
+var currentDomain = window.location.protocol + '//' + window.location.hostname;
+var emailsUrl = '/web#action=mail.action_view_mail_mail&view_type=list';
+var usersUrl = '/web#action=base.action_res_users&view_type=list';
+var resetLinkKey = 'website.tour_reset_password.resetLink';
+
+tour.register('website_reset_password', {
+ test: true,
+ url: '/web',
+ wait_for: base.ready(),
+},
+[
+ {
+ content: "Change the domain of the websites and go to users page",
+ trigger: '.oe_topbar_name:contains("Admin")',
+ run: function () {
+ // We could do it with the UI but this is not the goal of this test,
+ // so we just make an RPC to be faster.
+
+ // We change the domain of the website to test that the email that
+ // will be sent uses the correct domain for its links.
+ var def1 = rpc.query({
+ 'model': 'website',
+ 'method': 'write',
+ 'args': [[1], {
+ 'domain': "my-test-domain.com",
+ }],
+ });
+ // We need to change the domain of all the websites otherwise the
+ // website selector will return the website 2 since the domain we
+ // set on website 1 doesn't actually match our test server.
+ var def2 = rpc.query({
+ 'model': 'website',
+ 'method': 'write',
+ 'args': [[2], {
+ 'domain': "https://domain-not-used.fr",
+ }],
+ });
+ // Set a website on "Admin" partner to test the URL of the website.
+ var def3 = rpc.query({
+ model: 'res.partner',
+ method: 'name_search',
+ kwargs: {'name': 'Mitchell Admin'},
+ }).then(function (res) {
+ return rpc.query({
+ 'model': 'res.partner',
+ 'method': 'write',
+ 'args': [[res[0][0]], {
+ 'website_id': 1,
+ }],
+ });
+ });
+
+ return $.when(def1, def2, def3).then(function () {
+ window.location.href = usersUrl;
+ });
+ },
+ },
+ {
+ content: "click on Admin",
+ trigger: '.o_data_cell:contains("Admin")',
+ },
+ {
+ content: "click on reset password",
+ trigger: '.btn[name="action_reset_password"]',
+ },
+ {
+ content: "wait mail to be sent, and go see it",
+ trigger: 'a[name="signup_url"][href^="http://my-test-domain.com"]',
+ run: function () {
+ window.location.href = emailsUrl;
+ },
+ },
+ {
+ content: "click on the first email",
+ trigger: '.o_data_cell:contains("Password reset"):eq(0)',
+ },
+ {
+ content: "check page has an iframe",
+ trigger: 'iframe body',
+ run: function () {
+ var content = $('iframe').contents()[0];
+ console.log(content && new XMLSerializer().serializeToString(content));
+ },
+ },
+ {
+ content: "check iframe has the button",
+ trigger: 'iframe a:contains("Change password")',
+ run: function () {},
+ },
+ {
+ content: "check the URL is correct too",
+ trigger: 'iframe a:contains("Change password")[href^="http://my-test-domain.com"]',
+ run: function () {
+ // reset the domain of the websites, go to users page
+ return rpc.query({
+ 'model': 'website',
+ 'method': 'write',
+ 'args': [[1, 2], {
+ 'domain': "",
+ }],
+ }).then(function () {
+ window.location.href = usersUrl;
+ });
+ },
+ },
+ {
+ content: "click on Admin",
+ trigger: '.o_data_cell:contains("Admin")',
+ },
+ {
+ content: "click on reset password",
+ trigger: '.btn[name="action_reset_password"]',
+ },
+ {
+ content: "wait mail to be sent, and go see it",
+ trigger: 'a[name="signup_url"][href^="' + currentDomain + '"]',
+ run: function () {
+ window.location.href = emailsUrl;
+ },
+ },
+ {
+ content: "click on the first email",
+ trigger: '.o_data_cell:contains("Password reset"):eq(0)',
+ },
+ {
+ content: "check the link has the current host, save the link, logout",
+ trigger: 'iframe a:contains("Change password")[href^="' + currentDomain + '"]',
+ run: function () {
+ var link = $('iframe').contents().find('a:contains("Change password")').attr('href');
+ localStorage.setItem(resetLinkKey, link);
+ window.location.href = "/web/session/logout?redirect=/";
+ },
+ },
+ {
+ content: "go to the reset link",
+ trigger: 'a[href="/web/login"]',
+ run: function () {
+ window.location.href = localStorage.getItem(resetLinkKey);
+ },
+ },
+ {
+ content: "fill new password and submit",
+ trigger: '.oe_reset_password_form',
+ run: function () {
+ var $form = $('.oe_reset_password_form');
+ $form.find('input[name="password"]').val('adminadmin');
+ // password must be at least 8 if the module `auth_password_policy`
+ // is installed which is the case on runbot
+ $form.find('input[name="confirm_password"]').val('adminadmin');
+ $form.find('button[type="submit"]').click();
+ },
+ },
+ {
+ content: "check logged in, and reset admin website",
+ trigger: '.oe_topbar_name:contains("Admin")',
+ run: function () {
+ return rpc.query({
+ model: 'res.partner',
+ method: 'name_search',
+ kwargs: {'name': 'Admin'},
+ }).then(function (res) {
+ return rpc.query({
+ 'model': 'res.partner',
+ 'method': 'write',
+ 'args': [[res[0][0]], {
+ 'website_id': false,
+ }],
+ });
+ });
+ },
+ },
+]);
+});