doortts doortts 2017-10-03
webhook: Fix commit push hook check bug
See: Yona Github issue #307
@1fca9100e606463a6b20cb6d17283b1ae7174e88
app/controllers/ProjectApp.java
--- app/controllers/ProjectApp.java
+++ app/controllers/ProjectApp.java
@@ -18,6 +18,7 @@
 import models.enumeration.*;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.mail.HtmlEmail;
 import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -1252,10 +1253,10 @@
             return badRequest(ErrorViews.BadRequest.render());
         }
 
-        Webhook.create(project.id,
-                        addWebhookForm.field("payloadUrl").value(),
-                        addWebhookForm.field("secret").value(),
-                Boolean.valueOf(addWebhookForm.field("gitPushOnly").value()));
+        Webhook webhook = addWebhookForm.get();
+
+        Webhook.create(project.id, webhook.payloadUrl, webhook.secret,
+                BooleanUtils.toBooleanDefaultIfNull(webhook.gitPushOnly, false));
 
         return redirect(routes.ProjectApp.webhooks(project.owner, project.name));
     }
app/models/Webhook.java
--- app/models/Webhook.java
+++ app/models/Webhook.java
@@ -440,4 +440,16 @@
         targetProject.update();
         super.delete();
     }
+
+    @Override
+    public String toString() {
+        return "Webhook{" +
+                "id=" + id +
+                ", project=" + project +
+                ", payloadUrl='" + payloadUrl + '\'' +
+                ", secret='" + secret + '\'' +
+                ", gitPushOnly=" + gitPushOnly +
+                ", createdAt=" + createdAt +
+                '}';
+    }
 }
app/models/enumeration/EventType.java
--- app/models/enumeration/EventType.java
+++ app/models/enumeration/EventType.java
@@ -80,4 +80,13 @@
                 return false;
         }
     }
+
+    @Override
+    public String toString() {
+        return "EventType{" +
+                "descr='" + descr + '\'' +
+                ", order=" + order +
+                ", messageKey='" + messageKey + '\'' +
+                '}';
+    }
 }
app/views/project/partial_webhooks_list.scala.html
--- app/views/project/partial_webhooks_list.scala.html
+++ app/views/project/partial_webhooks_list.scala.html
@@ -33,8 +33,8 @@
     <div class="span8 payload-url">
       <strong>@Messages("project.webhook.payloadUrl")</strong>
     </div>
-      <div class="span4 secret">
-      <strong>@Messages("project.webhook.secret")</strong>
+    <div class="span4 secret">
+      <strong>@Messages("project.webhook.secret") / Working only when Git push</strong>
     </div>
   </div>
 
@@ -53,6 +53,11 @@
                   @webhook.secret
               </span>
             </td>
+            <td>
+              <span class="webhook-secret truncate">
+              <input type="checkbox" @if(webhook.gitPushOnly){checked} onclick="return false;" />
+              </span>
+            </td>
             <td class="actions">
               <button type="button" class="ybtn ybtn-danger ybtn-small" data-request-method="delete" data-request-uri="@routes.ProjectApp.deleteWebhook(project.owner, project.name, webhook.id)">
                 @Messages("button.delete")
app/views/project/webhooks.scala.html
--- app/views/project/webhooks.scala.html
+++ app/views/project/webhooks.scala.html
@@ -1,22 +1,8 @@
 @**
-* Yobi, Project Hosting SW
+* Yona, 21st Century Project Hosting SW
 *
-* Copyright 2015 NAVER Corp.
-* http://yobi.io
-*
-* @author Jihwan Chun
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*   http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+* Copyright Yona & Yobi Authors & NAVER Corp. & NAVER LABS Corp.
+* https://yona.io
 **@
 @(message: String, webhooks: List[models.Webhook], project:Project)
 
Add a comment
List