diff --git a/odex25_mobile/odex_mobile/controllers/rest_api_v2/firebase_notifications.py b/odex25_mobile/odex_mobile/controllers/rest_api_v2/firebase_notifications.py index 8cd4ebc24..9096ee7ba 100644 --- a/odex25_mobile/odex_mobile/controllers/rest_api_v2/firebase_notifications.py +++ b/odex25_mobile/odex_mobile/controllers/rest_api_v2/firebase_notifications.py @@ -1,55 +1,28 @@ import json from odoo import http from odoo.http import request -from odoo.addons.website.controllers.main import Website from odoo.tools.translate import _ -from odoo import models, fields -from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT -import pytz -from datetime import datetime -# Local modules +from odoo import fields from ...http_helper import http_helper -from ...data_util import data_util from ...validator import validator -# from odoo.addons.odex_mobile.validator import validator -# from odoo.addons.odex_mobile.http_helper import http_helper -# from odoo.addons.odex_mobile.data_util import data_util - -import logging -_logger = logging.getLogger(__name__) class NotificationController(http.Controller): - def convert_to_user_timezone(self, datetime_utc): + def convert_to_user_timezone(self, datetime_utc): datetime_user_tz = fields.Datetime.context_timestamp(request, fields.Datetime.from_string(datetime_utc)) return fields.Datetime.to_string(datetime_user_tz) - - @http.route(['/rest_api/v2/notifications/', '/rest_api/v2/notifications/page/'], type='http', auth='none', csrf=False, methods=['GET'], website=True) + @http.route(['/rest_api/v2/notifications/', '/rest_api/v2/notifications/page/'], type='http', auth='none', csrf=False, methods=['GET'] ,website='true') def index(self, page=1, **kw): - """ - fetch notifications - """ - - # Security check, parse http request, to get body, header, user token _, body, __, token = http_helper.parse_request() - - # Check token validate result = validator.verify_token(token) if not result.get('status', False): return http_helper.errcode(code=result['code'], message=result['message']) - # extract user from token user = validator.verify(token) if not user: return http_helper.response(code=400, message="You are not allowed to perform this operation. please check with one of your team admins", success=False) - - # security check done successfully - # - # partner_ids - # search([('partner_ids','in',user.partner_id.id)]) - # domain = [("sent", "=", True), '&', ("is_system", "=", True), ('partner_ids', 'in', user.partner_id.id)] ids = user.env['firebase.notification'].search(domain, order="create_date desc") notifications = [] @@ -96,30 +69,16 @@ class NotificationController(http.Controller): } return http_helper.response(message="Notifications found", data=values) - @http.route(['/rest_api/v2/notifications/'], type='http', auth='none', csrf=False, methods=['PATCH'], website=True) + @http.route(['/rest_api/v2/notifications/'], type='http', auth='none', csrf=False, methods=['PATCH']) def open_view(self, notif=None, **kw): - """ - Update stop - return Bad content if route not found or state invalid - """ - - # Security check, parse http request, to get body, header, user token _, body, __, token = http_helper.parse_request() - - # Check token validate result = validator.verify_token(token) if not result.get('status', False): return http_helper.errcode(code=result['code'], message=result['message']) - # extract user from token user = validator.verify(token) if not user: return http_helper.response(code=400, message="You are not allowed to perform this operation. please check with one of your team admins", success=False) - - # security check done successfully - # - notifications = [] - res = user.env['firebase.notification'].search([('id', '=', notif)]) if not res: return http_helper.response(code=400, @@ -150,30 +109,15 @@ class NotificationController(http.Controller): } return http_helper.response(message="Notification found", data=values) - @http.route(['/rest_api/v2/notifications/'], type='http', auth='none', csrf=False, methods=['DELETE'], website=True) + @http.route(['/rest_api/v2/notifications/'], type='http', auth='none', csrf=False, methods=['DELETE']) def delete_notification(self, notif=None, **kw): - """ - Update stop - return Bad content if route not found or state invalid - """ - - # Security check, parse http request, to get body, header, user token _, body, __, token = http_helper.parse_request() - - # Check token validate result = validator.verify_token(token) if not result.get('status', False): return http_helper.errcode(code=result['code'], message=result['message']) - # extract user from token user = validator.verify(token) if not user: return http_helper.response(code=400, message="You are not allowed to perform this operation. please check with one of your team admins", success=False) - - # security check done successfully - # - - notifications = [] - res = user.env['firebase.notification'].search([('id', '=', notif)]) if not res: return http_helper.response(code=400, @@ -190,31 +134,17 @@ class NotificationController(http.Controller): } return http_helper.response(message="Delete successfully", data=values) - @http.route(['/rest_api/v2/notifications/reset/'], type='http', auth='none', csrf=False, methods=['DELETE'], website=True) + @http.route(['/rest_api/v2/notifications/reset/'], type='http', auth='none', csrf=False, methods=['DELETE']) def reset(self, **kw): - """ - Update stop - return Bad content if route not found or state invalid - """ - - # Security check, parse http request, to get body, header, user token _, body, __, token = http_helper.parse_request() - - # Check token validate result = validator.verify_token(token) if not result.get('status', False): return http_helper.errcode(code=result['code'], message=result['message']) - # extract user from token user = validator.verify(token) if not user: return http_helper.response(code=400, message="You are not allowed to perform this operation. please check with one of your team admins", success=False) - - # security check done successfully - # - domain = [("sent", "=", True), '&', ("is_system", "=", True), ('partner_ids', 'in', user.partner_id.id)] ids = user.env['firebase.notification'].search(domain).unlink() - values = { 'links': None, 'results': {