[rt-commit] [svn] r513 - in rt/branches: . autrijus-3.1/etc autrijus-3.1/html/Admin/Elements autrijus-3.1/html/Admin/Users autrijus-3.1/lib/RT autrijus-3.1/lib/RT/Interface autrijus-3.1/spec

autrijus at fsck.com autrijus at fsck.com
Tue Mar 9 12:35:29 EST 2004


Author: autrijus
Date: Tue Mar  9 12:35:19 2004
New Revision: 513

Modified:
   rt/branches/   (props changed)
   rt/branches/autrijus-3.1/etc/RT_SiteConfig.pm
   rt/branches/autrijus-3.1/html/Admin/Elements/EditCustomFields
   rt/branches/autrijus-3.1/html/Admin/Users/Modify.html
   rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm
   rt/branches/autrijus-3.1/lib/RT/Group_Overlay.pm
   rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm
   rt/branches/autrijus-3.1/lib/RT/Queue_Overlay.pm
   rt/branches/autrijus-3.1/lib/RT/Record.pm
   rt/branches/autrijus-3.1/lib/RT/System.pm
   rt/branches/autrijus-3.1/lib/RT/Transaction_Overlay.pm
   rt/branches/autrijus-3.1/lib/RT/User_Overlay.pm
   rt/branches/autrijus-3.1/spec/spec.txt
Log:
* add language to admin/user/modify screen
* add CF rights to global rights
* finished CF's ACL.
* referentialising Txns completed!
* all User/Group/Ticket's _Set and CF changes makes Txn properly.


Modified: rt/branches/autrijus-3.1/etc/RT_SiteConfig.pm
==============================================================================
--- rt/branches/autrijus-3.1/etc/RT_SiteConfig.pm	(original)
+++ rt/branches/autrijus-3.1/etc/RT_SiteConfig.pm	Tue Mar  9 12:35:19 2004
@@ -1,5 +1 @@
-Set($WebBaseURL , "");
-Set($DatabaseUser , 'root');
-Set($DatabasePassword , '');
-Set($DatabaseName , 'rt31');
 1;

Modified: rt/branches/autrijus-3.1/html/Admin/Elements/EditCustomFields
==============================================================================
--- rt/branches/autrijus-3.1/html/Admin/Elements/EditCustomFields	(original)
+++ rt/branches/autrijus-3.1/html/Admin/Elements/EditCustomFields	Tue Mar  9 12:35:19 2004
@@ -44,10 +44,10 @@
 <h3><&|/l&>Global Custom Fields</&></h3>
 <& PickCustomFields, CustomFields => \@GlobalCFs, ReadOnly => 1, id => $id &>
 % }
-<h3><&|/l&>Associated Custom Fields (uncheck to unassociate)</&></h3>
+<h3><&|/l&>Assigned Custom Fields (uncheck to remove)</&></h3>
 <& PickCustomFields, CustomFields => [$ObjectCFs->CustomFields], id => $id, Checked => 1 &>
-<h3><&|/l&>Unassociated Custom Fields (check to associate)</&></h3>
-<& PickCustomFields, CustomFields => \@UnassociatedCFs, id => $id &>
+<h3><&|/l&>Unassigned Custom Fields (check to assign)</&></h3>
+<& PickCustomFields, CustomFields => \@UnassignedCFs, id => $id &>
 
 <& /Elements/Submit &>
 </FORM>
@@ -57,9 +57,14 @@
 my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
 my $caption;
 my @results;
-my (@GlobalCFs, @UnassociatedCFs);
+my (@GlobalCFs, @UnassignedCFs);
 
-# XXX - exception: by "RT::Queue" fields on UI we really mean "RT::Ticket" fields.
+if (!$Object->CurrentUserHasRight('AssignCustomFields')) {
+    $m->print('<P><i>', loc('(No custom fields)'), '</i></P>');
+    return;
+}
+
+# by "RT::Queue" fields on UI we really mean "RT::Ticket" fields.
 my $lookup = $ObjectType;
 $lookup = 'RT::Queue-RT::Ticket' if $lookup eq 'RT::Queue';
 $CustomFields->LimitToLookupType($lookup);
@@ -141,19 +146,20 @@
 	    if (!$ObjectCFs->HasEntryForCustomField($cf_id)) {
 		my ($val, $msg) = $cf->AddToObject($Object);
 		push (@results, $msg);
+		push @UnassignedCFs, $cf if !$val;
 	    }
