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.

47 lines
1.7 KiB

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