[Rt-commit] rt branch, 5.0/self-service-display-article, created. rt-5.0.0-138-ga21dca4638

Dianne Skoll dianne at bestpractical.com
Mon Dec 14 15:47:12 EST 2020


The branch, 5.0/self-service-display-article has been created
        at  a21dca46386025f495c33686b35cca6bf85a0941 (commit)

- Log -----------------------------------------------------------------
commit 67e5fbc322894b535fa8abbbda61ff814b2d3af1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Dec 10 11:49:17 2020 -0500

    Add SelfServiceShowArticleSearch configuration option
    
    This replaces a previous rights check for global ShowArticle
    permission to show the article search. The new configuration
    option is also global, so it has the same scope with less
    overhead than a rights check.
    
    It also makes it possible to show the search box in different
    rights configurations, like when granting article access rights
    at the class level.

diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0
index da90d1912e..f2e84f2c3a 100644
--- a/docs/UPGRADING-5.0
+++ b/docs/UPGRADING-5.0
@@ -218,4 +218,18 @@ will migrate your existing tokens to the new core RT tables.
 
 =back
 
+=head1 UPGRADING FROM 5.0.0 AND EARLIER
+
+=over 4
+
+=item *
+
+In the self service interface, the "Search Articles" box in the menu bar previously
+was displayed to users who had the global right "ShowArticle". This is now
+controlled by a new configuration option C<$SelfServiceShowArticleSearch>. This new
+option defaults to off, so if you currently allow self service users to use article search,
+enable this option to keep the article search box available.
+
+=back
+
 =cut
diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 2539240f4d..1f02a8488d 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2974,6 +2974,17 @@ Set(
     ]
 );
 
+=item C<$SelfServiceShowArticleSearch>
+
+If enabled, C<$SelfServiceShowArticleSearch> displays a "Search Articles"
+box in the menu bar in the self service interface. This option controls
+only showing or hiding the search box. Users still need appropriate rights
+to see article search results and view articles.
+
+=cut
+
+Set($SelfServiceShowArticleSearch, 0);
+
 =back
 
 =head2 Articles
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 59ce078f1c..64ef153f30 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1688,6 +1688,9 @@ our %META;
     SelfServiceShowGroupTickets => {
         Widget => '/Widgets/Form/Boolean',
     },
+    SelfServiceShowArticleSearch => {
+        Widget => '/Widgets/Form/Boolean',
+    },
     ShowSearchResultCount => {
         Widget => '/Widgets/Form/Boolean',
     },
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 1d63dc177d..b83c8da250 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -1659,7 +1659,7 @@ sub BuildSelfServiceNav {
         $about_me->child( logout => title => loc('Logout'), path => $logout_url );
     }
 
