Files
odoo_source/addons/portal/models/res_config_settings.py
T
Denis Ledoux 5b078f2a77 [ADD] portal: manage api keys in portal
Add the possibility for portal users to manage API keys
in the frontend portal interface.

- Allow for portal users to manage their API keys if the system parameter
  `portal.allow_api_keys` is set.
  A settting in `res.config.settings` is added in order
  to enable or disable the feature (to add/remove the system parameter)
  through a compute field,
  to avoid adding a new database column in standard
  (as this revision targets stable 15.0).
  The setting appear only in debug mode.

- Display the API keys in the portal in debug mode only
  (as in the back-end for regular users, in their profile)

- The flow in the frontend is a mimic of the flow from the backend,
  the wording and the look and feel is from the back-end.

closes odoo/odoo#86915

Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-03-22 15:17:08 +01:00

28 lines
1000 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
portal_allow_api_keys = fields.Boolean(
string='Customer API Keys',
compute='_compute_portal_allow_api_keys',
inverse='_inverse_portal_allow_api_keys',
)
def _compute_portal_allow_api_keys(self):
for setting in self:
setting.portal_allow_api_keys = self.env['ir.config_parameter'].sudo().get_param('portal.allow_api_keys')
def _inverse_portal_allow_api_keys(self):
self.env['ir.config_parameter'].sudo().set_param('portal.allow_api_keys', self.portal_allow_api_keys)
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
res['portal_allow_api_keys'] = bool(self.env['ir.config_parameter'].sudo().get_param('portal.allow_api_keys'))
return res