[Rt-commit] rt branch, 4.4/dump-and-merge-initialdata-savedsearch, created. rt-4.4.3-134-gcf06239df3
Jim Brandt
jbrandt at bestpractical.com
Mon Feb 3 11:56:09 EST 2020
The branch, 4.4/dump-and-merge-initialdata-savedsearch has been created
at cf06239df3baa161bff0f3ca9343f6a454e7b9d3 (commit)
- Log -----------------------------------------------------------------
commit fdd00f746d71bc62b576dfefae7dd1351ee6e217
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/Migrate/Serializer/JSON.pm b/lib/RT/Migrate/Serializer/JSON.pm
index 28835a892a..045cfc4f3f 100644
--- a/lib/RT/Migrate/Serializer/JSON.pm
+++ b/lib/RT/Migrate/Serializer/JSON.pm
@@ -540,6 +540,17 @@ 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 $dashboard = RT::Attribute->new( RT->SystemUser );
+ $dashboard->Load( $id );
+ if ( $dashboard->Id ) {
+ $record->{Content}{DashboardId} = $dashboard->Id;
+ }
+ }
+ }
}
}
commit cf06239df3baa161bff0f3ca9343f6a454e7b9d3
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..41e54adcd5 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -1017,6 +1017,53 @@ 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);
+ },
+ },
);
my $id = 0;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list