[Rt-commit] rt branch, 4.4/include-article-queue, repushed

Craig Kaiser craig at bestpractical.com
Fri Feb 16 13:26:48 EST 2018


The branch 4.4/include-article-queue was deleted and repushed:
       was c6eba2e699c81b4425d33c10175548861eab1fc0
       now 54242d489829d4248fb26970c8e5b8ef634151ab

1: f2d31f1db < -:  ------- Add test for 'Order by' dropdown content
2: 0494b9529 < -:  ------- Re-add Queue to 'Order by' dropdown in Search Builder
-:  ------- > 1: 2d2495159 Add callback to Bulk.html at start of Init block
-:  ------- > 2: 39e6fc1a2 Don't fail externalauth/auth_config.t tests if Net::LDAP is missing
-:  ------- > 3: eac112a02 Set proper HTTP Status codes on Abort
-:  ------- > 4: db9b71e9c Fix tests failing because they assume a 200 status response
-:  ------- > 5: 7ad0ed9e1 Avoid spuriously unchecking all recipient checkboxes
-:  ------- > 6: 2d9444120 Make RT owner dropdown limit a config option
3: 9a87e2e54 ! 7: 73ea73c1e Add support for Queue Default Article for web UI
    @@ -1,127 +1,59 @@
     Author: Craig Kaiser <craig at bestpractical.com>
     
    -    Add Default Article option for Queues
    +    Add support for Queue Default Article for web UI
         
    -    Currently there is not a simple way to apply boilerplate text to
    -    tickets automatically on initial create. By selecting a Default Article for a Queue, any
    -    ticket created in that Queue will automatically have the Article content
    -    added to the Ticket create page message box.
    -
    -diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
    ---- a/lib/RT/Queue.pm
    -+++ b/lib/RT/Queue.pm
    -@@
    -         CorrespondAddress => '',
    -         CommentAddress    => '',
    -         Lifecycle         => 'default',
    -+        QueueDefaultArticle    => undef,
    -         SubjectTag        => undef,
    -         Sign              => undef,
    -         SignAuto          => undef,
    +    For the Defaults page for Queues, add an option for a Default Article.
    +    Where the content of the Article will be loaded into the message box of
    +    any Ticket, on create in that Queue.
    +
    +diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
    +--- a/share/html/Admin/Queues/DefaultValues.html
    ++++ b/share/html/Admin/Queues/DefaultValues.html
    +@@
    +         Grouping => 'Basics',
    +         InTable => 1,
    +     &>
    ++
    ++    <tr><td class="label"><&|/l&>Article</&>:</td>
    ++        <td><& /Elements/ArticleSelect, QueueObj => $queue, Default => $queue->DefaultValue('QueueDefaultArticle') &>
    ++    </td></tr>
    ++
    +     </table>
    +     </&>
    + </div>
     @@
          }
    -     $RT::Handle->Commit;
    + }
    + elsif ( $ARGS{Update} ) {
    +-    for my $field ( qw/InitialPriority FinalPriority Starts Due/ ) {
    ++    for my $field ( qw/InitialPriority FinalPriority Starts Due QueueDefaultArticle/ ) {
    +         my ($ret, $msg) = $queue->SetDefaultValue(
    +             Name => $field,
    +             Value => $ARGS{$field},
    +
    +diff --git a/share/html/Articles/Elements/IncludeArticle b/share/html/Articles/Elements/IncludeArticle
    +--- a/share/html/Articles/Elements/IncludeArticle
    ++++ b/share/html/Articles/Elements/IncludeArticle
    +@@
    +         Value => $parent_args->{$arg},
    +         Queue => $Queue->Id,
    +     );
    ++
    ++    # Check if Ticket id is present, if it is not we know we are creating a Ticket
    ++    if ( !$parent_args->{'id'} ){
    ++        my $queue_id = $parent_args->{'Queue'};
    ++
    ++        my $QueueObj = RT::Queue->new($session{'CurrentUser'});
    ++        $QueueObj->Load( $queue_id );
    ++
    ++        if ($QueueObj->DefaultValue('QueueDefaultArticle') ){
    ++            $article->LoadByCols( Name => $QueueObj->DefaultValue('QueueDefaultArticle') );
    ++        }
    ++    }
    ++
    +     next unless $article && $article->id;
      
    --    for my $attr (qw/Sign SignAuto Encrypt SLA/) {
    -+    for my $attr (qw/Sign SignAuto Encrypt SLA QueueDefaultArticle/) {
    -         next unless defined $args{$attr};
    -         my $set = "Set" . $attr;
    -         my ($status, $msg) = $self->$set( $args{$attr} );
    -@@
    -     return ( $id, $self->loc("Queue created") );
    - }
    - 
    -+=head2 QueueDefaultArticle
    - 
    -+Returns ID for Default Article for Queue, if no value undef is returned.
    -+
    -+=cut
    -+
    -+sub QueueDefaultArticle {
    -+    my $self = shift;
    -+
    -+    my $attr = $self->FirstAttribute('QueueDefaultArticle') ;
    -+    my $content = $attr && $attr->Content ? $attr->Content : undef;
    -+    return $content;
    -+ }
    -+
    -+=head2 SetQueueDefaultArticle
    -+
    -+Takes ID value for Article and sets Queue attribute QueueDefaultArticle to that
    -+ID.
    -+
    -+=cut
    -+
    -+sub SetQueueDefaultArticle{
    -+    my $self = shift;
    -+    my $value = shift;
    -+
    -+    my $article = RT::Article->new( RT->SystemUser );
    -+    my $no_value = $self->loc("(no value)");
    -+    my $new_value;
    -+    my $old_value;
    -+
    -+    # If unsetting Default Article $value will come in as empty string, do not load that.
    -+    if ( length($value) ) {
    -+        my ($ret, $msg) = $article->Load( $value );
    -+        ($ret, $msg) = $article->LoadByCols( Name => $value ) unless $ret;
    -+        return ($ret, $msg) unless $ret;
    -+        $new_value = $article->Name;
    -+        $value = $article->Id;
    -+    }
    -+
    -+    if ( length($self->QueueDefaultArticle()) ) {
    -+        my ($ret, $msg) = $article->Load( $self->QueueDefaultArticle() );
    -+        return ($ret, $msg) unless $ret;
    -+        $old_value = $article->Name;
    -+    }
    -+
    -+    my ($ret, $msg) = $self->SetAttribute(
    -+        Name        => 'QueueDefaultArticle',
    -+        Content     => $value,
    -+    );
    -+    return ($ret, $msg) unless $ret;
    -+
    -+    return (1,
    -+        $self->loc("Default Article changed from [_1] to [_2]",
    -+            $old_value ? "'" . $old_value . "'" : $no_value,
    -+            $new_value ? "'" . $new_value . "'" : $no_value));
    -+}
    - 
    - sub Delete {
    -     my $self = shift;
    -
    -diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
    ---- a/share/html/Admin/Queues/Modify.html
    -+++ b/share/html/Admin/Queues/Modify.html
    -@@
    - % }
    - </td></tr>
    - 
    -+<tr><td align="right"><&|/l&>Default Article</&>:</td><td colspan="3">
    -+<& /Elements/ArticleSelect, QueueObj => $QueueObj &>
    -+</td></tr>
    -+
    - <tr><td align="right"><&|/l&>Subject Tag</&>:</td>
    - <td colspan="3"><input name="SubjectTag" value="<% $ARGS{'SubjectTag'} || ($Create ? "" : $QueueObj->SubjectTag || '' ) %>" size="60" /></td>
    - </tr>
    -@@
    - if ( $QueueObj->Id ) {
    -     $title = loc('Configuration for queue [_1]', $QueueObj->Name );
    -     my @attribs= qw(Description CorrespondAddress CommentAddress Name SortOrder
    --        Sign SignAuto Encrypt Lifecycle SubjectTag SLADisabled Disabled);
    -+        Sign SignAuto Encrypt Lifecycle QueueDefaultArticle SubjectTag SLADisabled Disabled);
    - 
    -     # we're asking about enabled on the web page but really care about disabled
    -     if ( $SetEnabled ) {
    -@@
    - $CommentAddress => undef
    - $SetSLAEnabled => undef
    - $SetEnabled => undef
    -+$QueueDefaultArticle => undef
    - $SetCrypt => undef
    - $SLAEnabled => undef
    - $Enabled => undef
    +     my $formatted_article = $m->scomp('/Articles/Article/Elements/Preformatted',
     
     diff --git a/share/html/Elements/ArticleSelect b/share/html/Elements/ArticleSelect
     new file mode 100644
    @@ -175,7 +107,7 @@
     +%# those contributions and any derivatives thereof.
     +%#
     +
    -+<& "SelectArticle$Widget", articles => $articles, QueueObj => $QueueObj &>
    ++<& "SelectArticle$Widget", articles => $articles, QueueObj => $QueueObj, Default => $Default &>
     +
     +<%INIT>
     +
    @@ -186,18 +118,27 @@
     +my $dropdown_limit = 50;
     +$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
     +
    -+my $Widget =  $articles->Count > $dropdown_limit ? 'Search' : 'Dropdown';
    ++my $Widget =  $articles->Count > $dropdown_limit ? 'Autocomplete' : 'Dropdown';
    ++
    ++my $default_article = RT::Article->new($session{'CurrentUser'});
    ++# Default Article is "" if no value selected
    ++if ( defined $QueueObj->DefaultValue('QueueDefaultArticle') && $QueueObj->DefaultValue('QueueDefaultArticle') ne "") {
    ++    my ($ret, $msg) = $default_article->LoadByCol( Name => $QueueObj->DefaultValue('QueueDefaultArticle') );
    ++    RT::Logger->error($msg) unless $ret;
    ++    $Default = $default_article->Name;
    ++}
     +
     +</%INIT>
     +
     +<%ARGS>
     +$QueueObj
    ++$Default => ""
     +</%ARGS>
     
    -diff --git a/share/html/Elements/SelectArticleDropdown b/share/html/Elements/SelectArticleDropdown
    +diff --git a/share/html/Elements/SelectArticleAutocomplete b/share/html/Elements/SelectArticleAutocomplete
     new file mode 100644
     --- /dev/null
    -+++ b/share/html/Elements/SelectArticleDropdown
    ++++ b/share/html/Elements/SelectArticleAutocomplete
     @@
     +%# BEGIN BPS TAGGED BLOCK {{{
     +%#
    @@ -246,39 +187,17 @@
     +%# those contributions and any derivatives thereof.
     +%#
     +%# END BPS TAGGED BLOCK }}}
    -+
    -+<select name='QueueDefaultArticle'>
    -+<option value="" selected><&|/l&><% $article_id->Name? $article_id->Name: '-'%></&></option>
    -+% if ( $article_id ) {
    -+<option value="">-</option>
    -+% }
    -+% while (my $article = $articles->Next) {
    -+%     if ( $article && $article->Id eq $article->Id) {
    -+<option value="<% $article->Id %>"><% $article->Name|| loc('(no name)')%><%$article->Summary || ''%></option>
    -+%     }
    -+% }
    -+</select>
    -+
    -+<%INIT>
    -+my $article_id = RT::Article->new($session{'CurrentUser'});
    -+
    -+# Default Article is "" if no value selected
    -+if ( defined $QueueObj->QueueDefaultArticle && $QueueObj->QueueDefaultArticle ne "") {
    -+    my ($ret, $msg) = $article_id->LoadByCol( id => $QueueObj->QueueDefaultArticle );
    -+    RT::Logger->error($msg) unless $ret;
    -+}
    -+</%INIT>
    ++<input data-autocomplete="Articles" data-autocomplete-return="Name" name='QueueDefaultArticle' value="<% $Default %>" selected>
     +
     +<%ARGS>
    -+$QueueObj
    -+$articles
    ++$Default => ""
     +</%ARGS>
    -+
    -
    -diff --git a/share/html/Elements/SelectArticleSearch b/share/html/Elements/SelectArticleSearch
    +\ No newline at end of file
    +
    +diff --git a/share/html/Elements/SelectArticleDropdown b/share/html/Elements/SelectArticleDropdown
     new file mode 100644
     --- /dev/null
    -+++ b/share/html/Elements/SelectArticleSearch
    ++++ b/share/html/Elements/SelectArticleDropdown
     @@
     +%# BEGIN BPS TAGGED BLOCK {{{
     +%#
    @@ -328,14 +247,18 @@
     +%#
     +%# END BPS TAGGED BLOCK }}}
     +
    -+<input name='QueueDefaultArticle' value="" selected placeholder="<% $article_id ? $article_id->Name : ''%>">
    -+
    -+<%INIT>
    -+my $article_id = RT::Article->new($session{'CurrentUser'});
    -+my ($ret, $msg) = $article_id->LoadByCol( id => $QueueObj->QueueDefaultArticle );
    -+RT::Logger->error($msg) unless $ret;
    -+</%INIT>
    ++<select name='QueueDefaultArticle'>
    ++<option value="">-</option>
    ++% while (my $article = $articles->Next) {
    ++<option <% ( $article->Name eq $Default) ? qq[ selected="selected"] : '' |n %>
    ++    value="<%$article->Name%>"
    ++><% $article->Name %></option>
    ++% }
    ++</select>
    ++
     +<%ARGS>
    -+$QueueObj
    ++$articles
    ++$Default => undef
     +</%ARGS>
    -
    ++
    +
4: 82bea6283 < -:  ------- Test Queue Default Article sub routines
5: 22a147bbc < -:  ------- Make default Article content show on Ticket create
7: f888fc715 ! 8: b4a79f43d Add autocomplete for Articles
    @@ -54,7 +54,7 @@
     +%# those contributions and any derivatives thereof.
     +%#
     +%# END BPS TAGGED BLOCK }}}
    -+% $r->content_type('application/json');
    ++% $r->content_type('application/json; charset=utf-8');
     +<% JSON( \@suggestions ) |n %>
     +% $m->abort;
     +<%ARGS>
    @@ -62,7 +62,7 @@
     +$max        => 10
     +$op         => 'STARTSWITH'
     +$right      => undef
    -+$return     => 'Name';
    ++$return     => 'Name'
     +</%ARGS>
     +<%INIT>
     +# Only allow certain return fields
    @@ -75,6 +75,8 @@
     +
     +# Sanity check the operator
     +$op = 'STARTSWITH' unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
    ++
    ++$m->callback( CallbackName => 'ModifyMaxResults', max => \$max );
     +
     +my $articles = RT::Articles->new( $session{CurrentUser} );
     +$articles->RowsPerPage( $max );
    @@ -91,6 +93,7 @@
     +    next if $right and not $a->CurrentUserHasRight($right);
     +    my $value = $a->$return;
     +    push @suggestions, { label => $a->Name, value => $value };
    ++    $m->callback( CallbackName => "ModifySuggestion", suggestions => @suggestions, label => $a );
     +}
     +</%INIT>
     
6: c6a3e3d86 ! 9: 54242d489 Test Ticket create web UI when Default Article
    @@ -2,8 +2,8 @@
     
         Test Ticket create web UI when Default Article
         
    -    Test that the QueueDefaultArticle content is being rendered in the
    -    message box on the Ticket create page when Default Article is selected.
    +    Test that when a Queue Default Value is selected for Article, the
    +    content of the Article is loaded on the Ticket create page.
     
     diff --git a/t/web/ticket-create-utf8.t b/t/web/ticket-create-utf8.t
     --- a/t/web/ticket-create-utf8.t
    @@ -34,11 +34,10 @@
     +my $queue = RT::Queue->new(RT->SystemUser);
     +$queue->Load('General');
     +ok( $queue, 'Loaded General Queue' );
    -+($ret, $msg) = $queue->SetQueueDefaultArticle($article->id);
    ++($ret, $msg) = $queue->SetDefaultValue( Name => 'QueueDefaultArticle', Value => $article->Name);
     +ok( $ret, $msg );
     +
     +ok $m->login(root => 'password'), "logged in";
     +$m->goto_create_ticket('General');
     +$m->scraped_id_is('Content', '#1: My Article <br />-------------- <br />Content: <br />------- <br />My Article Test Content <br />');
     +
    -
8: c6eba2e69 < -:  ------- Add autocomplete to Default Article text input



More information about the rt-commit mailing list