Browse Source

[MIG][website_mass_mailing_name] Migration to v10

- Relicense to LGPL.
- Fix all known issues.
- Enable tour only in demo instances.
- Fix Sass headers.
- Remove compiled css and maps.
- Update JS modules to new api.
- Update tour to new tours api.
- Update module structure to match latest template.
pull/179/head
Jairo Llopis 7 years ago
committed by Moisés López
parent
commit
4c61ceaf05
  1. 5
      .travis.yml
  2. 17
      website_mass_mailing_name/README.rst
  3. 3
      website_mass_mailing_name/__init__.py
  4. 17
      website_mass_mailing_name/__manifest__.py
  5. 3
      website_mass_mailing_name/controllers/__init__.py
  6. 28
      website_mass_mailing_name/controllers/main.py
  7. 17
      website_mass_mailing_name/demo/assets.xml
  8. 9
      website_mass_mailing_name/static/src/css/website_mass_mailing_name.css
  9. 7
      website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map
  10. 5
      website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass
  11. 50
      website_mass_mailing_name/static/src/js/editor_tour.js
  12. 77
      website_mass_mailing_name/static/src/js/public_tour.js
  13. 60
      website_mass_mailing_name/static/src/js/website_mass_mailing_name.js
  14. 138
      website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js
  15. 17
      website_mass_mailing_name/templates/assets.xml
  16. 14
      website_mass_mailing_name/templates/snippets.xml
  17. 3
      website_mass_mailing_name/tests/__init__.py
  18. 22
      website_mass_mailing_name/tests/test_ui.py
  19. 23
      website_mass_mailing_name/views/assets.xml

5
.travis.yml

@ -26,6 +26,11 @@ env:
virtualenv:
system_site_packages: true
before_install:
- rvm install ruby --latest
- rvm use ruby --latest
- gem install compass bootstrap-sass
install:
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}

17
website_mass_mailing_name/README.rst

@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
===========================================
Mass Mailing Subscription Snippet With Name
@ -11,7 +11,7 @@ the contact name directly in the subscription snippet.
If you want to get partners created automatically and linked to the contacts,
you can additionally install the `mass_mailing_partner
<https://www.odoo.com/apps/modules/8.0/mass_mailing_partner/>`_ module.
<https://www.odoo.com/apps/modules/10.0/mass_mailing_partner/>`_ module.
Usage
=====
@ -26,14 +26,7 @@ To use this module, you need to:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/186/8.0
Known issues / Roadmap
======================
* If you use Firefox, you could hit https://github.com/odoo/odoo/issues/7722.
Just use Chromium to work with this snippet until you update to Odoo 9.0.
* When migrating to v9, improve the tour test to check autofilling of inputs.
:target: https://runbot.odoo-community.org/runbot/186/10.0
Bug Tracker
===========

3
website_mass_mailing_name/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import controllers

17
website_mass_mailing_name/__openerp__.py → website_mass_mailing_name/__manifest__.py

@ -1,21 +1,24 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Mass Mailing Subscription Snippet With Name",
"summary": "Ask for name when subscribing, and create and/or link partner",
"version": "8.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Website",
"website": "https://tecnativa.com/",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": [
"mass_mailing",
"website_mass_mailing",
],
"demo": [
"demo/assets.xml",
],
"data": [
"views/assets.xml",
"views/snippets.xml",
"templates/assets.xml",
"templates/snippets.xml",
],
}

3
website_mass_mailing_name/controllers/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import main

28
website_mass_mailing_name/controllers/main.py

@ -1,22 +1,28 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openerp.addons.mass_mailing.controllers.main import MassMailController
from openerp.http import request, route
from odoo.addons.website_mass_mailing.controllers import main
from odoo.http import request, route
class MassMailingPartner(MassMailController):
class MassMailController(main.MassMailController):
@route()
def is_subscriber(self, *args, **kwargs):
"""Get user name too."""
result = super(MassMailingPartner, self).is_subscriber(*args, **kwargs)
email = result.get("email") or ""
result = super(MassMailController, self).is_subscriber(*args, **kwargs)
if request.website.user_id != request.env.user:
name = request.env.user.name
else:
name, email = (request.env["mail.mass_mailing.contact"]
.get_name_email(email, context=request.context))
result["name"] = name
result["email"] = email
name = request.session.get("mass_mailing_name", "")
return dict(result, name=name)
@route()
def subscribe(self, list_id, email, **post):
"""Store email with name in session."""
result = super(MassMailController, self).subscribe(
list_id, email, **post)
name, email = request.env['mail.mass_mailing.contact'].sudo() \
.get_name_email(email)
request.session["mass_mailing_name"] = name if name != email else ""
return result

