Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] website: fallback on odoo social by default in all cases #162375

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion addons/website/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,21 @@ def website_configurator(self, step=1, **kwargs):
action_url += '&step=' + str(step)
return request.redirect(action_url)

def _get_social_default_urls(self):
""" Return the default URLs for social networks. """
return {
'facebook': 'https://www.facebook.com/Odoo',
'github': 'https://github.com/odoo',
'linkedin': 'https://www.linkedin.com/company/odoo',
'youtube': 'https://www.youtube.com/user/OpenERPonline',
'instagram': 'https://www.instagram.com/odoo.official',
'twitter': 'https://twitter.com/Odoo',
'tiktok': 'https://www.tiktok.com/@odoo',
}

@http.route(['/website/social/<string:social>'], type='http', auth="public", website=True, sitemap=False)
def social(self, social, **kwargs):
url = getattr(request.website, 'social_%s' % social, False)
url = getattr(request.website, 'social_%s' % social, False) or self._get_social_default_urls().get(social)
if not url:
raise werkzeug.exceptions.NotFound()
return request.redirect(url, local=False)
Expand Down
20 changes: 19 additions & 1 deletion addons/website/tests/test_website_favicon.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

# TODO in master: rename this file to `test_website` only

from PIL import Image

from odoo.tests import tagged
from odoo.tests.common import TransactionCase
from odoo.tests.common import HttpCase, TransactionCase
from odoo.tools import base64_to_image, image_to_base64


@tagged('post_install', '-at_install')
# TODO: rename the class name, it's a bad copy paste
class TestWebsiteResetPassword(TransactionCase):

def test_01_website_favicon(self):
Expand All @@ -34,3 +37,18 @@ def test_01_website_favicon(self):
self.assertEqual(image.format, 'ICO')
self.assertEqual(image.size, (256, 256))
self.assertEqual(image.getpixel((0, 0)), bg_color)


@tagged('-at_install', 'post_install')
class TestWebsiteHttp(HttpCase):
def test_website_default_social_media(self):
rdeodoo marked this conversation as resolved.
Show resolved Hide resolved
# Demo data are setting the twitter account of the main company, we need
# to remove it for demo data to not interfere with the test
self.env.ref('base.main_company').social_twitter = None
website = self.env['website'].create({
'name': 'Test Website',
})
self.assertFalse(website.social_twitter)
r = self.url_open('/website/social/twitter', allow_redirects=False)
self.assertEqual(r.status_code, 303, "Should redirect to Odoo network")
self.assertEqual(r.headers.get('Location'), 'https://twitter.com/Odoo', "Should redirect to Odoo network (2)")