diff --git a/addons/website_forum/controllers/website_forum.py b/addons/website_forum/controllers/website_forum.py index 2b377bc0516..db3a448e640 100644 --- a/addons/website_forum/controllers/website_forum.py +++ b/addons/website_forum/controllers/website_forum.py @@ -283,8 +283,19 @@ class WebsiteForum(WebsiteProfile): # Compatibility pre-v14 return request.redirect(_build_url_w_params("/forum/%s/%s" % (slug(forum), slug(question)), request.params), code=301) - @http.route(['''/forum///'''], + type='http', auth="public", website=True, sitemap=sitemap_forum_post) def question(self, forum, question, **post): if not forum.active: return request.render("website_forum.header", {'forum': forum}) diff --git a/addons/website_forum/tests/__init__.py b/addons/website_forum/tests/__init__.py index eb576b9e6b9..fe2713a308a 100644 --- a/addons/website_forum/tests/__init__.py +++ b/addons/website_forum/tests/__init__.py @@ -6,4 +6,5 @@ from . import test_forum_internals from . import test_forum_karma_access from . import test_forum_tag from . import test_forum_tours +from . import test_sitemap from . import test_web_editor diff --git a/addons/website_forum/tests/test_sitemap.py b/addons/website_forum/tests/test_sitemap.py new file mode 100644 index 00000000000..1d003e0b6bc --- /dev/null +++ b/addons/website_forum/tests/test_sitemap.py @@ -0,0 +1,31 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from freezegun import freeze_time +from unittest.mock import patch + +from odoo.addons.website_forum.tests.common import TestForumCommon +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class TestWebsiteControllers(TestForumCommon): + + def test_01_forum_sitemap(self): + website = self.env['website'].browse(1) + + # Simulate post from 2023-05-31 + datetime = '2023-05-31' + with freeze_time(datetime), patch.object(self.env.cr, 'now', lambda: datetime): + self.post.name = "RenameIt" # update write_date + self.post._update_last_activity() # update last_activity_date + + locs = website._enumerate_pages(query_string='/forum/%s' % self.forum.name) + self.assertEqual(list(locs)[1]['lastmod'].strftime("%Y-%m-%d"), datetime) + + # Edit post content the 2024-01-01 + datetime = '2024-01-01' + with freeze_time(datetime), patch.object(self.env.cr, 'now', lambda: datetime): + self.post.content = "I am a bird" # update write_date + + locs = website._enumerate_pages(query_string='/forum/%s' % self.forum.name) + self.assertEqual(list(locs)[1]['lastmod'].strftime("%Y-%m-%d"), datetime)