[Rt-commit] rt branch, 4.0/lifecycle-default-value, created. rt-4.0.4-223-g689d5af

? sunnavy sunnavy at bestpractical.com
Thu Jun 21 15:43:51 EDT 2012


The branch, 4.0/lifecycle-default-value has been created
        at  689d5afb24025e7d2381f4fab5e1122ac07389c1 (commit)

- Log -----------------------------------------------------------------
commit d8dbf836464dcd56fe1d797a38236db523aff523
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jan 22 21:33:54 2012 +0800

    simplify Queue Lifecycle column's logic to avoid empty values

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 3cb87c4..72a6ae9 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -268,8 +268,9 @@ sub SetLifecycle {
     if ( $value && $value ne 'default' ) {
         return (0, $self->loc('[_1] is not valid lifecycle', $value ))
             unless $self->ValidateLifecycle( $value );
-    } else {
-        $value = undef;
+    }
+    else {
+        $value ||= 'default';
     }
 
     return $self->_Set( Field => 'Lifecycle', Value => $value, @_ );
@@ -412,8 +413,9 @@ sub Create {
     if ( $args{'Lifecycle'} && $args{'Lifecycle'} ne 'default' ) {
         return ( 0, $self->loc('Invalid lifecycle name') )
             unless $self->ValidateLifecycle( $args{'Lifecycle'} );
-    } else {
-        $args{'Lifecycle'} = undef;
+    }
+    else {
+        $args{'Lifecycle'} ||= 'default';
     }
 
     my %attrs = map {$_ => 1} $self->ReadableAttributes;
@@ -1211,6 +1213,13 @@ sub _Set {
     unless ( $self->CurrentUserHasRight('AdminQueue') ) {
         return ( 0, $self->loc('Permission Denied') );
     }
+
+    my %args = (
+        Field => undef,
+        Value => undef,
+        IsSQL => undef,
+        @_
+    );
     return ( $self->SUPER::_Set(@_) );
 }
 
@@ -1524,7 +1533,7 @@ sub _CoreAccessible {
         SubjectTag => 
         {read => 1, write => 1, sql_type => 12, length => 120,  is_blob => 0,  is_numeric => 0,  type => 'varchar(120)', default => ''},
         Lifecycle => 
-        {read => 1, write => 1, sql_type => 12, length => 32,  is_blob => 0,  is_numeric => 0,  type => 'varchar(32)', default => ''},
+        {read => 1, write => 1, sql_type => 12, length => 32,  is_blob => 0, is_numeric => 0,  type => 'varchar(32)', default => 'default'},
         InitialPriority => 
         {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
         FinalPriority => 
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index 5682eee..8b9f393 100755
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -197,10 +197,14 @@ if ( $QueueObj->Id ) {
         ARGSRef => \%ARGS,
     );
 
-    $ARGS{'Lifecycle'} = undef if defined $ARGS{'Lifecycle'} and $ARGS{'Lifecycle'} eq "default";
+    # avoid the result of "already the current value"
+    delete $ARGS{'Lifecycle'}
+      if $ARGS{'Lifecycle'}
+          && $ARGS{'Lifecycle'} eq $QueueObj->_Value('Lifecycle');
+
     push @results, UpdateRecordObject(
         AttributesRef => \@attribs,
-        Object => $QueueObj, 
+        Object => $QueueObj,
         ARGSRef => \%ARGS
     );
 

commit 45234ad690458483ebe011f3e345067e8198df27
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jan 22 22:23:50 2012 +0800

    test queue's lifecycle change in admin ui

diff --git a/t/web/admin_queue_lifecycle.t b/t/web/admin_queue_lifecycle.t
new file mode 100644
index 0000000..cb18d11
--- /dev/null
+++ b/t/web/admin_queue_lifecycle.t
@@ -0,0 +1,47 @@
+use strict;
+use warnings;
+
+use RT::Test tests => 13;
+
+my $lifecycles = RT->Config->Get('Lifecycles');
+$lifecycles->{foo} = {
+    initial  => ['initial'],
+    active   => ['open'],
+    inactive => ['resolved'],
+};
+
+RT::Lifecycle->FillCache();
+
+my ( $url, $m ) = RT::Test->started_ok;
+ok( $m->login(), 'logged in' );
+
+$m->get_ok( $url . '/Admin/Queues/Modify.html?id=1' );
+
+my $form            = $m->form_name('ModifyQueue');
+my $lifecycle_input = $form->find_input('Lifecycle');
+is( $lifecycle_input->value, 'default', 'default lifecycle' );
+
+my @lifecycles = sort $lifecycle_input->possible_values;
+is_deeply( \@lifecycles, [qw/approvals default foo/], 'found all lifecycles' );
+
+$m->submit_form();
+$m->content_lacks( 'Lifecycle changed from',
+    'no message of "Lifecycle changed from"' );
+$m->content_lacks( 'That is already the current value',
+    'no message of "That is already the current value"' );
+
+$form = $m->form_name('ModifyQueue');
+$m->submit_form( fields => { Lifecycle => 'foo' }, );
+$m->content_contains(
+    'Lifecycle changed from "default" to "foo"');
+$lifecycle_input = $form->find_input('Lifecycle');
+is( $lifecycle_input->value, 'foo', 'lifecycle is changed to foo' );
+
+$form = $m->form_name('ModifyQueue');
+$m->submit_form( fields => { Lifecycle => 'default' }, );
+$m->content_contains(
+    'Lifecycle changed from "foo" to "default"');
+$lifecycle_input = $form->find_input('Lifecycle');
+is( $lifecycle_input->value, 'default',
+    'lifecycle is changed back to default' );
+

commit 689d5afb24025e7d2381f4fab5e1122ac07389c1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 21 11:05:00 2012 +0800

    upgrade script to update queue lifecycle column from null to "default"
    
    as we don't allow to set the column empty value any more

diff --git a/etc/upgrade/4.0.7/content b/etc/upgrade/4.0.7/content
new file mode 100644
index 0000000..94214c7
--- /dev/null
+++ b/etc/upgrade/4.0.7/content
@@ -0,0 +1,17 @@
+ at Final = (
+    sub {
+        $RT::Logger->debug(
+            'Going to update empty Queue Lifecycle column to "default"');
+
+        my $queues = RT::Queues->new( RT->SystemUser );
+        $queues->Limit(
+            FIELD    => 'Lifecycle',
+            OPERATOR => 'IS',
+            VALUE    => 'NULL',
+        );
+
+        while ( my $q = $queues->Next ) {
+            $q->SetLifecycle('default');
+        }
+    }
+);

-----------------------------------------------------------------------


More information about the Rt-commit mailing list