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

Dev marshal shiva 2965 rrt #5152

Merged
merged 6 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 5 additions & 8 deletions request-management-api/request_api/services/documentservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from request_api.models.FOIApplicantCorrespondenceAttachments import FOIApplicantCorrespondenceAttachment
from request_api.services.eventservice import eventservice
from request_api.utils.enums import RequestType
from request_api.services.events.attachment import attachmentevent
import logging
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 import


import json
Expand Down Expand Up @@ -92,14 +93,6 @@ 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)

def createrawrequestdocument(self, requestid, documentschema, userid):
Expand Down Expand Up @@ -145,6 +138,10 @@ def uploadpersonaldocuments(self, requestid, attachments):
attachmentlist.append(attachmentresponse)

documentschema = CreateDocumentSchema().load({'documents': attachmentlist})
for document in documentschema['documents']:
# Add attachment event here as we need to pass in the document
# to the event service to identify if the document is an RRT document.
attachmenteventresponse = attachmentevent().createattachmentevent(requestid, userid, document)
return self.createrequestdocument(requestid, documentschema, None, "rawrequest")
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, attachmentevent call should be at resource level not at the service level.


def getattachments(self, requestid, requesttype, category):
Expand Down
32 changes: 26 additions & 6 deletions request-management-api/request_api/services/events/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ class attachmentevent():
""" FOI Attachment Event management service

"""
def createattachmentevent(self, ministryrequestid, message, userid, event):
def createattachmentevent(self, ministryrequestid, userid, document):
try:
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
self.__createnotification(message, ministryrequestid, notificationtype, userid)
return DefaultMethodResult(True, message, '')
if 'rrt' in document['category']:
#Create notification event for RRT document
print(f"RRT Uploaded on FOI Request {ministryrequestid}")
#message = f'RRT Uploaded on FOI Request {ministryrequestid}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment

message = self.notificationmessage('RRT', ministryrequestid)
notificationtype = NotificationType().getnotificationtypeid(self.__notificationtype())
self.__createnotification(message, ministryrequestid, notificationtype, userid)
self.__createcomment(ministryrequestid, message)
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')
Expand All @@ -26,8 +32,22 @@ 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 __createcomment(self, ministryrequestid, message):
if message is not None:
_comment = self.__preparecomment(ministryrequestid, message)
return commentservice().createcomments(_comment, self.__defaultuserid(), 2)

def __preparecomment(self, ministryrequestid, message):
_comment = dict()
_comment['comment'] = message
_comment['ministryrequestid'] = ministryrequestid
_comment['version'] = None
_comment['taggedusers'] = None
_comment['parentcommentid'] = None
return _comment
antsand marked this conversation as resolved.
Show resolved Hide resolved

def notificationmessage(self, type, ministryrequestid):
return f"{type} Attachment Uploaded on FOI Request {ministryrequestid}"

def __notificationtype(self):
return "Attachment Upload Event"
Expand Down
8 changes: 0 additions & 8 deletions request-management-api/request_api/services/eventservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ def posteventforaxisextension(self, ministryrequestid, extensionids, userid, use
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)

def postreminderevent(self):
divyav-aot marked this conversation as resolved.
Show resolved Hide resolved
try:
cfreventresponse = cfrdateevent().createdueevent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class notificationuser:

def getnotificationusers(self, notificationtype, requesttype, userid, foirequest, requestjson=None):
notificationusers = []
print("notificationtype", notificationtype)
print("requesttype", requesttype)
print("foirequest", foirequest)
Copy link
Collaborator

Choose a reason for hiding this comment

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

comments

if 'User Assignment Removal' == notificationtype:
_users = self.__getassignees(foirequest, requesttype, notificationtype, requestjson)
elif 'Assignment' in notificationtype:
Expand All @@ -26,7 +29,9 @@ def getnotificationusers(self, notificationtype, requesttype, userid, foirequest
elif 'Group Members' in notificationtype:
_users = self.__getgroupmembers(foirequest["assignedministrygroup"])
elif 'Watcher' in notificationtype:
_users = self.__getwatchers(notificationtype, foirequest, requesttype, requestjson)
_users = self.__getwatchers(notificationtype, foirequest, requesttype, requestjson)
elif 'Attachment Upload Event' in notificationtype:
_users = self.__getscanningteam()
else:
_users = self.__getassignees(foirequest, requesttype, notificationtype) + self.__getwatchers(notificationtype, foirequest, requesttype)
for user in _users:
Expand Down Expand Up @@ -130,4 +135,14 @@ def __getgroupmembers(self,groupid):
notificationusers.append({"userid":user["username"], "usertype":notificationusertypelabel})
return notificationusers
return []


Copy link
Contributor

Choose a reason for hiding this comment

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

Please make the necessary changes mentioned in accordance with callstack.

Copy link
Contributor

Choose a reason for hiding this comment

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

@antsand , use __getgroupmembers method.

def __getscanningteam(self):
notificationusers = []
print("Sending notification to scanning team")
notificationusertypelabel = notificationconfig().getnotificationusertypelabel("Group Members")
usergroupfromkeycloak= KeycloakAdminService().getmembersbygroupname("scanningteam")
if usergroupfromkeycloak is not None and len(usergroupfromkeycloak) > 0:
for user in usergroupfromkeycloak[0].get("members"):
notificationusers.append({"userid":user["username"], "usertype":notificationusertypelabel})
return notificationusers
return []
Loading