-	    # my ($val, $msg) = $cf->SetSortOrderForObject(Object => $Object, SortOrder => $ARGS{"Object-$id-CF-$cf_id-SortOrder"});
 	}
 	else {
-	    push @UnassociatedCFs, $cf;
+	    push @UnassignedCFs, $cf;
 	    if ($ObjectCFs->HasEntryForCustomField($cf_id)) {
 		my ($val, $msg) = $cf->RemoveFromObject($Object);
 		push (@results, $msg);
+		pop @UnassignedCFs if !$val;
 	    }
 	}
     }
     elsif (!$ObjectCFs->HasEntryForCustomField($cf_id)) {
-	push @UnassociatedCFs, $cf;
+	push @UnassignedCFs, $cf;
     }
 }
 

Modified: rt/branches/autrijus-3.1/html/Admin/Users/Modify.html
==============================================================================
--- rt/branches/autrijus-3.1/html/Admin/Users/Modify.html	(original)
+++ rt/branches/autrijus-3.1/html/Admin/Users/Modify.html	Tue Mar  9 12:35:19 2004
@@ -69,6 +69,11 @@
 <input name="Gecos" value="<%$UserObj->Gecos%>">
 </TD></TR>
 <TR><TD ALIGN="RIGHT">
+<&|/l&>Language</&>: 
+</TD><TD>
+<& /Elements/SelectLang, Name => 'Lang', Default => $UserObj->Lang &>
+</TD></TR>
+<TR><TD ALIGN="RIGHT">
 <&|/l&>Extra info</&>: 
 </TD><TD>
 <textarea name="FreeformContactInfo" cols=20 rows=5><%$UserObj->FreeformContactInfo%></TEXTAREA>

Modified: rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/CustomField_Overlay.pm	Tue Mar  9 12:35:19 2004
@@ -109,7 +109,7 @@
 	# do nothing -- things below are strictly backward compat
     }
     elsif (  ! $args{'Queue'} ) {
-        unless ( $self->CurrentUser->HasRight( Object => $RT::System, Right => 'AdminCustomFields') ) {
+        unless ( $self->CurrentUser->HasRight( Object => $RT::System, Right => 'AssignCustomFields') ) {
             return ( 0, $self->loc('Permission Denied') );
         }
 	$args{'LookupType'} = 'RT::Queue-RT::Ticket';
@@ -120,7 +120,7 @@
         unless ($queue->Id) {
             return (0, $self->loc("Queue not found"));
         }
-        unless ( $queue->CurrentUserHasRight('AdminCustomFields') ) {
+        unless ( $queue->CurrentUserHasRight('AssignCustomFields') ) {
             return ( 0, $self->loc('Permission Denied') );
         }
 	$args{'LookupType'} = 'RT::Queue-RT::Ticket';
@@ -248,7 +248,7 @@
 		     SortOrder => undef,
 		     @_ );
 
-    unless ($self->CurrentUserHasRight('AdminCustomFields')) {
+    unless ($self->CurrentUserHasRight('AdminCustomField')) {
         return (0, $self->loc('Permission Denied'));
     }
 
@@ -280,7 +280,7 @@
 sub DeleteValue {
 	my $self = shift;
     my $id = shift;
-    unless ($self->CurrentUserHasRight('AdminCustomFields')) {
+    unless ($self->CurrentUserHasRight('AdminCustomField')) {
         return (0, $self->loc('Permission Denied'));
     }
 
@@ -583,14 +583,13 @@
 =cut
 
 sub CurrentUserHasRight {
-    my $self = shift;
+    my $self  = shift;
     my $right = shift;
-    # if there's no queue, we want to know about a global right
-    if ( ( !defined $self->__Value('Queue') ) || ( $self->__Value('Queue') == 0 ) ) {
-         return $self->CurrentUser->HasRight( Object => $RT::System, Right => $right); 
-    } else {
-        return ( $self->QueueObj->CurrentUserHasRight($right) );
-    }
+
+    return $self->CurrentUser->HasRight(
+	Object => $self,
+	Right  => $right,
+    );
 }
 
 # }}}
@@ -600,7 +599,7 @@
 sub _Set {
     my $self = shift;
 
-    unless ( $self->CurrentUserHasRight('AdminCustomFields') ) {
+    unless ( $self->CurrentUserHasRight('AdminCustomField') ) {
         return ( 0, $self->loc('Permission Denied') );
     }
     return ( $self->SUPER::_Set(@_) );
@@ -721,7 +720,7 @@
 	return ( 0, $self->loc('Lookup type mismatch') );
     }
 
-    unless ( $object->CurrentUserHasRight('AdminCustomFields') ) {
+    unless ( $object->CurrentUserHasRight('AssignCustomFields') ) {
         return ( 0, $self->loc('Permission Denied') );
     }
 
@@ -746,7 +745,7 @@
 	return ( 0, $self->loc('Object type mismatch') );
     }
 
-    unless ( $object->CurrentUserHasRight('AdminCustomFields') ) {
+    unless ( $object->CurrentUserHasRight('AssignCustomFields') ) {
         return ( 0, $self->loc('Permission Denied') );
     }
 
@@ -831,7 +830,7 @@
     unless ($ret) {
         return(0, $self->loc("Custom field value could not be found"));
     }
-    return(1, $self->loc("Custom field value deleted"));
+    return($oldval->Id, $self->loc("Custom field value deleted"));
 }
 
 sub ValuesForObject {

Modified: rt/branches/autrijus-3.1/lib/RT/Group_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Group_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Group_Overlay.pm	Tue Mar  9 12:35:19 2004
@@ -446,6 +446,7 @@
         Type        => undef,
         Instance    => '0',
         InsideTransaction => undef,
+        _RecordTransaction => 1,
         @_
     );
 
@@ -491,8 +492,12 @@
     $cgm->Create(Group =>$self->PrincipalObj, Member => $self->PrincipalObj, ImmediateParent => $self->PrincipalObj);
 
 
+    if ( $args{'_RecordTransaction'} ) {
+	$self->_NewTransaction( Type => "Create" );
+    }
 
     $RT::Handle->Commit() unless ($args{'InsideTransaction'});
+
     return ( $id, $self->loc("Group created") );
 }
 
@@ -1180,7 +1185,14 @@
     	}
 	}
 
-    my ($ret, $msg) = ( $self->SUPER::_Set(@_) );
+    my $Old = $self->SUPER::_Value("$args{'Field'}");
+    
+    my ($ret, $msg) = $self->SUPER::_Set( Field => $args{'Field'},
+					  Value => $args{'Value'} );
+    
+    #If we can't actually set the field to the value, don't record
+    # a transaction. instead, get out of here.
+    if ( $ret == 0 ) { return ( 0, $msg ); }
 
     if ( $args{'RecordTransaction'} == 1 ) {
 
@@ -1188,7 +1200,8 @@
                                                Type => $args{'TransactionType'},
                                                Field     => $args{'Field'},
                                                NewValue  => $args{'Value'},
-                                               OldValue  => $self->SUPER::_Value("$args{'Field'}"),
+                                               OldValue  => $Old,
+                                               TimeTaken => $args{'TimeTaken'},
         );
         return ( $Trans, scalar $TransObj->Description );
     }

Modified: rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Interface/Web.pm	Tue Mar  9 12:35:19 2004
@@ -1178,6 +1178,7 @@
 			    LargeContent => do { local $/; scalar <$fh> },
 			    ContentType => $upload_info->{'Content-Type'},
 			);
+			push ( @results, $msg );
 		    }
 		    elsif ( $arg =~ /-DeleteValues$/ ) {
 			foreach my $value (@values) {

Modified: rt/branches/autrijus-3.1/lib/RT/Queue_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Queue_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Queue_Overlay.pm	Tue Mar  9 12:35:19 2004
@@ -68,7 +68,7 @@
     ShowACL             => 'Display Access Control List',             # loc_pair
     ModifyACL           => 'Modify Access Control List',              # loc_pair
     ModifyQueueWatchers => 'Modify the queue watchers',               # loc_pair
-    AdminCustomFields   => 'Assign and remove custom fields',         # loc_pair
+    AssignCustomFields  => 'Assign and remove custom fields',         # loc_pair
     ModifyTemplate      => 'Modify Scrip templates for this queue',   # loc_pair
     ShowTemplate        => 'Display Scrip templates for this queue',  # loc_pair
 

Modified: rt/branches/autrijus-3.1/lib/RT/Record.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Record.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Record.pm	Tue Mar  9 12:35:19 2004
@@ -600,6 +600,9 @@
         Type      => undef,
         OldValue  => undef,
         NewValue  => undef,
+        OldReference  => undef,
+        NewReference  => undef,
+        ReferenceType => undef,
         Data      => undef,
         Field     => undef,
         MIMEObj   => undef,
@@ -608,6 +611,19 @@
         @_
     );
 
+    my $old_ref = $args{'OldReference'};
+    my $new_ref = $args{'NewReference'};
+    my $ref_type = $args{'ReferenceType'};
+    if ($old_ref or $new_ref) {
+	$ref_type ||= ref($old_ref) || ref($new_ref);
+	if (!$ref_type) {
+	    $RT::Logger->error("Reference type not specified for transaction");
+	    return;
+	}
+	$old_ref = $old_ref->Id if ref($old_ref);
+	$new_ref = $new_ref->Id if ref($new_ref);
+    }
+
     require RT::Transaction;
     my $trans = new RT::Transaction( $self->CurrentUser );
     my ( $transaction, $msg ) = $trans->Create(
@@ -619,6 +635,9 @@
         Field     => $args{'Field'},
         NewValue  => $args{'NewValue'},
         OldValue  => $args{'OldValue'},
+        NewReference  => $new_ref,
+        OldReference  => $old_ref,
+        ReferenceType => $ref_type,
         MIMEObj   => $args{'MIMEObj'},
         ActivateScrips => $args{'ActivateScrips'},
         CommitScrips => $args{'CommitScrips'},
@@ -768,7 +787,6 @@
             while ( my $value = $values->Next ) {
                 $i++;
                 if ( $i < $cf_values ) {
-                    my $old_value = $value->Content;
                     my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $value->Content);
                     unless ($val) {
                         return (0,$msg);
@@ -777,16 +795,16 @@
                       $self->_NewTransaction(
                         Type     => 'CustomField',
                         Field    => $cf->Id,
-                        OldValue => $old_value
+                        OldReference => $value,
                       );
                 }
             }
         }
 
-        my $old_value;
-        if (my $value = $cf->ValuesForObject( $self )->First) {
-	    $old_value = $value->Content();
-	    return (1) if $old_value eq $args{'Value'};
+        my ($old_value, $old_content);
+        if ($old_value = $cf->ValuesForObject( $self )->First) {
+	    $old_content = $old_value->Content();
+	    return (1) if $old_content eq $args{'Value'};
 	}
 
         my ( $new_value_id, $value_msg ) = $cf->AddValueForObject(
@@ -807,7 +825,7 @@
 
         # now that adding the new value was successful, delete the old one
 	if ($old_value) {
-	    my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $old_value);
+	    my ($val, $msg) = $cf->DeleteValueForObject(Object => $self, Content => $old_content);
 	    unless ($val) { 
 	    		return (0,$msg);
 	    }
@@ -817,8 +835,8 @@
         my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
             Type     => 'CustomField',
             Field    => $cf->Id,
-            OldValue => $old_value,
-            NewValue => $new_value->Content
+            OldReference => $old_value,
+            NewReference => $new_value,
         );
 	}
 
@@ -851,7 +869,8 @@
         my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
             Type     => 'CustomField',
             Field    => $cf->Id,
-            NewValue => $args{'Value'}
+            NewReference => $new_value_id,
+	    ReferenceType => 'RT::ObjectCustomFieldValue',
         );
         unless ($TransactionId) {
             return ( 0,
@@ -914,13 +933,14 @@
         my ( $TransactionId, $Msg, $TransactionObj ) = $self->_NewTransaction(
             Type     => 'CustomField',
             Field    => $cf->Id,
-            OldValue => $args{'Value'}
+            OldReference => $val,
+	    ReferenceType => 'RT::ObjectCustomFieldValue',
         );
         unless($TransactionId) {
             return(0, $self->loc("Couldn't create a transaction: [_1]", $Msg));
         } 
 
-        return($TransactionId, $self->loc("[_1] is no longer a value for custom field [_2]", $args{'Value'}, $cf->Name));
+        return($TransactionId, $self->loc("[_1] is no longer a value for custom field [_2]", $TransactionObj->OldValue, $cf->Name));
 }
 
 # }}}

Modified: rt/branches/autrijus-3.1/lib/RT/System.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/System.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/System.pm	Tue Mar  9 12:35:19 2004
@@ -96,12 +96,14 @@
 
     my $queue = RT::Queue->new($RT::SystemUser);
     my $group = RT::Group->new($RT::SystemUser);
+    my $cf    = RT::CustomField->new($RT::SystemUser);
 
     my $qr =$queue->AvailableRights();
     my $gr = $group->AvailableRights();
+    my $cr = $cf->AvailableRights();
 
     # Build a merged list of all system wide rights, queue rights and group rights.
-    my %rights = (%{$RIGHTS}, %{$gr}, %{$qr});
+    my %rights = (%{$RIGHTS}, %{$gr}, %{$qr}, %{$cr});
     return(\%rights);
 }
 

