[Rt-commit] rt branch, 5.0/add-self-service-article-components, created. rt-5.0.0-132-g8d13c41de2

Dianne Skoll dianne at bestpractical.com
Mon Nov 30 09:07:46 EST 2020


The branch, 5.0/add-self-service-article-components has been created
        at  8d13c41de269fc9860f371646a56b861c8a49151 (commit)

- Log -----------------------------------------------------------------
commit 8d13c41de269fc9860f371646a56b861c8a49151
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Mon Nov 23 13:40:43 2020 -0500

    Add components to self-service dashboard to show Top or Newest articles.
    
    Git is claiming that Article/autohandler was renamed to
    ../Elements/SelfServiceNewestArticles, but that is wrong; the
    rename-detection algorithm failed.
    
    The autohandler was unnecessary and has been deleted; its permission
    check was wrong.  The existing permission checks in
    Elements/SelfService* are correct and sufficient.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 2539240f4d..09951b857d 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2970,12 +2970,10 @@ If this is not set at all, then $HomepageComponents is used instead.
 Set(
     $SelfServicePageComponents,
     [
-        qw(QuickCreate QueueList MyAdminQueues MySupportQueues MyReminders RefreshHomepage Dashboards SavedSearches FindUser MyAssets FindAsset FindGroup) # loc_qw
+        qw(SelfServiceTopArticles SelfServiceNewestArticles)
     ]
 );
 
-=back
-
 =head2 Articles
 
 =over 4
diff --git a/share/html/SelfService/Article/autohandler b/share/html/Elements/SelfServiceNewestArticles
similarity index 87%
copy from share/html/SelfService/Article/autohandler
copy to share/html/Elements/SelfServiceNewestArticles
index 82be63dab4..3237f398e4 100644
--- a/share/html/SelfService/Article/autohandler
+++ b/share/html/Elements/SelfServiceNewestArticles
@@ -45,14 +45,4 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<%INIT>
-
-if ( $session{'CurrentUser'}->HasRight( Right => 'ShowArticle',
-                   Object => $RT::System )) {
-    $m->comp( { base_comp => $m->request_comp }, $m->fetch_next, %ARGS);    
-}
-else {
-    RT::Interface::Web::Redirect($RT::WebURL."SelfService/");
-}
-
-</%INIT>
+<& /Elements/SelfServiceShowArticles &>
diff --git a/share/html/SelfService/Article/autohandler b/share/html/Elements/SelfServiceShowArticles
similarity index 52%
copy from share/html/SelfService/Article/autohandler
copy to share/html/Elements/SelfServiceShowArticles
index 82be63dab4..e09139cbee 100644
--- a/share/html/SelfService/Article/autohandler
+++ b/share/html/Elements/SelfServiceShowArticles
@@ -45,14 +45,57 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+<& /Widgets/TitleBoxStart, title => $title, bodyclass=> '' &>
+
+<div class="form-row article-headers">
+  <div class="label col-4 text-left">
+    <&|/l&>Name</&>
+  </div>
+</div>
+% while (my $Article = $MyArticles->Next) {
+% $i++;
+<div class="<% $i%2 ? 'oddline' : 'evenline'%> form-row article-metadata">
+  <div class="value col-4 text-left">
+    <span class="current-value font-weight-bold"><a href="<% RT->Config->Get('WebPath') %>/SelfService/Article/Display.html?id=<%$Article->Id%>"><%$Article->Name || loc('(no name)')%></a></span>
+  </div>
+</div>
+<div class="<% $i%2 ? 'oddline' : 'evenline'%> form-row article-summary">
+  <div class="col-11 col-offset-1">
+    <span class="current-value"><small><%$Article->Summary || loc('(no Summary)')%></small></span>
+  </div>
+</div>
+% }
+<& /Widgets/TitleBoxEnd &>
 <%INIT>
+my $i;
 
-if ( $session{'CurrentUser'}->HasRight( Right => 'ShowArticle',
-                   Object => $RT::System )) {
-    $m->comp( { base_comp => $m->request_comp }, $m->fetch_next, %ARGS);    
+# Get a list of classes for which current user has "ShowArticle" right.
+# We get the list of classes as RT->SystemUser; if we didn't do that,
+# we would have to grant the "SeeClass" right to self-service users
+# as well as the "ShowArticle" right.
+my $Classes = RT::Classes->new(RT->SystemUser);
+$Classes->LimitToEnabled;
+my @classes;
+while (my $c = $Classes->Next) {
+    push(@classes, $c->id) if $c->CurrentUserHasRight('ShowArticle');
 }
-else {
-    RT::Interface::Web::Redirect($RT::WebURL."SelfService/");
+
+# If the user does not have access to any article classes, then we need
+# to prohibit any articles from being shown.
+if (!scalar(@classes)) {
+    push(@classes, -1);  # -1 can never be the ID of a valid article class
 }
 
+my $MyArticles;
+$MyArticles = RT::Articles->new($session{'CurrentUser'});
+$MyArticles->Limit(FIELD => 'Class', OPERATOR => 'IN', VALUE => \@classes);
+$MyArticles->RowsPerPage($rows);
+$MyArticles->OrderBy(FIELD => $orderby_field, ORDER => $sortorder);
+
 </%INIT>
+<%ARGS>
+$orderby_field => 'LastUpdated'
+$sortorder     => 'Desc'
+$rows          => 10
+$title         => loc("[_1] Newest Articles", $rows)
+</%ARGS>
diff --git a/share/html/SelfService/Article/autohandler b/share/html/Elements/SelfServiceTopArticles
similarity index 87%
rename from share/html/SelfService/Article/autohandler
rename to share/html/Elements/SelfServiceTopArticles
index 82be63dab4..1e152df8f6 100644
--- a/share/html/SelfService/Article/autohandler
+++ b/share/html/Elements/SelfServiceTopArticles
@@ -45,14 +45,4 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<%INIT>
-
-if ( $session{'CurrentUser'}->HasRight( Right => 'ShowArticle',
-                   Object => $RT::System )) {
-    $m->comp( { base_comp => $m->request_comp }, $m->fetch_next, %ARGS);    
-}
-else {
-    RT::Interface::Web::Redirect($RT::WebURL."SelfService/");
-}
-
-</%INIT>
+<& /Elements/SelfServiceShowArticles, orderby_field => 'SortOrder', sortorder => 'Desc', title => loc('[_1] Top Articles', 10), rows => 10 &>

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


More information about the rt-commit mailing list