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

Shawn Moore shawn at bestpractical.com
Thu Mar 9 11:42:11 EST 2017


The branch, master has been updated
       via  ff1e3c8e046a200a3c90ae3a3225bd540dfd79ae (commit)
       via  447ca2287994f03481e9645c131f0da72b6003ae (commit)
       via  7975c55e2ab35929dcb8a6da8d6c0615252861c8 (commit)
      from  1c6a2de6faf1ebf7835aa9a9a8713dd8fb57a0ce (commit)

Summary of changes:
 html/Admin/RightsDebugger/index.html |  4 +--
 lib/RT/Extension/RightsDebugger.pm   | 53 ++++++++++++++++++++++--------------
 2 files changed, 34 insertions(+), 23 deletions(-)

- Log -----------------------------------------------------------------
commit 7975c55e2ab35929dcb8a6da8d6c0615252861c8
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 7 20:15:51 2017 +0000

    Fix right-name highlighting

diff --git a/lib/RT/Extension/RightsDebugger.pm b/lib/RT/Extension/RightsDebugger.pm
index a54b3f0..15db761 100644
--- a/lib/RT/Extension/RightsDebugger.pm
+++ b/lib/RT/Extension/RightsDebugger.pm
@@ -21,8 +21,8 @@ sub _EscapeHTML {
     return $s;
 }
 
-sub _HighlightTerm {
-    my ($text, $term) = @_;
+sub _RegexifyTermForHighlight {
+    my $term = shift;
 
     $term ||= '';
 
@@ -39,7 +39,21 @@ sub _HighlightTerm {
         $
     }{$2}xi;
 
-    my $re = qr/\Q$term\E/i;
+    return qr/\Q$term\E/i;
+}
+
+sub _HighlightTerm {
+    my ($text, $term) = @_;
+
+    my $re = ref($term) eq 'ARRAY'
+           ? join '|', map { _RegexifyTermForHighlight($_) } @$term
+           : _RegexifyTermForHighlight($term);
+
+    # if $term is an arrayref, make sure we qr-ify it
+    # without this, then if $term has no elements, we interpolate $re
+    # as an empty string which causes the regex engine to fall into
+    # an infinite loop
+    $re = qr/$re/ unless ref($re);
 
     $text =~ s{
         \G         # where we left off the previous iteration thanks to /g
@@ -59,7 +73,7 @@ sub _HighlightSerializedForSearch {
     my $args       = shift;
 
     # highlight matching terms
-    $serialized->{right_highlighted} = _HighlightTerm($serialized->{right}, $args->{search});
+    $serialized->{right_highlighted} = _HighlightTerm($serialized->{right}, [split ' ', $args->{right} || '']);
 
     for my $key (qw/principal object/) {
         for my $record ($serialized->{$key}, $serialized->{$key}->{primary_record}) {

commit 447ca2287994f03481e9645c131f0da72b6003ae
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Mar 9 16:36:54 2017 +0000

    Highlight entire record for type:foo type searches
    
    ... and don't highlight any other records that happen to match

diff --git a/html/Admin/RightsDebugger/index.html b/html/Admin/RightsDebugger/index.html
index e778563..5ce6561 100644
--- a/html/Admin/RightsDebugger/index.html
+++ b/html/Admin/RightsDebugger/index.html
@@ -15,7 +15,7 @@
 
 <script type="text/x-template" id="debugger-record-template">
   <span class="record {{#if disabled}}disabled{{/if}}">
-    <span class="name">
+    <span class="name {{#if highlight}}match{{/if}}">
       {{#if url}}
         <a target="_blank" href="{{url}}">{{{label_highlighted}}}</a>
       {{else}}
diff --git a/lib/RT/Extension/RightsDebugger.pm b/lib/RT/Extension/RightsDebugger.pm
index 15db761..85eb839 100644
--- a/lib/RT/Extension/RightsDebugger.pm
+++ b/lib/RT/Extension/RightsDebugger.pm
@@ -22,23 +22,7 @@ sub _EscapeHTML {
 }
 
 sub _RegexifyTermForHighlight {
-    my $term = shift;
-
-    $term ||= '';
-
-    # strip user:root leaving just root
-    $term =~ s{
-        ^
-            \s*
-            (u|user|g|group)
-            \s*
-            [:#]
-            \s*
-            (.+?)
-            \s*
-        $
-    }{$2}xi;
-
+    my $term = shift || '';
     return qr/\Q$term\E/i;
 }
 
@@ -69,8 +53,9 @@ sub _HighlightTerm {
 }
 
 sub _HighlightSerializedForSearch {
-    my $serialized = shift;
-    my $args       = shift;
+    my $serialized   = shift;
+    my $args         = shift;
+    my $regex_search = shift;
 
     # highlight matching terms
     $serialized->{right_highlighted} = _HighlightTerm($serialized->{right}, [split ' ', $args->{right} || '']);
@@ -79,8 +64,20 @@ sub _HighlightSerializedForSearch {
         for my $record ($serialized->{$key}, $serialized->{$key}->{primary_record}) {
             next if !$record;
 
-            for my $column (qw/label detail/) {
-                $record->{$column . '_highlighted'} = _HighlightTerm($record->{$column}, $args->{$key});
+            # if we used a regex search for this record, then highlight the
+            # text that the regex matched
+            if ($regex_search->{$key}) {
+                for my $column (qw/label detail/) {
+                    $record->{$column . '_highlighted'} = _HighlightTerm($record->{$column}, $args->{$key});
+                }
+            }
+            # otherwise we used a search like user:root and so we should
+            # highlight just that user completely (but not its parent group)
+            else {
+                $record->{'highlight'} = $record->{primary_record} ? 0 : 1;
+                for my $column (qw/label detail/) {
+                    $record->{$column . '_highlighted'} = _EscapeHTML($record->{$column});
+                }
             }
         }
     }
@@ -320,7 +317,7 @@ sub Search {
             }
         }
 
-        _HighlightSerializedForSearch($serialized, \%args);
+        _HighlightSerializedForSearch($serialized, \%args, \%use_regex_search_for);
 
         push @results, $serialized;
     }

commit ff1e3c8e046a200a3c90ae3a3225bd540dfd79ae
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Mar 9 16:41:44 2017 +0000

    Avoid submitting revoke buttons on enter keypress in search form
    
    Shoutout to http://stackoverflow.com/a/10836076

diff --git a/html/Admin/RightsDebugger/index.html b/html/Admin/RightsDebugger/index.html
index 5ce6561..e9ab702 100644
--- a/html/Admin/RightsDebugger/index.html
+++ b/html/Admin/RightsDebugger/index.html
@@ -44,7 +44,7 @@
     <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>
+        <button type="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>

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


More information about the Bps-public-commit mailing list