Files
odoo_source/addons/portal/models/res_users_apikeys_description.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

21 lines
708 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, _
from odoo.exceptions import AccessError
class APIKeyDescription(models.TransientModel):
_inherit = 'res.users.apikeys.description'
def check_access_make_key(self):
try:
return super().check_access_make_key()
except AccessError:
if self.env['ir.config_parameter'].sudo().get_param('portal.allow_api_keys'):
if self.user_has_groups('base.group_portal'):
return
else:
raise AccessError(_("Only internal and portal users can create API keys"))
raise