From 11ce31307fecf7b10feb7c6389878782a73052f0 Mon Sep 17 00:00:00 2001 From: Richard Qi Date: Mon, 27 Nov 2023 15:58:53 -0800 Subject: [PATCH 1/2] mute notifications for mcf #4548 --- .../notifications/notificationconfig.py | 8 +++- .../services/notificationservice.py | 44 +++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/request-management-api/request_api/services/notifications/notificationconfig.py b/request-management-api/request_api/services/notifications/notificationconfig.py index 522ba1749..c21b0b5c0 100644 --- a/request-management-api/request_api/services/notifications/notificationconfig.py +++ b/request-management-api/request_api/services/notifications/notificationconfig.py @@ -57,4 +57,10 @@ def getnotificationdays(self): if 'FOI_NOTIFICATION_DAYS' in os.environ and os.getenv('FOI_NOTIFICATION_DAYS') != '': return os.getenv('FOI_NOTIFICATION_DAYS') else: - return str(14) \ No newline at end of file + return str(14) + + def getmutenotifications(self): + if 'MUTE_NOTIFICATION' in os.environ: + return json.loads(os.getenv('MUTE_NOTIFICATION')) + else: + return {} \ No newline at end of file diff --git a/request-management-api/request_api/services/notificationservice.py b/request-management-api/request_api/services/notificationservice.py index ad9ac7469..09dc6e1a1 100644 --- a/request-management-api/request_api/services/notificationservice.py +++ b/request-management-api/request_api/services/notificationservice.py @@ -8,6 +8,7 @@ from request_api.services.notifications.notificationuser import notificationuser from request_api.models.FOIRawRequests import FOIRawRequest from request_api.models.FOIMinistryRequests import FOIMinistryRequest +from request_api.models.FOIRequests import FOIRequest from request_api.models.FOIRequestNotifications import FOIRequestNotification from request_api.models.FOIRequestNotificationUsers import FOIRequestNotificationUser from request_api.models.FOIRawRequestNotifications import FOIRawRequestNotification @@ -269,24 +270,59 @@ def __preparenotification(self, message, requesttype, notificationtype, userid, notification.createdby = 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: - users.append(self.__preparenotificationuser(requesttype, _notificationuser, userid)) + users.append(self.__preparenotificationuser(requesttype, _notificationuser, userid, mutenotification, ministryusers)) notification.notificationusers = users return notification if users else None - def __preparenotificationuser(self, requesttype, notificationuser, userid): + def __preparenotificationuser(self, requesttype, notificationuser, userid, mute=False, ministryusers=[]): if requesttype == "ministryrequest": user = FOIRequestNotificationUser() + if notificationuser["userid"] in ministryusers: + user.isdeleted = mute + else: + user.isdeleted = False else: user = FOIRawRequestNotificationUser() + user.isdeleted = False user.notificationusertypeid = notificationuser["usertype"] user.userid = notificationuser["userid"] user.createdby = userid - user.isdeleted = False return user - + + def __mutenotification(self, requesttype, notificationtype, request=None): + #get mute conditions from env + mutenotifications = notificationconfig().getmutenotifications() + if requesttype == "ministryrequest": + if mutenotifications is not None and len(mutenotifications) > 0: + if mutenotifications[request["programarea.bcgovcode"].upper()] is not None: + foirequest = FOIRequest.getrequest(request["foirequest_id"]) + if foirequest["requesttype"].upper() in (_requesttype.upper() for _requesttype in mutenotifications[request["programarea.bcgovcode"].upper()]["request_types"]): + if request["requeststatus.name"].upper() in (_state.upper() for _state in mutenotifications[request["programarea.bcgovcode"].upper()]["state_exceptions"]): + return False + if notificationtype.upper() in (_notificationtype.upper() for _notificationtype in mutenotifications[request["programarea.bcgovcode"].upper()]["type_exceptions"]): + return False + return True + else: + return False + else: + return False + else: + return False + else: + return False + def getrequest(self, requestid, requesttype): if requesttype == "ministryrequest": return FOIMinistryRequest.getrequestbyministryrequestid(requestid) From 9a3e59f1687ebdca20fb3dc80e6911671d5c0693 Mon Sep 17 00:00:00 2001 From: Richard Qi Date: Mon, 27 Nov 2023 16:00:09 -0800 Subject: [PATCH 2/2] env variable for mute notification --- docker-compose.yml | 1 + sample.env | 1 + 2 files changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 86cd37704..77423470b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -109,6 +109,7 @@ services: - EVENT_QUEUE_PDFSTITCH_STREAMKEY=${EVENT_QUEUE_PDFSTITCH_STREAMKEY} - EVENT_QUEUE_PDFSTITCH_LARGE_FILE_STREAMKEY=${EVENT_QUEUE_PDFSTITCH_LARGE_FILE_STREAMKEY} - STREAM_SEPARATION_FILE_SIZE_LIMIT=${STREAM_SEPARATION_FILE_SIZE_LIMIT} + - MUTE_NOTIFICATION=${MUTE_NOTIFICATION} #- LOG_ROOT=${LOG_ROOT} #- LOG_BASIC=${LOG_BASIC} #- LOG_TRACING=${LOG_TRACING} diff --git a/sample.env b/sample.env index e4f921332..e219c9c8e 100644 --- a/sample.env +++ b/sample.env @@ -159,3 +159,4 @@ DISABLE_REDACT_WEBLINK=false DISABLE_GATHERINGRECORDS_TAB=false KC_SRC_ACC_TOKEN_EXPIRY=60 +MUTE_NOTIFICATION={"MCF": {"request_types": ["Personal"], "state_exceptions": ["Call For Record", "Ministry Signoff"], "type_exceptions":["Reply User Comments", "Tagged User Comments"]}} \ No newline at end of file