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.

36 lines
1.2 KiB

7 years ago
7 years ago
7 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from uuid import uuid4
  5. from odoo import api, SUPERUSER_ID
  6. def migrate(cr, version):
  7. """Generate cookie keys for all users with MFA enabled and clean up."""
  8. env = api.Environment(cr, SUPERUSER_ID, {})
  9. user_model = env['res.users'].with_context(active_test=False)
  10. mfa_users = user_model.search([('mfa_enabled', '=', True)])
  11. for mfa_user in mfa_users:
  12. mfa_user.trusted_device_cookie_key = uuid4()
  13. # Clean up ir records for device model to prevent warnings
  14. removed_model = 'res.users.device'
  15. removed_model_record = env['ir.model'].search([
  16. ('model', '=', removed_model),
  17. ])
  18. removed_model_fields = removed_model_record.field_id
  19. removed_model_fields._prepare_update()
  20. env['ir.model.constraint'].search([
  21. ('model', '=', removed_model_record.id),
  22. ]).unlink()
  23. env['ir.model.data'].search([
  24. ('model', '=', 'ir.model'),
  25. ('res_id', '=', removed_model_record.id),
  26. ]).unlink()
  27. cr.execute(
  28. 'DELETE FROM ir_model WHERE model = %s',
  29. [removed_model],
  30. )