[Rt-commit] rt branch, 4.4/dump-and-merge-initialdata, updated. rt-4.4.3-135-g2d7b1f0384
? sunnavy
sunnavy at bestpractical.com
Mon Feb 3 15:58:44 EST 2020
The branch, 4.4/dump-and-merge-initialdata has been updated
via 2d7b1f0384296938457984ceabb1b69e010d8335 (commit)
via 1c951b1f8874cd08a51c6a279b6427b6a6305f47 (commit)
via 92a250d3a12144cb0bd75a960f16dc13db04889a (commit)
from 6f7a54d1384d31b6cac0a3abb72327d1b4184d31 (commit)
Summary of changes:
lib/RT/Handle.pm | 35 ++++++++++++++++-----------
lib/RT/Migrate/Serializer/JSON.pm | 15 ++++++++++++
t/api/initialdata-roundtrip.t | 51 +++++++++++++++++++++++++++++++++++++++
3 files changed, 87 insertions(+), 14 deletions(-)
- Log -----------------------------------------------------------------
commit 92a250d3a12144cb0bd75a960f16dc13db04889a
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Feb 4 03:16:36 2020 +0800
Refactor attributes sort code to be more scalable on insert
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index e70e8c54a3..0c2dbd6c65 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1792,20 +1792,12 @@ sub InsertData {
$RT::Logger->debug("Creating attributes...");
my $sys = RT::System->new(RT->SystemUser);
- for my $item (
- sort {
- $a->{Name} eq 'Pref-DashboardsInMenu' ? 1
- : (
- $b->{Name} eq 'Pref-DashboardsInMenu' ? -1
- : (
- $a->{Name} =~ /(?:^Dashboard|HomepageSettings)$/ ? 1
- : $b->{Name} =~ /(?:^Dashboard|HomepageSettings)$/ ? -1
- : 0
- )
- )
- } @Attributes
- )
- {
+ my %order = (
+ 'Dashboard' => 1,
+ 'HomepageSettings' => 1,
+ 'Pref-DashboardsInMenu' => 2,
+ );
+ for my $item ( sort { ( $order{ $a->{Name} } || 0 ) <=> ( $order{ $b->{Name} } || 0 ) } @Attributes ) {
if ( $item->{_Original} ) {
$self->_UpdateOrDeleteObject( 'RT::Attribute', $item );
next;
commit 1c951b1f8874cd08a51c6a279b6427b6a6305f47
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Mon Feb 3 11:50:26 2020 -0500
Convert subscription dashboard link to dashboard id
When serializing, the dashboard link inside a subscription
became a scalar reference to the attribute record for the
dashboard. When converting to JSON, this resulted in the error:
cannot encode reference to scalar
from the JSON module. Convert to the id so it can be exported
to JSON.
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 0c2dbd6c65..0197509494 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1796,6 +1796,7 @@ sub InsertData {
'Dashboard' => 1,
'HomepageSettings' => 1,
'Pref-DashboardsInMenu' => 2,
+ 'Subscription' => 2,
);
for my $item ( sort { ( $order{ $a->{Name} } || 0 ) <=> ( $order{ $b->{Name} } || 0 ) } @Attributes ) {
if ( $item->{_Original} ) {
@@ -2848,6 +2849,20 @@ sub _CanonilizeAttributeContent {
}
$item->{Content}{dashboards} = \@dashboards;
}
+ elsif ( $item->{Name} eq 'Subscription' ) {
+ my $entry = $item->{Content}{DashboardId};
+ if ( $entry->{ObjectType} && $entry->{ObjectId} && $entry->{Description} ) {
+ if ( my $object = $self->_LoadObject( $entry->{ObjectType}, $entry->{ObjectId} ) ) {
+ my $attributes = $object->Attributes;
+ $attributes->Limit( FIELD => 'Name', VALUE => 'Dashboard' );
+ $attributes->Limit( FIELD => 'Description', VALUE => $entry->{Description} );
+ if ( my $attribute = $attributes->First ) {
+ $item->{Content}{DashboardId} = $attribute->Id;
+ $item->{Description} = 'Subscription to dashboard ' . $attribute->Id;
+ }
+ }
+ }
+ }
}
sub _CanonilizeObjectCustomFieldValue {
diff --git a/lib/RT/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 28835a892a..3de1efb4b9 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -540,6 +540,21 @@ sub CanonicalizeAttributes {
}
$record->{Content}{dashboards} = \@dashboards;
}
+ elsif ( $record->{Name} eq 'Subscription' ) {
+ my $dashboard_id = $record->{Content}{DashboardId};
+ if ( ref $dashboard_id eq 'SCALAR' && $$dashboard_id =~ /(\d+)$/ ) {
+ my $id = $1;
+ my $attribute = RT::Attribute->new( RT->SystemUser );
+ $attribute->Load( $id );
+ if ( $attribute->Id ) {
+ $record->{Content}{DashboardId} = {
+ ObjectType => $attribute->ObjectType,
+ ObjectId => $attribute->Object->Name,
+ Description => $attribute->Description,
+ };
+ }
+ }
+ }
}
}
commit 2d7b1f0384296938457984ceabb1b69e010d8335
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Mon Feb 3 11:54:29 2020 -0500
Add attributes tests to JSON initialdata tests
Specifically, test a dashboard and subscription.
diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index d4020addb5..b108a868cb 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -1017,6 +1017,57 @@ my @tests = (
is($twd->CustomFieldValuesAsString('Tags', Separator => '.'), 'snakes.clowns', 'Tags CF');
},
},
+ {
+ name => 'Attributes',
+ create => sub {
+ my $root = RT::User->new(RT->SystemUser);
+ my ($ok, $msg) = $root->Load('root');
+ ok($ok, $msg);
+
+ my $dashboard = RT::Dashboard->new($root);
+ ($ok, $msg) = $dashboard->Save(
+ Name => 'My Dashboard',
+ Privacy => 'RT::User-' . $root->Id,
+ );
+ ok($ok, $msg);
+
+ my $subscription = RT::Attribute->new($root);
+ ($ok, $msg) = $subscription->Create(
+ Name => 'Subscription',
+ Description => 'Subscription to dashboard ' . $dashboard->Id,
+ ContentType => 'storable',
+ Object => $root,
+ Content => { 'Tuesday' => '1', 'DashboardId' => $dashboard->Id },
+ );
+ },
+ present => sub {
+ # Provided in core initialdata
+ my $homepage = RT::Attribute->new(RT->SystemUser);
+ $homepage->LoadByNameAndObject(Name => 'HomepageSettings', Object => RT->System);
+ ok($homepage->Id, 'Loaded homepage attribute');
+ is($homepage->Name, 'HomepageSettings', 'Name is HomepageSettings');
+ is($homepage->Description, 'HomepageSettings', 'Description is HomepageSettings');
+ is($homepage->ContentType, 'storable', 'ContentType is storable');
+
+ my $root = RT::User->new(RT->SystemUser);
+ my ($ok, $msg) = $root->Load('root');
+ ok($ok, $msg);
+
+ my $dashboard = RT::Attribute->new($root);
+ $dashboard->LoadByNameAndObject(Name => 'Dashboard', Object => $root);
+ ok($dashboard->Id, 'Loaded dashboard attribute with id ' . $dashboard->Id);
+
+ my $subscription = RT::Attribute->new($root);
+ $subscription->LoadByNameAndObject(Name => 'Subscription', Object => $root);
+ ok($subscription->Id, 'Loaded subscription attribute with id ' . $subscription->Id);
+ is($subscription->ContentType, 'storable', 'ContentType is storable');
+ is($subscription->Content->{DashboardId}, $dashboard->Id, 'Dashboard Id is ' . $dashboard->Id);
+ is( $subscription->Description,
+ 'Subscription to dashboard ' . $dashboard->Id,
+ 'Description is "Subscription to dashboard ' . $dashboard->Id . '"'
+ );
+ },
+ },
);
my $id = 0;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list