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.

43 lines
1.4 KiB

  1. # Copyright 2018 Tecnativa - Jairo Llopis
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from datetime import datetime
  4. from werkzeug.exceptions import NotFound
  5. from odoo.http import Controller, request, route
  6. class ConsentController(Controller):
  7. @route(
  8. "/privacy/consent/<any(accept,reject):choice>/<int:consent_id>/<token>",
  9. type="http",
  10. auth="public",
  11. website=True,
  12. )
  13. def consent(self, choice, consent_id, token, *args, **kwargs):
  14. """Process user's consent acceptance or rejection."""
  15. consent = (
  16. request.env["privacy.consent"]
  17. .with_context(subject_answering=True)
  18. .sudo()
  19. .browse(consent_id)
  20. )
  21. if not (consent.exists() and consent._token() == token):
  22. raise NotFound
  23. if consent.partner_id.lang:
  24. consent = consent.with_context(lang=consent.partner_id.lang)
  25. request.context = consent.env.context
  26. consent.action_answer(choice == "accept", self._metadata())
  27. return request.render("privacy_consent.form", {"consent": consent})
  28. def _metadata(self):
  29. return (
  30. u"User agent: {}\n"
  31. u"Remote IP: {}\n"
  32. u"Date and time: {:%Y-%m-%d %H:%M:%S}"
  33. ).format(
  34. request.httprequest.environ.get("HTTP_USER_AGENT"),
  35. request.httprequest.environ.get("REMOTE_ADDRESS"),
  36. datetime.now(),
  37. )