def _create_ticket(report): from worker import database ticket = database.create_ticket(report.defendant, report.category, report.service, priority=report.provider.priority) utils.scheduler.enqueue_in( timedelta(seconds=settings.GENERAL_CONFIG['phishing']['wait']), 'ticket.timeout', ticket_id=ticket.id, timeout=3600, ) ticket_snooze = settings.GENERAL_CONFIG['phishing']['wait'] ticket.previousStatus = ticket.status ticket.status = 'WaitingAnswer' ticket.snoozeDuration = ticket_snooze ticket.snoozeStart = datetime.now() ticket.save() return ticket
def apply(self, report, ticket, is_trusted=False, no_phishtocheck=False): """ Apply specific workflow on given `abuse.models.Report` :param `abuse.models.Report` report: A Cerberus report instance :param `abuse.models.Ticket` ticket: A Cerberus ticket instance :param bool is_trusted: If the report is trusted :param bool no_phishtocheck: if the report does not need PhishToCheck :return: If the workflow is applied :rtype: bool """ from worker import common, database ticket = database.create_ticket( report.defendant, report.category, report.service, attach_new=False ) database.log_action_on_ticket( ticket=ticket, action='attach_report', report=report, new_ticket=True ) # Add proof content = regexp.ACNS_PROOF.search(report.body).group() for email in re.findall(regexp.EMAIL, content): # Remove potentially sensitive emails content = content.replace(email, '*****@*****.**') Proof.objects.create( content=content, ticket=ticket, ) # Send emails to provider/defendant (template, email, lang) templates = [ (settings.CODENAMES['ack_received'], report.provider.email, 'EN'), (settings.CODENAMES['first_alert'], report.defendant.details.email, report.defendant.details.lang), ] for codename, email, lang in templates: common.send_email( ticket, [email], codename, lang=lang, acknowledged_report_id=report.id, ) # Close ticket ImplementationFactory.instance.get_singleton_of('MailerServiceBase').close_thread(ticket) resolution = Resolution.objects.get(codename=settings.CODENAMES['forward_acns']) ticket.resolution = resolution ticket.previousStatus = ticket.status ticket.status = 'Closed' ticket.update = False ticket.save() database.log_action_on_ticket( ticket=ticket, action='change_status', previous_value=ticket.previousStatus, new_value=ticket.status, close_reason=resolution.codename ) report.ticket = Ticket.objects.get(id=ticket.id) report.status = 'Archived' report.save() database.set_ticket_higher_priority(report.ticket) return True
def apply(self, report, ticket, is_trusted=False, no_phishtocheck=False): """ Apply specific workflow on given `abuse.models.Report` :param `abuse.models.Report` report: A Cerberus report instance :param `abuse.models.Ticket` ticket: A Cerberus ticket instance :param bool is_trusted: If the report is trusted :param bool no_phishtocheck: if the report does not need PhishToCheck :return: If the workflow is applied :rtype: bool """ from worker import common, database new_ticket = False if not ticket: # Create ticket ticket = database.create_ticket( report.defendant, report.category, report.service, attach_new=True ) new_ticket = True utils.scheduler.enqueue_in( timedelta(seconds=settings.GENERAL_CONFIG['copyright']['wait']), 'ticket.timeout', ticket_id=ticket.id, timeout=3600, ) ticket_snooze = settings.GENERAL_CONFIG['copyright']['wait'] ticket.previousStatus = ticket.status ticket.status = 'WaitingAnswer' ticket.snoozeDuration = ticket_snooze ticket.snoozeStart = datetime.now() ticket.save() database.log_action_on_ticket( ticket=ticket, action='attach_report', report=report, new_ticket=new_ticket, ) # Send emails to provider/defendant (template, email, lang) ticket.proof.all().delete() # Add proof content = report.body for email in re.findall(regexp.EMAIL, content): # Remove potentially sensitive emails content = content.replace(email, '*****@*****.**') Proof.objects.create( content=content, ticket=ticket, ) # Send emails templates = [ (settings.CODENAMES['ack_received'], report.provider.email, 'EN'), (settings.CODENAMES['first_alert'], report.defendant.details.email, report.defendant.details.lang), ] for codename, email, lang in templates: common.send_email( ticket, [email], codename, lang=lang, acknowledged_report_id=report.id, ) report.ticket = Ticket.objects.get(id=ticket.id) report.status = 'Attached' report.save() database.set_ticket_higher_priority(report.ticket) return True