[Bps-public-commit] rt-extension-rightsdebugger branch, master, updated. d531592624600b261c199918f76dfc54d746d7fb

Shawn Moore shawn at bestpractical.com
Tue Feb 28 15:28:00 EST 2017


The branch, master has been updated
       via  d531592624600b261c199918f76dfc54d746d7fb (commit)
      from  7a09b717fd952f62a76499a84cac8a7dbd366256 (commit)

Summary of changes:
 html/Admin/RightsDebugger/index.html |  2 +-
 html/Helpers/RightsDebugger/Revoke   | 19 ++++++++++++++
 lib/RT/Extension/RightsDebugger.pm   |  1 +
 static/css/rights-debugger.css       |  7 +++---
 static/js/rights-debugger.js         | 48 ++++++++++++++++++++++++++++++++++++
 5 files changed, 73 insertions(+), 4 deletions(-)
 create mode 100644 html/Helpers/RightsDebugger/Revoke

- Log -----------------------------------------------------------------
commit d531592624600b261c199918f76dfc54d746d7fb
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Feb 28 20:27:49 2017 +0000

    Implement revoking rights

diff --git a/html/Admin/RightsDebugger/index.html b/html/Admin/RightsDebugger/index.html
index 15f95d2..2af85f6 100644
--- a/html/Admin/RightsDebugger/index.html
+++ b/html/Admin/RightsDebugger/index.html
@@ -28,7 +28,7 @@
     <div class="object cell">{{> render_record item.object}}</div>
     <div class="right cell">{{search_highlight item.right search.right}}</div>
     <div class="revoke cell">
-        <button {{#if item.disable_revoke}}class="ui-state-disabled" disabled="disabled"{{/if}}>Revoke</button>
+        <button data-action="<%RT->Config->Get('WebPath')%>/Helpers/RightsDebugger/Revoke?id={{item.ace.id}}" {{#if item.disable_revoke}}class="ui-state-disabled" disabled="disabled"{{/if}}>Revoke</button>
     </div>
   </div>
 </script>
diff --git a/html/Helpers/RightsDebugger/Revoke b/html/Helpers/RightsDebugger/Revoke
new file mode 100644
index 0000000..edd4b3b
--- /dev/null
+++ b/html/Helpers/RightsDebugger/Revoke
@@ -0,0 +1,19 @@
+<%ARGS>
+$id => undef
+</%ARGS>
+<%INIT>
+sleep 5;
+my $ACE = RT::ACE->new($session{CurrentUser});
+$ACE->Load($id);
+
+my $Principal = $ACE->PrincipalObj;
+my $Object    = $ACE->Object;
+my $Right     = $ACE->RightName;
+
+my ($ok, $msg) = $Principal->RevokeRight(Object => $Object, Right => $Right);
+
+$r->content_type('application/json; charset=utf-8');
+$m->out(JSON({ok => $ok, msg => $msg}));
+$m->abort;
+</%INIT>
+
diff --git a/lib/RT/Extension/RightsDebugger.pm b/lib/RT/Extension/RightsDebugger.pm
index 7f4fd82..d3f42d5 100644
--- a/lib/RT/Extension/RightsDebugger.pm
+++ b/lib/RT/Extension/RightsDebugger.pm
@@ -16,6 +16,7 @@ sub SerializeACE {
         principal      => $self->SerializeRecord($ACE->PrincipalObj),
         object         => $self->SerializeRecord($ACE->Object),
         right          => $ACE->RightName,
+        ace            => { id => $ACE->Id },
         disable_revoke => $self->DisableRevoke($ACE),
     };
 }
diff --git a/static/css/rights-debugger.css b/static/css/rights-debugger.css
index 84171b8..680a397 100644
--- a/static/css/rights-debugger.css
+++ b/static/css/rights-debugger.css
@@ -8,9 +8,10 @@
     display: none;
 }
 
-#rights-debugger .search .loading img {
-    height: 1em;
-    width: 1em;
+#rights-debugger .search .loading img,
+#rights-debugger .results .revoke img {
+    height: 1.5em;
+    width: 1.5em;
 }
 
 #rights-debugger.refreshing .search .loading {
diff --git a/static/js/rights-debugger.js b/static/js/rights-debugger.js
index 77f4991..38f78c0 100644
--- a/static/js/rights-debugger.js
+++ b/static/js/rights-debugger.js
@@ -18,9 +18,20 @@ jQuery(function () {
     var renderItem = Handlebars.compile(resultTemplate);
     var form = jQuery('form#rights-debugger');
     var display = form.find('.results');
+    var loading = form.find('.search .loading');
 
+    var revoking = {};
     var existingRequest;
 
+    var buttonForAction = function (action) {
+        return display.find('.revoke button[data-action="' + action + '"]');
+    };
+
+    var displayRevoking = function (button) {
+        button.addClass('ui-state-disabled').prop('disabled', true);
+        button.after(loading.clone());
+    };
+
     var refreshResults = function () {
         form.addClass('refreshing');
         form.find('button').addClass('ui-state-disabled').prop('disabled', true);
@@ -46,12 +57,49 @@ jQuery(function () {
                 jQuery.each(items, function (i, item) {
                     display.append(renderItem({ search: search, item: item }));
                 });
+
+                jQuery.each(revoking, function (key, value) {
+                    var revokeButton = buttonForAction(key);
+                    displayRevoking(revokeButton);
+                });
+
             },
             error: function (xhr, reason) {
             }
         });
     };
 
+    display.on('click', '.revoke button', function (e) {
+        e.preventDefault();
+        var button = jQuery(e.target);
+        var action = button.data('action');
+
+        displayRevoking(button);
+
+        revoking[action] = 1;
+
+        jQuery.ajax({
+            url: action,
+            timeout: 30000, /* 30 seconds */
+            success: function (response) {
+                button = buttonForAction(action);
+                if (!button.length) {
+                    alert(response.msg);
+                }
+                else {
+                    button.closest('.revoke').text(response.msg);
+                }
+                delete revoking[action];
+            },
+            error: function (xhr, reason) {
+                button = buttonForAction(action);
+                button.closest('.revoke').text(reason);
+                delete revoking[action];
+                alert(reason);
+            }
+        });
+    });
+
     form.find('.search input').on('input', function () {
         refreshResults();
     });

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list