[Rt-commit] rt branch 5.0/self-service-dashboard-no-classes created. rt-5.0.4-54-g208bc3a8d7

BPS Git Server git at git.bestpractical.com
Mon Jul 10 14:48:00 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/self-service-dashboard-no-classes has been created
        at  208bc3a8d783591d11609841e86880b9be3394cc (commit)

- Log -----------------------------------------------------------------
commit 208bc3a8d783591d11609841e86880b9be3394cc
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Jul 10 10:31:34 2023 -0400

    Filter class rights before adding to IN clause
    
    When filtering classes through a rights check directly in
    the code for the Limit, the IN clause could end up empty,
    which causes an SQL error. Filter first, then run the IN
    Limit only if we have classes.
    
    Also limit the list to Enabled classes.

diff --git a/share/html/Elements/SelfServiceShowArticles b/share/html/Elements/SelfServiceShowArticles
index b208c1d6f8..acf993f34f 100644
--- a/share/html/Elements/SelfServiceShowArticles
+++ b/share/html/Elements/SelfServiceShowArticles
@@ -73,11 +73,20 @@ if ( $session{'CurrentUser'}->HasRight( Right => $right, Object => $RT::System )
 else {
     my $classes = RT::Classes->new( $session{'CurrentUser'} );
     $classes->UnLimit;
-    $articles->Limit(
-        FIELD    => 'Class',
-        VALUE    => [ map { $_->Id } grep { $_->CurrentUserHasRight($right) } @{ $classes->ItemsArrayRef } ],
-        OPERATOR => 'IN',
-    );
+    $classes->LimitToEnabled;
+
+    my @classes;
+    while ( my $class = $classes->Next ) {
+        push @classes, $class->id if $class->CurrentUserHasRight($right);
+    }
+
+    if ( @classes ) {
+        $articles->Limit(
+            FIELD    => 'Class',
+            VALUE    => \@classes,
+            OPERATOR => 'IN',
+        );
+    }
 }
 $articles->OrderBy(FIELD => $orderby_field, ORDER => $sortorder);
 $articles->RowsPerPage($rows);

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list