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

Shawn Moore shawn at bestpractical.com
Tue Feb 28 14:07:14 EST 2017


The branch, master has been updated
       via  dc5e61d18d7757e3e8e7197cb6834647ef280ad2 (commit)
      from  8e117ee921a6fbe6e062a7e9fa3441da7bf999ea (commit)

Summary of changes:
 html/Admin/RightsDebugger/index.html | 31 ++++++++----
 html/Helpers/RightsDebugger/Search   |  9 +---
 lib/RT/Extension/RightsDebugger.pm   | 92 ++++++++++++++++++++++++++++++++++++
 static/css/rights-debugger.css       |  8 ++++
 static/js/rights-debugger.js         |  9 ++--
 5 files changed, 128 insertions(+), 21 deletions(-)

- Log -----------------------------------------------------------------
commit dc5e61d18d7757e3e8e7197cb6834647ef280ad2
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Feb 28 19:06:32 2017 +0000

    WIP
    
    Improved rendering
    Linkify records
    Refactored more code from templates into lib/
    Added new record-rendering handlebars template

diff --git a/html/Admin/RightsDebugger/index.html b/html/Admin/RightsDebugger/index.html
index a5bd3a3..b5bd0bc 100644
--- a/html/Admin/RightsDebugger/index.html
+++ b/html/Admin/RightsDebugger/index.html
@@ -11,17 +11,28 @@
   </div>
 </form>
 
