[Rt-commit] [svn] r1914 - in rt/branches/3.3-TESTING: . lib/RT
jesse at pallas.eruditorum.org
jesse at pallas.eruditorum.org
Thu Nov 18 10:59:11 EST 2004
Author: jesse
Date: Thu Nov 18 10:59:05 2004
New Revision: 1914
Modified:
rt/branches/3.3-TESTING/ (props changed)
rt/branches/3.3-TESTING/UPGRADING
rt/branches/3.3-TESTING/lib/RT/ACE_Overlay.pm
rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm
rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValues_Overlay.pm
rt/branches/3.3-TESTING/lib/RT/Principal_Overlay.pm
rt/branches/3.3-TESTING/lib/RT/Ticket_Overlay.pm
Log:
r9280 at tinbook: jesse | 2004-11-17T18:34:51.857756Z
A bunch of CustomField related improvements. Autrijus is working on the new test suite. Coming "tomorrow"
UPGRADING FROM 3.3.11 and earlier - Changes:
= Rights Changes =
Custom Fields now have an additional right "ModifyObjectCustomFieldValues".
This right governs whether a user can modify an object's custom field values
for a particular custom field. This includes adding, deleting and changing values.
Modified: rt/branches/3.3-TESTING/UPGRADING
==============================================================================
--- rt/branches/3.3-TESTING/UPGRADING (original)
+++ rt/branches/3.3-TESTING/UPGRADING Thu Nov 18 10:59:05 2004
@@ -16,6 +16,16 @@
*******
+
+UPGRADING FROM 3.3.11 and earlier - Changes:
+
+= Rights Changes =
+
+Custom Fields now have an additional right "ModifyObjectCustomFieldValues".
+This right governs whether a user can modify an object's custom field values
+for a particular custom field. This includes adding, deleting and changing values.
+
+
UPGRADING FROM 3.2 and earlier - Changes:
= Rights changes =
Modified: rt/branches/3.3-TESTING/lib/RT/ACE_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/ACE_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/ACE_Overlay.pm Thu Nov 18 10:59:05 2004
@@ -211,6 +211,12 @@
ObjectType => the type of the object in question (ref ($object))
ObjectId => the id of the object in question $object->Id
+
+
+ Returns a tuple of (STATUS, MESSAGE); If the call succeeded, STATUS is true. Otherwise it's false.
+
+
+
=cut
sub Create {
Modified: rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/CustomField_Overlay.pm Thu Nov 18 10:59:05 2004
@@ -77,6 +77,8 @@
$RIGHTS = {
SeeCustomField => 'See custom fields', # loc_pair
AdminCustomField => 'Create, delete and modify custom fields', # loc_pair
+ ModifyObjectCustomFieldValues => 'Add, delete and modify custom field values for objects' #loc_pair
+
};
# Tell RT::ACE that this sort of object can get acls granted
@@ -134,6 +136,11 @@
@_);
+ 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);
}
@@ -357,6 +364,7 @@
my $self = shift;
my $cf_values = RT::CustomFieldValues->new($self->CurrentUser);
+ # if the user has no rights, return an empty object
if ($self->id && $self->CurrentUserHasRight( 'SeeCustomField') ) {
$cf_values->LimitToCustomField($self->Id);
}
@@ -382,12 +390,12 @@
sub ValuesForTicket {
my $self = shift;
my $ticket_id = shift;
+
+ $RT::Logger->debug( ref($self) . " -> ValuesForTicket deprecated in favor of ValuesForObject");
+ my $ticket = RT::Ticket->new($self->CurrentUser);
+ $ticket->Load($ticket_id);
- my $values = new RT::ObjectCustomFieldValues($self->CurrentUser);
- $values->LimitToCustomField($self->Id);
- $values->LimitToTicket($ticket_id);
-
- return ($values);
+ return $self->ValuesForObject($ticket);
}
# }}}
@@ -405,14 +413,12 @@
my %args = ( Ticket => undef,
Content => undef,
@_ );
+ $RT::Logger->debug( ref($self) . " -> AddValueForTicket deprecated in favor of ValuesForObject");
- my $newval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
- my $val = $newval->Create(ObjectType => 'RT::Ticket',
- ObjectId => $args{'Ticket'},
- Content => $args{'Content'},
- CustomField => $self->Id);
- return($val);
+ my $ticket = RT::Ticket->new($self->CurrentUser);
+ $ticket->Load($args{'Ticket'});
+ return($self->AddValueForObjecT(Content => $args{'Content'}, Object => $ticket));
}
@@ -433,23 +439,14 @@
Content => undef,
@_ );
- my $oldval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
- $oldval->LoadByTicketContentAndCustomField (Ticket => $args{'Ticket'},
- Content => $args{'Content'},
- CustomField => $self->Id );
- # check ot make sure we found it
- unless ($oldval->Id) {
- return(0, $self->loc("Custom field value [_1] could not be found for custom field [_2]", $args{'Content'}, $self->Name));
- }
- # delete it
+ $RT::Logger->debug( ref($self) . " -> DeleteValueForTicket deprecated in favor of ValuesForObject");
- my $ret = $oldval->Delete();
- unless ($ret) {
- return(0, $self->loc("Custom field value could not be found"));
- }
- return(1, $self->loc("Custom field value deleted"));
-}
+ my $ticket = RT::Ticket->new($self->CurrentUser);
+ $ticket->load($args{'Ticket'});
+ return ($self->DeleteValueForObject(Object => $ticket, Content => $args{'Content'}));
+
+}
# }}}
# }}}
@@ -572,7 +569,7 @@
my $type = shift;
if ($type =~ s/(?:Single|Multiple)$//) {
- warn "Prefix 'Single' and 'Multiple' to Type deprecated, use MaxValues instead";
+ $RT::Logger->warning( "Prefix 'Single' and 'Multiple' to Type deprecated, use MaxValues instead");
}
if( $TYPES{$type}) {
@@ -695,17 +692,30 @@
# }}}
sub Queue {
+ $RT::Logger->debug( ref($_[0]) . " -> Queue deprecated");
+
return 0;
}
sub SetQueue {
+ $RT::Logger->debug( ref($_[0]) . " -> SetQueue deprecated");
+
return 0;
}
sub QueueObj {
+ $RT::Logger->debug( ref($_[0]) . " -> QueueObj deprecated");
+
return undef;
}
+=head2 SetTypeComposite
+
+Set this custom field's type and maximum values as a composite value
+
+
+=cut
+
sub SetTypeComposite {
my $self = shift;
my $composite = shift;
@@ -714,6 +724,12 @@
$self->SetMaxValues($max_values);
}
+=head2 SetLookupType
+
+Autrijus: care to doc how LookupTypes work?
+
+=cut
+
sub SetLookupType {
my $self = shift;
my $lookup = shift;
@@ -725,25 +741,39 @@
}
$self->SUPER::SetLookupType($lookup);
}
+=head2 TypeComposite
+
+Returns a composite value composed of this object's type and maximum values
+
+=cut
+
sub TypeComposite {
my $self = shift;
join('-', $self->Type, $self->MaxValues);
}
+=head2 TypeComposites
+
+Returns an array of all possible composite values for custom fields.
+
+=cut
+
sub TypeComposites {
my $self = shift;
return grep !/Text-0/, map { ("$_-1", "$_-0") } $self->Types;
}
+=head2 LookupTypes
+
+Returns an array of LookupTypes available
+
+=cut
+
+
sub LookupTypes {
my $self = shift;
- qw(
- RT::Queue-RT::Ticket
- RT::Queue-RT::Ticket-RT::Transaction
- RT::User
- RT::Group
- );
+ return keys %FRIENDLY_OBJECT_TYPES;
}
my @FriendlyObjectTypes = (
@@ -752,6 +782,10 @@
"[_1]'s [_2]'s [_3] objects", # loc
);
+=head2 FriendlyTypeLookup
+
+=cut
+
sub FriendlyLookupType {
my $self = shift;
my $lookup = shift || $self->LookupType;
@@ -766,13 +800,23 @@
return ( $self->loc( $FriendlyObjectTypes[$#types], @types ) );
}
+
+=head2 AddToObject OBJECT
+
+Add this custom field as a custom field for a single object, such as a queue or group.
+
+Takes an object
+
+=cut
+
+
sub AddToObject {
my $self = shift;
my $object = shift;
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') ) {
@@ -791,6 +835,16 @@
return ( $id, $msg );
}
+
+=head2 RemoveFromObject OBJECT
+
+Remove this custom field for a single object, such as a queue or group.
+
+Takes an object
+
+=cut
+
+
sub RemoveFromObject {
my $self = shift;
my $object = shift;
@@ -832,6 +886,13 @@
@_ );
my $obj = $args{'Object'} or return;
+
+ unless ($self->CurrentUserHasRight('ModifyObjectCustomFieldValues')) {
+ return (0, $self->loc('Permission Denied'));
+ }
+
+
+
my $newval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
my $val = $newval->Create(ObjectType => ref($obj),
ObjectId => $obj->Id,
@@ -851,7 +912,9 @@
=head2 DeleteValueForObject HASH
-Adds a custom field value for a ticket. Takes a param hash of Object and Content
+Deletes a custom field value for a ticket. Takes a param hash of Object and Content
+
+Returns a tuple of (STATUS, MESSAGE). If the call succeeded, the STATUS is true. otherwise it's false
=cut
@@ -862,6 +925,10 @@
Id => undef,
@_ );
+ unless ($self->CurrentUserHasRight('ModifyObjectCustomFieldValues')) {
+ return (0, $self->loc('Permission Denied'));
+ }
+
my $oldval = RT::ObjectCustomFieldValue->new($self->CurrentUser);
if (my $id = $args{'Id'}) {
@@ -888,11 +955,24 @@
return($oldval->Id, $self->loc("Custom field value deleted"));
}
+
+=head2 ValuesForObject OBJECT
+
+Return an RT::ObjectCustomFieldValues object containing all of this custom field's values for OBJECT
+
+=cut
+
sub ValuesForObject {
my $self = shift;
my $object = shift;
my $values = new RT::ObjectCustomFieldValues($self->CurrentUser);
+ unless ($self->CurrentUserHasRight('ShowCustomField')) {
+ # Return an empty object if they have no rights to see
+ return ($values);
+ }
+
+
$values->LimitToCustomField($self->Id);
$values->LimitToObject($object);
Modified: rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValues_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValues_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/ObjectCustomFieldValues_Overlay.pm Thu Nov 18 10:59:05 2004
@@ -79,6 +79,10 @@
sub LimitToTicket {
my $self = shift;
my $ticket = shift;
+
+
+ $RT::Logger->warning(ref($self) . " -> LimitToTicket deprecated in favor of LimitToObject");
+
$self->Limit( FIELD => 'ObjectType',
VALUE => 'RT::Ticket',
OPERATOR => '=');
Modified: rt/branches/3.3-TESTING/lib/RT/Principal_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/Principal_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/Principal_Overlay.pm Thu Nov 18 10:59:05 2004
@@ -143,6 +143,11 @@
A helper function which calls RT::ACE->Create
+
+
+ Returns a tuple of (STATUS, MESSAGE); If the call succeeded, STATUS is true. Otherwise it's
+ false.
+
=cut
sub GrantRight {
@@ -184,6 +189,11 @@
Delete a right that a user has
+
+ Returns a tuple of (STATUS, MESSAGE); If the call succeeded, STATUS is true. Otherwise it's
+ false.
+
+
=cut
sub RevokeRight {
Modified: rt/branches/3.3-TESTING/lib/RT/Ticket_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/Ticket_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/Ticket_Overlay.pm Thu Nov 18 10:59:05 2004
@@ -66,12 +66,16 @@
ok($testqueue->Id != 0);
use_ok(RT::CustomField);
ok(my $testcf = RT::CustomField->new($RT::SystemUser));
-ok($testcf->Create( Name => 'selectmulti',
+my ($ret, $cmsg) = $testcf->Create( Name => 'selectmulti',
Queue => $testqueue->id,
- Type => 'SelectMultiple'));
-ok($testcf->AddValue ( Name => 'Value1',
+ Type => 'SelectMultiple');
+ok($ret,"Created the custom field - ".$cmsg);
+($ret,$cmsg) = $testcf->AddValue ( Name => 'Value1',
SortOrder => '1',
- Description => 'A testing value'));
+ Description => 'A testing value');
+
+ok($ret, "Added a value - ".$cmsg);
+
ok($testcf->AddValue ( Name => 'Value2',
SortOrder => '2',
Description => 'Another testing value'));
More information about the Rt-commit
mailing list