Skip to content

Commit

Permalink
Merge pull request #4786 from bcgov/dev-RQ-4548
Browse files Browse the repository at this point in the history
Mute notifications for MCFD Personal 4548
  • Loading branch information
richard-aot authored Nov 28, 2023
2 parents 16a16dd + 5efd0e0 commit bdbeb42
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
return str(14)

def getmutenotifications(self):
if 'MUTE_NOTIFICATION' in os.environ:
return json.loads(os.getenv('MUTE_NOTIFICATION'))
else:
return {}
44 changes: 40 additions & 4 deletions request-management-api/request_api/services/notificationservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}}

0 comments on commit bdbeb42

Please sign in to comment.