[Rt-commit] rt branch 5.0/add-link-asset-autocomplete created. rt-5.0.5-49-g634c3ef463

BPS Git Server git at git.bestpractical.com
Sun Nov 26 00:12:58 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/add-link-asset-autocomplete has been created
        at  634c3ef4638d2d084789b5e1fab23217190658ac (commit)

- Log -----------------------------------------------------------------
commit 634c3ef4638d2d084789b5e1fab23217190658ac
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 19 12:06:09 2023 -0800

    Add URI method so add link to user works
    
    The module was missing a URI method to ensure the URI prefix was correct
    for user objects.

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index bbf0085a8f..4a881003bc 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -829,6 +829,20 @@ sub EmailFrequency {
     return '';
 }
 
+=head2 URI
+
+Returns this user's URI
+
+=cut
+
+sub URI {
+    my $self = shift;
+
+    require RT::URI::user;
+    my $uri = RT::URI::user->new($self->CurrentUser);
+    return $uri->URIForObject($self);
+}
+
 =head2 CanonicalizeEmailAddress ADDRESS
 
 CanonicalizeEmailAddress converts email addresses into canonical form.

commit c0888d6165240f5e240ebbfe93c5ffc8da509e3d
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 12 20:04:32 2023 -0800

    Use LinkTargets autocomplete excluding existing links
    
    Commit is partially based on code in pull request 203 created by:
    Gérald SÉDRATI gibus
    
    See https://github.com/bestpractical/rt/pull/203

diff --git a/share/html/Elements/AddLinks b/share/html/Elements/AddLinks
index 4fd5279168..32cbf9c8fe 100644
--- a/share/html/Elements/AddLinks
+++ b/share/html/Elements/AddLinks
@@ -55,8 +55,52 @@ my $id = ($Object and $Object->id)
     ? $Object->id
     : "new";
 
