main.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import odoo.http as http
  4. from odoo.http import request
  5. from odoo.tools.misc import get_lang
  6. class CalendarController(http.Controller):
  7. # YTI Note: Keep id and kwargs only for retrocompatibility purpose
  8. @http.route('/calendar/meeting/accept', type='http', auth="calendar")
  9. def accept_meeting(self, token, id, **kwargs):
  10. attendee = request.env['calendar.attendee'].sudo().search([
  11. ('access_token', '=', token),
  12. ('state', '!=', 'accepted')])
  13. attendee.do_accept()
  14. return self.view_meeting(token, id)
  15. @http.route('/calendar/recurrence/accept', type='http', auth="calendar")
  16. def accept_recurrence(self, token, id, **kwargs):
  17. attendee = request.env['calendar.attendee'].sudo().search([
  18. ('access_token', '=', token),
  19. ('state', '!=', 'accepted')])
  20. if attendee:
  21. attendees = request.env['calendar.attendee'].sudo().search([
  22. ('event_id', 'in', attendee.event_id.recurrence_id.calendar_event_ids.ids),
  23. ('partner_id', '=', attendee.partner_id.id),
  24. ('state', '!=', 'accepted'),
  25. ])
  26. attendees.do_accept()
  27. return self.view_meeting(token, id)
  28. @http.route('/calendar/meeting/decline', type='http', auth="calendar")
  29. def decline_meeting(self, token, id, **kwargs):
  30. attendee = request.env['calendar.attendee'].sudo().search([
  31. ('access_token', '=', token),
  32. ('state', '!=', 'declined')])
  33. attendee.do_decline()
  34. return self.view_meeting(token, id)
  35. @http.route('/calendar/recurrence/decline', type='http', auth="calendar")
  36. def decline_recurrence(self, token, id, **kwargs):
  37. attendee = request.env['calendar.attendee'].sudo().search([
  38. ('access_token', '=', token),
  39. ('state', '!=', 'declined')])
  40. if attendee:
  41. attendees = request.env['calendar.attendee'].sudo().search([
  42. ('event_id', 'in', attendee.event_id.recurrence_id.calendar_event_ids.ids),
  43. ('partner_id', '=', attendee.partner_id.id),
  44. ('state', '!=', 'declined'),
  45. ])
  46. attendees.do_decline()
  47. return self.view_meeting(token, id)
  48. @http.route('/calendar/meeting/view', type='http', auth="calendar")
  49. def view_meeting(self, token, id, **kwargs):
  50. attendee = request.env['calendar.attendee'].sudo().search([
  51. ('access_token', '=', token),
  52. ('event_id', '=', int(id))])
  53. if not attendee:
  54. return request.not_found()
  55. timezone = attendee.partner_id.tz
  56. lang = attendee.partner_id.lang or get_lang(request.env).code
  57. event = request.env['calendar.event'].with_context(tz=timezone, lang=lang).sudo().browse(int(id))
  58. company = event.user_id and event.user_id.company_id or event.create_uid.company_id
  59. # If user is internal and logged, redirect to form view of event
  60. # otherwise, display the simplifyed web page with event informations
  61. if request.session.uid and request.env['res.users'].browse(request.session.uid).user_has_groups('base.group_user'):
  62. return request.redirect('/web?db=%s#id=%s&view_type=form&model=calendar.event' % (request.env.cr.dbname, id))
  63. # NOTE : we don't use request.render() since:
  64. # - we need a template rendering which is not lazy, to render before cursor closing
  65. # - we need to display the template in the language of the user (not possible with
  66. # request.render())
  67. response_content = request.env['ir.ui.view'].with_context(lang=lang)._render_template(
  68. 'calendar.invitation_page_anonymous', {
  69. 'company': company,
  70. 'event': event,
  71. 'attendee': attendee,
  72. })
  73. return request.make_response(response_content, headers=[('Content-Type', 'text/html')])
  74. @http.route('/calendar/meeting/join', type='http', auth="user", website=True)
  75. def calendar_join_meeting(self, token, **kwargs):
  76. event = request.env['calendar.event'].sudo().search([
  77. ('access_token', '=', token)])
  78. if not event:
  79. return request.not_found()
  80. event.action_join_meeting(request.env.user.partner_id.id)
  81. attendee = request.env['calendar.attendee'].sudo().search([('partner_id', '=', request.env.user.partner_id.id), ('event_id', '=', event.id)])
  82. return request.redirect('/calendar/meeting/view?token=%s&id=%s' % (attendee.access_token, event.id))
  83. # Function used, in RPC to check every 5 minutes, if notification to do for an event or not
  84. @http.route('/calendar/notify', type='json', auth="user")
  85. def notify(self):
  86. return request.env['calendar.alarm_manager'].get_next_notif()
  87. @http.route('/calendar/notify_ack', type='json', auth="user")
  88. def notify_ack(self):
  89. return request.env['res.partner'].sudo()._set_calendar_last_notif_ack()
  90. @http.route('/calendar/join_videocall/<string:access_token>', type='http', auth='public')
  91. def calendar_join_videocall(self, access_token):
  92. event = request.env['calendar.event'].sudo().search([('access_token', '=', access_token)])
  93. if not event:
  94. return request.not_found()
  95. # if channel doesn't exist
  96. if not event.videocall_channel_id:
  97. event._create_videocall_channel()
  98. return request.redirect(event.videocall_channel_id.invitation_url)