[Rt-commit] rt branch, 4.2/genericize-initialdata, created. rt-4.1.8-508-gea56d4f
Alex Vandiver
alexmv at bestpractical.com
Tue May 28 19:27:15 EDT 2013
The branch, 4.2/genericize-initialdata has been created
at ea56d4f81aa1a460ed2a9089461b1db73984cbd2 (commit)
- Log -----------------------------------------------------------------
commit 4166e796718197801ef3545c55309c00a59bd305
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..3c0f6e2 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -889,13 +889,14 @@ 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'} };
+ $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 +922,34 @@ 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 ( !$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 d9907dc542d6e12188ad8ac03d3fc7d7d02bf3fa
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 f2c34d395a340b0cadd48b358f5344379bc04f9a
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 3c0f6e2..2022c9e 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -970,6 +970,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 ea56d4f81aa1a460ed2a9089461b1db73984cbd2
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 2022c9e..108dd34 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -966,19 +966,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