diff --git a/notification-manager/notification_api/dao/models/FOIRequestNotificationUsers.py b/notification-manager/notification_api/dao/models/FOIRequestNotificationUsers.py index 43e4b57c2..df9bd1737 100644 --- a/notification-manager/notification_api/dao/models/FOIRequestNotificationUsers.py +++ b/notification-manager/notification_api/dao/models/FOIRequestNotificationUsers.py @@ -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: diff --git a/notification-manager/notification_api/services/notificationservice.py b/notification-manager/notification_api/services/notificationservice.py index b4991df83..29d793ae3 100644 --- a/notification-manager/notification_api/services/notificationservice.py +++ b/notification-manager/notification_api/services/notificationservice.py @@ -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) diff --git a/request-management-api/request_api/services/notificationservice.py b/request-management-api/request_api/services/notificationservice.py index 0ba52ede2..cc32ecc5d 100644 --- a/request-management-api/request_api/services/notificationservice.py +++ b/request-management-api/request_api/services/notificationservice.py @@ -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"] @@ -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: @@ -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"])