Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to notification and advanced serach #4980

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FOIRawRequestNotification(db.Model):
updated_at = db.Column(db.DateTime, nullable=True)
updatedby = db.Column(db.String(120), unique=False, nullable=True)

notificationtypeid = db.Column(db.Integer, nullable=False)
notificationtypelabel = db.Column(db.Integer, nullable=False)

notificationusers = db.relationship('FOIRawRequestNotificationUser', backref='FOIRawRequestNotifications', lazy='dynamic')
Expand Down
8 changes: 4 additions & 4 deletions request-management-api/request_api/models/FOIRawRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,14 +877,14 @@ def getfilterforrequeststate(cls, params, includeclosed):
#request state: unopened, call for records, etc.
requeststatecondition = []
for state in params['requeststate']:
if(state == '3'):
if(state == StateName.closed.name):
requeststatecondition.append(FOIRawRequest.status == StateName.closed.value)
includeclosed = True
elif(state == '4'):
elif(state == StateName.redirect.name):
requeststatecondition.append(FOIRawRequest.status == StateName.redirect.value)
elif(state == '5'):
elif(state == StateName.unopened.name):
requeststatecondition.append(FOIRawRequest.status == StateName.unopened.value)
elif(state == '6'):
elif(state == StateName.intakeinprogress.name):
requeststatecondition.append(FOIRawRequest.status == StateName.intakeinprogress.value)