-<script type="text/x-template" id="debugger-result">
+<script type="text/x-template" id="debugger-record-template">
+  {{#if url}}
+      <a target="_blank" href="{{url}}">{{label}}</a>
+  {{else}}
+      {{label}}
+  {{/if}}
+
+  {{#if show_detail}}
+    <span class="detail">
+      {{type}}
+      {{#if show_id}}
+        #{{id}}
+      {{/if}}
+    </span>
+  {{/if}}
+</script>
+
+<script type="text/x-template" id="debugger-result-template">
   <div class="result">
-    <div class="principal cell">
-        {{item.principal.type}} {{item.principal.label}}
-    </div>
-    <div class="object cell">
-        {{item.object.class}} #{{item.object.id}}
-    </div>
-    <div class="right cell">
-        {{search_highlight item.right search.right}}
-    </div>
+    <div class="principal cell">{{> render_record item.principal}}</div>
+    <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>Revoke</button></div>
   </div>
 </script>
diff --git a/html/Helpers/RightsDebugger/Search b/html/Helpers/RightsDebugger/Search
index 4374a2f..8515674 100644
--- a/html/Helpers/RightsDebugger/Search
+++ b/html/Helpers/RightsDebugger/Search
@@ -18,14 +18,7 @@ if ($ARGS{right}) {
 $ACL->UnLimit unless $has_search;
 
 while (my $ACE = $ACL->Next) {
-    my $principal = $ACE->PrincipalObj;
-    my $object = $ACE->Object;
-
-    push @results, {
-        principal => { type => $principal->PrincipalType, label => $principal->DisplayName },
-        object    => { class => ref($object), id => $object->id },
-        right     => $ACE->RightName,
-    };
+    push @results, RT::Extension::RightsDebugger->SerializeACE($ACE);
 }
 
 $r->content_type('application/json; charset=utf-8');
diff --git a/lib/RT/Extension/RightsDebugger.pm b/lib/RT/Extension/RightsDebugger.pm
index 43c129f..2ad153c 100644
--- a/lib/RT/Extension/RightsDebugger.pm
+++ b/lib/RT/Extension/RightsDebugger.pm
@@ -8,6 +8,98 @@ RT->AddStyleSheets("rights-debugger.css");
 RT->AddJavaScript("rights-debugger.js");
 RT->AddJavaScript("handlebars-4.0.6.min.js");
 
+sub SerializeACE {
+    my $self = shift;
+    my $ACE = shift;
+
+    return {
+        principal => $self->SerializeRecord($ACE->PrincipalObj),
+        object    => $self->SerializeRecord($ACE->Object),
+        right     => $ACE->RightName,
+    };
+}
+
+sub SerializeRecord {
+    my $self = shift;
+    my $record = shift;
+
+    if ($record->isa('RT::Principal')) {
+        $record = $record->Object;
+    }
+
+    if ($record->isa('RT::Group')) {
+        if ($record->Domain eq 'ACLEquivalence') {
+            my $principal = RT::Principal->new($record->CurrentUser);
+            $principal->Load($record->Instance);
+            $record = $principal->Object;
+        }
+    }
+
+    my $type = ref($record);
+    $type =~ s/^RT:://;
+
+    my $show_detail = 1;
+    $show_detail = 0 if $record->isa('RT::System');
+
+    my $show_id = 1;
+    $show_id = 0 if $record->isa('RT::Group') && $record->Domain eq 'SystemInternal';
+
+    return {
+        class       => ref($record),
+        id          => $record->id,
+        label       => $self->LabelForRecord($record),
+        url         => $self->URLForRecord($record),
+        type        => $type,
+        show_detail => $show_detail,
+        show_id     => $show_id,
+    };
+}
+
+sub LabelForRecord {
+    my $self = shift;
+    my $object = shift;
+
+    if ($object->isa('RT::Group')) {
+        return $object->Label;
+    }
+
+    return $object->Name;
+}
+
+sub URLForRecord {
+    my $self = shift;
+    my $object = shift;
+    my $id = $object->id;
+
+    if ($object->isa('RT::Queue')) {
+        return RT->Config->Get('WebURL') . 'Admin/Queues/Modify.html?id=' . $id;
+    }
+    elsif ($object->isa('RT::User')) {
+        return undef if $id == RT->SystemUser->id
+                     || $id == RT->Nobody->id;
+
+        return RT->Config->Get('WebURL') . 'Admin/Users/Modify.html?id=' . $id;
+    }
+    elsif ($object->isa('RT::Group')) {
+        return undef if $object->Domain eq 'SystemInternal';
+        return RT->Config->Get('WebURL') . 'Admin/Groups/Modify.html?id=' . $id;
+    }
+    elsif ($object->isa('RT::CustomField')) {
+        return RT->Config->Get('WebURL') . 'Admin/CustomFields/Modify.html?id=' . $id;
+    }
+    elsif ($object->isa('RT::Class')) {
+        return RT->Config->Get('WebURL') . 'Admin/Articles/Classes/Modify.html?id=' . $id;
+    }
+    elsif ($object->isa('RT::Catalog')) {
+        return RT->Config->Get('WebURL') . 'Admin/Assets/Catalogs/Modify.html?id=' . $id;
+    }
+    elsif ($object->isa('RT::CustomRole')) {
+        return RT->Config->Get('WebURL') . 'Admin/CustomRoles/Modify.html?id=' . $id;
+    }
+
+    return undef;
+}
+
 =head1 NAME
 
 RT-Extension-RightsDebugger - 
diff --git a/static/css/rights-debugger.css b/static/css/rights-debugger.css
index 0a2cc72..79b4a8c 100644
--- a/static/css/rights-debugger.css
+++ b/static/css/rights-debugger.css
@@ -6,6 +6,7 @@
 
 #rights-debugger .results .result .cell {
     padding: 2px;
+    vertical-align: top;
 }
 
 #rights-debugger .results .result:nth-child(even) {
@@ -15,3 +16,10 @@
 #rights-debugger .results .result .match {
     font-weight: bold;
 }
+
+#rights-debugger .results .result .detail {
+    font-size: 80%;
+    color: #AAA;
+    display: block;
+}
+
diff --git a/static/js/rights-debugger.js b/static/js/rights-debugger.js
index 205ce62..4199969 100644
--- a/static/js/rights-debugger.js
+++ b/static/js/rights-debugger.js
@@ -1,9 +1,12 @@
 jQuery(function () {
-    var template = jQuery('script#debugger-result').html();
-    if (!template) {
+    var recordTemplate = jQuery('script#debugger-record-template').html();
+    var resultTemplate = jQuery('script#debugger-result-template').html();
+    if (!recordTemplate || !resultTemplate) {
         return;
     }
 
+    Handlebars.registerPartial('render_record', recordTemplate);
+
     Handlebars.registerHelper('search_highlight', function (text, term) {
         // this is simplistic; better would be to highlight on the
         // unescaped text, and case insensitively
@@ -12,7 +15,7 @@ jQuery(function () {
         return new Handlebars.SafeString(text);
     });
 
-    var renderItem = Handlebars.compile(template);
+    var renderItem = Handlebars.compile(resultTemplate);
     var form = jQuery('form#rights-debugger');
     var display = form.find('.results');
 

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


More information about the Bps-public-commit mailing list