Esempio n. 1
0
    def done(self, form_list, **kwargs):
        req = kwargs.get('request') or self.request

        if self.object_to_edit:
            report = self.object_to_edit
        elif self.storage.extra_data.get('report_id'):
            report = Report.objects.get(id=self.storage.extra_data.get('report_id'))
        else:
            report = Report(owner=req.user)

        if not report.owner == req.user:
            self._unauthorized_access(req, report)

        key = list(form_list)[0].cleaned_data['key']

        report_text = json.dumps(self.processed_answers, sort_keys=True)
        report.encrypt_report(report_text, key, self.object_to_edit)
        report.save()

        # save anonymised answers
        if self.object_to_edit:
            EvalRow.store_eval_row(action=EvalRow.EDIT, report=report, decrypted_text=report_text)
        else:
            EvalRow.store_eval_row(action=EvalRow.CREATE, report=report, decrypted_text=report_text)

        return self.wizard_complete(report, **kwargs)
Esempio n. 2
0
 def auto_save(self, **kwargs):
     """
     Automatically save what's been entered so far before rendering the next step.
     We only do this on steps after the first non-key form because we can only save completed steps
     https://github.com/SexualHealthInnovations/callisto-core/issues/89
     """
     if not self.object_to_edit and int(self.steps.current) > 1:
         if self.storage.extra_data.get('report_id'):
             report = Report.objects.get(id=self.storage.extra_data.get('report_id'))
         else:
             req = kwargs.get('request') or self.request
             report = Report(owner=req.user)
         forms_so_far = self._get_forms_with_data()
         report_text = json.dumps(self.process_answers(forms_so_far.values(), form_dict=forms_so_far),
                                  sort_keys=True)
         key = forms_so_far['0'].cleaned_data['key']
         report.encrypt_report(report_text, key, edit=self.object_to_edit, autosave=True)
         report.save()
         self.storage.extra_data['report_id'] = report.id
         EvalRow.store_eval_row(action=EvalRow.AUTOSAVE, report=report, decrypted_text=report_text)
Esempio n. 3
0
def process_new_matches(matches, identifier, report_class):
    """Sends a report to the receiving authority and notifies the reporting users. Each user should only be notified
    one time when a match is found.

    Args:
      matches (list of MatchReports): the MatchReports that correspond to this identifier
      identifier (str): identifier associated with the MatchReports
      report_class(report generator class, optional): Must have `send_matching_report_to_school` method. (Default
      value = PDFMatchReport)
    """
    logger.info("new match found")
    owners_notified = []
    for match_report in matches:
        EvalRow.store_eval_row(action=EvalRow.MATCH_FOUND, report=match_report.report)
        owner = match_report.report.owner
        # only send notification emails to new matches
        if owner not in owners_notified and not match_report.report.match_found \
                and not match_report.report.submitted_to_school:
            send_notification_email(owner, match_report)
            owners_notified.append(owner)
    # send report to school
    report_class(matches, identifier).send_matching_report_to_school()
Esempio n. 4
0
 def test_make_eval_row(self):
     user = User.objects.create_user(username="******", password="******")
     report = Report.objects.create(owner=user, encrypted=b'first report')
     EvalRow.store_eval_row(EvalRow.CREATE, report=report)
     self.assertEqual(EvalRow.objects.count(), 1)