示例#1
0
def release_results(tally_sheet, tally_sheet_version_id):
    if tally_sheet.tallySheetCode in release_allowed_tally_sheet_codes:
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=tally_sheet.tallySheetId,
            tallySheetVersionId=tally_sheet_version_id)
        response, result_code = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
            result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        response['type'] = result_dissemination_result_type

        url = "%s/%s/%s/%s/%s" % (
            RESULT_DISSEMINATION_SYSTEM_URL, RELEASE_RESULTS_ENDPOINT,
            RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
            result_dissemination_result_type, result_code)

        print("#### RESULT_DISSEMINATION_API - Release #### ", [url, response])
        result = requests.post(url, verify=False, json=response)
        print(result.status_code, result.content)

        upload_proof_last_image(tally_sheet, tally_sheet_version)

        return result
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be released.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_RELEASED)
def notify_results(tally_sheet, tally_sheet_version_id):
    if tally_sheet.tallySheetCode in notify_allowed_tally_sheet_codes:
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=tally_sheet.tallySheetId,
            tallySheetVersionId=tally_sheet_version_id
        )
        response = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
            result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        url = "%s/%s/%s/%s" % (
            RESULT_DISSEMINATION_SYSTEM_URL,
            NOTIFY_RESULTS_ENDPOINT,
            RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
            # result_dissemination_result_type,
            response['result_code']
        )

        print("#### RESULT_DISSEMINATION_API - Notify #### ", [url, response])
        return requests.post(url, verify=False)
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be notified.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_NOTIFIED
        )
示例#3
0
    def authorize_workflow_action(self, workflow_action, content=None):
        from auth import has_role_based_access

        if not has_role_based_access(election=self.tallySheet.election,
                                     tally_sheet_code=self.tallySheet.tallySheetCode,
                                     access_type=workflow_action.actionType):
            UnauthorizedException(message="Not allowed to %s" % (workflow_action.actionName),
                                  code=MESSAGE_CODE_WORKFLOW_ACTION_NOT_AUTHORIZED)

        if workflow_action.actionType == WORKFLOW_ACTION_TYPE_REQUEST_CHANGES and workflow_action.toStatus in [
            WORKFLOW_STATUS_TYPE_CHANGES_REQUESTED]:

            from orm.entities import TallySheet
            from orm.entities.TallySheet import TallySheetTallySheetModel

            extended_election = self.tallySheet.election.get_extended_election()

            verified_parent_tally_sheets = db.session.query(
                TallySheet.Model.tallySheetId
            ).filter(
                TallySheetTallySheetModel.childTallySheetId == self.tallySheet.tallySheetId,
                TallySheet.Model.tallySheetId == TallySheetTallySheetModel.parentTallySheetId,
                WorkflowInstance.Model.workflowInstanceId == TallySheet.Model.workflowInstanceId,
                WorkflowInstance.Model.status.in_(
                    extended_election.tally_sheet_verified_statuses_list()
                )
            ).all()

            if len(verified_parent_tally_sheets) > 0:
                raise MethodNotAllowedException(
                    message="Cannot request changes since the data from this report has been already aggregated in verified summary reports.",
                    code=MESSAGE_CODE_TALLY_SHEET_CANNOT_BE_UNLOCKED_WHILE_HAVING_VERIFIED_PARENT_SUMMARY_SHEETS)
示例#4
0
def upload_proof_last_image(tally_sheet, tally_sheet_version):
    if tally_sheet.tallySheetCode in release_allowed_tally_sheet_codes:
        response, result_code = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
            result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        response['type'] = result_dissemination_result_type

        url = "%s/%s/%s/%s" % (RESULT_DISSEMINATION_SYSTEM_URL,
                               RESULTS_PROOF_IMAGE_UPLOAD_ENDPOINT,
                               RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
                               result_code)

        files = tally_sheet.submissionProof.scannedFiles
        last_file = files[len(files) - 1]

        last_file_data = open(last_file.get_file_path(), 'rb').read()

        print("#### RESULT_DISSEMINATION_API - Image Upload #### ",
              [url, response, last_file_data])

        result = requests.post(
            url=url,
            data=last_file_data,
            headers={'Content-Type': last_file.fileContentType})
        print(result.status_code, result.content)
        return result
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be released.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_RELEASED)
    def execute_action(self, action: WorkflowActionModel, meta: Meta):
        if self.status != action.fromStatus:
            raise MethodNotAllowedException(
                message="Workflow action is not allowed.",
                code=MESSAGE_CODE_WORKFLOW_ACTION_NOT_ALLOWED)
        else:
            self.status = action.toStatus
            self.latestLogId = WorkflowInstanceLog.create(
                workflowInstanceId=self.workflowInstanceId,
                status=action.toStatus,
                workflowActionId=action.workflowActionId,
                metaId=meta.metaId,
                proofId=self.proofId).workflowInstanceLogId

            self.proof.close()

            # proof is replaced only for WORKFLOW_ACTION_TYPE_REQUEST_CHANGES
            if action.actionType == WORKFLOW_ACTION_TYPE_REQUEST_CHANGES:
                self.proofId = Proof.create().proofId
            # For all the other actions, the proof is cloned.
            else:
                self.proofId = self.proof.clone().proofId

            db.session.add(self)
            db.session.flush()

            return self
