Exemple #1
0
    def create_zendesk_ticket(self, cleaned_data):

        request_data = {**cleaned_data}

        if not self.request.user.is_authenticated:
            request_data["text"] = "account reactivation request\n"
        else:
            request_data["email"] = self.request.user.email
            application = self.request.session.get(
                LAST_FAILED_APPLICATION_SESSION_KEY, "Unspecified")
            request_data[
                "text"] = f"require access to application: {application}\n"

        zendesk_user = ZendeskUser(name=cleaned_data["full_name"],
                                   email=request_data["email"])

        description = "Name: {full_name}\nTeam: {team}\nEmail: {email}\n{text}".format(
            **request_data)

        ticket = Ticket(
            subject=settings.ZENDESK_TICKET_SUBJECT,
            description=description,
            requester=zendesk_user,
            custom_fields=[CustomField(id="31281329", value="auth_broker")],
        )
        response = self.get_zendesk_client().tickets.create(ticket)
        return response.ticket.id
def create_support_request(user, email, message, attachments=()):
    client = Zenpy(
        subdomain=settings.ZENDESK_SUBDOMAIN,
        email=settings.ZENDESK_EMAIL,
        token=settings.ZENDESK_TOKEN,
    )
    ticket_audit = client.tickets.create(
        Ticket(
            subject='Data Workspace Support Request',
            description=message,
            requester=User(email=email, name=user.get_full_name()),
            custom_fields=[
                CustomField(
                    id=zendesk_service_field_id, value=zendesk_service_field_value
                )
            ],
        )
    )
    if attachments:
        uploads = [client.attachments.upload(x) for x in attachments]
        ticket_audit.ticket.comment = Comment(
            body='Additional attachments', uploads=[x.token for x in uploads]
        )
        client.tickets.update(ticket_audit.ticket)
    return ticket_audit.ticket.id
Exemple #3
0
def create_ticket(title, description, impact, history, name, email):
    global ticket_number

    zendesk_client = Zenpy(**creds)

    # Create a new ticket
    ticket_audit = zendesk_client.tickets.create(
        Ticket(
            subject=title,
            requester=User(name=name, email=email),
            comment=Comment(
                html_body=
                '<h3>Request Details</h3><pre><code>Title: {}<br>Request: {}<br>'
                'Impact: {}<br>History: {}</code></pre><h3>Submitter Details</h3><pre><code>'
                'Name: {}<br>Email: {}</code></pre>'.format(
                    title, description, impact, history, name, email)),
            type="problem",
            priority="normal",
            requester_id="366101959011",
            submitter_id="366101959011",
            ticket_form_id="360000072631",
            group_id="360000964291",
            collaborator_ids=["443254580", "656182144"],
            follower_ids=["443254580", "656182144"],
            custom_fields=[
                CustomField(id=360005680151,
                            value='request_to_update_existing_process')
            ]))

    ticket_number = ticket_audit.ticket.id
    def create_zendesk_ticket(self):

        zenpy_client = Zenpy(
            subdomain=settings.ZENDESK_SUBDOMAIN,
            email=settings.ZENDESK_EMAIL,
            token=settings.ZENDESK_TOKEN,
        )

        attachments = [
            value for field, value in self.cleaned_data.items()
            if field.startswith('attachment') and value
        ]

        if attachments:
            uploads = []
            for attachment in attachments:
                upload_instance = zenpy_client.attachments.upload(
                    attachment.temporary_file_path())
                uploads.append(upload_instance.token)
        else:
            uploads = None

        service = SERVICE_FIELD_MAPPING[self.cleaned_data['platform']]

        custom_fields = [
            CustomField(id=30041969, value=service),  # service
            CustomField(id=360000180437,
                        value=self.cleaned_data['department']),  # directorate
            CustomField(id=45522485,
                        value=self.cleaned_data['email']),  # email
            CustomField(id=360000188178,
                        value=self.cleaned_data['telephone']),  # Phone number
            CustomField(
                id=360000182638,
                value=self.cleaned_data['request_type']),  # Content request
            CustomField(id=360000180477,
                        value=self.cleaned_data['publication_date_explanation']
                        ),  # reason
            CustomField(id=360000180457,
                        value=str(
                            self.cleaned_data['publication_date']))  # due date
        ]

        ticket = zenpy_client.tickets.create(
            Ticket(subject=self.cleaned_data['title_of_request'],
                   custom_fields=custom_fields,
                   tags=['content_delivery', self.cleaned_data['platform']],
                   comment=Comment(html_body=self.formatted_text(),
                                   uploads=uploads),
                   requester=User(name=self.cleaned_data['name'],
                                  email=self.cleaned_data['email']))).ticket

        return ticket.id
