main.py 982 B

123456789101112131415161718192021222324
  1. # -*- coding: utf-8 -*-
  2. import functools
  3. from odoo import _
  4. from odoo.exceptions import AccessError
  5. from odoo.http import Controller, route, request, Response
  6. class ImportModule(Controller):
  7. @route(
  8. '/base_import_module/login_upload',
  9. type='http', auth='none', methods=['POST'], csrf=False, save_session=False)
  10. def login_upload(self, login, password, force='', mod_file=None, **kw):
  11. try:
  12. if not request.db:
  13. raise Exception(_("Could not select database '%s'", request.db))
  14. request.session.authenticate(request.db, login, password)
  15. # request.uid is None in case of MFA
  16. if request.uid and request.env.user._is_admin():
  17. return request.env['ir.module.module'].import_zipfile(mod_file, force=force == '1')[0]
  18. raise AccessError(_("Only administrators can upload a module"))
  19. except Exception as e:
  20. return Response(response=str(e), status=500)