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.

81 lines
3.3 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 'uninstall_authorized' in context:
  27. del context['uninstall_authorized']
  28. super(Module, self).button_uninstall(
  29. cr, uid, ids, context=context)
  30. return self._button_immediate_function(
  31. cr, uid, ids, self.button_uninstall, context=context)
  32. else:
  33. _, view_id = self.pool['ir.model.data'].get_object_reference(
  34. cr, uid, 'secure_uninstall', 'view_uninstall_wizard_form')
  35. return {
  36. 'view_id': view_id,
  37. 'view_mode': 'form',
  38. 'res_model': 'uninstall.check.wizard',
  39. 'context': {'module_id': ids[0]},
  40. 'name': "Uninstall Authorization",
  41. 'type': 'ir.actions.act_window',
  42. 'target': 'new',
  43. }
  44. class UninstallCheckWizard(orm.TransientModel):
  45. _name = 'uninstall.check.wizard'
  46. _columns = {
  47. 'password': fields.char(
  48. string='Password',
  49. help="'admin_passwd' value from Odoo configuration file")
  50. }
  51. def check_password(self, cr, uid, ids, context=None):
  52. for elm in self.browse(cr, uid, ids, context=context):
  53. config_passwd = config.get("admin_passwd")
  54. if not config_passwd:
  55. raise orm.except_orm(
  56. 'Missing configuration key',
  57. "'admin_passwd' configuration key is not set in "
  58. "your Odoo server configuration file: "
  59. "please set it a value")
  60. if elm.password != config_passwd:
  61. raise orm.except_orm(
  62. "Password Error",
  63. "Issue\n_____\nProvided password '%s' doesn't match with "
  64. "'admin_passwd' comes from your "
  65. "Odoo server configuration file."
  66. "\n\nResolution\n__________\n"
  67. "Please check your password and retry or cancel"
  68. % elm.password)
  69. context['uninstall_authorized'] = True
  70. module_id = context.get('module_id')
  71. self.pool['ir.module.module'].button_uninstall(
  72. cr, uid, [module_id], context=context)
  73. return True