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.

46 lines
1.7 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. from odoo.addons.web.controllers.main import ensure_db
  7. class ConsentController(Controller):
  8. @route("/privacy/consent/<any(accept,reject):choice>/"
  9. "<int:consent_id>/<token>",
  10. type="http", auth="none", website=True)
  11. def consent(self, choice, consent_id, token, *args, **kwargs):
  12. """Process user's consent acceptance or rejection."""
  13. ensure_db()
  14. try:
  15. # If there's a website, we need a user to render the template
  16. request.uid = request.website.user_id.id
  17. except AttributeError:
  18. # If there's no website, the default is OK
  19. pass
  20. consent = request.env["privacy.consent"] \
  21. .with_context(subject_answering=True) \
  22. .sudo().browse(consent_id)
  23. if not (consent.exists() and consent._token() == token):
  24. raise NotFound
  25. if consent.partner_id.lang:
  26. consent = consent.with_context(lang=consent.partner_id.lang)
  27. request.context = consent.env.context
  28. consent.action_answer(choice == "accept", self._metadata())
  29. return request.render("privacy_consent.form", {
  30. "consent": consent,
  31. })
  32. def _metadata(self):
  33. return (u"User agent: {}\n"
  34. u"Remote IP: {}\n"
  35. u"Date and time: {:%Y-%m-%d %H:%M:%S}").format(
  36. request.httprequest.environ.get("HTTP_USER_AGENT"),
  37. request.httprequest.environ.get("REMOTE_ADDRESS"),
  38. datetime.now(),
  39. )