From 959d63ab1a5559f5f60ba7378a59e2d0fdb17c73 Mon Sep 17 00:00:00 2001
From: Timothy Andrew <mail@timothyandrew.net>
Date: Fri, 24 Jun 2016 11:13:02 +0530
Subject: [PATCH] Clean up `protected_branches.js.coffee`

- Only send a param for the currently changed checkbox.
- Have the controller use strong parameters correctly, so that the PATCH
  works as expected.
---
 app/assets/javascripts/protected_branches.js.coffee | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/app/assets/javascripts/protected_branches.js.coffee b/app/assets/javascripts/protected_branches.js.coffee
index ce2fc883620..14afef2e2ee 100644
--- a/app/assets/javascripts/protected_branches.js.coffee
+++ b/app/assets/javascripts/protected_branches.js.coffee
@@ -1,21 +1,18 @@
 $ ->
   $(".protected-branches-list :checkbox").change (e) ->
     name = $(this).attr("name")
-    row = $(this).parents("tr")
     if name == "developers_can_push" || name == "developers_can_merge"
       id = $(this).val()
-      can_push = row.find("input[name=developers_can_push]").is(":checked")
-      can_merge = row.find("input[name=developers_can_merge]").is(":checked")
+      can_push = $(this).is(":checked")
       url = $(this).data("url")
       $.ajax
-        type: "PUT"
+        type: "PATCH"
         url: url
         dataType: "json"
         data:
           id: id
           protected_branch:
-            developers_can_push: can_push
-            developers_can_merge: can_merge
+            "#{name}": can_push
 
         success: ->
           row = $(e.target)
-- 
GitLab