Exemple #5
0
def create_support_request(user, email, message):
    client = Zenpy(
        subdomain=settings.ZENDESK_SUBDOMAIN,
        email=settings.ZENDESK_EMAIL,
        token=settings.ZENDESK_TOKEN,
    )
    ticket_audit = client.tickets.create(
        Ticket(
            subject='Data Workspace Support Request',
            description=message,
            requester=User(email=email, name=user.get_full_name()),
            custom_fields=[
                CustomField(id=zendesk_service_field_id,
                            value=zendesk_service_field_value)
            ],
        ))
    return ticket_audit.ticket.id
def create_zendesk_ticket(
    contact_email,
    user,
    goal,
    justification_text,
    approval_url,
    dataset_name,
    dataset_url,
    information_asset_owner,  # nb this can be null
    information_asset_manager,  # so can this
):
    client = Zenpy(
        subdomain=settings.ZENDESK_SUBDOMAIN,
        email=settings.ZENDESK_EMAIL,
        token=settings.ZENDESK_TOKEN,
    )

    ticket_description = build_ticket_description_text(
        dataset_name, dataset_url, contact_email, user, justification_text, goal
    )

    private_comment = build_private_comment_text(
        information_asset_owner, information_asset_manager, approval_url
    )

    username = get_username(user)
    subject = f'Access Request for {dataset_name}'

    ticket_audit = client.tickets.create(
        Ticket(
            subject=subject,
            description=ticket_description,
            requester=User(email=contact_email, name=username),
            custom_fields=[
                CustomField(
                    id=zendesk_service_field_id, value=zendesk_service_field_value
                )
            ],
        )
    )

    ticket_audit.ticket.comment = Comment(body=private_comment, public=False)
    client.tickets.update(ticket_audit.ticket)

    return ticket_audit.ticket.id
Exemple #7
0
def create_zendesk_ticket(request, access_request, catalogue_item=None):
    client = Zenpy(
        subdomain=settings.ZENDESK_SUBDOMAIN,
        email=settings.ZENDESK_EMAIL,
        token=settings.ZENDESK_TOKEN,
    )

    access_request_url = request.build_absolute_uri(
        reverse("admin:request_access_accessrequest_change",
                args=(access_request.id, )))

    authorize_url = request.build_absolute_uri(
        reverse("admin:auth_user_change", args=[access_request.requester.id]))

    ticket_description = build_ticket_description_text(access_request,
                                                       access_request_url,
                                                       catalogue_item)

    private_comment = (build_private_comment_text(
        catalogue_item, authorize_url) if catalogue_item else None)

    username = get_username(access_request.requester)

    subject = f"Access Request for {catalogue_item if catalogue_item else username}"

    ticket_audit = client.tickets.create(
        Ticket(
            subject=subject,
            description=ticket_description,
            requester=User(email=access_request.requester.email,
                           name=username),
            custom_fields=[
                CustomField(id=zendesk_service_field_id,
                            value=zendesk_service_field_value)
            ],
        ))

    ticket_audit.ticket.comment = Comment(body=private_comment, public=False)
    client.tickets.update(ticket_audit.ticket)

    return ticket_audit.ticket.id
Exemple #8
0
    def create_zendesk_ticket(self, cleaned_data):

        email = self.request.user.email
        application = self.request.session.get('_last_failed_access_app', 'Unspecified')

        zendesk_user = ZendeskUser(name=cleaned_data['full_name'], email=email)

        description = (
            'Name: {full_name}\n'
            'Team: {team}\n'
            'Email: {email}\n'
            'Application: {application}\n'
        ).format(email=email, application=application, **cleaned_data)
        ticket = Ticket(
            subject=settings.ZENDESK_TICKET_SUBJECT,
            description=description,
            requester=zendesk_user,
            custom_fields=[CustomField(id='31281329', value='auth_broker')]
        )
        response = self.get_zendesk_client().tickets.create(ticket)
        return response.ticket.id
Exemple #9
0
def create_adf_zendesk_tickets(instances):
    try:

        print('init adf creation')

        zenpy_client = Zenpy(**settings.ZENDESK)

        scs = ScheduledExam.objects.filter(id__in=instances)

        if not scs:
            print("No adf tickets to create")
            return

        onesc = scs.first()
        mp = onesc.prescription

        desc = """Data de abertura: {}
        Laboratório:{}
        Exames: {}
        """
        lab_name = onesc.laboratory.description if onesc.laboratory else ''
        print(desc)

        ticket = zenpy_client.tickets.create(
            Ticket(
                subject='Abertura de ficha para: {} no laboratório: {}'.format(
                    mp.patient.full_name, lab_name),
                requester=User(name=mp.patient.full_name,
                               external_id=mp.patient.user.id,
                               email=mp.patient.user.email),
                type='task',
                status='open',
                priority='normal',
                due_at=onesc.scheduled_time,
                custom_fields=[
                    CustomField(id=114103586991, value='patient_requested'),
                    CustomField(id=114103769352, value=mp.patient.phone),
                    CustomField(id=114103769652, value=mp.patient.gender),
                    CustomField(id=360002412071,
                                value=onesc.scheduled_time.date())
                ],
                description=desc.format(
                    onesc.scheduled_time.strftime('%d/%m/%Y %H:%M'),
                    onesc.laboratory.description,
                    ', '.join([i.exam.name for i in scs]))))

        et = ticket.ticket

        tdata = et.to_dict()
        del (tdata['via'])

        print(tdata)

        try:
            zticket = ZendeskASFTicket.objects.create(external_id=et.id,
                                                      content=tdata)
        except Exception as e:
            print('*** {} ***'.format(e))
            print("Ticket for exams: {} already created".format(
                scs.values('id')))
            zticket = ZendeskASFTicket.objects.filter(
                external_id=et.id).first()
        print(zticket)

        et.external_id = zticket.id
        et.tags.extend([u'saracare', u'aberturadeficha'])

        ppieces = []

        for name, file in [
            ("RG frente", mp.picture_id_front_uploadcare.file
             if mp.picture_id_front_uploadcare else None),
            ("RG verso", mp.picture_id_back_uploadcare.file
             if mp.picture_id_back_uploadcare else None),
            ("Plano frente", mp.picture_insurance_card_front_uploadcare.file
             if mp.picture_insurance_card_front_uploadcare else None),
            ("Plano verso", mp.picture_insurance_card_back_uploadcare.file
             if mp.picture_insurance_card_back_uploadcare else None)
        ] + ppieces:

            if file:
                upload_instance = zenpy_client.attachments.upload(file)
                et.comment = Comment(body=name,
                                     uploads=[upload_instance.token])
                zenpy_client.tickets.update(et)

        zenpy_client.tickets.update(et)
        scs.update(zendesk_adf_ticket=zticket)
    except Exception as e:
        print("Creation Error: {}".format(e))
