From eb87fd7274fe7750cd6bc68ea812e298ca04e920 Mon Sep 17 00:00:00 2001 From: divyav-aot Date: Tue, 16 Jan 2024 16:13:44 -0500 Subject: [PATCH 1/3] fix for dismiss notification raw request --- .../request_api/models/FOIRawRequestNotificationUsers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py b/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py index 2f114310d..3533c4aab 100644 --- a/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py +++ b/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py @@ -96,10 +96,10 @@ def getnotificationsbyuser(cls, userid): return notifications @classmethod - def getnotificationsbyuserandtype(cls, userid, typeid): - for key in notificationusertypes_cache: - if (notificationusertypes_cache[key].notificationusertypeid == typeid) or (notificationusertypes_cache[key].notificationusertypelabel == typeid): - notificationusertypelabel = notificationusertypes_cache[key].notificationusertypelabel + def getnotificationsbyuserandtype(cls, userid, notificationusertypelabel): + # for key in notificationusertypes_cache: + # if (notificationusertypes_cache[key].notificationusertypeid == typeid) or (notificationusertypes_cache[key].notificationusertypelabel == typeid): + # notificationusertypelabel = notificationusertypes_cache[key].notificationusertypelabel notifications = [] try: sql = """select notificationid, count(1) as relcount from "FOIRawRequestNotificationUsers" frnu From a847723ced990a7c7d197cd141e90f84e01e799c Mon Sep 17 00:00:00 2001 From: divyav-aot Date: Tue, 16 Jan 2024 18:07:48 -0500 Subject: [PATCH 2/3] dismiss notification related to tagged comments and triggered user is fixed --- .../common/notificationusertypes.json | 2 +- .../dao/models/NotificationUserTypes.py | 20 +++++++++++ .../notifications/notificationconfig.py | 33 ++++++++++++++----- .../notifications/notificationuser.py | 10 +++--- .../services/notificationservice.py | 8 ++--- .../common/notificationusertypes.json | 4 +-- 6 files changed, 57 insertions(+), 20 deletions(-) diff --git a/notification-manager/common/notificationusertypes.json b/notification-manager/common/notificationusertypes.json index 0ea835c44..0964c4f59 100644 --- a/notification-manager/common/notificationusertypes.json +++ b/notification-manager/common/notificationusertypes.json @@ -25,6 +25,6 @@ "name": "Triggered User", "description": "Triggered User", "isactive": true, - "notificationusertypelabel": "triggereduser" + "notificationusertypelabel": "assignee" } } diff --git a/notification-manager/notification_api/dao/models/NotificationUserTypes.py b/notification-manager/notification_api/dao/models/NotificationUserTypes.py index ae06e67f6..99bd7be46 100644 --- a/notification-manager/notification_api/dao/models/NotificationUserTypes.py +++ b/notification-manager/notification_api/dao/models/NotificationUserTypes.py @@ -26,3 +26,23 @@ def getid(self, name): finally: if conn: conn.close() + + def getidbylabel(self, label): + conn = None + try: + _notificationusertypes = [] + conn = getconnection() + cursor = conn.cursor() + cursor.execute("""select notificationusertypeid from "NotificationUserTypes" nt where isactive = true and notificationusertypelabel = '{0}'""".format(label)) + data = cursor.fetchone() + if data is not None: + data = {"notificationusertypeid": data[0]} + return data + + cursor.close() + return _notificationusertypes + except(Exception) as error: + logging.error(error) + finally: + if conn: + conn.close() diff --git a/notification-manager/notification_api/services/notifications/notificationconfig.py b/notification-manager/notification_api/services/notifications/notificationconfig.py index 6b18da016..215a969b0 100644 --- a/notification-manager/notification_api/services/notifications/notificationconfig.py +++ b/notification-manager/notification_api/services/notifications/notificationconfig.py @@ -5,32 +5,47 @@ import os from notification_api.dao.models.NotificationTypes import NotificationType from notification_api.dao.models.NotificationUserTypes import NotificationUserType +notificationuserfile = open('common/notificationusertypes.json', encoding="utf8") +notificationusertypes_cache = json.load(notificationuserfile) + +notificationfile = open('common/notificationtypes.json', encoding="utf8") +notificationtypes_cache = json.load(notificationfile) class notificationconfig: """ Notfication config """ - - def getnotificationtypeid(self, notificationtype): - notificationid = NotificationType().getid(notificationtype) - if notificationid is not None: - return notificationid - def getnotificationtype(self, notificationtype): notificationid = NotificationType().getid(notificationtype) if notificationid is not None: return notificationid - def getnotificationusertypeid(self, notificationusertype): + def getnotificationusertype(self, notificationusertype): notificationuserid = NotificationUserType().getid(notificationusertype) if notificationuserid is not None: return notificationuserid + - def getnotificationusertype(self, notificationusertype): - notificationuserid = NotificationUserType().getid(notificationusertype) + # This method is used to get the notification user type label + # It first tries to get the notification user type label from the cache + # If it is not found in the cache, it fetches it from the DB + def getnotificationusertypelabel(self, notificationusertype): + notificationusertype_format = notificationusertype.replace(" ", "").lower() + if notificationusertype_format in notificationusertypes_cache: + return notificationusertypes_cache[notificationusertype_format]['notificationusertypelabel'] + else: + print("Notification user type not found in json. Fetching from DB", notificationusertype) + notificationusertypeobj = self.getnotificationusertype(notificationusertype) + if notificationusertypeobj is not None: + return notificationusertypeobj['notificationusertypelabel'] + return None + + def getnotificationusertypeidbylabel(self, label): + notificationuserid = NotificationUserType().getidbylabel(label) if notificationuserid is not None: return notificationuserid + def getnotificationdays(self): if 'FOI_NOTIFICATION_DAYS' in os.environ and os.getenv('FOI_NOTIFICATION_DAYS') != '': return os.getenv('FOI_NOTIFICATION_DAYS') diff --git a/notification-manager/notification_api/services/notifications/notificationuser.py b/notification-manager/notification_api/services/notifications/notificationuser.py index 35341738f..24e99537c 100644 --- a/notification-manager/notification_api/services/notifications/notificationuser.py +++ b/notification-manager/notification_api/services/notifications/notificationuser.py @@ -53,22 +53,24 @@ def __istaggeduser(self, notificationuser, foicomment, notificationtype): def __gettriggereduser(self, userid, notificationtype): notificationusers = [] + notificationtypelabel = "assignee" if notificationtype in ["Records", "PDFStitch"]: - notificationusers.append({"userid":userid, "usertype":notificationconfig().getnotificationusertype("Triggered User")['notificationusertypelabel']}) + notificationusers.append({"userid":userid, "usertype":notificationtypelabel}) return notificationusers def __getwatchers(self, notificationtype, foirequest, requesttype, requestjson=None): notificationusers = [] - if notificationtype == "Watcher": - notificationusers.append({"userid": requestjson['watchedby'], "usertype":notificationconfig().getnotificationusertype("Watcher")['notificationusertypelabel']}) + notificationtypelabel = "watcher" + if notificationtype == "Watcher": + notificationusers.append({"userid": requestjson['watchedby'], "usertype":notificationtypelabel}) else: if requesttype == "ministryrequest": watchers = FOIMinistryRequest().getwatchers(foirequest["foiministryrequestid"]) else: watchers = FOIRawRequest().getwatchers(foirequest['requestid']) for watcher in watchers: - notificationusers.append({"userid":watcher["watchedby"], "usertype":notificationconfig().getnotificationusertype("Watcher")['notificationusertypelabel']}) + notificationusers.append({"userid":watcher["watchedby"], "usertype":notificationtypelabel}) return notificationusers def __getassignees(self, foirequest, requesttype, notificationtype, requestjson=None): diff --git a/notification-manager/notification_api/services/notificationservice.py b/notification-manager/notification_api/services/notificationservice.py index 3a9df645d..aa6fe43fe 100644 --- a/notification-manager/notification_api/services/notificationservice.py +++ b/notification-manager/notification_api/services/notificationservice.py @@ -87,10 +87,10 @@ def __preparenotificationuser(self, notificationid, notificationuser, userid, mu usertype = notificationusertypes_cache[notificationuser["usertype"]] if usertype is None: print('User type not found', notificationuser["usertype"]) - return None - notificationtypes = notificationconfig().getnotificationusertype(usertype['name']) - user.notificationusertypelabel = notificationtypes['notificationusertypelabel'] - user.notificationusertypeid = notificationtypes['notificationusertypeid'] + return None + notificationusertypelabel = notificationconfig().getnotificationusertypelabel(usertype['name']) + user.notificationusertypelabel = notificationusertypelabel + user.notificationusertypeid = notificationconfig().getnotificationusertypeidbylabel(notificationusertypelabel)['notificationusertypeid'] user.notificationid = notificationid user.userid = notificationuser["userid"] user.createdby = userid diff --git a/request-management-api/common/notificationusertypes.json b/request-management-api/common/notificationusertypes.json index 1048cc990..8efa082d3 100644 --- a/request-management-api/common/notificationusertypes.json +++ b/request-management-api/common/notificationusertypes.json @@ -46,13 +46,13 @@ "name": "comment tagged user", "description": "Comment User", "isactive": true, - "notificationusertypelabel": "commentuser" + "notificationusertypelabel": "assignee" }, "triggereduser": { "notificationusertypeid": 4, "name": "Triggered User", "description": "Triggered User", "isactive": true, - "notificationusertypelabel": "triggereduser" + "notificationusertypelabel": "assignee" } } From 4082abbe7576dae1004af2add9e9c7b1a250fe25 Mon Sep 17 00:00:00 2001 From: divyav-aot Date: Tue, 16 Jan 2024 18:09:38 -0500 Subject: [PATCH 3/3] removed commented lines --- .../request_api/models/FOIRawRequestNotificationUsers.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py b/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py index 3533c4aab..9d3b15523 100644 --- a/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py +++ b/request-management-api/request_api/models/FOIRawRequestNotificationUsers.py @@ -97,9 +97,6 @@ def getnotificationsbyuser(cls, userid): @classmethod def getnotificationsbyuserandtype(cls, userid, notificationusertypelabel): - # for key in notificationusertypes_cache: - # if (notificationusertypes_cache[key].notificationusertypeid == typeid) or (notificationusertypes_cache[key].notificationusertypelabel == typeid): - # notificationusertypelabel = notificationusertypes_cache[key].notificationusertypelabel notifications = [] try: sql = """select notificationid, count(1) as relcount from "FOIRawRequestNotificationUsers" frnu