if(len(requeststatecondition) == 0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def dismissnotificationbyuserandtype(cls, userid, notificationusertypelabel):

@classmethod
def dismissbynotificationid(cls, notificationids, userid='system'):
db.session.query(FOIRequestNotificationUser).filter(FOIRequestNotificationUser.notificationid.in_(notificationids), FOIRequestNotificationUser.isdeleted == False).update({FOIRequestNotificationUser.isdeleted: True, FOIRequestNotificationUser.updatedby: userid,
db.session.query(FOIRequestNotificationUser).filter(FOIRequestNotificationUser.notificationid.in_(notificationids)).update({FOIRequestNotificationUser.isdeleted: True, FOIRequestNotificationUser.updatedby: userid,
FOIRequestNotificationUser.updated_at: datetime2.now()}, synchronize_session=False)
db.session.commit()
return DefaultMethodResult(True,'Notifications deleted for id',notificationids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def getextensionnotifications(cls, extensionid):
@classmethod
def dismissnotification(cls, notificationids, userid='system'):
try:
db.session.query(FOIRequestNotification).filter(FOIRequestNotification.notificationid.in_(notificationids), FOIRequestNotification.isdeleted == False).update({FOIRequestNotification.isdeleted: True, FOIRequestNotification.updatedby: userid,
db.session.query(FOIRequestNotification).filter(FOIRequestNotification.notificationid.in_(notificationids)).update({FOIRequestNotification.isdeleted: True, FOIRequestNotification.updatedby: userid,
FOIRequestNotification.updated_at: datetime2.now()}, synchronize_session=False)
db.session.commit()
return DefaultMethodResult(True,'Notifications deleted ', notificationids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from request_api.models.FOIRawRequests import FOIRawRequest
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRequestStatus import FOIRequestStatus
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from request_api.utils.enums import CommentType
Expand Down Expand Up @@ -38,7 +39,8 @@ def createassignmentevent(self, requestid, requesttype, userid, isministryuser,a

def __createnotification(self, requestid, requesttype, userid, isministryuser):
notification = self.__preparenotification()
return notificationservice().createnotification({"message" : notification}, requestid, requesttype, self.__assignmenttype(isministryuser), userid)
notificationtype = NotificationType().getnotificationtypeid(self.__assignmenttype(isministryuser))
return notificationservice().createnotification({"message" : notification}, requestid, requesttype, notificationtype, userid)

def __createnotificationforremoval(self, requestid, requesttype, userid, username, previousassignee):
notification = self.__preparenotification(username, True)
Expand Down
20 changes: 6 additions & 14 deletions request-management-api/request_api/services/events/cfrdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from request_api.services.commentservice import commentservice
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRequestComments import FOIRequestComment
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from enum import Enum
Expand All @@ -25,37 +26,28 @@ class cfrdateevent(duecalculator):
def createdueevent(self):
try:
_today = self.gettoday()
time = t.time()
notificationservice().dismissremindernotification("ministryrequest", self.__notificationtype())
dismissremindernotification_time = t.time()
print("dismissremindernotification_time: %s" % (dismissremindernotification_time - time))

ca_holidays = self.getholidays()
time = t.time()
_upcomingdues = FOIMinistryRequest.getupcomingcfrduerecords()
getupcomingcfrduerecords_time = t.time()
print("getupcomingcfrduerecords_time: %s" % (getupcomingcfrduerecords_time - time))

notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
for entry in _upcomingdues:
_duedate = self.formatduedate(entry['cfrduedate'])
message = None
if _duedate == _today:
message = self.__todayduemessage()
elif self.getpreviousbusinessday(entry['cfrduedate'],ca_holidays) == _today:
message = self.__upcomingduemessage(_duedate)
createnotification_time = t.time()
self.__createnotification(message,entry['foiministryrequestid'])
message = self.__upcomingduemessage(_duedate)
self.__createnotification(message,entry['foiministryrequestid'], notificationtype)
self.__createcomment(entry, message)
createnotification_time = t.time() - createnotification_time
print("createnotification_time: %s" % createnotification_time)
return DefaultMethodResult(True,'CFR reminder notifications created',_today)
except BusinessException as exception:
current_app.logger.error("%s,%s" % ('CFR reminder Notification Error', exception.message))
return DefaultMethodResult(False,'CFR reminder notifications failed',_today)

def __createnotification(self, message, requestid):
def __createnotification(self, message, requestid, notificationtype):
if message is not None:
return notificationservice().createremindernotification({"message" : message}, requestid, "ministryrequest", self.__notificationtype(), self.__defaultuserid())
return notificationservice().createremindernotification({"message" : message}, requestid, "ministryrequest", notificationtype, self.__defaultuserid())

def __createcomment(self, entry, message):
if message is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from request_api.services.commentservice import commentservice
from request_api.services.cfrfeeservice import cfrfeeservice
from request_api.services.notificationservice import notificationservice
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from enum import Enum
Expand Down Expand Up @@ -60,7 +61,8 @@ def __createcomment(self, requestid, state, userid, username, updatedamounts=Non

def __createnotification(self, requestid, state, userid):
notification = self.__preparenotification(state)
return notificationservice().createnotification({"message" : notification}, requestid, "ministryrequest", "CFR Fee Form", userid)
notificationtype = NotificationType().getnotificationtypeid("CFR Fee Form")
return notificationservice().createnotification({"message" : notification}, requestid, "ministryrequest", notificationtype, userid)

def __preparecomment(self, requestid, state, username, updatedamounts):
comment = {"comment": self.__commentmessage(state, username, updatedamounts)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from request_api.services.commentservice import commentservice
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRequestComments import FOIRequestComment
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from enum import Enum
Expand All @@ -26,23 +27,24 @@ def createdueevent(self):
notificationservice().dismissremindernotification("ministryrequest", self.__notificationtype())
ca_holidays = self.getholidays()
_upcomingdues = FOIMinistryRequest.getupcomingdivisionduerecords()
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
for entry in _upcomingdues:
_duedate = self.formatduedate(entry['duedate'])
message = None
if _duedate == _today:
message = self.__todayduemessage(entry)
elif self.getpreviousbusinessday(entry['duedate'],ca_holidays) == _today:
message = self.__upcomingduemessage(entry)
self.__createnotification(message,entry['foiministryrequestid'])
self.__createnotification(message,entry['foiministryrequestid'], notificationtype)
self.__createcomment(entry, message)
return DefaultMethodResult(True,'Division reminder notifications created',_today)
except BusinessException as exception:
current_app.logger.error("%s,%s" % ('Legislative reminder Notification Error', exception.message))
return DefaultMethodResult(False,'Division reminder notifications failed',_today)

def __createnotification(self, message, requestid):
def __createnotification(self, message, requestid, notificationtype):
if message is not None:
return notificationservice().createnotification({"message" : message}, requestid, "ministryrequest", self.__notificationtype(), self.__defaultuserid(), False)
return notificationservice().createnotification({"message" : message}, requestid, "ministryrequest", notificationtype, self.__defaultuserid(), False)

def __createcomment(self, entry, message):
if message is not None:
Expand Down
4 changes: 3 additions & 1 deletion request-management-api/request_api/services/events/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from request_api.models.FOIRawRequests import FOIRawRequest
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRequestStatus import FOIRequestStatus
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
import logging
Expand Down Expand Up @@ -35,7 +36,8 @@ def __createcomment(self, requestid, requesttype, stage, reason, userid):

def __createnotification(self, requestid, requesttype, stage):
notification = self.__preparenotification(stage)
return notificationservice().createnotification({"message" : notification}, requestid, requesttype, "Email Failure", self.__defaultuserid())
notificationtype = NotificationType().getnotificationtypeid("Email Failure")
return notificationservice().createnotification({"message" : notification}, requestid, requesttype, notificationtype, self.__defaultuserid())

def __preparenotification(self, stage):
return self.__notificationmessage(stage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRequestComments import FOIRequestComment
from request_api.models.FOIRequestNotifications import FOIRequestNotification
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from enum import Enum
Expand Down Expand Up @@ -72,7 +73,8 @@ def createnotification(self, ministryrequestid, extensionid, curextension, preve
notification = self.__preparenotification(extensionsummary)
if notificationandcleanup == True:
self.__deleteextensionnotification(extensionid)
return notificationservice().createnotification({"extensionid": extensionid, "message": notification}, ministryrequestid, "ministryrequest", "Extension", userid, False)
notificationtype = NotificationType().getnotificationtypeid("Extension")
return notificationservice().createnotification({"extensionid": extensionid, "message": notification}, ministryrequestid, "ministryrequest", notificationtype, userid, False)

def __deleteaxisextensionnotifications(self, notificationids):
notificationservice().dismissnotificationbyid("ministryrequest", notificationids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from request_api.services.commentservice import commentservice
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRequestComments import FOIRequestComment
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from enum import Enum
Expand All @@ -29,29 +30,25 @@ def createdueevent(self):
notificationservice().dismissremindernotification("ministryrequest", self.__notificationtype())
ca_holidays = self.getholidays()
_upcomingdues = FOIMinistryRequest.getupcominglegislativeduerecords()
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
for entry in _upcomingdues:
_duedate = self.formatduedate(entry['duedate'])
message = None
if _duedate == _today:
message = self.__todayduemessage()
elif self.getpreviousbusinessday(entry['duedate'],ca_holidays) == _today or self.getbusinessdaysbetween(entry['duedate'],_today) == 5:
message = self.__upcomingduemessage(_duedate)
createnotification_time = t.time()
self.__createnotification(message,entry['foiministryrequestid'])
createnotification_time = t.time() - createnotification_time
print("createnotification_time: %s" % createnotification_time)
createcomment_time = t.time()

self.__createnotification(message,entry['foiministryrequestid'], notificationtype)
self.__createcomment(entry, message)
createcomment_time = t.time() - createcomment_time
print("createcomment_time: %s" % createcomment_time)
return DefaultMethodResult(True,'Legislative reminder notifications created',_today)
except BusinessException as exception:
current_app.logger.error("%s,%s" % ('Legislative reminder Notification Error', exception.message))
return DefaultMethodResult(False,'Legislative reminder notifications failed',_today)

def __createnotification(self, message, requestid):
def __createnotification(self, message, requestid, notificationtype):
if message is not None:
return notificationservice().createnotification({"message" : message}, requestid, "ministryrequest", self.__notificationtype(), self.__defaultuserid(), False)
return notificationservice().createnotification({"message" : message}, requestid, "ministryrequest", notificationtype, self.__defaultuserid(), False)

def __createcomment(self, entry, message):
if message is not None:
Expand Down
11 changes: 7 additions & 4 deletions request-management-api/request_api/services/events/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from request_api.models.FOIMinistryRequests import FOIMinistryRequest
from request_api.models.FOIRawRequests import FOIRawRequest
from request_api.models.FOIRequestStatus import FOIRequestStatus
from request_api.models.NotificationTypes import NotificationType
import json
from request_api.models.default_method_result import DefaultMethodResult
from enum import Enum
Expand Down Expand Up @@ -46,6 +47,7 @@ def createpaymentreminderevent(self):
notificationservice().dismissremindernotification("rawrequest", self.__notificationtype())
eventtype = PaymentEventType.reminder.value
_onholdrequests = FOIRawRequest.getappfeeowingrequests()
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
for entry in _onholdrequests:
_dateofstatechange = datetimehandler().formatdate(entry['updated_at'])
businessdayselapsed = duecalculator().getbusinessdaysbetween(_dateofstatechange)
Expand All @@ -57,7 +59,7 @@ def createpaymentreminderevent(self):
commentexists = True
if not commentexists:
self.__createcommentforrawrequest(entry['requestid'], eventtype)
self.__createnotificationforrawrequest(entry['requestid'], eventtype)
self.__createnotificationforrawrequest(entry['requestid'], eventtype, notificationtype)
return DefaultMethodResult(True,'Payment reminder notifications created',_today)
except BusinessException as exception:
current_app.logger.error("%s,%s" % ('Payment reminder Notification Error', exception.message))
Expand All @@ -67,17 +69,18 @@ def __createcommentforrawrequest(self, requestid, eventtype):
comment = self.__preparecomment(requestid, eventtype)
return commentservice().createrawrequestcomment(comment, "system", 2)

def __createnotificationforrawrequest(self, requestid, eventtype):
def __createnotificationforrawrequest(self, requestid, eventtype, notificationtype):
notification = self.__preparenotification(requestid, eventtype)
return notificationservice().createnotification({"message" : notification}, requestid, "rawrequest", self.__notificationtype(), "system")
return notificationservice().createnotification({"message" : notification}, requestid, "rawrequest", notificationtype, "system")

def __createcomment(self, requestid, eventtype):
comment = self.__preparecomment(requestid, eventtype)
return commentservice().createministryrequestcomment(comment, self.__defaultuserid(), 2)

def __createnotification(self, requestid, eventtype):
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
notification = self.__preparenotification(requestid, eventtype)
return notificationservice().createnotification({"message" : notification}, requestid, "ministryrequest", "Payment", self.__defaultuserid())
return notificationservice().createnotification({"message" : notification}, requestid, "ministryrequest", notificationtype, self.__defaultuserid())

def __preparenotification(self, requestid, eventtype):
return self.__notificationmessage(requestid, eventtype)
Expand Down
Loading
Loading