Exemplo n.º 1
0
 def get(foirequestid, foiministryrequestid, usertype=None):
     try:
         jsondata = {}
         statuscode = 200
         if (AuthHelper.getusertype() == "iao") and (usertype is None or
                                                     (usertype == "iao")):
             jsondata = requestservice().getrequest(foirequestid,
                                                    foiministryrequestid)
         elif usertype is not None and usertype == "ministry" and AuthHelper.getusertype(
         ) == "ministry":
             jsondata = requestservice().getrequestdetailsforministry(
                 foirequestid, foiministryrequestid,
                 AuthHelper.getministrygroups())
         else:
             statuscode = 401
         return jsondata, statuscode
     except ValueError:
         return {'status': 500, 'message': "Invalid Request Id"}, 500
     except KeyError as err:
         return {'status': False, 'message': err.messages}, 400
     except BusinessException as exception:
         return {
             'status': exception.status_code,
             'message': exception.message
         }, 500
Exemplo n.º 2
0
    def createrequestextensionversion(self, foirequestid, ministryrequestid,
                                      extensionid, extensionschema, userid,
                                      username):
        updatedduedate = None
        ministryversion = self.__getversionforrequest(ministryrequestid)
        extension = FOIRequestExtension.getextension(extensionid)
        extensionversion = extension['version']
        prevstatus = extension["extensionstatusid"]
        currentstatus = extensionschema["extensionstatusid"]
        isstatuschangedfromapproved = self.__isstatuschangedfromapproved(
            prevstatus, currentstatus)
        if isstatuschangedfromapproved == True:
            # gets the latest approved request
            approvedextension = self.getlatestapprovedrequest(
                extensionid, ministryrequestid, ministryversion)
            # gets the latest approved due date if any else gets the original due date
            updatedduedate = self.getlatestapprovedduedate(
                prevstatus, ministryrequestid, approvedextension)

        isdeletedocument = self.__isdeletedocument(isstatuschangedfromapproved,
                                                   extensionid,
                                                   extensionversion)
        if isdeletedocument == True:
            self.deletedocuments(extensionid, extensionversion,
                                 ministryrequestid, userid)

        #copyextension has the updated extension with data passed from FE with the new version of extension
        updatedextension = self.__copyextensionproperties(
            extension, extensionschema, extensionversion)
        # if current state is approved then gets the current extended due date
        extendedduedate = self.getextendedduedate(updatedextension)

        extensionresult = FOIRequestExtension.createextensionversion(
            ministryrequestid, ministryversion, updatedextension, userid)
        # save documents if it is part of current extension (update to the ministrydocuments table and extensiondocumentmapping table)
        if 'documents' in updatedextension and updatedextension[
                'documents'] and updatedextension['extensionstatusid'] != 1:
            self.saveextensiondocument(updatedextension['documents'],
                                       ministryrequestid, userid, extensionid)
        # Post event for system generated comments
        asyncio.create_task(eventservice().posteventforextension(
            ministryrequestid, extensionid, userid, username, "modify"))
        # updates the duedate to extendedduedate or updatedduedate
        # new ministry, extension, extensionmapping and document version gets created
        if extensionresult.success == True and (
                isstatuschangedfromapproved == True
                or updatedextension['extensionstatusid'] == 2):
            ministryrequestschema = {
                "duedate":
                extendedduedate if extendedduedate else updatedduedate
            }
            requestservice().saveministryrequestversion(
                ministryrequestschema, foirequestid, ministryrequestid, userid)
        return extensionresult
Exemplo n.º 3
0
 def post():
     """ POST Method for capturing FOI requests before processing"""
     try:
         request_json = request.get_json()
         foirequestschema = FOIRequestWrapperSchema().load(request_json)
         assignedgroup = request_json[
             'assignedGroup'] if 'assignedGroup' in foirequestschema else None
         assignedto = request_json[
             'assignedTo'] if 'assignedTo' in foirequestschema else None
         assignedtofirstname = request_json[
             "assignedToFirstName"] if request_json.get(
                 "assignedToFirstName") != None else None
         assignedtomiddlename = request_json[
             "assignedToMiddleName"] if request_json.get(
                 "assignedToMiddleName") != None else None
         assignedtolastname = request_json[
             "assignedToLastName"] if request_json.get(
                 "assignedToLastName") != None else None
         rawresult = rawrequestservice().saverawrequestversion(
             request_json, request_json['id'], assignedgroup, assignedto,
             "Archived", AuthHelper.getuserid(), AuthHelper.getusername(),
             AuthHelper.isministrymember(), assignedtofirstname,
             assignedtomiddlename, assignedtolastname)
         if rawresult.success == True:
             result = requestservice().saverequest(foirequestschema,
                                                   AuthHelper.getuserid())
             if result.success == True:
                 requestservice().copywatchers(request_json['id'],
                                               result.args[0],
                                               AuthHelper.getuserid())
                 requestservice().copycomments(request_json['id'],
                                               result.args[0],
                                               AuthHelper.getuserid())
                 requestservice().copydocuments(request_json['id'],
                                                result.args[0],
                                                AuthHelper.getuserid())
                 requestservice().postopeneventtoworkflow(
                     result.identifier, rawresult.args[0], request_json,
                     result.args[0])
         return {
             'status': result.success,
             'message': result.message,
             'id': result.identifier,
             'ministryRequests': result.args[0]
         }, 200
     except ValidationError as err:
         return {'status': False, 'message': err.messages}, 400
     except KeyError as err:
         return {'status': False, 'message': err.messages}, 400
     except BusinessException as exception:
         return {
             'status': exception.status_code,
             'message': exception.message
         }, 500
