Send an X-CSRFToken header when deleting integrations

Review Request #8490 — Created Oct. 25, 2016 and submitted

Information

Djblets
release-0.10.x

Reviewers

Previously, integrations could not be deleted. The view required a CSRF
token to be submitted but we were not sending one. Now we check for a
CSRF token field in the form before executing our HTTP DELETE request
and, if present, we add the X-CSRFToken header to the request. This
allows integrations to be deleted.

Able to delete an integration with this patch applied.

Description From Last Updated

Because there's only ever one of these on the page, and .val() returns undefined when there are no matching elements, …

daviddavid

There should only ever be one <input name="csrfmiddlewaretoken"> on the page, so this selector can just be $('input[name="csrfmiddlewaretoken"]')

daviddavid
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        djblets/integrations/templates/integrations/configure_integration.html
    
    
    
    Tool: Pyflakes
    Ignored Files:
        djblets/integrations/templates/integrations/configure_integration.html
    
    
  2. 
      
david
  1. 
      
  2. Show all issues

    Because there's only ever one of these on the page, and .val() returns undefined when there are no matching elements, this whole thing could be:

    var csrfToken = $('input[name="csrfmiddlewaretoken"]').val();
    
    if (csrfToken) {
        xhr.setRequestHeader('X-CSRFToken', csrfToken);
    }
    
  3. 
      
brennie
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        djblets/integrations/templates/integrations/configure_integration.html
    
    
    
    Tool: Pyflakes
    Ignored Files:
        djblets/integrations/templates/integrations/configure_integration.html
    
    
  2. 
      
david
  1. 
      
  2. Show all issues

    There should only ever be one <input name="csrfmiddlewaretoken"> on the page, so this selector can just be $('input[name="csrfmiddlewaretoken"]')

  3. 
      
brennie
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        djblets/integrations/templates/integrations/configure_integration.html
    
    
    
    Tool: Pyflakes
    Ignored Files:
        djblets/integrations/templates/integrations/configure_integration.html
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
brennie
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-0.10.x (70b7578)
Loading...