Commit 8c84e38b authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Merge branch '4.2/loadable-object-for-attribute-initialdata' into 4.2-trunk

parents 15a3df1b e7290b0e
......@@ -427,8 +427,33 @@ L<RT::Template/Create> for the fields you can use.
An array of L<RT::Attribute>s to create. You likely don't need to mess with
this. If you do, know that the key C<Object> is expected to be an
L<RT::Record> object on which to call C<AddAttribute>. If you don't provide
C<Object> or it's undefined, C<< RT->System >> will be used.
L<RT::Record> object or a subroutine reference that returns an object on which
to call C<AddAttribute>. If you don't provide C<Object> or it's undefined,
C<< RT->System >> will be used.
Here is an example of using a subroutine reference as a value for Object:
@Attributes = ({
Name => 'SavedSearch',
Description => 'New Tickets in SomeQueue',
Object => sub {
my $GroupName = 'SomeQueue Group';
my $group = RT::Group->new( RT->SystemUser );
my( $ret, $msg ) = $group->LoadUserDefinedGroup( $GroupName );
die $msg unless $ret;
return $group;
},
Content => {
Format => <<' END_OF_FORMAT',
....
END_OF_FORMAT
Query => "Status = 'new' AND Queue = 'SomeQueue'",
OrderBy => 'id',
Order => 'DESC'
},
});
=head2 C<@Initial>
......
......@@ -1208,7 +1208,12 @@ sub InsertData {
my $sys = RT::System->new(RT->SystemUser);
for my $item (@Attributes) {
my $obj = delete $item->{Object}; # XXX: make this something loadable
my $obj = delete $item->{Object};
if ( ref $obj eq 'CODE' ) {
$obj = $obj->();
}
$obj ||= $sys;
my ( $return, $msg ) = $obj->AddAttribute (%$item);
unless ( $return ) {
......
......@@ -69,3 +69,22 @@
Right => 'SeeCustomField',
},
);
@Attributes = ({
Name => 'SavedSearch',
Description => 'New Tickets in Test Queue',
Object => sub {
my $GroupName = 'Test Employees';
my $group = RT::Group->new( RT->SystemUser );
my( $ret, $msg ) = $group->LoadUserDefinedGroup( $GroupName );
die $msg unless $ret;
return $group;
},
Content => {
Query => "Status = 'new' AND Queue = 'Test Queue'",
OrderBy => 'id',
Order => 'DESC'
},
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment