From 1c81de987a6d098c41b993c9bfa2310942e0aa4b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Tue, 12 Dec 2023 12:34:30 +0000 Subject: [PATCH] [FIX] website_slides, website_event{_exhibitor,_meet}: fix "Go to website" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit How to reproduce: - Install website_slides with demo data - Log in from localhost - Log in from dev.localhost - Switch to localhost - (The system property web.base.url is http://dev.localhost:8069 but we are on localhost) - Go to a course in the back end and click on “Go to website” button You are redirected to the frontend website home page instead of the course home page. This fix solves the problem. Afer correcting this error for the courses (slide.channel), we have found the same problem for: - event.sponsor - event.meeting.room - slide.slide So we apply the same correction for them. Technical note: the button "Go to website" uses the open_website_url method of WebsitePublishedMultiMixin that relies on website_url. That method expects a relative URL in the computed field website_url and not an absolute one (actually, the method already handle adding the website domain, so it expect the relative part). The problem is that the compute method for the field website_url of channel compute an absolute URL. The consequence is that the user is redirected to the home page instead of the course page (by WebsitePreview, see get path method). In stable, we cannot change easily website_url to make it relative as it is used in other of places (ex.: if we make it relative the share link in the sidebar on the frontend is relative which is not correct and in mail template, the URL might not be correct as the mail system append the default domain for relative URLs). So instead, we override open_website_url to use a relative URL when the website is not defined. If the website is defined on the course, we call the super implementation because a domain change might be required. Note that by doing that, we duplicate the code of _compute_website_url in open_website_url but making the URL relative instead of absolute. So we should clean that in master. Task-3635856 closes odoo/odoo#160763 X-original-commit: 1f798428fc0f403755512a45f67b5f70aae0c808 Signed-off-by: Warnon Aurélien (awa) Signed-off-by: Pierre-Yves Dufays (pydu) --- addons/website_event_exhibitor/models/event_sponsor.py | 6 ++++++ addons/website_event_meet/models/event_meeting_room.py | 6 ++++++ addons/website_slides/models/slide_channel.py | 6 ++++++ addons/website_slides/models/slide_slide.py | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/addons/website_event_exhibitor/models/event_sponsor.py b/addons/website_event_exhibitor/models/event_sponsor.py index 91af79d7edd..7b6a699014c 100644 --- a/addons/website_event_exhibitor/models/event_sponsor.py +++ b/addons/website_event_exhibitor/models/event_sponsor.py @@ -224,6 +224,12 @@ class Sponsor(models.Model): def get_backend_menu_id(self): return self.env.ref('event.event_main_menu').id + def open_website_url(self): + """ Overridden to use a relative URL instead of an absolute when website_id is False. """ + if self.event_id.website_id: + return super().open_website_url() + return self.env['website'].get_client_action(f'/event/{slug(self.event_id)}/exhibitor/{slug(self)}') + # ------------------------------------------------------------ # MESSAGING # ------------------------------------------------------------ diff --git a/addons/website_event_meet/models/event_meeting_room.py b/addons/website_event_meet/models/event_meeting_room.py index b8e17ed8f39..6a08d209311 100644 --- a/addons/website_event_meet/models/event_meeting_room.py +++ b/addons/website_event_meet/models/event_meeting_room.py @@ -52,3 +52,9 @@ class EventMeetingRoom(models.Model): ("room_participant_count", "=", 0), ("room_last_activity", "<", fields.Datetime.now() - self._DELAY_CLEAN), ]).active = False + + def open_website_url(self): + """ Overridden to use a relative URL instead of an absolute when website_id is False. """ + if self.event_id.website_id: + return super().open_website_url() + return self.env['website'].get_client_action(f'/event/{slug(self.event_id)}/meeting_room/{slug(self)}') diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 3500f4165c1..c1872242076 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -1272,3 +1272,9 @@ class Channel(models.Model): if field in image_fields: return self.website_default_background_image_url return super()._get_placeholder_filename(field) + + def open_website_url(self): + """ Overridden to use a relative URL instead of an absolute when website_id is False. """ + if self.website_id: + return super().open_website_url() + return self.env['website'].get_client_action(f'/slides/{slug(self)}') diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index 1a81ff84a18..6e24bbfcf59 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -1402,3 +1402,9 @@ class Slide(models.Model): data['course'] = _('Course: %s', slide.channel_id.name) data['course_url'] = slide.channel_id.website_url return results_data + + def open_website_url(self): + """ Overridden to use a relative URL instead of an absolute when website_id is False. """ + if self.website_id: + return super().open_website_url() + return self.env['website'].get_client_action(f'/slides/slide/{slug(self)}')