[Rt-commit] rt branch, 4.2/attributes-in-initialdata, created. rt-4.2.9-15-ga8df27b
Alex Vandiver
alexmv at bestpractical.com
Thu Nov 13 20:12:15 EST 2014
The branch, 4.2/attributes-in-initialdata has been created
at a8df27bb87a87003963b3e82ea61ef40dbef13ef (commit)
- Log -----------------------------------------------------------------
commit a8df27bb87a87003963b3e82ea61ef40dbef13ef
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed Apr 9 17:51:30 2014 -0400
Allow attributes to be set after object creation
diff --git a/docs/initialdata.pod b/docs/initialdata.pod
index ac55dcf..2d58190 100644
--- a/docs/initialdata.pod
+++ b/docs/initialdata.pod
@@ -70,8 +70,10 @@ descriptions of the values to place in them, is below.
Each hashref in C<@Users> is treated as a new user to create and passed
straight into C<< RT::User->Create >>. All of the normal user fields are
-available, as well as C<Privileged> and C<Disabled> (both booleans) which will
-do the appropriate internal group/flag handling.
+available, as well as C<Privileged> and C<Disabled> (both booleans) which
+will do the appropriate internal group/flag handling. Also accepts an
+C<Attributes> key, which is equivalent to pushing its arrayref of values
+onto C<@Attributes>, below, with C<Object> set to the new user.
For a full list of fields, read the documentation for L<RT::User/Create>.
@@ -94,6 +96,10 @@ array ref. Each value should be a user-defined group name or hashref to
pass into L<RT::Group/LoadByCols>. Each group found will have the new
group added as a member.
+It also accepts an C<Attributes> key, which is equivalent to pushing its
+arrayref of values onto C<@Attributes>, below, with C<Object> set to the
+new group.
+
=head2 C<@Queues>
push @Queues, {
@@ -103,7 +109,10 @@ group added as a member.
};
Creates a new L<RT::Queue> for each hashref. Refer to the documentation of
-L<RT::Queue/Create> for the fields you can use.
+L<RT::Queue/Create> for the fields you can use. It also accepts an
+C<Attributes> key, which is equivalent to pushing its arrayref of values
+onto C<@Attributes>, below, with C<Object> set to the new queue.
+
=head2 C<@CustomFields>
@@ -242,6 +251,10 @@ The regular expression text (not C<qr//>!) used to validate values.
=back
+It also accepts an C<Attributes> key, which is equivalent to pushing its
+arrayref of values onto C<@Attributes>, below, with C<Object> set to the
+new custom field.
+
Refer to the documentation and implementation of L<RT::CustomField/Create> and
L<RT::CustomFieldValue/Create> for the full list of available fields and
allowed values.
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 29802ad..9d726e3 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -825,6 +825,7 @@ sub InsertData {
if ( @Groups ) {
$RT::Logger->debug("Creating groups...");
foreach my $item (@Groups) {
+ my $attributes = delete $item->{ Attributes };
my $new_entry = RT::Group->new( RT->SystemUser );
$item->{'Domain'} ||= 'UserDefined';
my $member_of = delete $item->{'MemberOf'};
@@ -835,6 +836,8 @@ sub InsertData {
next;
} else {
$RT::Logger->debug($return .".");
+ $_->{Object} = $new_entry for @{$attributes || []};
+ push @Attributes, @{$attributes || []};
}
if ( $member_of ) {
$member_of = [ $member_of ] unless ref $member_of eq 'ARRAY';
@@ -883,12 +886,15 @@ sub InsertData {
if ( $item->{'Name'} eq 'root' && $root_password ) {
$item->{'Password'} = $root_password;
}
+ my $attributes = delete $item->{ Attributes };
my $new_entry = RT::User->new( RT->SystemUser );
my ( $return, $msg ) = $new_entry->Create(%$item);
unless ( $return ) {
$RT::Logger->error( $msg );
} else {
$RT::Logger->debug( $return ."." );
+ $_->{Object} = $new_entry for @{$attributes || []};
+ push @Attributes, @{$attributes || []};
}
if ( $member_of ) {
$member_of = [ $member_of ] unless ref $member_of eq 'ARRAY';
@@ -954,12 +960,15 @@ sub InsertData {
if ( @Queues ) {
$RT::Logger->debug("Creating queues...");
for my $item (@Queues) {
+ my $attributes = delete $item->{ Attributes };
my $new_entry = RT::Queue->new(RT->SystemUser);
my ( $return, $msg ) = $new_entry->Create(%$item);
unless ( $return ) {
$RT::Logger->error( $msg );
} else {
$RT::Logger->debug( $return ."." );
+ $_->{Object} = $new_entry for @{$attributes || []};
+ push @Attributes, @{$attributes || []};
}
}
$RT::Logger->debug("done.");
@@ -967,6 +976,7 @@ sub InsertData {
if ( @CustomFields ) {
$RT::Logger->debug("Creating custom fields...");
for my $item ( @CustomFields ) {
+ my $attributes = delete $item->{ Attributes };
my $new_entry = RT::CustomField->new( RT->SystemUser );
my $values = delete $item->{'Values'};
@@ -1042,6 +1052,9 @@ sub InsertData {
}
}
}
+
+ $_->{Object} = $new_entry for @{$attributes || []};
+ push @Attributes, @{$attributes || []};
}
$RT::Logger->debug("done.");
diff --git a/t/data/initialdata/initialdata b/t/data/initialdata/initialdata
index fb89479..d74504c 100644
--- a/t/data/initialdata/initialdata
+++ b/t/data/initialdata/initialdata
@@ -58,6 +58,17 @@
{
Name => 'Test Employees',
Description => 'All of the employees of my company',
+ Attributes => [
+ {
+ Name => 'SavedSearch',
+ Description => 'Stalled Tickets in Test Queue',
+ Content => {
+ Query => "Status = 'stalled' AND Queue = 'Test Queue'",
+ OrderBy => 'id',
+ Order => 'DESC'
+ },
+ },
+ ],
}
);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list