Modified: rt/branches/autrijus-3.1/lib/RT/Transaction_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/Transaction_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/Transaction_Overlay.pm	Tue Mar  9 12:35:19 2004
@@ -502,13 +502,15 @@
         return $self->loc("No transaction type specified");
     }
 
+    my $obj_type = $self->FriendlyObjectType;
+
     if ( $type eq 'Create' ) {
-        return ($self->loc("Ticket created"));
+        return ($self->loc("[_1] created", $obj_type));
     }
     elsif ( $type =~ /Status/ ) {
         if ( $self->Field eq 'Status' ) {
             if ( $self->NewValue eq 'deleted' ) {
-                return ($self->loc("Ticket deleted"));
+                return ($self->loc("[_1] deleted", $obj_type));
             }
             else {
                 return ( $self->loc("Status changed from [_1] to [_2]", $self->loc($self->OldValue), $self->loc($self->NewValue) ));
@@ -719,6 +721,7 @@
 
 sub IsInbound {
     my $self = shift;
+    $self->ObjectType eq 'RT::Ticket' or return undef;
     return ( $self->TicketObj->IsRequestor( $self->CreatorObj->PrincipalId ) );
 }
 
@@ -839,6 +842,9 @@
 	$Object->Load($self->__Value('OldReference'));
 	return $Object->Content;
     }
+    else {
+	return $self->__Value('OldValue');
+    }
 }
 
 sub NewValue {
@@ -848,6 +854,9 @@
 	$Object->Load($self->__Value('NewReference'));
 	return $Object->Content;
     }
+    else {
+	return $self->__Value('NewValue');
+    }
 }
 
 sub Object {
@@ -857,5 +866,11 @@
     return($Object);
 }
 