-my $exclude = qq| data-autocomplete="Tickets" data-autocomplete-multiple="1"|;
-$exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;
+my $exclude = qq| data-autocomplete="LinkTargets" data-autocomplete-multiple="1"|;
+my @excludes;
+push @excludes, ( $Object->isa('RT::Asset') ? 'asset:' : '' ) . $id
+    if $id ne 'new';
+
+my %exclude_links = (
+    Depend => [ qw( DependsOn DependedOnBy ) ],
+    Member => [ qw( MemberOf Members ) ],
+    Refer  => [ qw( RefersTo ReferredToBy ) ],
+);
+foreach my $exclude_type ( keys %exclude_links ) {
+    my @ids;
+    if ( $id ne 'new' ) {
+        foreach my $link_type ( @{ $exclude_links{$exclude_type} } ) {
+            my $links = $Object->$link_type;
+            while ( my $link = $links->Next ) {
+                my $LinkedObj = $link->TargetObj;
+                # if $LinkedObj is same as $Object we want the BaseObj
+                $LinkedObj = $link->BaseObj
+                    if (
+                        ( ref($Object) eq ref($LinkedObj) )
+                        &&
+                        ( $id == $LinkedObj->id )
+                    );
+                if ( $LinkedObj ) {
+                    my $prefix = '';
+                    if ( $LinkedObj->isa('RT::Asset') ) {
+                        $prefix = 'asset:';
+                    }
+                    elsif ( $LinkedObj->isa('RT::Article') ) {
+                        $prefix = 'a:';
+                    }
+                    elsif ( $LinkedObj->isa('RT::Group') ) {
+                        $prefix = 'group:';
+                    }
+                    elsif ( $LinkedObj->isa('RT::User') ) {
+                        $prefix = 'user:';
+                    }
+                    push @ids, $prefix . $LinkedObj->id;
+                }
+            }
+        }
+    }
+    $exclude_links{$exclude_type} = $exclude . ' data-autocomplete-exclude="' . join( ' ', @excludes, @ids ) . '"'
+        if @excludes || @ids;
+}
 </%init>
 % if (ref($Object) eq 'RT::Ticket') {
 <i><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&>
@@ -76,24 +120,24 @@ $exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;
 
 
 <&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Depends on'), Relation => 'DependsOn') &>
-  <input type="text" class="form-control" name="<%$id%>-DependsOn" value="<% $ARGSRef->{"$id-DependsOn"} || '' %>" <% $exclude |n%>/>
+  <input type="text" class="form-control" name="<%$id%>-DependsOn" value="<% $ARGSRef->{"$id-DependsOn"} || '' %>" <% $exclude_links{Depend} |n%>/>
 </&>
 <&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Depended on by'), Relation => 'DependedOnBy') &>
-  <input type="text" class="form-control" name="DependsOn-<%$id%>" value="<% $ARGSRef->{"DependsOn-$id"} || '' %>" <% $exclude |n%>/>
+  <input type="text" class="form-control" name="DependsOn-<%$id%>" value="<% $ARGSRef->{"DependsOn-$id"} || '' %>" <% $exclude_links{Depend} |n%>/>
 </&>
 
 <&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Parents'), Relation => 'Parents') &>
-  <input type="text" class="form-control" name="<%$id%>-MemberOf" value="<% $ARGSRef->{"$id-MemberOf"} || '' %>" <% $exclude |n%>/>
+  <input type="text" class="form-control" name="<%$id%>-MemberOf" value="<% $ARGSRef->{"$id-MemberOf"} || '' %>" <% $exclude_links{Member} |n%>/>
 </&>
 <&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Children'), Relation => 'Children') &>
-  <input type="text" class="form-control" name="MemberOf-<%$id%>" value="<% $ARGSRef->{"MemberOf-$id"} || '' %>" <% $exclude |n%>/>
+  <input type="text" class="form-control" name="MemberOf-<%$id%>" value="<% $ARGSRef->{"MemberOf-$id"} || '' %>" <% $exclude_links{Member} |n%>/>
 </&>
 
 <&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Refers to'), Relation => 'RefersTo') &>
-  <input type="text" class="form-control" name="<%$id%>-RefersTo" value="<% $ARGSRef->{"$id-RefersTo"} || '' %>" <% $exclude |n%>/>
+  <input type="text" class="form-control" name="<%$id%>-RefersTo" value="<% $ARGSRef->{"$id-RefersTo"} || '' %>" <% $exclude_links{Refer} |n%>/>
 </&>
 <&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Referred to by'), Relation => 'ReferredToBy') &>
-  <input type="text" class="form-control" name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" <% $exclude |n%>/>
+  <input type="text" class="form-control" name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" <% $exclude_links{Refer} |n%>/>
 </&>
 
   <& /Elements/EditCustomFields,

commit 5f557b11f71c398a61f7b7663b9aa785f6f93043
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 12 20:02:04 2023 -0800

    Exclude assets that are already linked

diff --git a/share/html/Ticket/Elements/ShowAssets b/share/html/Ticket/Elements/ShowAssets
index e6c60bb728..51bfbd152e 100644
--- a/share/html/Ticket/Elements/ShowAssets
+++ b/share/html/Ticket/Elements/ShowAssets
@@ -214,7 +214,7 @@ if ($ShowRelatedTickets) {
     <label><&|/l&>Add an asset to this ticket:</&></label>
     <div class="form-row">
       <div class="form-group mx-sm-3 mb-2">
-        <input data-autocomplete="Assets" class="form-control mb-2" size="10" name="<% $Ticket->id %>-RefersTo" placeholder="<&|/l&>Asset #</&>" type="text">
+        <input data-autocomplete="Assets" class="form-control mb-2" size="10" name="<% $Ticket->id %>-RefersTo" placeholder="<&|/l&>Asset #</&>" data-autocomplete-exclude="<% join(',', @linked_assets) |n %>" type="text">
       </div>
       <button type="submit" name="AddAsset" value="Add" class="button btn btn-primary form-control mb-2">Add</button>
     </div>

commit 6d0b00e669cc84de2d4729ecc71ca4343da42fd8
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 12 20:00:54 2023 -0800

    Add support for LinkTargets autocomplete

diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index c967050ddf..fd41ab592d 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -9,7 +9,8 @@ window.RT.Autocomplete.Classes = {
     Queues: 'queues',
     Articles: 'articles',
     Assets: 'assets',
-    Principals: 'principals'
+    Principals: 'principals',
+    LinkTargets: 'link-targets'
 };
 
 Selectize.define('rt_drag_drop', function(options) {
@@ -150,7 +151,7 @@ window.RT.Autocomplete.bind = function(from) {
         }
 
         if (input.is('[data-autocomplete-multiple]')) {
-            if ( what != 'Tickets' ) {
+            if ( what != 'Tickets' && what != 'LinkTargets' ) {
                 queryargs.push("delim=,");
             }
 
@@ -160,13 +161,13 @@ window.RT.Autocomplete.bind = function(from) {
             }
 
             options.select = function(event, ui) {
-                var terms = this.value.split(what == 'Tickets' ? /\s+/ : /,\s*/);
+                var terms = this.value.split((what == 'Tickets' || what == 'LinkTargets') ? /\s+/ : /,\s*/);
                 terms.pop();                    // remove current input
-                if ( what == 'Tickets' ) {
+                if ( what == 'Tickets' || what == 'LinkTargets' ) {
                     // remove non-integers in case subject search with spaces in (like "foo bar")
                     var new_terms = [];
                     for ( var i = 0; i < terms.length; i++ ) {
-                        if ( terms[i].match(/\D/) ) {
+                        if ( terms[i].match(/^(?:(asset|a|group|user):)\D/) ) {
                             break; // Items after the first non-integers are all parts of search string
                         }
                         new_terms.push(terms[i]);
@@ -175,7 +176,7 @@ window.RT.Autocomplete.bind = function(from) {
                 }
                 terms.push( ui.item.value );    // add selected item
                 terms.push(''); // add trailing delimeter so user can input another value directly
-                this.value = terms.join(what == 'Tickets' ? ' ' : ", ");
+                this.value = terms.join((what == 'Tickets' || what == 'LinkTargets') ? ' ' : ", ");
                 jQuery(this).change();
 
                 return false;

commit 7e2d4f0d69f2989c0ec6f117c4c45d730f869486
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 12 19:58:56 2023 -0800

    Format asset suggestions as id: Name

diff --git a/share/html/Helpers/Autocomplete/Assets b/share/html/Helpers/Autocomplete/Assets
index 1278f6c5e7..5659915e42 100644
--- a/share/html/Helpers/Autocomplete/Assets
+++ b/share/html/Helpers/Autocomplete/Assets
@@ -96,7 +96,8 @@ my @suggestions;
 while (my $a = $assets->Next) {
     next if $right and not $a->CurrentUserHasRight($right);
     my $value = $a->$return;
-    push @suggestions, { label => $a->Name, value => $value };
+    my $formatted = loc( "#[_1]: [_2]", $a->id, $a->Name );
+    push @suggestions, { label => $formatted, value => $value };
 }
 return @suggestions if defined wantarray;
 </%INIT>

commit 5059bf4d240f2b4d3c1f19e36a22a4d1692b8105
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 19 14:34:42 2023 -0800

    Add exclude arg to Articles Autocomplete

diff --git a/share/html/Helpers/Autocomplete/Articles b/share/html/Helpers/Autocomplete/Articles
index 3d3b21097e..10781ca32c 100644
--- a/share/html/Helpers/Autocomplete/Articles
+++ b/share/html/Helpers/Autocomplete/Articles
@@ -49,12 +49,13 @@
 <% JSON( \@suggestions ) |n %>
 % $m->abort;
 <%ARGS>
-$term       => undef
-$max        => undef
-$op         => undef
-$right      => undef
-$return     => ''
-$queue      => undef
+$term    => undef
+$max     => undef
+$op      => undef
+$right   => undef
+$return  => ''
+$queue   => undef
+$exclude => ''
 </%ARGS>
 <%INIT>
 # Only allow certain return fields
@@ -78,6 +79,16 @@ $articles->SimpleSearch(
 );
 $m->callback( CallbackName => "ModifyArticlesLimit", Articles => $articles, Term => $term, ARGSRef => \%ARGS );
 
+# Exclude articles we don't want
+my @not_in = split /\s*,\s*/, $exclude;
+$articles->Limit(
+    FIELD           => 'id',
+    VALUE           => \@not_in,
+    OPERATOR        => 'NOT IN',
+    ENTRYAGGREGATOR => 'AND',
+    SUBCLAUSE       => 'excludeautocomplete'
+) if @not_in;
+
 my @suggestions;
 while (my $a = $articles->Next) {
     next if $right and not $a->CurrentUserHasRight($right);

commit 40a025cf4120eb9889149fb6f2e9ac0cf303a1eb
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 12 19:58:01 2023 -0800

    Add exclude arg to Assets autocomplete

diff --git a/share/html/Helpers/Autocomplete/Assets b/share/html/Helpers/Autocomplete/Assets
index c2b7bd4be6..1278f6c5e7 100644
--- a/share/html/Helpers/Autocomplete/Assets
+++ b/share/html/Helpers/Autocomplete/Assets
@@ -50,12 +50,13 @@
 % $m->abort;
 
 <%ARGS>
-$term   => undef
-$max    => 10
-$op     => 'STARTSWITH'
-$right  => undef
-$return => 'id'
-$queue  => undef
+$term    => undef
+$max     => 10
+$op      => 'STARTSWITH'
+$right   => undef
+$return  => 'id'
+$queue   => undef
+$exclude => ''
 </%ARGS>
 
 <%INIT>
@@ -81,6 +82,16 @@ $assets->Limit(
     CASESENSITIVE   => 0,
 );
 
+# Exclude assets we don't want
+my @not_in = split /\s*,\s*/, $exclude;
+$assets->Limit(
+    FIELD           => 'id',
+    VALUE           => \@not_in,
+    OPERATOR        => 'NOT IN',
+    ENTRYAGGREGATOR => 'AND',
+    SUBCLAUSE       => 'excludeautocomplete'
+) if @not_in;
+
 my @suggestions;
 while (my $a = $assets->Next) {
     next if $right and not $a->CurrentUserHasRight($right);

commit 900c5268283b1f2864dd0705279e8478cd326c7b
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 12 19:54:57 2023 -0800

    Return suggestions if called from another component

diff --git a/share/html/Helpers/Autocomplete/Articles b/share/html/Helpers/Autocomplete/Articles
index 9873c2b9a9..3d3b21097e 100644
--- a/share/html/Helpers/Autocomplete/Articles
+++ b/share/html/Helpers/Autocomplete/Articles
@@ -85,4 +85,5 @@ while (my $a = $articles->Next) {
     push @suggestions, { label => $a->Name, value => $value };
     $m->callback( CallbackName => "ModifySuggestion", suggestions => @suggestions, label => $a );
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/Assets b/share/html/Helpers/Autocomplete/Assets
index ef93af5acc..c2b7bd4be6 100644
--- a/share/html/Helpers/Autocomplete/Assets
+++ b/share/html/Helpers/Autocomplete/Assets
@@ -50,12 +50,12 @@
 % $m->abort;
 
 <%ARGS>
-$term       => undef
-$max        => 10
-$op         => 'STARTSWITH'
-$right      => undef
-$return     => 'id'
-$queue      => undef
+$term   => undef
+$max    => 10
+$op     => 'STARTSWITH'
+$right  => undef
+$return => 'id'
+$queue  => undef
 </%ARGS>
 
 <%INIT>
@@ -87,4 +87,5 @@ while (my $a = $assets->Next) {
     my $value = $a->$return;
     push @suggestions, { label => $a->Name, value => $value };
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/CustomFieldValues b/share/html/Helpers/Autocomplete/CustomFieldValues
index 74344ed48d..bb90f762b2 100644
--- a/share/html/Helpers/Autocomplete/CustomFieldValues
+++ b/share/html/Helpers/Autocomplete/CustomFieldValues
@@ -144,4 +144,5 @@ while( my $value = $values->Next ) {
         : $value->Name,
       };
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/Groups b/share/html/Helpers/Autocomplete/Groups
index aae0a839f2..5ec6592d15 100644
--- a/share/html/Helpers/Autocomplete/Groups
+++ b/share/html/Helpers/Autocomplete/Groups
@@ -92,4 +92,5 @@ while ( my $group = $groups->Next ) {
     $m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, group => $group );
     push @suggestions, $suggestion;
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/LinkTargets b/share/html/Helpers/Autocomplete/LinkTargets
index 4e8835f541..cdbf808c34 100644
--- a/share/html/Helpers/Autocomplete/LinkTargets
+++ b/share/html/Helpers/Autocomplete/LinkTargets
@@ -89,4 +89,5 @@ else {
     my $exclude_tickets = join( ' ', grep( /^\d+$/, @excludes ) );
     @suggestions = $m->comp( 'Tickets', return => $return, term => $term, max => $max, exclude => $exclude_tickets );
 }
+return @suggestions if defined wantarray;
 </%init>
diff --git a/share/html/Helpers/Autocomplete/Owners b/share/html/Helpers/Autocomplete/Owners
index 8f721bafad..6d38423e23 100644
--- a/share/html/Helpers/Autocomplete/Owners
+++ b/share/html/Helpers/Autocomplete/Owners
@@ -141,4 +141,5 @@ for my $tuple ( @users ) {
     };
     $count++;
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/Principals b/share/html/Helpers/Autocomplete/Principals
index f09d47267d..ae669d17e1 100644
--- a/share/html/Helpers/Autocomplete/Principals
+++ b/share/html/Helpers/Autocomplete/Principals
@@ -170,4 +170,5 @@ if ($groups) {
         last if @suggestions >= $max;
     }
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/Queues b/share/html/Helpers/Autocomplete/Queues
index 1735dcbb06..5b923e948a 100644
--- a/share/html/Helpers/Autocomplete/Queues
+++ b/share/html/Helpers/Autocomplete/Queues
@@ -83,4 +83,5 @@ while (my $q = $queues->Next) {
     my $value = $q->$return;
     push @suggestions, { label => $q->Name, value => $value };
 }
+return @suggestions if defined wantarray;
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
index 8e9462ce6a..f1694018aa 100644
--- a/share/html/Helpers/Autocomplete/Tickets
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -110,5 +110,6 @@ while ( my $ticket = $tickets->Next ) {
     my $formatted = loc("#[_1]: [_2]", $ticket->Id, $ticket->Subject);
     push @suggestions, { label => $formatted, value => $ticket->$return };
 }
+return @suggestions if defined wantarray;
 
 </%INIT>
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index 2a03bf1eff..7b5c4a3035 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -116,5 +116,5 @@ while ( my $user = $users->Next ) {
     $m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, user => $user );
     push @suggestions, $suggestion;
 }
-
+return @suggestions if defined wantarray;
 </%INIT>

commit 18c322095f3d9c2649341724cd3df1f608042ea6
Author: Brad Embree <brad at bestpractical.com>
Date:   Sun Nov 19 12:07:50 2023 -0800

    Add LinkTargets autocomplete component

diff --git a/share/html/Helpers/Autocomplete/LinkTargets b/share/html/Helpers/Autocomplete/LinkTargets
new file mode 100644
index 0000000000..4e8835f541
--- /dev/null
+++ b/share/html/Helpers/Autocomplete/LinkTargets
@@ -0,0 +1,92 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+% $r->content_type('application/json; charset=utf-8');
+<% JSON( \@suggestions ) |n %>
+% $m->abort;
+<%args>
+$return => ''
+$term => undef
+$max => undef
+$exclude => ''
+</%args>
+<%init>
+$m->abort unless defined $term
+             and length $term;
+
+my @suggestions;
+my @excludes;
+
+( my $prev, my $type, $term ) = $term =~ /^((?:(asset:|a:|group:|user:)?\d+\s+)*)(.*)/;
+ at excludes = split ' ', $prev if $prev;
+push @excludes, split ' ', $exclude if $exclude;
+
+if ( $term =~ /^asset:./ ) {
+    my $exclude_assets = join( ',', map( /(\d+)/, grep( /^asset:\d+$/, @excludes ) ) );
+    @suggestions = $m->comp( 'Assets', term => substr($term, 6), max => $max, exclude => $exclude_assets, return => 'id'  );
+    @suggestions = map { { id => $_->{id}, label => $_->{label}, value => 'asset:' . $_->{value} } } @suggestions;
+}
+elsif ( $term =~ /^a:./ ) {
+    my $exclude_articles = join( ',', map( /(\d+)/, grep( /^a:\d+$/, @excludes ) ) );
+    @suggestions = $m->comp( 'Articles', term => substr($term, 2), max => $max, exclude => $exclude_articles, return => 'id' );
+    @suggestions = map { { id => $_->{id}, label => $_->{label}, value => 'a:' . $_->{value} } } @suggestions;
+}
+elsif ( $term =~ /^group:./ ) {
+    my $exclude_groups = join( ',', map( /(\d+)/, grep( /^group:\d+$/, @excludes ) ) );
+    @suggestions = $m->comp( 'Groups', term => substr($term, 6), max => $max, exclude => $exclude_groups );
+    @suggestions = map { { id => $_->{id}, label => $_->{label}, value => 'group:' . $_->{id} } } @suggestions;
+}
+elsif ( $term =~ /^user:./ ) {
+    my $exclude_users = join( ',', map( /(\d+)/, grep( /^user:\d+$/, @excludes ) ) );
+    @suggestions = $m->comp( 'Users', term => substr($term, 5), max => $max, exclude => $exclude_users );
+    @suggestions = map { { id => $_->{id}, label => $_->{label}, value => 'user:' . $_->{id} } } @suggestions;
+}
+else {
+    my $exclude_tickets = join( ' ', grep( /^\d+$/, @excludes ) );
+    @suggestions = $m->comp( 'Tickets', return => $return, term => $term, max => $max, exclude => $exclude_tickets );
+}
+</%init>

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list