[Rt-commit] rt branch, 4.2/genericize-initialdata, created. rt-4.1.8-508-g7f005ad
Alex Vandiver
alexmv at bestpractical.com
Fri May 31 23:08:46 EDT 2013
The branch, 4.2/genericize-initialdata has been created
at 7f005ad7e791825b54d2603cb4cfce78c17c41e4 (commit)
- Log -----------------------------------------------------------------
commit fdca1f95de8fde07bc52ca729efa0999f4429e05
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue May 28 18:44:23 2013 -0400
Allow CFs to be applied to one or more objects, for non-Queue CFs
diff --git a/docs/initialdata.pod b/docs/initialdata.pod
index 3f271e9..1f8641b 100644
--- a/docs/initialdata.pod
+++ b/docs/initialdata.pod
@@ -144,7 +144,6 @@ L<RT::Queue/Create> for the fields you can use.
=head2 C<@CustomFields>
push @CustomFields, {
- Queue => 0,
Name => 'Favorite color',
Type => 'FreeformSingle',
LookupType => 'RT::Queue-RT::Ticket',
@@ -163,10 +162,15 @@ The name of this CF as displayed in RT.
A short summary of what this CF is for.
-=item C<Queue>
+=item C<ApplyTo>
-May be a Name or ID. The single queue or array ref of queues to apply this CF
-to. This does not apply when C<LookupType> does not start with C<RT::Queue>.
+May be a single value, or an array reference of such; each should be
+either an ID or Name. If omitted, the CF is applied globally. This
+should not be used for User or Group custom fields.
+
+This argument may also be passed via C<Queue>, for backwards
+compatibility, which also defaults the C<LookupType> to
+C<RT::Queue-RT::Ticket>.
=item C<Type>
@@ -246,7 +250,6 @@ field. This only makes sense for "Select" CFs. An example:
my $i = 1;
push @CustomFields, {
- Queue => 0, # Globally applied
LookupType => 'RT::Queue-RT::Ticket', # for Tickets
Name => 'Type of food',
Type => 'SelectSingle', # SelectSingle is the same as: Type => 'Select', MaxValues => 1
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index aceb23a..ca840f7 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -889,13 +889,16 @@ sub InsertData {
my $new_entry = RT::CustomField->new( RT->SystemUser );
my $values = delete $item->{'Values'};
- my @queues;
- # if ref then it's list of queues, so we do things ourself
- if ( exists $item->{'Queue'} && ref $item->{'Queue'} ) {
+ # Back-compat for the old "Queue" argument
+ if ( exists $item->{'Queue'} ) {
$item->{'LookupType'} ||= 'RT::Queue-RT::Ticket';
- @queues = @{ delete $item->{'Queue'} };
+ $RT::Logger->warn("Queue provided for non-ticket custom field")
+ unless $item->{'LookupType'} =~ /^RT::Queue-/;
+ $item->{'ApplyTo'} = delete $item->{'Queue'};
}
+ my $apply_to = delete $item->{'ApplyTo'};
+
if ( $item->{'BasedOn'} ) {
if ( $item->{'LookupType'} ) {
my $basedon = RT::CustomField->new($RT::SystemUser);
@@ -921,29 +924,38 @@ sub InsertData {
}
foreach my $value ( @{$values} ) {
- my ( $return, $msg ) = $new_entry->AddValue(%$value);
+ ( $return, $msg ) = $new_entry->AddValue(%$value);
$RT::Logger->error( $msg ) unless $return;
}
- # apply by default
- if ( !@queues && !exists $item->{'Queue'} && $item->{LookupType} ) {
- my $ocf = RT::ObjectCustomField->new(RT->SystemUser);
- $ocf->Create( CustomField => $new_entry->Id );
- }
-
- for my $q (@queues) {
- my $q_obj = RT::Queue->new(RT->SystemUser);
- $q_obj->Load($q);
- unless ( $q_obj->Id ) {
- $RT::Logger->error("Could not find queue ". $q );
- next;
+ my $class = $new_entry->RecordClassFromLookupType;
+ if ($class) {
+ if ($new_entry->IsOnlyGlobal and $apply_to) {
+ $RT::Logger->warn("ApplyTo provided for global custom field ".$new_entry->Name );
+ undef $apply_to;
+ }
+ if ( !$apply_to ) {
+ # Apply to all by default
+ my $ocf = RT::ObjectCustomField->new(RT->SystemUser);
+ ( $return, $msg) = $ocf->Create( CustomField => $new_entry->Id );
+ $RT::Logger->error( $msg ) unless $return and $ocf->Id;
+ } else {
+ $apply_to = [ $apply_to ] unless ref $apply_to;
+ for my $name ( @{ $apply_to } ) {
+ my $obj = $class->new(RT->SystemUser);
+ $obj->Load($name);
+ if ( $obj->Id ) {
+ my $ocf = RT::ObjectCustomField->new(RT->SystemUser);
+ ( $return, $msg ) = $ocf->Create(
+ CustomField => $new_entry->Id,
+ ObjectId => $obj->Id,
+ );
+ $RT::Logger->error( $msg ) unless $return and $ocf->Id;
+ } else {
+ $RT::Logger->error("Could not find $class $name to apply ".$new_entry->Name." to" );
+ }
+ }
}
- my $OCF = RT::ObjectCustomField->new(RT->SystemUser);
- ( $return, $msg ) = $OCF->Create(
- CustomField => $new_entry->Id,
- ObjectId => $q_obj->Id,
- );
- $RT::Logger->error( $msg ) unless $return and $OCF->Id;
}
}
commit 5876e4688cca2a83a6be72bc32b2f79b16af58ba
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue May 28 18:45:08 2013 -0400
Mention that Article CFs can be made via initialdata
diff --git a/docs/initialdata.pod b/docs/initialdata.pod
index 1f8641b..168ef58 100644
--- a/docs/initialdata.pod
+++ b/docs/initialdata.pod
@@ -218,6 +218,7 @@ is for Tickets, Transactions, Users, Groups, or Queues. Possible values:
RT::User # Users
RT::Group # Groups
RT::Queue # Queues
+ RT::Class-RT::Article # Articles
Ticket CFs are the most common, meaning C<RT::Queue-RT::Ticket> is the most
common C<LookupType>.
commit e0e19ea8c111f07af59a0b2b4924f61e932e9e14
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue May 28 19:26:13 2013 -0400
Allow applying rights to arbitrary classes, like Classes
diff --git a/docs/initialdata.pod b/docs/initialdata.pod
index 168ef58..ef5fb20 100644
--- a/docs/initialdata.pod
+++ b/docs/initialdata.pod
@@ -314,6 +314,11 @@ granted. This is B<different> than the user/group/role receiving the right.
CF => 'Name',
Queue => 'Name',
+=item Granted on some other object (article Classes, etc)
+
+ ObjectType => 'RT::Class',
+ ObjectId => 'Name',
+
=item Granted globally
Specifying none of the above will get you a global right.
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index ca840f7..aab455a 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -976,6 +976,9 @@ sub InsertData {
} elsif ( $item->{'Queue'} ) {
$object = RT::Queue->new(RT->SystemUser);
$object->Load( $item->{'Queue'} );
+ } elsif ( $item->{ObjectType} and $item->{ObjectId}) {
+ $object = $item->{ObjectType}->new(RT->SystemUser);
+ $object->Load( $item->{ObjectId} );
} else {
$object = $RT::System;
}
commit 7f005ad7e791825b54d2603cb4cfce78c17c41e4
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue May 28 19:26:41 2013 -0400
Provide more specific error messages on @ACL target objects
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index aab455a..33ec3f7 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -972,19 +972,29 @@ sub InsertData {
$object = RT::CustomField->new( RT->SystemUser );
my @columns = ( Name => $item->{'CF'} );
push @columns, Queue => $item->{'Queue'} if $item->{'Queue'} and not ref $item->{'Queue'};
- $object->LoadByName( @columns );
+ my ($ok, $msg) = $object->LoadByName( @columns );
+ unless ( $ok ) {
+ RT->Logger->error("Unable to load CF ".$item->{CF}.": $msg");
+ next;
+ }
} elsif ( $item->{'Queue'} ) {
$object = RT::Queue->new(RT->SystemUser);
- $object->Load( $item->{'Queue'} );
+ my ($ok, $msg) = $object->Load( $item->{'Queue'} );
+ unless ( $ok ) {
+ RT->Logger->error("Unable to load queue ".$item->{Queue}.": $msg");
+ next;
+ }
} elsif ( $item->{ObjectType} and $item->{ObjectId}) {
$object = $item->{ObjectType}->new(RT->SystemUser);
- $object->Load( $item->{ObjectId} );
+ my ($ok, $msg) = $object->Load( $item->{ObjectId} );
+ unless ( $ok ) {
+ RT->Logger->error("Unable to load ".$item->{ObjectType}." ".$item->{ObjectId}.": $msg");
+ next;
+ }
} else {
$object = $RT::System;
}
- $RT::Logger->error("Couldn't load object") and next unless $object and $object->Id;
-
# Group rights or user rights?
if ( $item->{'GroupDomain'} ) {
$princ = RT::Group->new(RT->SystemUser);
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list