+sub FriendlyObjectType {
+    my $self = shift;
+    my $type = $self->ObjectType or return undef;
+    $type =~ s/^RT:://;
+    return $self->loc($type);
+}
 
 1;

Modified: rt/branches/autrijus-3.1/lib/RT/User_Overlay.pm
==============================================================================
--- rt/branches/autrijus-3.1/lib/RT/User_Overlay.pm	(original)
+++ rt/branches/autrijus-3.1/lib/RT/User_Overlay.pm	Tue Mar  9 12:35:19 2004
@@ -148,9 +148,13 @@
         Privileged => 0,
         Disabled => 0,
         EmailAddress => '',
+        _RecordTransaction => 1,
         @_    # get the real argumentlist
     );
 
+    # remove the value so it does not cripple SUPER::Create
+    my $record_transaction = delete $args{'_RecordTransaction'};
+
     #Check the ACL
     unless ( $self->CurrentUser->HasRight(Right => 'AdminUsers', Object => $RT::System) ) {
         return ( 0, $self->loc('No permission to create users') );
@@ -269,6 +273,10 @@
         $unpriv->AddMember($self->PrincipalId);  
     }
 
+    if ( $record_transaction ) {
+	$self->_NewTransaction( Type => "Create" );
+    }
+
 
    #  $RT::Logger->debug("Finished creating the user");
     return ( $id, $self->loc('User created') );
@@ -1482,11 +1490,14 @@
         return ( 0, $self->loc("Permission Denied") );
     }
 
-    #Set the new value
-    my ( $ret, $msg ) = $self->SUPER::_Set(
-        Field => $args{'Field'},
-        Value => $args{'Value'}
-    );
+    my $Old = $self->SUPER::_Value("$args{'Field'}");
+    
+    my ($ret, $msg) = $self->SUPER::_Set( Field => $args{'Field'},
+					  Value => $args{'Value'} );
+    
+    #If we can't actually set the field to the value, don't record
+    # a transaction. instead, get out of here.
+    if ( $ret == 0 ) { return ( 0, $msg ); }
 
     if ( $args{'RecordTransaction'} == 1 ) {
 
@@ -1494,7 +1505,8 @@
                                                Type => $args{'TransactionType'},
                                                Field     => $args{'Field'},
                                                NewValue  => $args{'Value'},
-                                               OldValue  => $self->SUPER::_Value("$args{'Field'}"),
+                                               OldValue  => $Old,
+                                               TimeTaken => $args{'TimeTaken'},
         );
         return ( $Trans, scalar $TransObj->Description );
     }

Modified: rt/branches/autrijus-3.1/spec/spec.txt
==============================================================================
--- rt/branches/autrijus-3.1/spec/spec.txt	(original)
+++ rt/branches/autrijus-3.1/spec/spec.txt	Tue Mar  9 12:35:19 2004
@@ -2,8 +2,6 @@
 
 Finish Txn display for User and Group
     UI done, needs to referentialise OldReference etc.
-ACL for per-CF editing
-    UI done, needs to verify API
 
 ===================================================================================
     AdminThis ACL for CFs controls CF data and metadata, but _not_ where it applies



More information about the Rt-commit mailing list