diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 12fd63f2fab..b6812de155f 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -260,7 +260,7 @@ class WebsiteBlog(http.Controller): subtype='mt_comment', author_id=partner_ids[0], path=post.get('path', False), - context=dict(context, mail_create_nosubcribe=True)) + context=context) return message_id @http.route(['/blogpost/comment'], type='http', auth="public", methods=['POST'], website=True) @@ -302,14 +302,13 @@ class WebsiteBlog(http.Controller): @http.route('/blogpost/new', type='http', auth="public", website=True) def blog_post_create(self, blog_id, **post): cr, uid, context = request.cr, request.uid, request.context - create_context = dict(context, mail_create_nosubscribe=True) new_blog_post_id = request.registry['blog.post'].create(cr, uid, { 'blog_id': blog_id, 'name': _("Blog Post Title"), 'subtitle': _("Subtitle"), 'content': '', 'website_published': False, - }, context=create_context) + }, context=context) new_blog_post = request.registry['blog.post'].browse(cr, uid, new_blog_post_id, context=context) return werkzeug.utils.redirect("/blog/%s/post/%s?enable_editor=1" % (slug(new_blog_post.blog_id), slug(new_blog_post))) diff --git a/addons/website_blog/data/website_blog_data.xml b/addons/website_blog/data/website_blog_data.xml index 03f3c13127d..fa33afc0ad2 100644 --- a/addons/website_blog/data/website_blog_data.xml +++ b/addons/website_blog/data/website_blog_data.xml @@ -28,29 +28,13 @@ open - - - New Post - blog.post - - New Post - - - Post Published - blog.post - - Post Published - - - - - New Post + + + Published Post blog.blog - - blog_id + Published Post - diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py index f3c43bce4dd..4aa78f68239 100644 --- a/addons/website_blog/models/website_blog.py +++ b/addons/website_blog/models/website_blog.py @@ -7,6 +7,7 @@ import random from openerp import tools from openerp import SUPERUSER_ID +from openerp.addons.website.models.website import slug from openerp.osv import osv, fields from openerp.tools.translate import _ @@ -173,6 +174,23 @@ class BlogPost(osv.Model): } history.create(cr, uid, res) + def _check_for_publication(self, cr, uid, ids, vals, context=None): + if vals.get('website_published'): + base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') + for post in self.browse(cr, uid, ids, context=context): + post.blog_id.message_post( + body='

%(post_publication)s %(post_link)s