Exemplo n.º 4
0
 def put(foirequestid):
     """ PUT Method for capturing FOI requests before processing"""
     try:
         request_json = request.get_json()
         foirequestschema = EditableFOIRequestWrapperSchema().load(
             request_json)
         result = requestservice().updaterequest(foirequestschema,
                                                 foirequestid,
                                                 AuthHelper.getuserid())
         if result != {}:
             return {
                 'status': result.success,
                 'message': result.message,
                 'id': result.identifier
             }, 200
         else:
             return {
                 'status': False,
                 'message': EXCEPTION_MESSAGE_NOTFOUND_REQUEST,
                 'id': foirequestid
             }, 404
     except ValidationError as err:
         return {'status': False, 'message': err.messages}, 40
     except BusinessException as exception:
         return {
             'status': exception.status_code,
             'message': exception.message
         }, 500
Exemplo n.º 5
0
    def createrequestextension(self, foirequestid, ministryrequestid,
                               extensionschema, userid):
        version = self.__getversionforrequest(ministryrequestid)
        reasonid = extensionschema['extensionreasonid']
        extensionreason = extensionreasonservice().getextensionreasonbyid(
            reasonid)
        ispublicbodyextension = self.__ispublicbodyextension(reasonid)
        if ('extensionstatusid' in extensionschema
                and extensionschema['extensionstatusid']
                == 2) or ispublicbodyextension == True:
            ministryrequestschema = {
                "duedate": extensionschema['extendedduedate']
            }
            result = requestservice().saveministryrequestversion(
                ministryrequestschema, foirequestid, ministryrequestid, userid)

            if result.success == True:
                version = self.__getversionforrequest(ministryrequestid)
                extnsionresult = FOIRequestExtension.saveextension(
                    ministryrequestid, version, extensionschema,
                    extensionreason, userid)
        else:
            extnsionresult = FOIRequestExtension.saveextension(
                ministryrequestid, version, extensionschema, extensionreason,
                userid)
        if 'documents' in extensionschema and extensionschema[
                'extensionstatusid'] != 1:
            self.saveextensiondocument(extensionschema['documents'],
                                       ministryrequestid, userid,
                                       extnsionresult.identifier)
        return extnsionresult
Exemplo n.º 6
0
 def post(foirequestid, foiministryrequestid, usertype):
     """ POST Method for capturing FOI requests before processing"""
     try:
         if usertype != "ministry":
             return {'status': False, 'message': 'Bad Request'}, 400
         request_json = request.get_json()
         ministryrequestschema = FOIRequestMinistrySchema().load(
             request_json)
         result = requestservice().saveministryrequestversion(
             ministryrequestschema, foirequestid, foiministryrequestid,
             AuthHelper.getuserid())
         if result.success == True:
             metadata = json.dumps({
                 "id": result.identifier,
                 "ministries": result.args[0]
             })
             asyncio.create_task(requestservice().posteventtoworkflow(
                 foiministryrequestid, result.args[1],
                 ministryrequestschema, json.loads(metadata), "ministry"))
             asyncio.create_task(eventservice().postevent(
                 foiministryrequestid, "ministryrequest",
                 AuthHelper.getuserid(), AuthHelper.getusername(),
                 AuthHelper.isministrymember()))
             return {
                 'status': result.success,
                 'message': result.message,
                 'id': result.identifier,
                 'ministryRequests': result.args[0]
             }, 200
         else:
             return {
                 'status': False,
                 'message': EXCEPTION_MESSAGE_NOTFOUND_REQUEST,
                 'id': foirequestid
             }, 404
     except ValidationError as err:
         return {'status': False, 'message': err.messages}, 400
     except KeyError as err:
         return {'status': False, 'message': err.messages}, 400
     except BusinessException as exception:
         return {
             'status': exception.status_code,
             'message': exception.message
         }, 500
Exemplo n.º 7
0
    def createrequestextensionversionfordelete(self, requestid,
                                               ministryrequestid, extensionid,
                                               extensionschema, userid):
        ministryversion = self.__getversionforrequest(ministryrequestid)
        extension = FOIRequestExtension.getextension(extensionid)
        prevstatus = extension["extensionstatusid"]
        extensionversion = extension['version']

        # this will be true if any document is attched to the extension
        isdeletedocument = self.__isdeletedocument(True, extensionid,
                                                   extensionversion)

        # gets the latest approvedextension if any
        approvedextension = self.getlatestapprovedrequest(
            extensionid, ministryrequestid, ministryversion)
        # gets the latest approved due date if any else gets the original due date
        updatedduedate = self.getlatestapprovedduedate(prevstatus,
                                                       ministryrequestid,
                                                       approvedextension)

        #copyextension has the updated extension with soft delete(isactive: False) with the new version of extension
        updatedextension = self.__copyextensionproperties(
            extension, extensionschema, extensionversion)
        # this will create a new version of extension with isactive = False
        extensionresult = FOIRequestExtension.createextensionversion(
            ministryrequestid, ministryversion, updatedextension, userid)
        # once soft deleted, revert back the due date to prev due date
        # creates a new version of ministry request, extension, extensiondocuments(if any) and documents(if any)
        if extensionresult.success == True and prevstatus == 2:
            ministryrequestschema = {"duedate": updatedduedate}
            requestservice().saveministryrequestversion(
                ministryrequestschema, requestid, ministryrequestid, userid)
        # soft delete the documents attached to the extension
        if extensionresult.success == True and isdeletedocument == True:
            self.deletedocuments(extensionid, extensionversion,
                                 ministryrequestid, userid)
        return extensionresult