From a00ba036048f1c7b1187553e49bd0e1991d80e57 Mon Sep 17 00:00:00 2001 From: odex Date: Thu, 11 Jul 2024 12:13:55 +0300 Subject: [PATCH] fix api 001 --- .../rest_api_v2/firebase_notifications.py | 20 ++++++----- .../controllers/rest_api_v2/leave.py | 1 + .../models/firebase_notification.py | 2 +- .../models/hr_firebase_notification.py | 2 +- .../odex_mobile/models/res_partner.py | 2 -- .../controllers/controllers.py | 36 +++++++++++++------ 6 files changed, 40 insertions(+), 23 deletions(-) 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 b78f88a1a..f2d6caf6f 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 @@ -18,7 +18,7 @@ _logger = logging.getLogger(__name__) class NotificationController(http.Controller): - @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 @@ -41,7 +41,7 @@ class NotificationController(http.Controller): # partner_ids # search([('partner_ids','in',user.partner_id.id)]) # - domain = [("sent", "=", True),'&',("is_system", "=", True),('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 = [] pager = request.website.pager( @@ -54,11 +54,10 @@ class NotificationController(http.Controller): records = user.env['firebase.notification'].search(domain).search( domain, limit=20, offset=pager['offset']) - for res in records: notifications.append({ 'notification':{"title":res.title, - "body": res.body,}, + "body": res.body, }, "id":res.id, "title":res.title, "body": res.body, @@ -66,7 +65,9 @@ class NotificationController(http.Controller): "sent": res.sent, "viewed": res.viewed, "meta": res.meta, - "data": res.iso_date, +"write_date": str(res.write_date), + "iso_date": str(res.iso_date), + "create_date": str(res.create_date), "uuid": res.uid, }) prev = pager['page_previous']['url'] @@ -126,10 +127,11 @@ class NotificationController(http.Controller): "sent": res.sent, "viewed": res.viewed, "meta": res.meta, - "data": str(res.create_date), + "write_date": str(res.write_date), + "iso_date": str(res.iso_date), + "create_date": str(res.create_date), "uuid": res.uid, }) - values = { 'links': None, @@ -202,7 +204,7 @@ class NotificationController(http.Controller): # security check done successfully # - domain = [("sent", "=", True),'&',("is_system", "=", True),('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).unlink() values = { @@ -212,4 +214,4 @@ class NotificationController(http.Controller): }, "count": None, } - return http_helper.response(message="Delete successfully", data=values) \ No newline at end of file + return http_helper.response(message="Delete successfully", data=values) diff --git a/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py b/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py index 1a79f5075..def52f682 100644 --- a/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py +++ b/odex25_mobile/odex_mobile/controllers/rest_api_v2/leave.py @@ -232,6 +232,7 @@ class LeaveController(http.Controller): 'res_id': holidays.id, }) if holidays: + # holidays.confirm() holidays.number_of_days_temp = holidays._get_number_of_days(body['start_date'], body['end_date'], employee) data = self.get_return_data(holidays) diff --git a/odex25_mobile/odex_mobile/models/firebase_notification.py b/odex25_mobile/odex_mobile/models/firebase_notification.py index 0bcebe393..a2d4c2386 100644 --- a/odex25_mobile/odex_mobile/models/firebase_notification.py +++ b/odex25_mobile/odex_mobile/models/firebase_notification.py @@ -56,7 +56,7 @@ class FirebaseNotification(models.Model): #@api.multi def send(self, **kwargs): - print("**********************************************") + # print("**********************************************") if kwargs is None: kwargs = {} for notif in self: diff --git a/odex25_mobile/odex_mobile/models/hr_firebase_notification.py b/odex25_mobile/odex_mobile/models/hr_firebase_notification.py index a6d8bb01d..668cbcefc 100644 --- a/odex25_mobile/odex_mobile/models/hr_firebase_notification.py +++ b/odex25_mobile/odex_mobile/models/hr_firebase_notification.py @@ -95,7 +95,7 @@ class HrHolidays(models.Model): }) } _logger.warning(type(data)) - _logger.warning(data) + # _logger.warning(data) if users: partner = users.mapped('partner_id') for part in partner: diff --git a/odex25_mobile/odex_mobile/models/res_partner.py b/odex25_mobile/odex_mobile/models/res_partner.py index edd28b51e..cce590859 100644 --- a/odex25_mobile/odex_mobile/models/res_partner.py +++ b/odex25_mobile/odex_mobile/models/res_partner.py @@ -22,8 +22,6 @@ class Partner(models.Model): "sent": True, } notification = self.env['firebase.notification'].sudo().create(notification_data) - print(notification) - print(notification_data) if all_device: for reg in self.firebase_registration_ids: reg.with_context(lang=self.lang).send_message( diff --git a/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py b/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py index 50c57f523..233cae2f8 100644 --- a/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py +++ b/odex25_mobile/odoo_dynamic_workflow_mobile/controllers/controllers.py @@ -16,13 +16,8 @@ NODE = "workflow.mobile.node" # filtered_domain # mapped class RestApi(Controller): - @route( - ["/rest_api/workflows/", "/rest_api/workflow/", "/workflows/", "/workflow/"], - type="http", - auth="none", - method=["GET"], - csrf=False, - ) + + @route(["/rest_api/workflows/", "/rest_api/workflow/", "/workflows/", "/workflow/"], type="http", auth="none", method=["GET"], csrf=False,) def get_all_workflow(self, mobile_id=None, **kw): try: http_method, body, headers, token = http_helper.parse_request() @@ -85,7 +80,7 @@ class RestApi(Controller): @route([ "/rest_api/workflow/record_btns//", - "/workflow/record_btns//",], + "/workflow/record_btns//", ], type="http", auth="none", method=["GET"], @@ -206,7 +201,7 @@ class RestApi(Controller): @route( [ "/rest_api/workflow/execute_btn//", - "/workflow/execute_btn//",], + "/workflow/execute_btn//", ], type="http", auth="none", method=["GET"], @@ -263,7 +258,11 @@ class RestApi(Controller): [], ) ) - users = btn_new.mapped("group_ids").mapped("users") or None + group_ids = btn_new.mapped("group_ids") + users = group_ids.mapped("users") or None + print("***************************************users", users) + users_list = self.access_users(group_ids, btn) + print("***************************************users_list", users_list) if reject_reason: obj.write({"reason": reject_reason}) obj.firebase_notification(users) @@ -274,3 +273,20 @@ class RestApi(Controller): return http_helper.response(code=400, message=str(error), success=False) except Exception as e: return http_helper.response_500(str(e)) + + def has_access(self, user_id, record, mode='read'): + try: + access = record.with_user(user_id).check_access_rule(mode) + print("-----------------------",access) + return True + except: + return False + + def access_users(self, groups, record): + users = [] + print(groups,record) + for group in groups: + for user in group.users: + if self.has_access(user_id=user.id, record=record, mode='read'): + users.append(user) + return users