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

Added RTT tag and notification for RTT attachments #5148

Merged
merged 9 commits into from
Apr 15, 2024
7 changes: 7 additions & 0 deletions forms-flow-web/src/constants/FOI/statusEnum.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ const AttachmentCategories = Object.freeze({
bgcolor: "#595959",
type: ["tag"],
},
{
name: "rrt",
tags: ["rrt"],
display: "RRT",
bgcolor: "#003366",
type: ["tag"],
},
{
// transition: Response -> On hold
name: "response-onhold",
Expand Down
4 changes: 4 additions & 0 deletions notification-manager/common/notificationtypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@
"oipcduereminder": {
"name": "OIPC Due Reminder",
"notificationtypelabel": "oipcduereminder"
},
"attachmentuploadevent": {
"name": "Attachment Upload Event",
"notificationtypelabel": "attachmentuploadevent"
}
}
4 changes: 4 additions & 0 deletions request-management-api/common/notificationtypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@
"oipcduereminder": {
"name": "OIPC Due Reminder",
"notificationtypelabel": "oipcduereminder"
},
"attachmentuploadevent": {
"name": "Attachment Upload Event",
"notificationtypelabel": "attachmentuploadevent"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Add RTT tag

Revision ID: e698b39da6bd
Revises: 6646acda32fe
Create Date: 2024-04-15 08:17:20.554269

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e698b39da6bd'
down_revision = '6646acda32fe'
branch_labels = None
depends_on = None

def upgrade():
op.execute('INSERT INTO public."NotificationTypes"(name, description, isactive,notificationtypelabel ) VALUES (\'Attachment Upload Event\', \'Attachment Upload Event\', true, \'attachmentuploadevent\');')

def downgrade():
op.execute('DELETE FROM public."NotificationTypes" WHERE name = \'Attachment Upload Event\';')
12 changes: 6 additions & 6 deletions request-management-api/request_api/models/FOIMinistryRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us
dbquery = basequery.filter(FOIMinistryRequest.assignedto == None).filter(ministryfilter)
elif(additionalfilter.lower() == 'all'):
if(requestby == 'IAO'):
dbquery = basequery.filter(ministryfilter).filter(or_(or_(FOIRestrictedMinistryRequest.isrestricted == isiaorestrictedfilemanager, FOIRestrictedMinistryRequest.isrestricted == None), and_(FOIRestrictedMinistryRequest.isrestricted == True, FOIMinistryRequest.assignedto == userid)))
dbquery = basequery.filter(ministryfilter).filter(FOIMinistryRequest.assignedto.isnot(None)).filter(or_(FOIRestrictedMinistryRequest.isrestricted == isiaorestrictedfilemanager, or_(FOIRestrictedMinistryRequest.isrestricted.is_(None), FOIRestrictedMinistryRequest.isrestricted == False)))
else:
dbquery = basequery.filter(ministryfilter).filter(or_(or_(ministry_restricted_requests.isrestricted == isministryrestrictedfilemanager, ministry_restricted_requests.isrestricted == None), and_(ministry_restricted_requests.isrestricted == True, FOIMinistryRequest.assignedministryperson == userid)))
dbquery = basequery.filter(ministryfilter).filter(or_(ministry_restricted_requests.isrestricted == isministryrestrictedfilemanager, or_(ministry_restricted_requests.isrestricted.is_(None), ministry_restricted_requests.isrestricted == False)))
else:
if(isiaorestrictedfilemanager == True or isministryrestrictedfilemanager == True):
dbquery = basequery.filter(ministryfilter)
Expand Down Expand Up @@ -733,7 +733,7 @@ def getgroupfilters(cls, groups):
)
)
)
statusfilter = FOIMinistryRequest.requeststatuslabel.in_([StateName.callforrecords.name,StateName.recordsreview.name,StateName.recordsreadyforreview.name,StateName.feeestimate.name,StateName.consult.name,StateName.ministrysignoff.name,StateName.onhold.name,StateName.deduplication.name,StateName.harmsassessment.name,StateName.response.name,StateName.peerreview.name,StateName.tagging.name,StateName.readytoscan.name])
statusfilter = FOIMinistryRequest.requeststatuslabel.in_([StateName.callforrecords.name,StateName.recordsreview.name,StateName.feeestimate.name,StateName.consult.name,StateName.ministrysignoff.name,StateName.onhold.name,StateName.deduplication.name,StateName.harmsassessment.name,StateName.response.name,StateName.peerreview.name,StateName.tagging.name,StateName.readytoscan.name, StateName.recordsreadyforreview.name])
ministryfilter = and_(
FOIMinistryRequest.isactive == True,
FOIRequestStatus.isactive == True,
Expand Down Expand Up @@ -1166,15 +1166,15 @@ def getbasequery(cls, iaoassignee, ministryassignee, userid=None, requestby='IAO
if(requestby == 'IAO'):
dbquery = newbasequery.filter(
or_(
or_(FOIRestrictedMinistryRequest.isrestricted == False, FOIRestrictedMinistryRequest.isrestricted == None),
or_(FOIRestrictedMinistryRequest.isrestricted == False, FOIRestrictedMinistryRequest.isrestricted.is_(None)),
and_(FOIRestrictedMinistryRequest.isrestricted == True, FOIMinistryRequest.assignedto == userid),
and_(FOIRestrictedMinistryRequest.isrestricted == True, subquery_watchby.c.watchedby == userid),
)
).filter(ministryfilter)
else:
dbquery = newbasequery.filter(
or_(
or_(ministry_restricted_requests.isrestricted == False, ministry_restricted_requests.isrestricted == None),
or_(ministry_restricted_requests.isrestricted == False, ministry_restricted_requests.isrestricted.is_(None)),
and_(ministry_restricted_requests.isrestricted == True, FOIMinistryRequest.assignedministryperson == userid),
and_(ministry_restricted_requests.isrestricted == True, subquery_watchby.c.watchedby == userid),
)
Expand All @@ -1193,7 +1193,7 @@ def advancedsearch(cls, params, userid, isministryrestrictedfilemanager = False)
groupfilter.append(FOIMinistryRequest.assignedministrygroup == group)

#ministry advanced search show cfr onwards
statefilter = FOIMinistryRequest.requeststatuslabel.in_([StateName.callforrecords.name,StateName.closed.name,StateName.recordsreview.name,StateName.recordsreadyforreview.name,StateName.feeestimate.name,StateName.consult.name,StateName.ministrysignoff.name,StateName.onhold.name,StateName.deduplication.name,StateName.harmsassessment.name,StateName.response.name,StateName.peerreview.name,StateName.tagging.name,StateName.readytoscan.name])
statefilter = FOIMinistryRequest.requeststatuslabel.in_([StateName.callforrecords.name,StateName.closed.name,StateName.recordsreview.name,StateName.feeestimate.name,StateName.consult.name,StateName.ministrysignoff.name,StateName.onhold.name,StateName.deduplication.name,StateName.harmsassessment.name,StateName.response.name,StateName.peerreview.name,StateName.tagging.name,StateName.readytoscan.name,StateName.recordsreadyforreview.name])

ministry_queue = FOIMinistryRequest.advancedsearchsubquery(params, iaoassignee, ministryassignee, userid, 'Ministry', False, isministryrestrictedfilemanager).filter(and_(or_(*groupfilter), statefilter))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from request_api.schemas.foidocument import CreateDocumentSchema
from request_api.services.external.storageservice import storageservice
from request_api.models.FOIApplicantCorrespondenceAttachments import FOIApplicantCorrespondenceAttachment
from request_api.services.eventservice import eventservice
from request_api.utils.enums import RequestType
import logging

Expand Down Expand Up @@ -91,6 +92,14 @@ def copyrequestdocuments(self, ministryrequestid, documents, userid):

def createministryrequestdocument(self, ministryrequestid, documentschema, userid):
version = self.__getversionforrequest(ministryrequestid, "ministryrequest")
for document in documentschema['documents']:
if 'rrt' in document['category']:
#Create notification event for RRT document
message = f'RRT Uploaded on FOI Request {ministryrequestid}'
eventservice().attachmentevent(ministryrequestid, document, userid, "add", message)
#if 'rrt' in documentschema['documents']['category']:
#Create notification event for RRT document
# eventservice().posteventforextension(ministryrequestid, '', userid, '' , "add")
return FOIMinistryRequestDocument.createdocuments(ministryrequestid, version, documentschema['documents'], userid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the RRT related changes to events/attatment.py
Also, call the attachmentevent from the resource level(POST)


def createrawrequestdocument(self, requestid, documentschema, userid):
Expand Down
36 changes: 36 additions & 0 deletions request-management-api/request_api/services/events/attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

from request_api.services.commons.duecalculator import duecalculator
from request_api.services.notificationservice import notificationservice
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
from request_api.exceptions import BusinessException
from request_api.models.default_method_result import DefaultMethodResult
from flask import current_app

class attachmentevent():
""" FOI Attachment Event management service

"""
def createattachmentevent(self, ministryrequestid, message, userid, event):
try:
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
self.__createnotification(message, ministryrequestid, notificationtype, userid)
return DefaultMethodResult(True, message, '')
except BusinessException as exception:
current_app.logger.error("%s,%s" % ('Attachment upload notification error', exception.message))
return DefaultMethodResult(False,'Attachemnt notifications failed')

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

def notificationmessage(self, type):
return f"{type} Attachment Uploaded"

def __notificationtype(self):
return "Attachment Upload Event"

def __defaultuserid(self):
return "System"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary codes or functions.
prepare the notification and comments message here.
include createcomment() also.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make sure to include scanning team members as discussed. The changes should be done in services\notifications\notificationuser.py

10 changes: 10 additions & 0 deletions request-management-api/request_api/services/eventservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from request_api.services.events.oipcduedate import oipcduedateevent
from request_api.services.events.extension import extensionevent
from request_api.services.events.cfrfeeform import cfrfeeformevent
from request_api.services.events.attachment import attachmentevent
from request_api.services.events.payment import paymentevent
from request_api.services.events.email import emailevent
from request_api.services.events.section5pending import section5pendingevent
Expand All @@ -32,6 +33,7 @@ async def postevent(self, requestid, requesttype, userid, username, isministryus
self.posteventsync(requestid, requesttype, userid, username, isministryuser,assigneename)

def posteventsync(self, requestid, requesttype, userid, username, isministryuser,assigneename=''):
print("\n ..... postevent is triggered ...... \n")
try:
stateeventresponse = stateevent().createstatetransitionevent(requestid, requesttype, userid, username)
divisioneventresponse = divisionevent().createdivisionevent(requestid, requesttype, userid)
Expand All @@ -58,6 +60,14 @@ def posteventforaxisextension(self, ministryrequestid, extensionids, userid, use
current_app.logger.error("FOI Notification failed for event for extension= %s" % (extensionid))
except BusinessException as exception:
self.__logbusinessexception(exception)

def attachmentevent(self, ministryrequestid, document, userid, event, message):
try:
attachmenteventresponse = attachmentevent().createattachmentevent(ministryrequestid, message , userid, event)
if attachmenteventresponse.success == False:
current_app.logger.error("FOI Notification failed for event for attachment= %s" % (document['category']))
except BusinessException as exception:
self.__logbusinessexception(exception)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update it as async event.


def postreminderevent(self):
try:
Expand Down
Loading