[Rt-commit] rt branch 5.0/simply-has-rights-query created. rt-5.0.3-126-g116684e51e

BPS Git Server git at git.bestpractical.com
Wed Oct 5 22:48:02 UTC 2022


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/simply-has-rights-query has been created
        at  116684e51eeeea91df9d17b998cae5f9a74e5d04 (commit)

- Log -----------------------------------------------------------------
commit 116684e51eeeea91df9d17b998cae5f9a74e5d04
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 6 06:13:28 2022 +0800

    No need to duplicate system object in EquivObjects on system rights check
    
    On system rights check, "Object => RT->System" is passed and thus
    already added to EquivObjects.
    
    This is to simplify SQL a tiny bit from
    
        (ACL.ObjectType = 'RT::System' AND ACL.ObjectId = 1) OR (ACL.ObjectType = 'RT::System' AND ACL.ObjectId = 1)
    
    to
    
        (ACL.ObjectType = 'RT::System' AND ACL.ObjectId = 1)

diff --git a/lib/RT/Principal.pm b/lib/RT/Principal.pm
index 1c1e533508..679efa7f56 100644
--- a/lib/RT/Principal.pm
+++ b/lib/RT/Principal.pm
@@ -341,7 +341,7 @@ sub HasRight {
 
     unshift @{ $args{'EquivObjects'} },
         $args{'Object'}->ACLEquivalenceObjects;
-    unshift @{ $args{'EquivObjects'} }, $RT::System;
+    unshift @{ $args{'EquivObjects'} }, $RT::System unless $args{'Object'}->isa('RT::System');
 
     # If we've cached a win or loss for this lookup say so
 
@@ -414,7 +414,7 @@ sub HasRights {
     push @{ $args{'EquivObjects'} }, $object;
     unshift @{ $args{'EquivObjects'} },
         $args{'Object'}->ACLEquivalenceObjects;
-    unshift @{ $args{'EquivObjects'} }, $RT::System;
+    unshift @{ $args{'EquivObjects'} }, $RT::System unless $object->isa('RT::System');
 
     my %res = ();
     {

commit 96af0d01d45473f4e171e72c7abb0ef96a31ce96
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 6 05:57:41 2022 +0800

    Wrap direct SQL in Rights code to SearchBuilder's SimpleQuery
    
    This is to log statements(enabled by $StatementLog), which is quite
    useful when debugging perforamnce issues.

diff --git a/lib/RT/Principal.pm b/lib/RT/Principal.pm
index 27200c3c0f..1c1e533508 100644
--- a/lib/RT/Principal.pm
+++ b/lib/RT/Principal.pm
@@ -421,19 +421,23 @@ sub HasRights {
         my ( $query, @bind_values ) = $self->_HasGroupRightQuery( EquivObjects => $args{'EquivObjects'} );
         $query = "SELECT DISTINCT ACL.RightName $query";
 
-        my $rights = $RT::Handle->dbh->selectcol_arrayref($query, undef, @bind_values);
-        unless ($rights) {
+        if ( my $sth = $self->_Handle->SimpleQuery( $query, @bind_values ) ) {
+            my $rights = [ map { $_->[0] } @{$sth->fetchall_arrayref()} ];
+            $res{$_} = 1 foreach @$rights;
+        }
+        else {
             $RT::Logger->warning( $RT::Handle->dbh->errstr );
             return ();
         }
-        $res{$_} = 1 foreach @$rights;
     }
     my $roles;
     {
         my ( $query, @bind_values ) = $self->_HasRoleRightQuery( EquivObjects => $args{'EquivObjects'} );
         $query = "SELECT DISTINCT Groups.Name $query";
-        $roles = $RT::Handle->dbh->selectcol_arrayref($query, undef, @bind_values);
-        unless ($roles) {
+        if ( my $sth = $self->_Handle->SimpleQuery( $query, @bind_values ) ) {
+            $roles = [ map { $_->[0] } @{$sth->fetchall_arrayref()} ];
+        }
+        else {
             $RT::Logger->warning( $RT::Handle->dbh->errstr );
             return ();
         }
@@ -467,12 +471,14 @@ sub HasRights {
         $query = "SELECT DISTINCT ACL.RightName $query";
         $query .= ' AND ('. join( ' OR ', ("PrincipalType = ?") x @enabled_roles ) .')';
         push @bind_values, @enabled_roles;
-        my $rights = $RT::Handle->dbh->selectcol_arrayref($query, undef, @bind_values);
-        unless ($rights) {
+        if ( my $sth = $self->_Handle->SimpleQuery( $query, @bind_values ) ) {
+            my $rights = [ map { $_->[0] } @{$sth->fetchall_arrayref()} ];
+            $res{$_} = 1 foreach @$rights;
+        }
+        else {
             $RT::Logger->warning( $RT::Handle->dbh->errstr );
             return ();
         }
-        $res{$_} = 1 foreach @$rights;
     }
 
     delete $res{'ExecuteCode'} if 
@@ -685,8 +691,11 @@ sub RolesWithRight {
     my ($query, @bind_values) = $self->_RolesWithRightQuery( %args );
     $query = "SELECT DISTINCT PrincipalType $query";
 
-    my $roles = $RT::Handle->dbh->selectcol_arrayref($query, undef, @bind_values);
-    unless ($roles) {
+    my $roles;
+    if ( my $sth = $self->_Handle->SimpleQuery( $query, @bind_values ) ) {
+        $roles = [ map { $_->[0] } @{$sth->fetchall_arrayref()} ];
+    }
+    else {
         $RT::Logger->warning( $RT::Handle->dbh->errstr );
         return ();
     }

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list