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

Test rook merge dev #5012

Merged
merged 15 commits into from
Jan 18, 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 @@ -323,8 +323,8 @@ export default function AttachmentModal({
body: (
<>
Replace the existing record with a reformatted or updated
version of the same record.<br></br>The original file that was
uploaded will still be available for download.
version of the same record.<br></br>If the file being replaced
is also a pdf file, the replaced file will no longer be available.
</>
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ export const getErrorMessage = (_duplicateFiles, _typeErrorFiles, _overSizedFile
if (_overSizedFiles.length > 0) {
_errorMessage.push(<>The specified file(s) <b>{_overSizedFiles.join(", ")}</b> could not be uploaded. Only files <b>{maxFileSize}MB</b> or under can be uploaded.</>);
}
const hasOnlyPdfMimeTypes = (mimeTypes) => {
let result = true;
mimeTypes.forEach((mimeType) => {
if (mimeType !== 'application/pdf' && mimeType !== '.pdf') result = false;
})
return result;
}

if (_typeErrorFiles.length > 0) {
if (mimeTypes.length === 1 && mimeTypes[0] === 'application/pdf') {
if (hasOnlyPdfMimeTypes(mimeTypes)) {
_errorMessage.push(<>The specified file(s) <b>{_typeErrorFiles.join(", ")}</b> could not be uploaded. Only PDF filetypes are allowed.</>);
} else {
_errorMessage.push(<>The specified file(s) <b>{_typeErrorFiles.join(", ")}</b> could not be uploaded. Only files with the following extensions are allowed: <b>{multipleFiles ? 'Excel (xls, xlsx, macro), pdf, image, word, email' : singleFileUploadAllowedFileExtensions}</b></>);
Expand Down
4 changes: 2 additions & 2 deletions notification-manager/common/notificationusertypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
},
"comment tagged user": {
"name": "comment tagged user",
"notificationusertypelabel": "commentuser"
"notificationusertypelabel": "assignee"
},
"triggereduser": {
"name": "Triggered User",
"notificationusertypelabel": "triggereduser"
"notificationusertypelabel": "assignee"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ def getid(self, name):
finally:
if conn:
conn.close()

def getidbylabel(self, label):
conn = None
try:
_notificationusertypes = []
conn = getconnection()
cursor = conn.cursor()
cursor.execute("""select notificationusertypeid from "NotificationUserTypes" nt where isactive = true and notificationusertypelabel = '{0}'""".format(label))
data = cursor.fetchone()
if data is not None:
data = {"notificationusertypeid": data[0]}
return data

cursor.close()
return _notificationusertypes
except(Exception) as error:
logging.error(error)
finally:
if conn:
conn.close()
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,47 @@
import os
from notification_api.dao.models.NotificationTypes import NotificationType
from notification_api.dao.models.NotificationUserTypes import NotificationUserType
notificationuserfile = open('common/notificationusertypes.json', encoding="utf8")
notificationusertypes_cache = json.load(notificationuserfile)

notificationfile = open('common/notificationtypes.json', encoding="utf8")
notificationtypes_cache = json.load(notificationfile)

class notificationconfig:
""" Notfication config

"""

def getnotificationtypeid(self, notificationtype):
notificationid = NotificationType().getid(notificationtype)
if notificationid is not None:
return notificationid

def getnotificationtype(self, notificationtype):
notificationid = NotificationType().getid(notificationtype)
if notificationid is not None:
return notificationid

def getnotificationusertypeid(self, notificationusertype):
def getnotificationusertype(self, notificationusertype):
notificationuserid = NotificationUserType().getid(notificationusertype)
if notificationuserid is not None:
return notificationuserid


def getnotificationusertype(self, notificationusertype):
notificationuserid = NotificationUserType().getid(notificationusertype)
# This method is used to get the notification user type label
# It first tries to get the notification user type label from the cache
# If it is not found in the cache, it fetches it from the DB
def getnotificationusertypelabel(self, notificationusertype):
notificationusertype_format = notificationusertype.replace(" ", "").lower()
if notificationusertype_format in notificationusertypes_cache:
return notificationusertypes_cache[notificationusertype_format]['notificationusertypelabel']
else:
print("Notification user type not found in json. Fetching from DB", notificationusertype)
notificationusertypeobj = self.getnotificationusertype(notificationusertype)
if notificationusertypeobj is not None:
return notificationusertypeobj['notificationusertypelabel']
return None

def getnotificationusertypeidbylabel(self, label):
notificationuserid = NotificationUserType().getidbylabel(label)
if notificationuserid is not None:
return notificationuserid


def getnotificationdays(self):
if 'FOI_NOTIFICATION_DAYS' in os.environ and os.getenv('FOI_NOTIFICATION_DAYS') != '':
return os.getenv('FOI_NOTIFICATION_DAYS')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ def __istaggeduser(self, notificationuser, foicomment, notificationtype):

def __gettriggereduser(self, userid, notificationtype):
notificationusers = []
notificationtypelabel = "assignee"
if notificationtype in ["Records", "PDFStitch"]:
notificationusers.append({"userid":userid, "usertype":notificationconfig().getnotificationusertype("Triggered User")['notificationusertypelabel']})
notificationusers.append({"userid":userid, "usertype":notificationtypelabel})
return notificationusers


def __getwatchers(self, notificationtype, foirequest, requesttype, requestjson=None):
notificationusers = []
if notificationtype == "Watcher":
notificationusers.append({"userid": requestjson['watchedby'], "usertype":notificationconfig().getnotificationusertype("Watcher")['notificationusertypelabel']})
notificationtypelabel = "watcher"
if notificationtype == "Watcher":
notificationusers.append({"userid": requestjson['watchedby'], "usertype":notificationtypelabel})
else:
if requesttype == "ministryrequest":
watchers = FOIMinistryRequest().getwatchers(foirequest["foiministryrequestid"])
else:
watchers = FOIRawRequest().getwatchers(foirequest['requestid'])
for watcher in watchers:
notificationusers.append({"userid":watcher["watchedby"], "usertype":notificationconfig().getnotificationusertype("Watcher")['notificationusertypelabel']})
notificationusers.append({"userid":watcher["watchedby"], "usertype":notificationtypelabel})
return notificationusers

def __getassignees(self, foirequest, requesttype, notificationtype, requestjson=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def __preparenotificationuser(self, notificationid, notificationuser, userid, mu
usertype = notificationusertypes_cache[notificationuser["usertype"]]
if usertype is None:
print('User type not found', notificationuser["usertype"])
return None
notificationtypes = notificationconfig().getnotificationusertype(usertype['name'])
user.notificationusertypelabel = notificationtypes['notificationusertypelabel']
user.notificationusertypeid = notificationtypes['notificationusertypeid']
return None
notificationusertypelabel = notificationconfig().getnotificationusertypelabel(usertype['name'])
user.notificationusertypelabel = notificationusertypelabel
user.notificationusertypeid = notificationconfig().getnotificationusertypeidbylabel(notificationusertypelabel)['notificationusertypeid']
user.notificationid = notificationid
user.userid = notificationuser["userid"]
user.createdby = userid
Expand Down
4 changes: 2 additions & 2 deletions request-management-api/common/notificationusertypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
},
"comment tagged user": {
"name": "comment tagged user",
"notificationusertypelabel": "commentuser"
"notificationusertypelabel": "assignee"
},
"triggereduser": {
"name": "Triggered User",
"notificationusertypelabel": "triggereduser"
"notificationusertypelabel": "assignee"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ def getnotificationsbyuser(cls, userid):
return notifications

@classmethod
def getnotificationsbyuserandtype(cls, userid, typeid):
for key in notificationusertypes_cache:
if (notificationusertypes_cache[key].notificationusertypeid == typeid) or (notificationusertypes_cache[key].notificationusertypelabel == typeid):
notificationusertypelabel = notificationusertypes_cache[key].notificationusertypelabel
def getnotificationsbyuserandtype(cls, userid, notificationusertypelabel):
notifications = []
try:
sql = """select notificationid, count(1) as relcount from "FOIRawRequestNotificationUsers" frnu
Expand Down
6 changes: 4 additions & 2 deletions request-management-api/request_api/services/events/oipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class oipcevent:
""" FOI OIPC Event management service
"""

def createoipcevent(self, requestid, userid):
def createoipcevent(self, requestid, requesttype, userid):
if requesttype != "ministryrequest":
return DefaultMethodResult(True,'No change',requestid)
ministryrequest = FOIMinistryRequest.getmetadata(requestid)
if ministryrequest["isoipcreview"] in (None, False):
notificationservice().dismissnotifications_by_requestid_type(requestid, "ministryrequest", self.__notificationtype())
return DefaultMethodResult(True,'No change',requestid)
return DefaultMethodResult(True,'Dismiss OIPC events',requestid)
inquiryoutcomes = oipcservice().getinquiryoutcomes()
version = ministryrequest["version"]
curoipcs = FOIRequestOIPC.getoipc(requestid, version)
Expand Down
4 changes: 3 additions & 1 deletion request-management-api/request_api/services/events/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __createnotification(self, requestid, state, requesttype, userid):
if state == StateName.callforrecords.value and requesttype == "ministryrequest":
foirequest = notificationservice().getrequest(requestid, requesttype)
_notificationtype = "Group Members" if foirequest['assignedministryperson'] is None else "State"
notificationtype = NotificationType().getnotificationtypeid(_notificationtype)
notification = self.__preparenotification(state)
if state == StateName.response.value and requesttype == "ministryrequest":
signgoffapproval = FOIMinistryRequest().getrequest(requestid)['ministrysignoffapproval']
Expand All @@ -74,10 +73,13 @@ def __createnotification(self, requestid, state, requesttype, userid):
if state == StateName.archived.value:
_openedministries = FOIMinistryRequest.getministriesopenedbyuid(requestid)
for ministry in _openedministries:
notificationtype = NotificationType().getnotificationtypeid("State")
response = notificationservice().createnotification({"message" : notification}, ministry["ministryrequestid"], 'ministryrequest', notificationtype, userid)
else:
notificationtype = NotificationType().getnotificationtypeid("State")
response = notificationservice().createnotification({"message" : notification}, requestid, requesttype, notificationtype, userid)
if _notificationtype == "Group Members":
notificationtype = NotificationType().getnotificationtypeid(_notificationtype)
notification = self.__preparegroupmembernotification(state, requestid)
groupmemberresponse = notificationservice().createnotification({"message" : notification}, requestid, requesttype, notificationtype, userid)
if response.success == True and groupmemberresponse.success == True :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def posteventsync(self, requestid, requesttype, userid, username, isministryuser
stateeventresponse = stateevent().createstatetransitionevent(requestid, requesttype, userid, username)
divisioneventresponse = divisionevent().createdivisionevent(requestid, requesttype, userid)
assignmentresponse = assignmentevent().createassignmentevent(requestid, requesttype, userid, isministryuser,assigneename,username)
oipcresponse = oipcevent().createoipcevent(requestid, userid)
oipcresponse = oipcevent().createoipcevent(requestid, requesttype, userid)
if stateeventresponse.success == False or divisioneventresponse.success == False or assignmentresponse.success == False or oipcresponse.success == False:
current_app.logger.error("FOI Notification failed for event for request= %s ; state response=%s ; division response=%s ; assignment response=%s ; oipc response=%s" % (requestid, stateeventresponse.message, divisioneventresponse.message, assignmentresponse.message, oipcresponse.message))
except BusinessException as exception:
Expand Down
Loading