[Rt-commit] rt branch 5.0/acl-and-scrip-changes-in-initialdata created. rt-5.0.2-15-g9371e76f12

BPS Git Server git at git.bestpractical.com
Fri Oct 1 20:40:23 UTC 2021


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/acl-and-scrip-changes-in-initialdata has been created
        at  9371e76f12784d03067366cca3869b3346827bdc (commit)

- Log -----------------------------------------------------------------
commit 9371e76f12784d03067366cca3869b3346827bdc
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Oct 1 17:52:58 2021 +0800

    Do not keep track of ObjectScrips ids when calculating changes
    
    This is like how we deleted ids of CustomFieldValues and
    ObjectCustomFieldValues, which are allowed to be different.

diff --git a/sbin/rt-dump-initialdata.in b/sbin/rt-dump-initialdata.in
index 1ecfa8449e..63984df0e7 100644
--- a/sbin/rt-dump-initialdata.in
+++ b/sbin/rt-dump-initialdata.in
@@ -285,6 +285,10 @@ sub find_differences {
         if ( $record->{Topics} ) {
             delete $_->{id} for @{$record->{Topics}};
         }
+
+        if ( $type eq 'Scrips' && $record->{Queue} ) {
+            delete $_->{id} for @{$record->{Queue}};
+        }
     }
 
     my @changes;

commit 25433c35a736fd1da887a728f75d52dfd54d0643
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 21 21:55:32 2021 +0800

    ACL in initialdata is applied globally by default
    
    When ObjectType/ObjectId are absent in ACL records, it means global.
    This is to get rid of errors from RT::ACE::_ParseObjectArg:
    
        Method called with wrong args

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index dceb7e5007..ff66fe02a4 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2831,6 +2831,8 @@ sub _LoadObject {
         $object->LoadByValues(
             PrincipalId   => $principal_id,
             PrincipalType => $principal_type,
+            ObjectType    => 'RT::System',
+            ObjectId      => RT->System->Id,
             map { $_ => $values->{_Original}{$_} } grep { $values->{_Original}{$_} } qw/ObjectType ObjectId RightName/,
         );
     }

commit 799922172c7ed1bd52e1d6a09806917d5276e215
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Sep 22 03:07:57 2021 +0800

    Handle ObjectScrips updates for Scrips in initialdata

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index dc3f171f14..dceb7e5007 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2626,6 +2626,80 @@ sub _UpdateObject {
                 next;
             }
         }
+        elsif ( $class eq 'RT::Scrip' ) {
+            if ( $field eq 'Queue' ) {
+                my %current;
+                my %new;
+
+                my $object_scrips = RT::ObjectScrips->new(RT->SystemUser);
+                $object_scrips->LimitToScrip($object->id);
+
+                while ( my $object_scrip = $object_scrips->Next ) {
+                    $current{$object_scrip->Stage}{$object_scrip->ObjectId} = $object_scrip->SortOrder;
+                }
+
+                for my $item ( @{ $value || [] } ) {
+                    if ( $item->{ObjectId} eq 0 ) {
+                        $new{ $item->{Stage} }{0} = $item->{SortOrder};
+                    }
+                    else {
+                        my $queue = RT::Queue->new( RT->SystemUser );
+                        $queue->Load( $item->{ObjectId} );
+                        if ( $queue->id ) {
+                            $new{ $item->{Stage} }{ $queue->id } = $item->{SortOrder};
+                        }
+                    }
+                }
+
+                for my $stage ( sort keys %current ) {
+                    for my $id ( sort { $current{$stage}{$a} <=> $current{$stage}{$b} } keys %{ $current{$stage} } ) {
+                        my $object_scrip = RT::ObjectScrip->new( RT->SystemUser );
+                        $object_scrip->LoadByCols( Scrip => $object->id, ObjectId => $id, Stage => $stage );
+                        if ( $object_scrip->id ) {
+                            if ( defined $new{$stage}{$id} ) {
+                                if ( $new{$stage}{$id} != $current{$stage}{$id} ) {
+                                    my ( $ret, $msg ) = $object_scrip->SetSortOrder( $new{$stage}{$id} );
+                                    if ( !$ret ) {
+                                        RT->Logger->error( "Couldn't update SortOrder of ObjectScrip #"
+                                                . $object_scrip->id
+                                                . ": $msg" );
+                                    }
+                                }
+                            }
+                            else {
+                                my ( $ret, $msg ) = $object_scrip->Delete;
+                                if ( !$ret ) {
+                                    RT->Logger->error( "Couldn't delete ObjectScrip #" . $object_scrip->id . ": $msg" );
+                                }
+                            }
+                        }
+                    }
+                }
+
+                for my $stage ( sort keys %new ) {
+                    for my $id ( sort { $new{$stage}{$a} <=> $new{$stage}{$b} } keys %{ $new{$stage} } ) {
+                        next if defined $current{$stage}{$id};
+
+                        my $object_scrip = RT::ObjectScrip->new( RT->SystemUser );
+                        $object_scrip->LoadByCols( Scrip => $object->id, ObjectId => $id, Stage => $stage );
+                        if ( !$object_scrip->id ) {
+                            my ( $ret, $msg ) = $object_scrip->Create(
+                                Scrip     => $object->id,
+                                ObjectId  => $id,
+                                Stage     => $stage,
+                                SortOrder => $new{$stage}{SortOrder},
+                            );
+                            if ( !$ret ) {
+                                RT->Logger->error( "Couldn't create ObjectScrip for Scrip #"
+                                        . $object->id
+                                        . " and Queue #$id: $msg" );
+                            }
+                        }
+                    }
+                }
+                next;
+            }
+        }
 
         next unless $object->can( $field ) || $object->_Accessible( $field, 'read' );
         my $old_value = $object->can( $field ) ? $object->$field : $object->_Value( $field );

