You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/02/24 12:48:04 UTC

[10/50] [abbrv] allura git commit: [#4542] ticket:714 Delete webhooks

[#4542] ticket:714 Delete webhooks


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/ad60782f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/ad60782f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/ad60782f

Branch: refs/heads/ib/7827
Commit: ad60782fef61daad65b93dcd7e00c1079468b4d8
Parents: 4e8acf6
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Jan 28 14:56:01 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon Feb 16 10:16:48 2015 +0000

----------------------------------------------------------------------
 .../ext/admin/templates/webhooks_list.html      | 35 +++++++++++++++++---
 Allura/allura/webhooks.py                       | 19 +++++++++--
 2 files changed, 47 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ad60782f/Allura/allura/ext/admin/templates/webhooks_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/webhooks_list.html b/Allura/allura/ext/admin/templates/webhooks_list.html
index d591173..f54b7fb 100644
--- a/Allura/allura/ext/admin/templates/webhooks_list.html
+++ b/Allura/allura/ext/admin/templates/webhooks_list.html
@@ -27,17 +27,20 @@
     <p><a href="{{c.app.url}}webhooks/{{ hook.type }}">Create</a></p>
     {% if configured_hooks[hook.type] %}
       <table>
-        {% for h in configured_hooks[hook.type] %}
+        {% for wh in configured_hooks[hook.type] %}
         <tr>
           <td>
-            <a href="{{ h.url() }}">{{ h.hook_url }}</a>
+            <a href="{{ wh.url() }}">{{ wh.hook_url }}</a>
           </td>
           <td>
-            <a href="{{ h.app_config.url() }}">{{ h.app_config.options.mount_label }}</a>
+            <a href="{{ wh.app_config.url() }}">{{ wh.app_config.options.mount_label }}</a>
           </td>
-          <td>{{ h.secret or '' }}</td>
+          <td>{{ wh.secret or '' }}</td>
           <td>
-            <a href="#" title="Delete">
+            <a href="{{c.app.url}}webhooks/{{hook.type}}/delete"
+               class="delete-link"
+               data-id="{{h.really_unicode(wh._id)}}"
+               title="Delete">
               <b data-icon="{{g.icons['delete'].char}}" class="ico {{g.icons['delete'].css}}" title="Delete"></b>
             </a>
           </td>
@@ -47,3 +50,25 @@
     {% endif %}
   {% endfor %}
 {% endblock %}
+
+{% block extra_js %}
+<script type="text/javascript">
+$(function() {
+  $('.delete-link').click(function(e) {
+    e.preventDefault();
+    var id = $(this).attr('data-id');
+    var csrf = $.cookie('_session_id');
+    var data = {'webhook': id, '_session_id': csrf};
+    var url = $(this).attr('href');
+    var $tr = $(this).parents('tr')
+    $.post(url, data, function(data) {
+      if (data['status'] == 'ok') {
+        $tr.remove();
+      } else {
+        console.log(data);
+      }
+    });
+  });
+});
+</script>
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/ad60782f/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index 8fb62d5..c4c6ca6 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -21,7 +21,7 @@ import hmac
 import hashlib
 
 import requests
-from tg import expose, validate, redirect
+from tg import expose, validate, redirect, flash
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from pylons import tmpl_context as c
 from formencode import validators as fev, schema, Invalid
@@ -87,7 +87,7 @@ class WebhookEditForm(WebhookCreateForm):
 
 class WebhookControllerMeta(type):
     def __call__(cls, sender, *args, **kw):
-        """Decorate the `create` post handler with a validator that references
+        """Decorate post handlers with a validator that references
         the appropriate webhook sender for this controller.
         """
         if hasattr(cls, 'create'):
@@ -136,6 +136,7 @@ class WebhookController(BaseController):
         session(wh).flush(wh)
         M.AuditLog.log('add webhook %s %s %s',
                        wh.type, wh.hook_url, wh.app_config.url())
+        flash('Created successfully', 'ok')
         redirect(c.project.url() + 'admin/webhooks/')
 
     @expose()
@@ -154,8 +155,22 @@ class WebhookController(BaseController):
         M.AuditLog.log('edit webhook %s\n%s => %s\n%s => %s\n%s',
             webhook.type, old_url, url, old_app, app.url(),
             'secret changed' if old_secret != secret else '')
+        flash('Edited successfully', 'ok')
         redirect(c.project.url() + 'admin/webhooks/')
 
+    @expose('json:')
+    @require_post()
+    def delete(self, webhook):
+        form = self.edit_form(self.sender)
+        try:
+            wh = form.fields['webhook'].to_python(webhook)
+        except Invalid:
+            raise exc.HTTPNotFound()
+        wh.delete()
+        M.AuditLog.log('delete webhook %s %s %s',
+                       wh.type, wh.hook_url, wh.app_config.url())
+        return {'status': 'ok'}
+
     @without_trailing_slash
     @expose('jinja:allura:templates/webhooks/create_form.html')
     def _default(self, webhook, **kw):