-    if ($current_user->HasRight( Right => 'ShowArticle', Object => RT->System )) {
+    if ( RT->Config->Get('SelfServiceShowArticleSearch') ) {
         $widgets->child( 'goto-article' => raw_html => $HTML::Mason::Commands::m->scomp('/SelfService/Elements/SearchArticle') );
     }
 

commit 1d382799b679fcab419131f50fa8ac7f9223ddd1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Dec 10 13:26:00 2020 -0500

    Allow class-level rights to show self service articles
    
    Allow self service users to see article pages if they have
    access to see articles via ShowArticle at the class level.
    Previously self service users required global access.

diff --git a/share/html/SelfService/Article/autohandler b/share/html/SelfService/Article/autohandler
index 82be63dab4..b201bcd414 100644
--- a/share/html/SelfService/Article/autohandler
+++ b/share/html/SelfService/Article/autohandler
@@ -46,9 +46,22 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
+my $classes = RT::Classes->new($session{'CurrentUser'});
+$classes->UnLimit;
 
-if ( $session{'CurrentUser'}->HasRight( Right => 'ShowArticle',
-                   Object => $RT::System )) {
+my $right = 'ShowArticle';
+my $can_see_articles;
+
+# Check global access, then check class-level rights
+if ( $session{'CurrentUser'}->HasRight( Right => $right,
+        Object => $RT::System )) {
+    $can_see_articles = 1;
+}
+elsif ( grep { $_->CurrentUserHasRight($right) } @{$classes->ItemsArrayRef} ) {
+    $can_see_articles = 1;
+}
+
+if ( $can_see_articles ) {
     $m->comp( { base_comp => $m->request_comp }, $m->fetch_next, %ARGS);    
 }
 else {

commit 2d3d55a665440e366305c7b6e471c49567d64fbf
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Dec 10 13:57:47 2020 -0500

    Display article content in a titlebox container
    
    Also set display page title to the article name rather than the
    generic "Article 1" title. This is more appropriate for end users
    viewing an FAQ entry.

diff --git a/share/html/SelfService/Article/Display.html b/share/html/SelfService/Article/Display.html
index 8355b9be08..b35a311cf5 100644
--- a/share/html/SelfService/Article/Display.html
+++ b/share/html/SelfService/Article/Display.html
@@ -45,11 +45,12 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<& /SelfService/Elements/Header, Title => loc('Display Article [_1]', $id) &>
-<div class="label col-3"><%$article->Name || loc("(no name)")%></div><br />
-<em><div class="value col-9"><%$article->Summary%></div></em>
+<& /SelfService/Elements/Header, Title => $article->Name &>
+<div id="article-display-container" class="mx-auto max-width-md">
+<&| /Widgets/TitleBox, title => $article->Summary, class => 'article-display-simple', content_class => 'mx-auto width-md' &>
 <& /Elements/ShowCustomFields, Object => $article &>
-
+</&>
+</div>
 <%init>
 
 my $article = RT::Article->new( $session{'CurrentUser'} );
@@ -63,7 +64,6 @@ unless ( $article->Id ) {
 unless ( $article->CurrentUserHasRight('ShowArticle') ) {
     $m->comp( "/Elements/Error", Why => loc("Permission Denied") );
 }
-my $title = loc( "Article #[_1]: [_2]", $article->Id, $article->Name || loc("(no name)"));
 
 $id = $article->id;
 

commit a21dca46386025f495c33686b35cca6bf85a0941
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Fri Dec 11 09:30:09 2020 -0500

    Load class show/hide settings for article components
    
    Use the custom field settings to filter the content to display
    for the article.

diff --git a/share/html/Elements/ShowArticleCustomFields b/share/html/Elements/ShowArticleCustomFields
new file mode 100644
index 0000000000..5c156e1964
--- /dev/null
+++ b/share/html/Elements/ShowArticleCustomFields
@@ -0,0 +1,132 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2020 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 }}}
+% $m->callback( CallbackName => 'BeforeCustomFields', Object => $Object,
+%               ARGSRef => \%ARGS, CustomFields => $CustomFields);
+<div>
+% while ( my $CustomField = $CustomFields->Next ) {
+% my $Values = $Object->CustomFieldValues( $CustomField->Id );
+% my $count = $Values->Count;
+% next if $HideEmpty and not $count;
+% my $CustomFieldName = $CustomField->Name;
+%#The following substitution replaces all non-ID_Continue characters with a dash character. The ID_Continue Unicode property was chosen because it (combined with ID_Start) is meant for variable names. ID_Continue includes characters suitable for use in CSS-class names (even non-Latin ones, to support non-English custom field names) and excludes syntactic characters that are not (such as whitespace characters).
+% $CustomFieldName =~ s/\P{ID_Continue}+/-/g;
+% my @classes = (
+%   'custom-field',
+%   'custom-field-'.$CustomField->id,
+%   'custom-field-'.$CustomFieldName,
+% );
+% push @classes, 'unset-field' if not $count;
+% $m->callback( CallbackName => 'ModifyFieldClasses', CustomField => $CustomField,
+%               Object => $Object, Classes => \@classes );
+  <div class="form-row <% join(' ', @classes) %>" id="CF-<%$CustomField->id%>-ShowRow">
+% if ($HideFieldnames->{$CustomField->id}) {
+    <div class="value col-12 <% $count ? '' : ' no-value' %>">
+%} else {
+    <div class="label col-3"><% $CustomField->Name %>:</div>
+    <div class="value col-9 <% $count ? '' : ' no-value' %>">
+% }
+      <span class="current-value">
+% unless ( $count ) {
+<&|/l&>(no value)</&>
+% } elsif ( $count == 1 ) {
+%   $print_value->( $CustomField, $Values->First );
+% } else {
+<ul class="list-group list-group-compact">
+% while ( my $Value = $Values->Next ) {
+<li class="list-group-item">
+% $print_value->( $CustomField, $Value );
+</li>
+% }
+</ul>
+% }
+      </span>
+    </div>
+% $m->callback( CallbackName => 'AfterCustomFieldValue', CustomField => $CustomField,
+%               Object => $Object );
+  </div>
+% }
+</div>
+% $m->callback( CallbackName => 'AfterCustomFields', Object => $Object,
+%               ARGSRef => \%ARGS );
+<%INIT>
+$m->callback(
+    %ARGS,
+    CallbackName => 'MassageCustomFields',
+    Object       => $Object,
+    CustomFields => $CustomFields,
+);
+
+# don't print anything if there is no custom fields
+return unless $CustomFields->First;
+$CustomFields->GotoFirstItem;
+
+my $print_value = sub {
+    my ($cf, $value) = @_;
+
+    my $comp = "ShowCustomField". $cf->Type;
+    $m->callback(
+        CallbackName => 'ShowComponentName',
+        Name         => \$comp,
+        CustomField  => $cf,
+        Object       => $Object,
+    );
+    if ( $m->comp_exists( $comp ) ) {
+        $m->comp( $comp, Object => $value, EscapeHTML => $EscapeHTML );
+    } else {
+        $m->out( $m->interp->apply_escapes( $value->Content, 'h' ) );
+    }
+};
+
+</%INIT>
+<%ARGS>
+$Object => undef
+$CustomFields => $Object->CustomFields
+$HideEmpty => 0
+$HideFieldnames => {}
+$EscapeHTML => 1
+</%ARGS>
diff --git a/share/html/Elements/ShowCustomFieldText b/share/html/Elements/ShowCustomFieldText
index 1bcd6febb9..ff597a8a57 100644
--- a/share/html/Elements/ShowCustomFieldText
+++ b/share/html/Elements/ShowCustomFieldText
@@ -46,11 +46,17 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%init>
- my $content = $Object->LargeContent || $Object->Content;
- $content = $m->comp('/Elements/ScrubHTML', Content => $content);
- $content =~ s|\n|<br />|g;
+my $content = $Object->LargeContent || $Object->Content;
+if ($EscapeHTML) {
+    RT::Interface::Web::EscapeHTML(\$content);
+    $content =~ s|\n|<br />|g;
+} else {
+    $content = $m->comp('/Elements/ScrubHTML', Content => $content);
+    $content =~ s|\n|<br />|g;
+}
 </%init>
 <%$content|n%>
 <%ARGS>
 $Object
+$EscapeHTML => 0
 </%ARGS>
diff --git a/share/html/SelfService/Article/Display.html b/share/html/SelfService/Article/Display.html
index b35a311cf5..3463f7a321 100644
--- a/share/html/SelfService/Article/Display.html
+++ b/share/html/SelfService/Article/Display.html
@@ -47,8 +47,10 @@
 %# END BPS TAGGED BLOCK }}}
 <& /SelfService/Elements/Header, Title => $article->Name &>
 <div id="article-display-container" class="mx-auto max-width-md">
-<&| /Widgets/TitleBox, title => $article->Summary, class => 'article-display-simple', content_class => 'mx-auto width-md' &>
-<& /Elements/ShowCustomFields, Object => $article &>
+% my $title = "";
+% $title = $article->Summary if $include{Summary};
+<&| /Widgets/TitleBox, title => $title, class => 'article-display-simple', content_class => 'mx-auto width-md' &>
+<& /Elements/ShowArticleCustomFields, Object => $article, CustomFields => $custom_fields, HideFieldnames => \%hide_field_names, EscapeHTML => $include{EscapeHTML} &>
 </&>
 </div>
 <%init>
@@ -66,6 +68,35 @@ unless ( $article->CurrentUserHasRight('ShowArticle') ) {
 }
 
 $id = $article->id;
+my $class = $article->ClassObj;
+
+# Build up the hash of things to include/exclude, as well
+# as the array of custom field IDs to limit by
+my %include = (Name => 1, Summary => 1, EscapeHTML => 1);
+my @exclude_cf_ids;
+my %hide_field_names;
+
+my $cfs = $article->CustomFields;
+while ( my $cf = $cfs->Next ) {
+    $include{"CF-Title-" . $cf->Id} = 1;
+    $include{"CF-Value-" . $cf->Id} = 1;
+}
+foreach my $key ( keys %include ) {
+    $include{$key} = not $class->FirstAttribute("Skip-$key");
+    if ($key =~ /^CF-Value-(\d+)$/ && !$include{$key}) {
+        push(@exclude_cf_ids, $1);
+    }
+    if ($key =~ /^CF-Title-(\d+)$/ && !$include{$key}) {
+        $hide_field_names{$1} = 1;
+    }
+}
+
+my $custom_fields = $article->CustomFields;
+if (scalar(@exclude_cf_ids)) {
+    $custom_fields->Limit(FIELD    => 'id',
+                          OPERATOR => 'NOT IN',
+                          VALUE    => \@exclude_cf_ids);
+}
 
 </%init>
 <%args>

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


More information about the rt-commit mailing list