From da09f610d0ff003778d4ddd4925f79aee04d79ca Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 25 Feb 2025 14:06:04 +0100 Subject: [PATCH] [IMP] runbot: improve og data When adding an internal link in discord or other platform, a preview of the login page is given. This is not usefull nor elegant. This commit proposes to remove the logo and give useful information instead --- runbot/models/__init__.py | 1 + runbot/models/website.py | 40 ++++++++++++++++++++++++++++++ runbot/views/build_error_views.xml | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 runbot/models/website.py diff --git a/runbot/models/__init__.py b/runbot/models/__init__.py index 60601d60..dbd376be 100644 --- a/runbot/models/__init__.py +++ b/runbot/models/__init__.py @@ -27,6 +27,7 @@ from . import team from . import upgrade from . import user from . import version +from . import website # those imports have to be at the end otherwise the sql view cannot be initialised from . import build_stat diff --git a/runbot/models/website.py b/runbot/models/website.py new file mode 100644 index 00000000..f7fc6588 --- /dev/null +++ b/runbot/models/website.py @@ -0,0 +1,40 @@ +from odoo import models, fields, api +from odoo.http import request +from odoo.addons.web.controllers.utils import get_action_triples +import re + + +class Website(models.AbstractModel): + _inherit = "website.seo.metadata" + + def get_website_meta(self): + # this is kind of hacky but should improve user experience when sharing runbot links + # right now, a backend link will lead to the login page creating a link preview of the login page. + # this override will hopefully remove the website image and try to improve the meta based on the record + # in the backend, if possible to extract + res = super().get_website_meta() + del res['opengraph_meta']['og:image'] + del res['twitter_meta'] + if request and request.params.get('redirect') and not request.params.get('login_success'): + redirect = request.params['redirect'] + if redirect.startswith('/odoo/'): + try: + actions = list(get_action_triples(self.env, redirect.split('?')[0].removeprefix('/odoo/'))) + except ValueError: + actions = None + if actions: + _active_id, action, record_id = actions[-1] + model = action.res_model + record = self.env[model] + if record_id and model.startswith('runbot.'): + record = self.env[model].browse(record_id).exists() + if record.sudo(False)._check_access('read'): + record = self.env[model] + title = f'{record._description}' + if record: + title = f'{record._description} | {record.display_name}' + if 'description' in record._fields: + res['opengraph_meta']['og:description'] = record.description + res['opengraph_meta']['og:title'] = title + res['opengraph_meta']['og:url'] = request.httprequest.url_root.strip('/') + redirect + return res \ No newline at end of file diff --git a/runbot/views/build_error_views.xml b/runbot/views/build_error_views.xml index a0e66684..7aaec957 100644 --- a/runbot/views/build_error_views.xml +++ b/runbot/views/build_error_views.xml @@ -466,12 +466,14 @@ Errors runbot.build.error + error list,form {'search_default_not_fixed_errors': True, 'active_test': False} Build errors contents + error_content runbot.build.error.content list,form {'search_default_not_fixed_errors': True, 'active_test': False}