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.

86 lines
3.5 KiB

10 years ago
10 years ago
  1. # coding: utf-8
  2. ##############################################################################
  3. #
  4. # Copyright (C) All Rights Reserved 2014 Akretion
  5. # @author David BEAL <david.beal@akretion.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ###############################################################################
  21. from openerp.osv import orm, fields
  22. from openerp.tools.config import config
  23. class Module(orm.Model):
  24. _inherit = 'ir.module.module'
  25. def button_uninstall(self, cr, uid, ids, context=None):
  26. if not context:
  27. context = {}
  28. if 'uninstall_authorized' in context:
  29. ctx = context.copy()
  30. del ctx['uninstall_authorized']
  31. super(Module, self).button_uninstall(
  32. cr, uid, ids, context=ctx)
  33. return self._button_immediate_function(
  34. cr, uid, ids, self.button_uninstall, context=ctx)
  35. else:
  36. _, view_id = self.pool['ir.model.data'].get_object_reference(
  37. cr, uid, 'secure_uninstall', 'view_uninstall_wizard_form')
  38. return {
  39. 'view_id': view_id,
  40. 'view_mode': 'form',
  41. 'res_model': 'uninstall.check.wizard',
  42. 'context': {'module_id': ids[0]},
  43. 'name': "Uninstall Authorization",
  44. 'type': 'ir.actions.act_window',
  45. 'target': 'new',
  46. }
  47. class UninstallCheckWizard(orm.TransientModel):
  48. _name = 'uninstall.check.wizard'
  49. _columns = {
  50. 'password': fields.char(
  51. string='Password', required=True,
  52. help="'admin_passwd' value from Odoo configuration file "
  53. "(aka 'Master Password')")
  54. }
  55. def check_password(self, cr, uid, ids, context=None):
  56. for elm in self.browse(cr, uid, ids, context=context):
  57. config_passwd = config.get("admin_passwd")
  58. if not config_passwd:
  59. raise orm.except_orm(
  60. 'Missing configuration key',
  61. "'admin_passwd' configuration key "
  62. "(aka 'Master Password') is not set in \n"
  63. "your Odoo server configuration file: "
  64. "please set it a value")
  65. if elm.password != config_passwd:
  66. raise orm.except_orm(
  67. "Password Error",
  68. "Issue\n_____\nProvided password '%s' doesn't match with "
  69. "'Master Password' ('admin_passwd' key) found in the "
  70. "Odoo server configuration file ."
  71. "\n\nResolution\n__________\n"
  72. "Please check your password and retry or cancel"
  73. % elm.password)
  74. context['uninstall_authorized'] = True
  75. module_id = context.get('module_id')
  76. self.pool['ir.module.module'].button_uninstall(
  77. cr, uid, [module_id], context=context)
  78. return True