[Rt-commit] r5677 - in rt/branches/3.7-EXPERIMENTAL: .
ruz at bestpractical.com
ruz at bestpractical.com
Wed Aug 2 15:42:29 EDT 2006
Author: ruz
Date: Wed Aug 2 15:42:27 2006
New Revision: 5677
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
Log:
r3570 at cubic-pc: cubic | 2006-07-31 19:37:57 +0400
* minor
Modified: rt/branches/3.7-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/RT/CustomField_Overlay.pm Wed Aug 2 15:42:27 2006
@@ -48,57 +48,55 @@
use strict;
no warnings qw(redefine);
-use vars qw(%FieldTypes $RIGHTS %FRIENDLY_OBJECT_TYPES);
-
use RT::CustomFieldValues;
use RT::ObjectCustomFieldValues;
-%FieldTypes = (
+our %FieldTypes = (
Select => [
- 'Select multiple values', # loc
- 'Select one value', # loc
- 'Select up to [_1] values', # loc
+ 'Select multiple values', # loc
+ 'Select one value', # loc
+ 'Select up to [_1] values', # loc
],
Freeform => [
- 'Enter multiple values', # loc
- 'Enter one value', # loc
- 'Enter up to [_1] values', # loc
+ 'Enter multiple values', # loc
+ 'Enter one value', # loc
+ 'Enter up to [_1] values', # loc
],
Text => [
- 'Fill in multiple text areas', # loc
- 'Fill in one text area', # loc
+ 'Fill in multiple text areas', # loc
+ 'Fill in one text area', # loc
'Fill in up to [_1] text areas',# loc
],
Wikitext => [
- 'Fill in multiple wikitext areas', # loc
- 'Fill in one wikitext area', # loc
+ 'Fill in multiple wikitext areas', # loc
+ 'Fill in one wikitext area', # loc
'Fill in up to [_1] wikitext areas',# loc
],
Image => [
- 'Upload multiple images', # loc
- 'Upload one image', # loc
- 'Upload up to [_1] images', # loc
+ 'Upload multiple images', # loc
+ 'Upload one image', # loc
+ 'Upload up to [_1] images', # loc
],
Binary => [
- 'Upload multiple files', # loc
- 'Upload one file', # loc
- 'Upload up to [_1] files', # loc
+ 'Upload multiple files', # loc
+ 'Upload one file', # loc
+ 'Upload up to [_1] files', # loc
],
Combobox => [
- 'Combobox: Select or enter multiple values', # loc
- 'Combobox: Select or enter one value', # loc
- 'Combobox: Select or enter up to [_1] values', # loc
+ 'Combobox: Select or enter multiple values', # loc
+ 'Combobox: Select or enter one value', # loc
+ 'Combobox: Select or enter up to [_1] values', # loc
],
Autocomplete => [
- 'Enter multiple values with autocompletion', # loc
- 'Enter one value with autocompletion', # loc
- 'Enter up to [_1] values with autocompletion', # loc
+ 'Enter multiple values with autocompletion', # loc
+ 'Enter one value with autocompletion', # loc
+ 'Enter up to [_1] values with autocompletion', # loc
],
);
-%FRIENDLY_OBJECT_TYPES = ();
+our %FRIENDLY_OBJECT_TYPES = ();
RT::CustomField->_ForObjectType( 'RT::Queue-RT::Ticket' => "Tickets", ); #loc
RT::CustomField->_ForObjectType(
@@ -106,7 +104,7 @@
RT::CustomField->_ForObjectType( 'RT::User' => "Users", ); #loc
RT::CustomField->_ForObjectType( 'RT::Group' => "Groups", ); #loc
-$RIGHTS = {
+our $RIGHTS = {
SeeCustomField => 'See custom fields', # loc_pair
AdminCustomField => 'Create, delete and modify custom fields', # loc_pair
ModifyCustomField => 'Add, delete and modify custom field values for objects' #loc_pair
@@ -121,7 +119,7 @@
sub AvailableRights {
my $self = shift;
- return($RIGHTS);
+ return $RIGHTS;
}
=head1 NAME
@@ -153,39 +151,38 @@
sub Create {
my $self = shift;
- my %args = (
- Name => '',
- Type => '',
- MaxValues => '0',
- Pattern => '',
- Description => '',
- Disabled => '0',
- LookupType => '',
- Repeated => '0',
- @_,
- );
+ my %args = (
+ Name => '',
+ Type => '',
+ MaxValues => 0,
+ Pattern => '',
+ Description => '',
+ Disabled => 0,
+ LookupType => '',
+ Repeated => 0,
+ @_,
+ );
- unless ($self->CurrentUser->HasRight(Object => $RT::System, Right => 'AdminCustomField')) {
+ unless ( $self->CurrentUser->HasRight(Object => $RT::System, Right => 'AdminCustomField') ) {
return (0, $self->loc('Permission Denied'));
}
-
- if ($args{TypeComposite}) {
- @args{'Type', 'MaxValues'} = split(/-/, $args{TypeComposite}, 2);
+ if ( $args{TypeComposite} ) {
+ @args{'Type', 'MaxValues'} = split(/-/, $args{TypeComposite}, 2);
}
- elsif ($args{Type} =~ s/(?:(Single)|Multiple)$//) {
- # old style Type string
- $args{'MaxValues'} = $1 ? 1 : 0;
+ elsif ( $args{Type} =~ s/(?:(Single)|Multiple)$// ) {
+ # old style Type string
+ $args{'MaxValues'} = $1 ? 1 : 0;
}
if ( !exists $args{'Queue'}) {
- # do nothing -- things below are strictly backward compat
+ # do nothing -- things below are strictly backward compat
}
elsif ( ! $args{'Queue'} ) {
unless ( $self->CurrentUser->HasRight( Object => $RT::System, Right => 'AssignCustomFields') ) {
return ( 0, $self->loc('Permission Denied') );
}
- $args{'LookupType'} = 'RT::Queue-RT::Ticket';
+ $args{'LookupType'} = 'RT::Queue-RT::Ticket';
}
else {
my $queue = RT::Queue->new($self->CurrentUser);
@@ -196,24 +193,22 @@
unless ( $queue->CurrentUserHasRight('AssignCustomFields') ) {
return ( 0, $self->loc('Permission Denied') );
}
- $args{'LookupType'} = 'RT::Queue-RT::Ticket';
+ $args{'LookupType'} = 'RT::Queue-RT::Ticket';
}
- my ($ok, $msg) = $self->_IsValidRegex($args{'Pattern'});
- if (!$ok) {
- return (0, $self->loc("Invalid pattern: [_1]", $msg));
- }
+ my ($ok, $msg) = $self->_IsValidRegex( $args{'Pattern'} );
+ return (0, $self->loc("Invalid pattern: [_1]", $msg)) unless $ok;
my $rv = $self->SUPER::Create(
- Name => $args{'Name'},
- Type => $args{'Type'},
- MaxValues => $args{'MaxValues'},
- Pattern => $args{'Pattern'},
- Description => $args{'Description'},
- Disabled => $args{'Disabled'},
- LookupType => $args{'LookupType'},
- Repeated => $args{'Repeated'},
-);
+ Name => $args{'Name'},
+ Type => $args{'Type'},
+ MaxValues => $args{'MaxValues'},
+ Pattern => $args{'Pattern'},
+ Description => $args{'Description'},
+ Disabled => $args{'Disabled'},
+ LookupType => $args{'LookupType'},
+ Repeated => $args{'Repeated'},
+ );
if ( exists $args{'ValuesClass'} ) {
$self->SetValuesClass( $args{'ValuesClass'} );
@@ -222,10 +217,10 @@
return $rv unless exists $args{'Queue'};
# Compat code -- create a new ObjectCustomField mapping
- my $OCF = RT::ObjectCustomField->new($self->CurrentUser);
+ my $OCF = RT::ObjectCustomField->new( $self->CurrentUser );
$OCF->Create(
- CustomField => $self->Id,
- ObjectId => $args{'Queue'},
+ CustomField => $self->Id,
+ ObjectId => $args{'Queue'},
);
return $rv;
@@ -241,10 +236,10 @@
my $self = shift;
my $id = shift;
- if ($id =~ /^\d+$/) {
- return ($self->SUPER::Load($id));
+ if ( $id =~ /^\d+$/ ) {
+ return $self->SUPER::Load( $id );
} else {
- return($self->LoadByName(Name => $id));
+ return $self->LoadByName( Name => $id );
}
}
@@ -300,10 +295,8 @@
# We only want one entry.
$CFs->RowsPerPage(1);
- unless ( $CFs->First ) {
- return 0;
- }
- return($self->Load($CFs->First->id));
+ return (0, $self->loc("Not found")) unless my $first = $CFs->First;
+ return $self->LoadById( $first->id );
}
# }}}
@@ -363,7 +356,7 @@
eval "require $class" or die "$@";
my $cf_values = $class->new( $self->CurrentUser );
# if the user has no rights, return an empty object
- if ($self->id && $self->CurrentUserHasRight( 'SeeCustomField') ) {
+ if ( $self->id && $self->CurrentUserHasRight( 'SeeCustomField') ) {
$cf_values->LimitToCustomField( $self->Id );
}
return ($cf_values);
@@ -397,12 +390,12 @@
return (0, $self->loc('Permission Denied'));
}
- unless (length $args{'Name'}) {
- return(0, $self->loc("Can't add a custom field value without a name"));
+ unless ( length $args{'Name'} ) {
+ return (0, $self->loc("Can't add a custom field value without a name"));
}
- my $newval = RT::CustomFieldValue->new($self->CurrentUser);
- return($newval->Create(%args, CustomField => $self->Id));
+ my $newval = RT::CustomFieldValue->new( $self->CurrentUser );
+ return $newval->Create( %args, CustomField => $self->Id );
}
@@ -412,7 +405,7 @@
=head3 DeleteValue ID
-Deletes a value from this custom field by id.
+Deletes a value from this custom field by id.
Does not remove this value for any article which has had it selected
@@ -421,13 +414,13 @@
sub DeleteValue {
my $self = shift;
my $id = shift;
- unless ($self->CurrentUserHasRight('AdminCustomField')) {
+ unless ( $self->CurrentUserHasRight('AdminCustomField') ) {
return (0, $self->loc('Permission Denied'));
}
my $val_to_del = RT::CustomFieldValue->new( $self->CurrentUser );
$val_to_del->Load( $id );
- unless ($val_to_del->Id) {
+ unless ( $val_to_del->Id ) {
return (0, $self->loc("Couldn't find that value"));
}
unless ( $val_to_del->CustomField == $self->Id ) {
@@ -436,7 +429,7 @@
my $retval = $val_to_del->Delete;
unless ( $retval ) {
- return(0, $self->loc("Custom field value could not be deleted"));
+ return (0, $self->loc("Custom field value could not be deleted"));
}
return ($retval, $self->loc("Custom field value deleted"));
}
@@ -474,7 +467,7 @@
=cut
sub Types {
- return (keys %FieldTypes);
+ return (keys %FieldTypes);
}
# }}}
@@ -581,11 +574,11 @@
my $self = shift;
my $type = shift;
- if ($type =~ s/(?:Single|Multiple)$//) {
+ if ( $type =~ s/(?:Single|Multiple)$// ) {
$RT::Logger->warning( "Prefix 'Single' and 'Multiple' to Type deprecated, use MaxValues instead at (". join(":",caller).")");
}
- if( $FieldTypes{$type}) {
+ if ( $FieldTypes{$type} ) {
return 1;
}
else {
@@ -636,8 +629,8 @@
my $regex = shift or return (1, 'valid');
local $^W; local $@;
- $SIG{__DIE__} = sub { 1 };
- $SIG{__WARN__} = sub { 1 };
+ local $SIG{__DIE__} = sub { 1 };
+ local $SIG{__WARN__} = sub { 1 };
if (eval { qr/$regex/; 1 }) {
return (1, 'valid');
@@ -708,7 +701,7 @@
unless ( $self->CurrentUserHasRight('AdminCustomField') ) {
return ( 0, $self->loc('Permission Denied') );
}
- return ( $self->SUPER::_Set(@_) );
+ return $self->SUPER::_Set( @_ );
}
@@ -726,14 +719,12 @@
sub _Value {
my $self = shift;
- my $field = shift;
# we need to do the rights check
- unless ( $self->id && $self->CurrentUserHasRight( 'SeeCustomField') ) {
+ unless ( $self->id && $self->CurrentUserHasRight('SeeCustomField') ) {
return (undef);
}
- return ( $self->__Value($field) );
-
+ return $self->__Value( @_ );
}
# }}}
@@ -742,8 +733,8 @@
=head2 SetDisabled
Takes a boolean.
-1 will cause this custom field to no longer be avaialble for tickets.
-0 will re-enable this queue
+1 will cause this custom field to no longer be avaialble for objects.
+0 will re-enable this field.
=cut
@@ -773,13 +764,13 @@
sub SetLookupType {
my $self = shift;
my $lookup = shift;
- if ($lookup ne $self->LookupType) {
+ if ( $lookup ne $self->LookupType ) {
# Okay... We need to invalidate our existing relationships
my $ObjectCustomFields = RT::ObjectCustomFields->new($self->CurrentUser);
$ObjectCustomFields->LimitToCustomField($self->Id);
$_->Delete foreach @{$ObjectCustomFields->ItemsArrayRef};
}
- $self->SUPER::SetLookupType($lookup);
+ return $self->SUPER::SetLookupType($lookup);
}
=head2 TypeComposite
@@ -818,8 +809,8 @@
}
my @FriendlyObjectTypes = (
- "[_1] objects", # loc
- "[_1]'s [_2] objects", # loc
+ "[_1] objects", # loc
+ "[_1]'s [_2] objects", # loc
"[_1]'s [_2]'s [_3] objects", # loc
);
@@ -832,7 +823,7 @@
my $lookup = shift || $self->LookupType;
return ($self->loc( $FRIENDLY_OBJECT_TYPES{$lookup} ))
- if (defined $FRIENDLY_OBJECT_TYPES{$lookup} );
+ if (defined $FRIENDLY_OBJECT_TYPES{$lookup} );
my @types = map { s/^RT::// ? $self->loc($_) : $_ }
grep { defined and length }
@@ -857,7 +848,7 @@
my $id = $object->Id || 0;
unless (index($self->LookupType, ref($object)) == 0) {
- return ( 0, $self->loc('Lookup type mismatch') );
+ return ( 0, $self->loc('Lookup type mismatch') );
}
unless ( $object->CurrentUserHasRight('AssignCustomFields') ) {
@@ -964,14 +955,13 @@
unless ( $extra_item->id ) {
$RT::Logger->crit(
-"We were just asked to delete a custom fieldvalue that doesn't exist!"
+"We were just asked to delete a custom field value that doesn't exist!"
);
$RT::Handle->Rollback();
return (undef);
}
$extra_item->Delete;
$extra_values--;
-
}
}
my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
@@ -1009,7 +999,7 @@
my $self = shift;
my $regex = $self->Pattern;
- return 1 if !length($regex);
+ return 1 unless length $regex;
return ($_[0] =~ $regex);
}
@@ -1029,8 +1019,8 @@
my $self = shift;
my $regex = $self->Pattern;
- return '' if !length($regex);
- if ($regex =~ /\(\?#([^)]*)\)/) {
+ return '' unless length $regex;
+ if ( $regex =~ /\(\?#([^)]*)\)/ ) {
return '[' . $self->loc($1) . ']';
}
else {
@@ -1056,7 +1046,7 @@
my %args = ( Object => undef,
Content => undef,
Id => undef,
- @_ );
+ @_ );
unless ($self->CurrentUserHasRight('ModifyCustomField')) {
@@ -1104,21 +1094,21 @@
=cut
sub ValuesForObject {
- my $self = shift;
+ my $self = shift;
my $object = shift;
- my $values = new RT::ObjectCustomFieldValues($self->CurrentUser);
- unless ($self->CurrentUserHasRight('SeeCustomField')) {
+ my $values = new RT::ObjectCustomFieldValues($self->CurrentUser);
+ unless ($self->CurrentUserHasRight('SeeCustomField')) {
# Return an empty object if they have no rights to see
return ($values);
}
-
-
- $values->LimitToCustomField($self->Id);
- $values->LimitToEnabled();
+
+
+ $values->LimitToCustomField($self->Id);
+ $values->LimitToEnabled();
$values->LimitToObject($object);
- return ($values);
+ return ($values);
}
@@ -1128,10 +1118,10 @@
Examples:
- 'RT::Queue-RT::Ticket' => "Tickets", # loc
- 'RT::Queue-RT::Ticket-RT::Transaction' => "Ticket Transactions", # loc
- 'RT::User' => "Users", # loc
- 'RT::Group' => "Groups", # loc
+ 'RT::Queue-RT::Ticket' => "Tickets", # loc
+ 'RT::Queue-RT::Ticket-RT::Transaction' => "Ticket Transactions", # loc
+ 'RT::User' => "Users", # loc
+ 'RT::Group' => "Groups", # loc
This is a class method.
@@ -1219,4 +1209,5 @@
}
}
+
1;
More information about the Rt-commit
mailing list