res_users.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # BizzAppDev
  5. # Copyright (C) 2015-TODAY bizzappdev(<http://www.bizzappdev.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. import openerp
  22. from openerp import SUPERUSER_ID, api, models
  23. from openerp.tools import config
  24. DEVELOP = True
  25. TEST = False
  26. class res_users(models.Model):
  27. _inherit = 'res.users'
  28. @api.model
  29. def set_test_password(self):
  30. users = self.search([])
  31. for user in users:
  32. user.write({'password': 'Qw3r7y'})
  33. return True
  34. def __set_from_config_test(self, db):
  35. cr = openerp.registry(db).cursor()
  36. config_parameters = self.pool.get("ir.config_parameter")
  37. if DEVELOP:
  38. config_parameters.set_param(
  39. cr, SUPERUSER_ID, "develop", DEVELOP)
  40. if TEST:
  41. config_parameters.set_param(
  42. cr, SUPERUSER_ID, "test", TEST)
  43. if not config.get('test'):
  44. config['test'] = {}
  45. if not config.get('develop'):
  46. config['develop'] = {}
  47. if db not in config['test']:
  48. ir_config_val = self.pool.get("ir.config_parameter").get_param(
  49. cr, SUPERUSER_ID, "test", default=None)
  50. config['test'][db] = ir_config_val
  51. if db not in config['develop']:
  52. ir_config_val = self.pool.get("ir.config_parameter").get_param(
  53. cr, SUPERUSER_ID, "develop", default=None)
  54. config['develop'][db] = ir_config_val
  55. cr.close()
  56. def check(self, db, uid, passwd):
  57. self.__set_from_config_test(db)
  58. return super(res_users, self).check(db, uid, passwd)
  59. def authenticate(self, db, login, password, user_agent_env):
  60. self.__set_from_config_test(db)
  61. return super(res_users, self).authenticate(db, login, password,
  62. user_agent_env)
  63. res_users()
  64. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: