diff --git a/addons/web/static/src/core/debug/profiling/profiling_service.js b/addons/web/static/src/core/debug/profiling/profiling_service.js index 1ae4afb3888..4e76743c9cd 100644 --- a/addons/web/static/src/core/debug/profiling/profiling_service.js +++ b/addons/web/static/src/core/debug/profiling/profiling_service.js @@ -46,11 +46,15 @@ const profilingService = { params ); const resp = await orm.call("ir.profile", "set_profiling", [], kwargs); - state.session = resp.session; - state.collectors = resp.collectors; - state.params = resp.params; - bus.trigger("UPDATE"); - updateDebugIcon(); + if (resp.type) { // most likely an "ir.actions.act_window" + env.services.action.doAction(resp); + } else { + state.session = resp.session; + state.collectors = resp.collectors; + state.params = resp.params; + bus.trigger("UPDATE"); + updateDebugIcon(); + } } function profilingSeparator() { diff --git a/addons/web/tests/test_profiler.py b/addons/web/tests/test_profiler.py index e420e58d7b4..0a5a82a39cd 100644 --- a/addons/web/tests/test_profiler.py +++ b/addons/web/tests/test_profiler.py @@ -46,7 +46,7 @@ class TestProfilingWeb(ProfilingHttpCase): # Trying to start profiling when not enabled self.env['ir.config_parameter'].set_param('base.profiling_enabled_until', '') res = self.profile_rpc({'profile': 1}) - self.assertEqual(res['error']['data']['message'], 'Profiling is not enabled on this database') + self.assertEqual(res['result']['res_model'], 'base.enable.profiling.wizard') self.assertEqual(last_profile, self.env['ir.profile'].search([], limit=1, order='id desc')) # Enable profiling and start blank profiling @@ -92,7 +92,7 @@ class TestProfilingPublic(ProfilingHttpCase): res = self.url_open('/web/set_profiling?profile=1') self.assertEqual(res.status_code, 500) - self.assertEqual(res.text, 'error: Profiling is not enabled on this database') + self.assertEqual(res.text, 'error: Profiling is not enabled on this database. Please contact an administrator.') expiration = datetime.datetime.now() + datetime.timedelta(seconds=50) self.env['ir.config_parameter'].set_param('base.profiling_enabled_until', expiration) diff --git a/odoo/addons/base/models/ir_profile.py b/odoo/addons/base/models/ir_profile.py index 84155deb978..9375ee86dca 100644 --- a/odoo/addons/base/models/ir_profile.py +++ b/odoo/addons/base/models/ir_profile.py @@ -6,6 +6,8 @@ import datetime import json import logging +from dateutil.relativedelta import relativedelta + from odoo import fields, models, api, _ from odoo.exceptions import UserError from odoo.http import request @@ -86,7 +88,15 @@ class IrProfile(models.Model): _logger.info("User %s started profiling", self.env.user.name) if not limit: request.session.profile_session = None - raise UserError(_('Profiling is not enabled on this database')) + if self.env.user._is_system(): + return { + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'base.enable.profiling.wizard', + 'target': 'new', + 'views': [[False, 'form']], + } + raise UserError(_('Profiling is not enabled on this database. Please contact an administrator.')) if not request.session.profile_session: request.session.profile_session = make_session(self.env.user.name) request.session.profile_expiration = limit @@ -108,3 +118,26 @@ class IrProfile(models.Model): 'collectors': request.session.profile_collectors, 'params': request.session.profile_params, } + + +class EnableProfilingWizard(models.TransientModel): + _name = 'base.enable.profiling.wizard' + _description = "Enable profiling for some time" + + duration = fields.Selection([ + ('minutes_5', "5 Minutes"), + ('hours_1', "1 Hour"), + ('days_1', "1 Day"), + ('months_1', "1 Month"), + ], string="Enable profiling for") + expiration = fields.Datetime("Enable profiling until", compute='_compute_expiration', store=True, readonly=False) + + @api.depends('duration') + def _compute_expiration(self): + for record in self: + unit, quantity = (record.duration or 'days_0').split('_') + record.expiration = fields.Datetime.now() + relativedelta(**{unit: int(quantity)}) + + def submit(self): + self.env['ir.config_parameter'].set_param('base.profiling_enabled_until', self.expiration) + return False diff --git a/odoo/addons/base/security/ir.model.access.csv b/odoo/addons/base/security/ir.model.access.csv index 9b649170f85..912e65ad337 100644 --- a/odoo/addons/base/security/ir.model.access.csv +++ b/odoo/addons/base/security/ir.model.access.csv @@ -122,3 +122,4 @@ "access_base_partner_merge_line","access.base.partner.merge.line","model_base_partner_merge_line","base.group_partner_manager",1,1,1,0 "access_base_partner_merge_automatic_wizard","access.base.partner.merge.automatic.wizard","model_base_partner_merge_automatic_wizard","base.group_partner_manager",1,1,1,0 "access_ir_profile","ir_profile","model_ir_profile","group_system",1,1,1,1 +"access_base_enable_profiling_wizard","access.base.enable.profiling.wizard","model_base_enable_profiling_wizard","group_system",1,1,1,0 diff --git a/odoo/addons/base/views/ir_profile_views.xml b/odoo/addons/base/views/ir_profile_views.xml index 6f9a272223a..1030c76fd9a 100644 --- a/odoo/addons/base/views/ir_profile_views.xml +++ b/odoo/addons/base/views/ir_profile_views.xml @@ -43,6 +43,30 @@ + + Enable profiling + base.enable.profiling.wizard + + + + Profiling is currently disabled. + Profiling is a developer feature that should be used with caution on production database. + It may add some load on the server, and potentially make it less responsive. + Enabling the profiling here allows all users to activate profiling on their session. + Profiling can be disabled at any moment in the settings. + + + + + + + + + + Ir profile ir.actions.act_window