Files
odoo_source/addons/event/controllers/main.py
T
Alex Tuyls 0d7ef88299 [FIX] event: allow ics file with public user
If you register online on a free event, there is an
access rights error when trying to download the ICS file
if you are connectd with public user.

`if not event` part is pointless, if event cannot be resolved,
@http.route would return a 404 anyway.
`if not event.registration_ids` does not make sense from a
functional point of view: there is no problem in generating
an .ics file for a public event that has no registrations (yet)
and the button we use to generate the .ics file is displayed
after the registration anyway.

opw-2066847

closes odoo/odoo#37012

X-origin-commit: f4ca5897df9295b684bcbfcafd98fbde2f8bf673
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2019-09-17 13:33:08 +00:00

22 lines
806 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug.exceptions import NotFound
from odoo.http import Controller, request, route, content_disposition
class EventController(Controller):
@route(['''/event/<model("event.event", "[('state', 'in', ('confirm', 'done'))]"):event>/ics'''], type='http', auth="public")
def event_ics_file(self, event, **kwargs):
files = event._get_ics_file()
if not event.id in files:
return NotFound()
content = files[event.id]
return request.make_response(content, [
('Content-Type', 'application/octet-stream'),
('Content-Length', len(content)),
('Content-Disposition', content_disposition('%s.ics' % event.name))
])