' % { + 'post_publication': _('A new post %s has been published on the %s blog.') % (post.name, post.blog_id.name), + 'post_link': _('Click here to access the post.'), + 'base_url': base_url, + 'blog_slug': slug(post.blog_id), + 'post_slug': slug(post), + }, + subtype='website_blog.mt_blog_blog_published', + context=context) + return True + return False + def create(self, cr, uid, vals, context=None): if context is None: context = {} @@ -181,6 +199,7 @@ class BlogPost(osv.Model): create_context = dict(context, mail_create_nolog=True) post_id = super(BlogPost, self).create(cr, uid, vals, context=create_context) self.create_history(cr, uid, [post_id], vals, context) + self._check_for_publication(cr, uid, [post_id], vals, context=context) return post_id def write(self, cr, uid, ids, vals, context=None): @@ -188,6 +207,7 @@ class BlogPost(osv.Model): vals['content'] = self._postproces_content(cr, uid, None, vals['content'], context=context) result = super(BlogPost, self).write(cr, uid, ids, vals, context) self.create_history(cr, uid, ids, vals, context) + self._check_for_publication(cr, uid, ids, vals, context=context) return result class BlogPostHistory(osv.Model): diff --git a/addons/website_blog/security/ir.model.access.csv b/addons/website_blog/security/ir.model.access.csv index cb0498a958b..b539a6c893a 100644 --- a/addons/website_blog/security/ir.model.access.csv +++ b/addons/website_blog/security/ir.model.access.csv @@ -1,5 +1,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink blog_blog_all,blog.blog,model_blog_blog,,1,0,0,0 +blog_blog,blog.blog,model_blog_blog,base.group_document_user,1,1,1,1 blog_post_all,blog.post,model_blog_post,,1,0,0,0 blog_post,blog.post,model_blog_post,base.group_document_user,1,1,1,1 blog_post_history,blog.post.history,model_blog_post_history,base.group_document_user,1,0,1,0 diff --git a/addons/website_blog/tests/__init__.py b/addons/website_blog/tests/__init__.py index 157f4549988..3d2b61f96b2 100644 --- a/addons/website_blog/tests/__init__.py +++ b/addons/website_blog/tests/__init__.py @@ -1,24 +1,4 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Business Applications -# Copyright (c) 20123TODAY OpenERP S.A. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -import test_ui - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +from openerp.addons.website_blog.tests import test_ui +from openerp.addons.website_blog.tests import test_website_blog_flow diff --git a/addons/website_blog/tests/common.py b/addons/website_blog/tests/common.py new file mode 100644 index 00000000000..9147d2a3739 --- /dev/null +++ b/addons/website_blog/tests/common.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from openerp.tests import common + + +class TestWebsiteBlogCommon(common.TransactionCase): + def setUp(self): + super(TestWebsiteBlogCommon, self).setUp() + + Users = self.env['res.users'] + + group_blog_manager_id = self.ref('base.group_document_user') + group_employee_id = self.ref('base.group_user') + group_public_id = self.ref('base.group_public') + + self.user_employee = Users.with_context({'no_reset_password': True}).create({ + 'name': 'Armande Employee', + 'login': 'armande', + 'alias_name': 'armande', + 'email': 'armande.employee@example.com', + 'notify_email': 'none', + 'groups_id': [(6, 0, [group_employee_id])] + }) + self.user_blogmanager = Users.with_context({'no_reset_password': True}).create({ + 'name': 'Bastien BlogManager', + 'login': 'bastien', + 'alias_name': 'bastien', + 'email': 'bastien.blogmanager@example.com', + 'notify_email': 'none', + 'groups_id': [(6, 0, [group_blog_manager_id, group_employee_id])] + }) + self.user_public = Users.with_context({'no_reset_password': True}).create({ + 'name': 'Cedric Public', + 'login': 'cedric', + 'alias_name': 'cedric', + 'email': 'cedric.public@example.com', + 'notify_email': 'none', + 'groups_id': [(6, 0, [group_public_id])] + }) diff --git a/addons/website_blog/tests/test_website_blog_flow.py b/addons/website_blog/tests/test_website_blog_flow.py new file mode 100644 index 00000000000..05c2420e59a --- /dev/null +++ b/addons/website_blog/tests/test_website_blog_flow.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +from openerp.addons.website_blog.tests.common import TestWebsiteBlogCommon + + +class TestWebsiteBlogFlow(TestWebsiteBlogCommon): + + def test_website_blog_followers(self): + """ Test the flow of followers and notifications for blogs. Intended + flow : + + - people subscribe to a blog + - when creating a new post, nobody except the creator follows it + - people subscribed to the blog does not receive comments on posts + - when published, a notification is sent to all blog followers + - if someone subscribe to the post or comment it, it become follower + and receive notification for future comments. """ + + # Create a new blog, subscribe the employee to the blog + test_blog = self.env['blog.blog'].sudo(self.user_blogmanager).create({ + 'name': 'New Blog', + 'description': 'Presentation of new Odoo features' + }) + self.assertIn( + self.user_blogmanager.partner_id, test_blog.message_follower_ids, + 'website_blog: blog create should be in the blog followers') + test_blog.message_subscribe([self.user_employee.partner_id.id, self.user_public.partner_id.id]) + + # Create a new post, blog followers should not follow the post + test_blog_post = self.env['blog.post'].sudo(self.user_blogmanager).create({ + 'name': 'New Post', + 'blog_id': test_blog.id, + }) + self.assertNotIn( + self.user_employee.partner_id, test_blog_post.message_follower_ids, + 'website_blog: subscribing to a blog should not subscribe to its posts') + self.assertNotIn( + self.user_public.partner_id, test_blog_post.message_follower_ids, + 'website_blog: subscribing to a blog should not subscribe to its posts') + + # Publish the blog + test_blog_post.write({'website_published': True}) + + # Check publish message has been sent to blog followers + publish_message = next((m for m in test_blog_post.blog_id.message_ids if m.subtype_id.id == self.ref('website_blog.mt_blog_blog_published')), None) + self.assertEqual( + set(publish_message.notified_partner_ids._ids), + set([self.user_employee.partner_id.id, self.user_public.partner_id.id]), + 'website_blog: peuple following a blog should be notified of a published post') + + # Armand posts a message -> becomes follower + test_blog_post.sudo().message_post( + body='Armande BlogUser Commented', + type='comment', + author_id=self.user_employee.partner_id.id, + subtype='mt_comment', + ) + self.assertIn( + self.user_employee.partner_id, test_blog_post.message_follower_ids, + 'website_blog: people commenting a post should follow it afterwards')