summaryrefslogtreecommitdiff
path: root/addons/microsoft_calendar/controllers
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/microsoft_calendar/controllers
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/microsoft_calendar/controllers')
-rw-r--r--addons/microsoft_calendar/controllers/__init__.py4
-rw-r--r--addons/microsoft_calendar/controllers/main.py50
2 files changed, 54 insertions, 0 deletions
diff --git a/addons/microsoft_calendar/controllers/__init__.py b/addons/microsoft_calendar/controllers/__init__.py
new file mode 100644
index 00000000..5d4b25db
--- /dev/null
+++ b/addons/microsoft_calendar/controllers/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import main
diff --git a/addons/microsoft_calendar/controllers/main.py b/addons/microsoft_calendar/controllers/main.py
new file mode 100644
index 00000000..5e10e6a2
--- /dev/null
+++ b/addons/microsoft_calendar/controllers/main.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import http
+from odoo.http import request
+from odoo.addons.microsoft_calendar.utils.microsoft_calendar import MicrosoftCalendarService
+
+
+class MicrosoftCalendarController(http.Controller):
+
+ @http.route('/microsoft_calendar/sync_data', type='json', auth='user')
+ def sync_data(self, model, **kw):
+ """ This route/function is called when we want to synchronize Odoo
+ calendar with Microsoft Calendar.
+ Function return a dictionary with the status : need_config_from_admin, need_auth,
+ need_refresh, success if not calendar_event
+ The dictionary may contains an url, to allow Odoo Client to redirect user on
+ this URL for authorization for example
+ """
+ if model == 'calendar.event':
+ MicrosoftCal = MicrosoftCalendarService(request.env['microsoft.service'])
+
+ # Checking that admin have already configured Microsoft API for microsoft synchronization !
+ client_id = request.env['ir.config_parameter'].sudo().get_param('microsoft_calendar_client_id')
+
+ if not client_id or client_id == '':
+ action_id = ''
+ if MicrosoftCal._can_authorize_microsoft(request.env.user):
+ action_id = request.env.ref('base_setup.action_general_configuration').id
+ return {
+ "status": "need_config_from_admin",
+ "url": '',
+ "action": action_id
+ }
+
+ # Checking that user have already accepted Odoo to access his calendar !
+ if not MicrosoftCal.is_authorized(request.env.user):
+ url = MicrosoftCal._microsoft_authentication_url(from_url=kw.get('fromurl'))
+ return {
+ "status": "need_auth",
+ "url": url
+ }
+ # If App authorized, and user access accepted, We launch the synchronization
+ need_refresh = request.env.user.sudo()._sync_microsoft_calendar(MicrosoftCal)
+ return {
+ "status": "need_refresh" if need_refresh else "no_new_event_from_microsoft",
+ "url": ''
+ }
+
+ return {"status": "success"}