Exemple #10
0
def create_zendesk_ticket(instance):
    try:

        zenpy_client = Zenpy(**settings.ZENDESK)

        if type(instance) in [str, int]:
            instance = domain_models.MedicalPrescription.objects.filter(
                id=int(instance)).first()
        desc = ""

        if instance.period_info:
            desc = "Última menstruação: {}".format(instance.period_info)

        desc = """{}
Informações Adicionais: {}""".format(desc, instance.additional_info
                                     or "Nenhuma")

        try:
            if instance.preferred_laboratory:
                desc = """{}
        Laboratório preferido: {}""".format(
                    desc, instance.preferred_laboratory.description
                    or "Nenhuma")
        except Exception:
            print(instance.preferred_laboratory)

        try:
            if instance.preferred_date_to_schedule:
                desc = """{}
        Data preferida: {}""".format(
                    desc,
                    instance.preferred_date_to_schedule.strftime(
                        "%Y-%m-%d %H:%M:%S") or "Nenhuma")
        except Exception:
            print(instance.preferred_date_to_schedule)
        selfie = ''
        if instance.patient.selfie_uploadcare:
            selfie = instance.patient.selfie_uploadcare.url
        elif instance.patient.selfie:
            selfie = instance.patient.selfie.url

        ticket = zenpy_client.tickets.create(
            Ticket(subject='Prescrição para: {}'.format(
                instance.patient.full_name),
                   requester=User(name=instance.patient.full_name,
                                  external_id=instance.patient.user.id,
                                  email=instance.patient.user.email,
                                  remote_photo_url=selfie,
                                  user_fields=UserField(
                                      gender=instance.patient.gender,
                                      phone=str(instance.patient.phone))),
                   type='task',
                   priority='normal',
                   custom_fields=[
                       CustomField(id=114103586991, value='patient_requested'),
                       CustomField(id=114103769352,
                                   value=instance.patient.phone),
                       CustomField(id=114103769652,
                                   value=instance.patient.gender)
                   ],
                   description=desc))

        # a = MedicalPrescription.objects.all().last()
        # from general_utils.utils import create_zendesk_ticket
        # create_zendesk_ticket(a)
        et = ticket.ticket

        tdata = et.to_dict()
        del (tdata['via'])

        print(tdata)

        try:
            print('###')
            zticket = ZendeskTicket.objects.create(external_id=et.id,
                                                   prescription=instance,
                                                   content=tdata)
        except Exception:
            print('***')
            zticket = ZendeskTicket.objects.filter(
                prescription=instance).first()
            zticket.external_id = et.id
            zticket.content = tdata
            zticket.save()

        print(zticket)

        et.external_id = zticket.id
        et.tags.extend([u'prescrição', u'saracare'])
        #
        # from general_utils.utils import create_zendesk_ticket
        # p = MedicalPrescription.objects.all().last()
        # create_zendesk_ticket(p)

        ppieces = []

        for ppiece in instance.pieces.all():
            if ppiece.picture:
                ppieces.append(("Precrição", ppiece.picture.file))

        for name, file in [
            ("RG frente", instance.picture_id_front_uploadcare.file
             if instance.picture_id_front_uploadcare else None),
            ("RG verso", instance.picture_id_back_uploadcare.file
             if instance.picture_id_back_uploadcare else None),
            ("Plano frente",
             instance.picture_insurance_card_front_uploadcare.file
             if instance.picture_insurance_card_front_uploadcare else None),
            ("Plano verso",
             instance.picture_insurance_card_back_uploadcare.file
             if instance.picture_insurance_card_back_uploadcare else None)
        ] + ppieces:

            if file:
                upload_instance = zenpy_client.attachments.upload(file)
                et.comment = Comment(body=name,
                                     uploads=[upload_instance.token])
                zenpy_client.tickets.update(et)

        zenpy_client.tickets.update(et)
    except Exception as e:
        print("Creation Error: {}".format(e))