Exemplo n.º 1
0
def create_issue(order_item, description, summary):
    order_item_content_type = ContentType.objects.get_for_model(order_item)

    if not support_models.Issue.objects.filter(
            resource_object_id=order_item.id,
            resource_content_type=order_item_content_type).exists():
        issue_details = dict(
            caller=order_item.order.created_by,
            project=order_item.order.project,
            customer=order_item.order.project.customer,
            type=settings.WALDUR_SUPPORT['DEFAULT_OFFERING_ISSUE_TYPE'],
            description=description,
            summary=summary,
            resource=order_item)
        issue_details['summary'] = support_serializers.render_issue_template(
            'summary', issue_details)
        issue_details[
            'description'] = support_serializers.render_issue_template(
                'description', issue_details)
        issue = support_models.Issue.objects.create(**issue_details)
        try:
            support_backend.get_active_backend().create_issue(issue)
        except support_exceptions.SupportUserInactive:
            issue.delete()
            order_item.resource.set_state_erred()
            order_item.resource.save(update_fields=['state'])
            raise rf_exceptions.ValidationError(
                _('Delete resource process is cancelled and issue not created '
                  'because a caller is inactive.'))
    else:
        message = 'An issue creating is skipped because an issue for order item %s exists already.' % order_item.uuid
        logger.warning(message)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        models.RequestType.objects.all().delete()
        backend = support_backend.get_active_backend()
        backend.pull_request_types()

        for support_customer in models.SupportCustomer.objects.all():
            exists_user = backend.manager.search_users(
                support_customer.user.email)

            if exists_user:
                backend_user = exists_user[0]
            else:
                backend_user = backend.create_user(support_customer.user)

            support_customer.backend_id = backend_user.key
            support_customer.save()
Exemplo n.º 3
0
 def create(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     expert_request = serializer.save()
     support_backend.get_active_backend().create_issue(expert_request.issue)
     return response.Response(serializer.data, status=status.HTTP_201_CREATED)
Exemplo n.º 4
0
def create_issue(order_item, description, summary, confirmation_comment=None):
    order_item_content_type = ContentType.objects.get_for_model(order_item)

    if support_models.Issue.objects.filter(
        resource_object_id=order_item.id, resource_content_type=order_item_content_type
    ).exists():
        logger.warning(
            'An issue creating is skipped because an issue for order item %s exists already.'
            % order_item.uuid
        )
        return
    issue_details = dict(
        caller=order_item.order.created_by,
        project=order_item.order.project,
        customer=order_item.order.project.customer,
        type=settings.WALDUR_SUPPORT['DEFAULT_OFFERING_ISSUE_TYPE'],
        description=description,
        summary=summary,
        resource=order_item,
    )
    issue_details['summary'] = support_serializers.render_issue_template(
        'summary', issue_details
    )
    issue_details['description'] = support_serializers.render_issue_template(
        'description', issue_details
    )
    issue = support_models.Issue.objects.create(**issue_details)
    try:
        support_backend.get_active_backend().create_issue(issue)
    except support_exceptions.SupportUserInactive:
        issue.delete()
        order_item.resource.set_state_erred()
        order_item.resource.save(update_fields=['state'])
        raise rf_exceptions.ValidationError(
            _(
                'Delete resource process is cancelled and issue not created '
                'because a caller is inactive.'
            )
        )

    if order_item.resource:
        ids = marketplace_models.OrderItem.objects.filter(
            resource=order_item.resource
        ).values_list('id', flat=True)
        linked_issues = support_models.Issue.objects.filter(
            resource_object_id__in=ids, resource_content_type=order_item_content_type,
        ).exclude(id=issue.id)
        try:
            support_backend.get_active_backend().create_issue_links(
                issue, list(linked_issues)
            )
        except JIRAError as e:
            logger.exception('Linked issues have not been added: %s', e)

    if confirmation_comment:
        try:
            support_backend.get_active_backend().create_confirmation_comment(
                issue, confirmation_comment
            )
        except JIRAError as e:
            logger.exception('Unable to create confirmation comment: %s', e)

    return issue