Skip to content

Commit

Permalink
Merge pull request #5001 from bcgov/main-DV-4707
Browse files Browse the repository at this point in the history
quick fix to dismiss notification issue
  • Loading branch information
divyav-aot authored Jan 16, 2024
2 parents 5d51fd5 + 4082abb commit 9463ba1
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion notification-manager/common/notificationusertypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"name": "Triggered User",
"description": "Triggered User",
"isactive": true,
"notificationusertypelabel": "triggereduser"
"notificationusertypelabel": "assignee"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions request-management-api/common/notificationusertypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ 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):
notifications = []
try:
sql = """select notificationid, count(1) as relcount from "FOIRawRequestNotificationUsers" frnu
Expand Down

0 comments on commit 9463ba1

Please sign in to comment.