Skip to content

Commit

Permalink
Merge pull request #4800 from bcgov/dev-RQ-4548
Browse files Browse the repository at this point in the history
Bug fix for issues with raw requests and notification manager
  • Loading branch information
richard-aot authored Nov 30, 2023
2 parents 9c95a66 + af5aa29 commit 96bf970
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def savenotificationuser(self, notificationuser):
conn = getconnection()
cursor = conn.cursor()
cursor.execute('INSERT INTO public."FOIRequestNotificationUsers" (notificationid, userid, notificationusertypeid, createdby, created_at, isdeleted) \
VALUES(%s::integer, %s, %s::integer, %s, %s, %i)',
(int(notificationuser.notificationid), str(notificationuser.userid), int(notificationuser.notificationusertypeid), str(notificationuser.createdby), datetime.now(), notificationuser.isdeleted))
VALUES(%s::integer, %s, %s::integer, %s, %s, %s::boolean)',
(int(notificationuser.notificationid), str(notificationuser.userid), int(notificationuser.notificationusertypeid), str(notificationuser.createdby), datetime.now(), int(notificationuser.isdeleted)))
conn.commit()
cursor.close()
except(Exception) as error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ def createnotification(self, requesttype, requestid, message, notificationtype,
notificationid = self.__createnotification(message, requesttype, notificationtype, userid, foirequest)

#mute notifications for ministry users
mutenotification = self.__mutenotification(requesttype, notificationtype, foirequest)
ministryusers = []
usergroupfromkeycloak = KeycloakAdminService().getmembersbygroupname(foirequest["assignedministrygroup"])
if usergroupfromkeycloak is not None and len(usergroupfromkeycloak) > 0:
for user in usergroupfromkeycloak[0].get("members"):
ministryusers.append(user["username"])
if requesttype == "ministryrequest":
mutenotification = self.__mutenotification(requesttype, notificationtype, foirequest)
usergroupfromkeycloak = KeycloakAdminService().getmembersbygroupname(foirequest["assignedministrygroup"])
if usergroupfromkeycloak is not None and len(usergroupfromkeycloak) > 0:
for user in usergroupfromkeycloak[0].get("members"):
ministryusers.append(user["username"])
else:
mutenotification = False

#Create notification users
return self.__createnotificationusers(requesttype, notificationid, notificationusers, userid, mutenotification, ministryusers)
Expand Down
22 changes: 13 additions & 9 deletions request-management-api/request_api/services/notificationservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,24 @@ def __getnotificationtypefromid(self, idnumber):
return 'rawrequest' if idnumber.lower().startswith('u-00') else 'ministryrequest'

def __preparenotification(self, message, requesttype, notificationtype, userid, foirequest, requestjson=None):
ministryusers = []
if requesttype == "ministryrequest":
notification = FOIRequestNotification()
notification.requestid = foirequest["foiministryrequestid"]
notification.idnumber = foirequest["filenumber"]
notification.foirequestid = foirequest["foirequest_id"]

#mute notifications for ministry users
mutenotification = self.__mutenotification(requesttype, notificationtype, foirequest)
usergroupfromkeycloak = KeycloakAdminService().getmembersbygroupname(foirequest["assignedministrygroup"])
if usergroupfromkeycloak is not None and len(usergroupfromkeycloak) > 0:
for user in usergroupfromkeycloak[0].get("members"):
ministryusers.append(user["username"])
else:
notification = FOIRawRequestNotification()
notification.requestid = foirequest["requestid"]
notification.idnumber ='U-00' + str(foirequest['requestid'])
mutenotification = False

notification.notificationtypeid = notificationconfig().getnotificationtypeid(notificationtype)
notification.axisnumber = foirequest["axisrequestid"]
Expand All @@ -271,14 +280,6 @@ def __preparenotification(self, message, requesttype, notificationtype, userid,
notification.notification = message
notification.isdeleted = False

#mute notifications for ministry users
mutenotification = self.__mutenotification(requesttype, notificationtype, foirequest)
ministryusers = []
usergroupfromkeycloak = KeycloakAdminService().getmembersbygroupname(foirequest["assignedministrygroup"])
if usergroupfromkeycloak is not None and len(usergroupfromkeycloak) > 0:
for user in usergroupfromkeycloak[0].get("members"):
ministryusers.append(user["username"])

notificationusers = notificationuser().getnotificationusers(notificationtype, requesttype, userid, foirequest, requestjson)
users = []
for _notificationuser in notificationusers:
Expand All @@ -301,9 +302,12 @@ def __preparenotificationuser(self, requesttype, notificationuser, userid, mute=
user.createdby = userid
return user

def __mutenotification(self, requesttype, notificationtype, request=None):
def __mutenotification(self, requesttype, notificationtype, request):
#get mute conditions from env
mutenotifications = notificationconfig().getmutenotifications()
if "programarea.bcgovcode" in request:
return False

bcgovcode = request["programarea.bcgovcode"].upper()
if requesttype == "ministryrequest"and bcgovcode in mutenotifications:
foirequest = FOIRequest.getrequest(request["foirequest_id"])
Expand Down

0 comments on commit 96bf970

Please sign in to comment.