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

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


The branch, master has been updated
       via  394e2b3fffa4722626d1834f9e1adfdf11f41196 (commit)
       via  08f2b614ede3ebdc824dd97c4384c4fed7251987 (commit)
       via  c4b1732378606628247feaf5ccbc01cb990b04e2 (commit)
       via  5912397177e55b1018712a07362601d511d51e9e (commit)
      from  a3bdf4d6b9450b3e9f3d2f5c20dcd3a6e193e790 (commit)

Summary of changes:
 html/Admin/RightsDebugger/index.html | 12 +++---
 html/Helpers/RightsDebugger/Search   | 72 +++++++++++++++++++++++++++++++-----
 static/css/rights-debugger.css       |  3 +-
 3 files changed, 71 insertions(+), 16 deletions(-)

- Log -----------------------------------------------------------------
commit 5912397177e55b1018712a07362601d511d51e9e
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Feb 28 21:21:32 2017 +0000

    Compile regexes only once per search, rather than once per item

diff --git a/html/Helpers/RightsDebugger/Search b/html/Helpers/RightsDebugger/Search
index 0857251..3df5941 100644
--- a/html/Helpers/RightsDebugger/Search
+++ b/html/Helpers/RightsDebugger/Search
@@ -17,15 +17,24 @@ if ($ARGS{right}) {
 
 $ACL->UnLimit unless $has_search;
 
+for my $key (qw/principal object/) {
+    if (my $search = $ARGS{$key}) {
+        my @matchers;
+        for my $word (split ' ', $search) {
+            push @matchers, qr/\Q$word\E/i;
+        }
+        $ARGS{$key} = \@matchers;
+    }
+}
+
 ACE: while (my $ACE = $ACL->Next) {
     my $serialized = RT::Extension::RightsDebugger->SerializeACE($ACE);
 
     # this is hacky, but doing the searching in SQL is absolutely a nonstarter
     for my $key (qw/principal object/) {
-        if (my $search = $ARGS{$key}) {
+        if (my $matchers = $ARGS{$key}) {
             my $record = $serialized->{$key};
-            for my $word (split ' ', $search) {
-                my $re = qr/\Q$word\E/i;
+            for my $re (@$matchers) {
                 next ACE unless $record->{class}  =~ $re
                              || $record->{id}     =~ $re
                              || $record->{label}  =~ $re

commit c4b1732378606628247feaf5ccbc01cb990b04e2
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Feb 28 21:49:33 2017 +0000

    Highlight with a nice lovely yellow background

diff --git a/static/css/rights-debugger.css b/static/css/rights-debugger.css
index f09040a..298f45a 100644
--- a/static/css/rights-debugger.css
+++ b/static/css/rights-debugger.css
@@ -37,6 +37,7 @@
 }
 
 #rights-debugger .results .result .match {
+    background-color: rgb(255, 253, 56);
     font-weight: bold;
 }
 

commit 08f2b614ede3ebdc824dd97c4384c4fed7251987
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Feb 28 22:02:20 2017 +0000

    Highlight matching words serverside
    
    Perl's \G and /g features for s/// are perfect for making sure we escape
    both non-matching and matching text into HTML; also, /i makes it easier to
    do case insensitive matching while preserving case
    
    This also sneaks in searching for multiple rights at once

diff --git a/html/Admin/RightsDebugger/index.html b/html/Admin/RightsDebugger/index.html
index 01b2328..7ac11aa 100644
--- a/html/Admin/RightsDebugger/index.html
+++ b/html/Admin/RightsDebugger/index.html
@@ -14,19 +14,19 @@
 
 <script type="text/x-template" id="debugger-record-template">
   {{#if url}}
-      <a target="_blank" href="{{url}}">{{search_highlight label search}}</a>
+      <a target="_blank" href="{{url}}">{{{label_highlighted}}}</a>
   {{else}}
-      {{search_highlight label search}}
+      {{{label_highlighted}}}
   {{/if}}
 
-  <span class="detail">{{search_highlight detail search}}</span>
+  <span class="detail">{{{detail_highlighted}}}</span>
 </script>
 
 <script type="text/x-template" id="debugger-result-template">
   <div class="result">
-    <div class="principal cell">{{> render_record item.principal search=search.principal}}</div>
-    <div class="object cell">{{> render_record item.object search=search.object}}</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">{{{item.right_highlighted}}}</div>
     <div class="revoke cell">
         <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>
diff --git a/html/Helpers/RightsDebugger/Search b/html/Helpers/RightsDebugger/Search
index 3df5941..c5d0698 100644
--- a/html/Helpers/RightsDebugger/Search
+++ b/html/Helpers/RightsDebugger/Search
@@ -1,5 +1,6 @@
 <%INIT>
 my @results;
+my %search;
 
 my $ACL = RT::ACL->new($session{CurrentUser});
 
@@ -7,32 +8,57 @@ my $has_search = 0;
 
 if ($ARGS{right}) {
     $has_search = 1;
-    $ACL->Limit(
-        FIELD         => 'RightName',
-        OPERATOR      => 'LIKE',
-        VALUE         => $ARGS{right},
-        CASESENSITIVE => 0,
-    );
+    for my $word (split ' ', $ARGS{right}) {
+        $ACL->Limit(
+            FIELD           => 'RightName',
+            OPERATOR        => 'LIKE',
+            VALUE           => $word,
+            CASESENSITIVE   => 0,
+            ENTRYAGGREGATOR => 'OR',
+        );
+    }
 }
 
 $ACL->UnLimit unless $has_search;
 
-for my $key (qw/principal object/) {
+for my $key (qw/principal object right/) {
     if (my $search = $ARGS{$key}) {
         my @matchers;
         for my $word (split ' ', $search) {
             push @matchers, qr/\Q$word\E/i;
         }
-        $ARGS{$key} = \@matchers;
+        $search{$key} = \@matchers;
     }
 }
 
+my $escape_html = sub {
+    my $s = shift;
+    RT::Interface::Web::EscapeHTML(\$s);
+    return $s;
+};
+
+my $highlight_term = sub {
+    my ($text, $re) = @_;
+
+    $text =~ s{
+        \G         # where we left off the previous iteration thanks to /g
+        (.*?)      # non-matching text before the match
+        ($re|$)    # matching text, or the end of the line (to escape any
+                   # text after the last match)
+    }{
+      $escape_html->($1) .
+      (length $2 ? '<span class="match">' . $escape_html->($2) . '</span>' : '')
+    }xeg;
+
+    return $text; # now escape as html
+};
+
 ACE: while (my $ACE = $ACL->Next) {
     my $serialized = RT::Extension::RightsDebugger->SerializeACE($ACE);
 
     # this is hacky, but doing the searching in SQL is absolutely a nonstarter
     for my $key (qw/principal object/) {
-        if (my $matchers = $ARGS{$key}) {
+        if (my $matchers = $search{$key}) {
             my $record = $serialized->{$key};
             for my $re (@$matchers) {
                 next ACE unless $record->{class}  =~ $re
@@ -43,6 +69,25 @@ ACE: while (my $ACE = $ACL->Next) {
         }
     }
 
+    # highlight matching words
+    $serialized->{right_highlighted} = $highlight_term->($serialized->{right}, join '|', @{ $search{right} || [] });
+
+    for my $key (qw/principal object/) {
+        my $record = $serialized->{$key};
+
+        if (my $matchers = $search{$key}) {
+            my $re = join '|', @$matchers;
+            for my $column (qw/label detail/) {
+                $record->{$column . '_highlighted'} = $highlight_term->($record->{$column}, $re);
+            }
+        }
+
+        for my $column (qw/label detail/) {
+            # make sure we escape html if there was no search
+            $record->{$column . '_highlighted'} //= $escape_html->($record->{$column});
+        }
+    }
+
     push @results, $serialized;
 }
 

commit 394e2b3fffa4722626d1834f9e1adfdf11f41196
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Feb 28 22:04:29 2017 +0000

    My zebras are THIS blue

diff --git a/static/css/rights-debugger.css b/static/css/rights-debugger.css
index 298f45a..06898a6 100644
--- a/static/css/rights-debugger.css
+++ b/static/css/rights-debugger.css
@@ -33,7 +33,7 @@
 }
 
 #rights-debugger .results .result:nth-child(even) {
-    background-color: #DBE5F0;
+    background-color: rgb(236, 246, 252);
 }
 
 #rights-debugger .results .result .match {

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


More information about the Bps-public-commit mailing list