You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

8 years ago
8 years ago
  1. # coding: utf-8
  2. # Copyright 2014 David BEAL @ Akretion <david.beal@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, fields, api
  5. from openerp.exceptions import Warning as UserError
  6. from openerp.tools.config import config
  7. def _get_authorized_password():
  8. """ You can define your own authorized keys
  9. """
  10. return [config.get("secure_uninstall"), config.get("admin_passwd")]
  11. class BaseModuleUpgrade(models.TransientModel):
  12. _inherit = 'base.module.upgrade'
  13. uninstall_password = fields.Char(
  14. string='Password',
  15. help="'secure_uninstall' value from Odoo configuration file ")
  16. @api.multi
  17. def upgrade_module(self):
  18. for elm in self:
  19. if not config.get("secure_uninstall"):
  20. raise UserError(
  21. "Missing configuration key\n--------------------\n"
  22. "'secure_uninstall' configuration key "
  23. "is not set in \n"
  24. "your Odoo server configuration file: "
  25. "please set it a value")
  26. if elm.uninstall_password not in _get_authorized_password():
  27. raise UserError(
  28. "Password Error\n--------------------\n"
  29. "Provided password '%s' doesn't match with "
  30. "'Master Password'\n('secure_uninstall' key) found in "
  31. "the Odoo server configuration file ."
  32. "\n\nResolution\n-------------\n"
  33. "Please check your password and retry or cancel"
  34. % elm.uninstall_password)
  35. # keep this password in db is insecure, then we remove it
  36. elm.uninstall_password = False
  37. return super(BaseModuleUpgrade, self).upgrade_module()