示例#6
0
    def on_before_tally_sheet_post(self):
        workflow_actions = self._get_allowed_workflow_actions(workflow_action_type=WORKFLOW_ACTION_TYPE_SAVE)

        if len(workflow_actions) == 0:
            raise MethodNotAllowedException(message="Tally sheet is no longer editable.",
                                            code=MESSAGE_CODE_TALLY_SHEET_NO_LONGER_EDITABLE)

        return workflow_actions
示例#7
0
    def create_version(self):
        if self.locked is True:
            raise MethodNotAllowedException(
                "Tally sheet is Locked. (tallySheetId=%d)" % self.tallySheetId)

        tallySheetVersion = self.create_empty_version()

        return tallySheetVersion
示例#8
0
    def on_before_tally_sheet_proof_upload(self):
        workflow_actions = self._get_allowed_workflow_actions(
            workflow_action_type=WORKFLOW_ACTION_TYPE_UPLOAD_PROOF_DOCUMENT)

        if len(workflow_actions) == 0:
            raise MethodNotAllowedException(message="Tally sheet is longer accepting proof documents.",
                                            code=MESSAGE_CODE_TALLY_SHEET_NO_LONGER_ACCEPTING_PROOF_DOCUMENTS)

        return workflow_actions
示例#9
0
    def set_locked_version(self, submissionVersion: SubmissionVersion):
        if submissionVersion is None:
            self.lockedVersionId = None
        else:
            if submissionVersion.submissionId is not self.submissionId:
                raise MethodNotAllowedException(
                    "%s version is not belongs to the %s (submissionId=%d, submissionVersionId=%d)"
                    %
                    (self.submissionType.name, self.submissionType.name,
                     self.submissionId, submissionVersion.submissionVersionId))

            self.lockedVersionId = submissionVersion.submissionVersionId

        db.session.add(self)
        db.session.flush()
示例#10
0
    def set_latest_version(self, tallySheetVersion: TallySheetVersion):
        if tallySheetVersion is None:
            self.latestVersionId = None
        else:
            if tallySheetVersion.tallySheetId != self.tallySheetId:
                raise MethodNotAllowedException(
                    message=
                    "Tally sheet version is not belongs to the tally sheet (tallySheetId=%d, tallySheetVersionId=%d)"
                    %
                    (self.tallySheetId, tallySheetVersion.tallySheetVersionId),
                    code=
                    MESSAGE_CODE_IRRELEVANT_VERSION_CANNOT_BE_MAPPED_TO_TALLY_SHEET
                )

            self.latestVersionId = tallySheetVersion.tallySheetVersionId

        db.session.add(self)
        db.session.flush()
    def set_latest_version(self, submissionVersion: SubmissionVersion):
        if submissionVersion is None:
            self.latestVersionId = None
            self.latestStampId = None
        else:
            if submissionVersion.submissionId != self.submissionId:
                raise MethodNotAllowedException(
                    message="%s version is not belongs to the %s (submissionId=%d, submissionVersionId=%d, submissionVersion.submissionId=%d)" % (
                        self.submissionType.name, self.submissionType.name, self.submissionId,
                        submissionVersion.submissionVersionId, submissionVersion.submissionId
                    ),
                    code=MESSAGE_CODE_SUBMISSION_IRRELEVANT_VERSION_CANNOT_BE_MAPPED
                )

            self.latestVersionId = submissionVersion.submissionVersionId
            self.latestStampId = Stamp.create().stampId

        db.session.add(self)
        db.session.flush()
示例#12
0
def notify_results(tally_sheet, tally_sheet_version_id):
    if tally_sheet.tallySheetCode in notify_allowed_tally_sheet_codes:
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=tally_sheet.tallySheetId,
            tallySheetVersionId=tally_sheet_version_id
        )
        response, result_code = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        # if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
        #     result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        response['type'] = result_dissemination_result_type

        url = "%s/%s/%s/%s/%s" % (
            RESULT_DISSEMINATION_SYSTEM_URL,
            NOTIFY_RESULTS_ENDPOINT,
            RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
            result_dissemination_result_type,
            result_code
        )

        params = {
            "level": get_result_level(tally_sheet),
        }

        required_params_from_response = [PARAM_ED_NAME, PARAM_PD_NAME]
        for required_param in required_params_from_response:
            if required_param in response:
                params[required_param] = response[required_param]

        print("#### RESULT_DISSEMINATION_API - Notify #### ", [url, response, params])
        result = requests.post(url, verify=False, params=params)
        print(result.status_code, result.content)
        return result
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be notified.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_NOTIFIED
        )
 def on_before_workflow_action(self, workflow_action, tally_sheet_version):
     if not tally_sheet_version.isComplete:
         raise MethodNotAllowedException(
             message="Incomplete tally sheet.",
             code=MESSAGE_CODE_TALLY_SHEET_INCOMPLETE)
示例#14
0
 def on_before_workflow_action(self, workflow_action, tally_sheet_version):
     if workflow_action.actionType not in [WORKFLOW_ACTION_TYPE_VIEW, WORKFLOW_ACTION_TYPE_PRINT,
                                           WORKFLOW_ACTION_TYPE_SAVE] and not tally_sheet_version.isComplete:
         raise MethodNotAllowedException(message="Incomplete tally sheet.", code=MESSAGE_CODE_TALLY_SHEET_INCOMPLETE)