17
website_mass_mailing_name/demo/assets.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="assets_frontend_demo"
inherit_id="website.assets_frontend">
<xpath expr=".">
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/editor_tour.js"/>
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/public_tour.js"/>
</xpath>
</template>
</odoo>

9
website_mass_mailing_name/static/src/css/website_mass_mailing_name.css

@ -1,9 +0,0 @@
@charset "UTF-8";
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
.js_subscribe .form-control {
width: 50%; }
.js_subscribe[data-subscribe="on"] .js_subscribe_name:not([disabled]) {
display: none; }
/*# sourceMappingURL=website_mass_mailing_name.css.map */

7
website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map

@ -1,7 +0,0 @@
{
"version": 3,
"mappings": ";;;AAKI,2BAAa;EACT,KAAK,EAAE,GAAG;AAGV,qEAAkC;EAC9B,OAAO,EAAE,IAAI",
"sources": ["website_mass_mailing_name.sass"],
"names": [],
"file": "website_mass_mailing_name.css"
}

5
website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass

@ -1,6 +1,5 @@
@charset "UTF-8"
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
/*! Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
.js_subscribe
.form-control

50
website_mass_mailing_name/static/src/js/editor_tour.js

@ -0,0 +1,50 @@
/* Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
odoo.define("website_mass_mailing_name.editor_tour", function (require) {
"use strict";
var base = require("web_editor.base");
var tour = require("web_tour.tour");
tour.register(
"mass_mailing_name_editor",
{
test: true,
wait_for: base.ready(),
},
[
{
content: "Edit the homepage",
trigger: ".o_menu_systray a[data-action=edit]",
},
{
content: "Drag and drop a text snippet",
trigger: ".oe_snippet[name='Text Block'] .oe_snippet_thumbnail",
run: "drag_and_drop #wrap",
},
{
content: "Drag and drop a newsletter snippet",
trigger: ".oe_snippet[name='Newsletter'] .oe_snippet_thumbnail",
run: "drag_and_drop #wrap .s_text_block",
},
{
content: "Let the default mailing list",
trigger: ".modal-dialog button:contains('Continue')",
},
{
content: "Save changes",
extra_trigger: "body:not(:has(.modal:visible))",
trigger: "#web_editor-top-edit button[data-action=save]",
},
{
content: "Subscribe Administrator",
extra_trigger: "body:not(:has(#web_editor-top-edit))",
trigger: ".js_subscribe_btn",
},
{
content: "Open user menu",
extra_trigger: ".js_subscribe .alert-success",
trigger: "#top_menu span:contains('Administrator')",
},
]
);
});

77
website_mass_mailing_name/static/src/js/public_tour.js

@ -0,0 +1,77 @@
/* Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
odoo.define("website_mass_mailing_name.public_tour", function (require) {
"use strict";
var base = require("web_editor.base");
var tour = require("web_tour.tour");
tour.register(
"mass_mailing_name_public",
{
test: true,
wait_for: base.ready(),
},
[
{
content: "Try to subscribe without data",
trigger: ".js_subscribe_btn",
},
{
content: "Enter a name",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_name",
run: "text Visitor",
},
{
content: "Try to subscribe without email",
trigger: ".js_subscribe_btn",
},
{
content: "Remove the name",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_name",
run: function () {
$(".js_subscribe_name").val("");
},
},
{
content: "Enter an email",
trigger: ".js_subscribe_email",
run: "text example@example.com",
},
{
content: "Try to subscribe without name",
trigger: ".js_subscribe_btn",
},
{
content: "Enter the name again",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_name",
run: "text Visitor",
},
{
content: "Enter a wrong email",
trigger: ".js_subscribe_email",
run: "text bad email",
},
{
content: "Try to subscribe with a bad email",
trigger: ".js_subscribe_btn",
},
{
content: "Enter the good email",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_email",
run: "text example@example.com",
},
{
content: "Try to subscribe with good information",
trigger: ".js_subscribe_btn",
},
{
content: "Subscription successful",
trigger: ".js_subscribe:not(.has-error) .alert-success",
},
]
);
});

60
website_mass_mailing_name/static/src/js/website_mass_mailing_name.js

@ -1,55 +1,53 @@
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
/* Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
"use strict";
(function ($) {
openerp.website.snippet.animationRegistry.subscribe.include({
start: function(editable_mode) {
var self = this;
self.$email = self.$target.find(".js_subscribe_email");
self.$name = self.$target.find(".js_subscribe_name");
odoo.define("website_mass_mailing_name.subscribe", function (require) {
"use strict";
require("mass_mailing.website_integration");
var animation = require("web_editor.snippets.animation");
animation.registry.subscribe.include({
start: function(editable_mode) {
this.$email = this.$target.find(".js_subscribe_email");
this.$name = this.$target.find(".js_subscribe_name");
// Thanks upstream for your @$&#?!! inheritance-ready code.
// Injecting ajax events to modify behavior of snippet.
if (self.$name) {
$(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
return self.on_ajax_send(event, jqXHR, ajaxOptions);
});
if (this.$name) {
$(document).ajaxSend($.proxy(this.on_ajax_send, this));
}
return self._super(editable_mode);
return this._super(editable_mode);
},
on_click: function() {
var self = this,
email_error = !self.$email.val().match(/.+@.+/),
name_error = self.$name.length && !self.$name.val(),
var email_error = !this.$email.val().match(/.+@.+/),
name_error = this.$name.length && !this.$name.val(),
values = {
"list_id": self.$target.data('list-id'),
"email": self.$email.val(),
"list_id": this.$target.data('list-id'),
"email": this.$email.val(),
};
// Stop on error
if (email_error || name_error) {
self.$target.addClass("has-error")
this.$target.addClass("has-error")
return false;
}
return self._super();
return this._super.apply(this, arguments);
},
on_ajax_send: function(event, jqXHR, ajaxOptions) {
var self = this;
on_ajax_send: function(event, jqXHR, ajaxOptions) {
// Add handlers on correct requests
if (ajaxOptions.url == "/website_mass_mailing/is_subscriber") {
jqXHR.then(function(data) {
return self.on_start(data);
});
jqXHR.done($.proxy(this.on_start, this));
} else if (ajaxOptions.url == "/website_mass_mailing/subscribe") {
var data = JSON.parse(ajaxOptions.data);
data.params.email =
self.$name.val() + " <" + data.params.email + ">";
data.params.email = _.str.sprintf(
"%s <%s>",
this.$name.val(),
data.params.email
);
ajaxOptions.data = JSON.stringify(data);
}
},
on_start: function(data) {
this.$name.val(data.result.name)
.attr(
@ -58,4 +56,4 @@
);
},
});
})(jQuery);
});

138
website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js

@ -1,138 +0,0 @@
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
"use strict";
(function ($) {
openerp.Tour.register({
id: "mass_mailing_partner",
name: "Insert a newsletter snippet and subscribe",
path: "/",
mode: "test",
steps: [
{
title: "Edit the homepage",
waitFor: "button[data-action=edit]",
element: "button[data-action=edit]",
},
{
title: "Click on Insert Blocks",
waitFor: "button[data-action=snippet]",
element: "button[data-action=snippet]",
},
{
title: "Click on Structure",
waitFor: "a[href='#snippet_structure']",
element: "a[href='#snippet_structure']",
},
{
title: "Drag and drop a text snippet",
waitFor: ".oe_snippet:contains('Text Block'):visible",
snippet: ".oe_snippet:contains('Text Block')",
},
{
title: "Click on Insert Blocks again",
waitFor: "#wrap h2:contains('A Great Headline'), \
button[data-action=snippet]",
element: "button[data-action=snippet]",
},
{
title: "Click on Content",
waitFor: "a[href='#snippet_content']",
element: "a[href='#snippet_content']",
},
{
title: "Drag and drop a newsletter snippet",
waitFor: ".oe_snippet:contains('Newsletter'):visible",
snippet: ".oe_snippet:contains('Newsletter')",
},
{
title: "Let the default mailing list",
waitFor: ".modal button:contains('Continue'):visible",
element: ".modal button:contains('Continue'):visible",
},
{
title: "Save changes",
waitNot: ".modal:visible",
element: "button[data-action=save]",
},
{
title: "Subscribe Administrator",
waitFor: "button[data-action=edit]:visible, \
.js_subscribe_btn:visible",
element: ".js_subscribe_btn",
},
{
title: "Open user menu",
waitFor: ".js_subscribe .alert-success:visible",
element: "#top_menu span:contains('Administrator')",
},
{
title: "Log out",
waitFor: ".js_usermenu a:contains('Logout'):visible",
element: ".js_usermenu a:contains('Logout'):visible",
},
{
title: "Try to subscribe without data",
waitFor: "#top_menu a[href='/web/login']:visible, \
.js_subscribe_btn:visible",
element: ".js_subscribe_btn",
},
{
title: "Enter a name",
waitFor: ".js_subscribe.has-error",
element: ".js_subscribe_name",
sampleText: "Visitor",
},
{
title: "Try to subscribe without email",
element: ".js_subscribe_btn",
},
{
title: "Remove the name",
waitFor: ".js_subscribe.has-error",
element: ".js_subscribe_name",
sampleText: "",
},
{
title: "Enter an email",
element: ".js_subscribe_email",
sampleText: "example@example.com",
},
{
title: "Try to subscribe without name",
element: ".js_subscribe_btn",
},
{
title: "Enter the name again",
waitFor: ".js_subscribe.has-error",
element: ".js_subscribe_name",
sampleText: "Visitor",
},
{
title: "Enter a wrong email",
element: ".js_subscribe_email",
sampleText: "bad email",
},
{
title: "Try to subscribe with a bad email",
element: ".js_subscribe_btn",
},
{
title: "Enter the good email",
waitFor: ".js_subscribe.has-error",
element: ".js_subscribe_email",
sampleText: "example@example.com",
},
{
title: "Try to subscribe with good information",
element: ".js_subscribe_btn",
},
// Expect this test to work in v9 when uncommenting this
// {
// title: "Subscription successful",
// waitFor: ".js_subscribe:not(.has-error) \
// .alert-success:visible",
// },
],
});
})(jQuery);

17
website_mass_mailing_name/templates/assets.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="assets_frontend"
inherit_id="website.assets_frontend">
<xpath expr=".">
<link rel="stylesheet"
href="/website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass"/>
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js"/>
</xpath>
</template>
</odoo>

14
website_mass_mailing_name/views/snippets.xml → website_mass_mailing_name/templates/snippets.xml

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<!-- Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<openerp>
<data>
<odoo>
<template id="mailing_list_subscribe"
inherit_id="mass_mailing.mailing_list_subscribe">
<template id="s_newsletter_subscribe_form"
inherit_id="website_mass_mailing.s_newsletter_subscribe_form">
<xpath expr="//input[@class='js_subscribe_email form-control']"
position="before">
<input
@ -16,5 +15,4 @@
</xpath>
</template>
</data>
</openerp>
</odoo>

3
website_mass_mailing_name/tests/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import test_ui

22
website_mass_mailing_name/tests/test_ui.py

@ -1,15 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openerp.tests.common import HttpCase
from odoo.http import root
from odoo.tests.common import HttpCase
class UICase(HttpCase):
def test_ui(self):
"""Test snippet behavior."""
tour = "odoo.__DEBUG__.services['web_tour.tour'].%s"
# Admin edits home page and adds subscription snippet
self.phantom_js(
"/",
"openerp.Tour.run('mass_mailing_partner', 'test')",
"openerp.Tour.tours.mass_mailing_partner",
"admin")
tour % "run('mass_mailing_name_editor')",
tour % "tours.mass_mailing_name_editor.ready",
login="admin")
# Forced log out
root.session_store.delete(self.session)
# Public user uses subscription snippet
self.phantom_js(
"/",
tour % "run('mass_mailing_name_public')",
tour % "tours.mass_mailing_name_public.ready")

23
website_mass_mailing_name/views/assets.xml

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data>
<template id="assets_frontend"
inherit_id="mass_mailing.assets_frontend">
<xpath expr=".">
<link rel="stylesheet"
href="/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css"/>
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js"/>
<t t-if="request.registry.test_cr">
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js"/>
</t>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save