commit 2af46d9279eada8347004c376d2895e5d44fd51e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 21 21:47:18 2021 +0800

    Handle system internal and role groups for ACL updates in initialdata

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index e29344e2d5..dc3f171f14 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2712,6 +2712,43 @@ sub _LoadObject {
                 return;
             }
         }
+        elsif ( $values->{_Original}{GroupType} ) {
+
+            my $group = RT::Group->new(RT->SystemUser);
+            if ( $values->{_Original}{'GroupDomain'} eq 'SystemInternal' ) {
+                $group->LoadSystemInternalGroup( $values->{_Original}{GroupType} );
+            }
+            elsif ( $values->{_Original}{'GroupDomain'} eq 'RT::System-Role' ) {
+                $group->LoadRoleGroup( Object => RT->System, Name => $values->{_Original}{GroupType} );
+            }
+            elsif ( $values->{_Original}{'GroupDomain'} =~ /-Role$/ ) {
+                my $object;
+                if ( $values->{_Original}{ObjectType} and $values->{_Original}{ObjectId} ) {
+                    $object = $values->{_Original}{ObjectType}->new( RT->SystemUser );
+                    my ( $ok, $msg ) = $object->Load( $values->{_Original}{ObjectId} );
+                    unless ($ok) {
+                        RT->Logger->error( "Unable to load "
+                                . $values->{_Original}{ObjectType} . " "
+                                . $values->{_Original}{ObjectId}
+                                . ": $msg" );
+                        return;
+                    }
+                }
+                else {
+                    $object = RT->System;
+                }
+                $group->LoadRoleGroup( Object => $object, Name => $values->{_Original}{GroupType} );
+            }
+
+            if ( $group->id ) {
+                $principal_id   = $group->PrincipalId;
+                $principal_type = 'Group';
+            }
+            else {
+                RT->Logger->error("Couldn't load group $values->{_Original}{GroupType}");
+                return;
+            }
+        }
         else {
             RT->Logger->error( "Invalid principal type in $class" );
             return;

commit 8f78526be1c88f522ff6cb6b443c3958bc9f4610
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 21 21:44:26 2021 +0800

    Fix typo, this block is to check GroupId

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 3f741fa7ff..e29344e2d5 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -2708,7 +2708,7 @@ sub _LoadObject {
                 $principal_type = 'Group';
             }
             else {
-                RT->Logger->error( "Couldn't load group $values->{_Original}{UserId}" );
+                RT->Logger->error( "Couldn't load group $values->{_Original}{GroupId}" );
                 return;
             }
         }

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list