[Rt-commit] rt branch, 5.0/self-service-article-check-right-beforehand, created. rt-5.0.0-172-gdfb5e71edd

? sunnavy sunnavy at bestpractical.com
Wed Dec 23 03:09:29 EST 2020


The branch, 5.0/self-service-article-check-right-beforehand has been created
        at  dfb5e71edd11fd628aa3fa0fc2cace7f2c6e075f (commit)

- Log -----------------------------------------------------------------
commit dfb5e71edd11fd628aa3fa0fc2cace7f2c6e075f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Dec 23 15:34:23 2020 +0800

    Check "ShowArticle" right beforehand to get accurate number of articles
    
    The right filter is set up in RT::Articles::AddRecord, which is after
    SQL search, thus the number of returned articles could be inaccurate
    when there is RowsPerPage limitation.

diff --git a/share/html/Elements/SelfServiceShowArticles b/share/html/Elements/SelfServiceShowArticles
index 4718ed195e..636f12289c 100644
--- a/share/html/Elements/SelfServiceShowArticles
+++ b/share/html/Elements/SelfServiceShowArticles
@@ -61,8 +61,24 @@
 </&>
 <%INIT>
 
-my $articles = RT::Articles->new($session{'CurrentUser'});
-$articles->UnLimit;
+my $articles = RT::Articles->new( $session{'CurrentUser'} );
+
+# By default article right check is not at SQL level, which could lead
+# to empty or wrong article counts. Here we check right beforehand to
+# get rid of it.
+my $right = 'ShowArticle';
+if ( $session{'CurrentUser'}->HasRight( Right => $right, Object => $RT::System ) ) {
+    $articles->UnLimit;
+}
+else {
+    my $classes = RT::Classes->new( $session{'CurrentUser'} );
+    $classes->UnLimit;
+    $articles->Limit(
+        FIELD    => 'Class',
+        VALUE    => [ map { $_->Id } grep { $_->CurrentUserHasRight($right) } @{ $classes->ItemsArrayRef } ],
+        OPERATOR => 'IN',
+    );
+}
 $articles->OrderBy(FIELD => $orderby_field, ORDER => $sortorder);
 $articles->RowsPerPage($rows);
 

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


More information about the rt-commit mailing list