[Jifty-commit] r1328 - in jifty/trunk: . lib/Jifty lib/Jifty/Action lib/Jifty/Action/Record t/TestApp/lib/TestApp/Model t/TestApp/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jun 20 23:15:28 EDT 2006


Author: trs
Date: Tue Jun 20 23:15:27 2006
New Revision: 1328

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action.pm
   jifty/trunk/lib/Jifty/Action/Record.pm
   jifty/trunk/lib/Jifty/Action/Record/Create.pm
   jifty/trunk/lib/Jifty/Action/Record/Update.pm
   jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm
   jifty/trunk/t/TestApp/share/web/templates/editform
   jifty/trunk/t/TestApp/t/05-editactions-Record.t

Log:
 r13274 at zot:  tom | 2006-06-20 23:14:04 -0400
 * Make immutable columns part of record update actions, but render them as a read-only field.
 * Make sure Jifty::Action::form_field renders unwritable fields as read-only unless explicitly asked otherwise
 * Add two simple tests to make sure that manually trying to set the unwritable fields in an update action won't have any effect


Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Tue Jun 20 23:15:27 2006
@@ -289,10 +289,15 @@
 sub form_field {
     my $self = shift;
     my $arg_name = shift;
+
+    my $mode = (defined $self->arguments->{$arg_name}{'render_mode'}
+                    and $self->arguments->{$arg_name}{'render_mode'} eq 'read')
+                        ? 'read'
+                        : 'update';
+    
     $self->_form_widget( argument => $arg_name,
-                         render_mode => 'update',
+                         render_mode => $mode,
                          @_);
-
 }
 
 

Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Tue Jun 20 23:15:27 2006
@@ -255,13 +255,13 @@
 =head2 possible_fields
 
 Returns the list of fields on the object that the action can update.
-This defaults to only the writable fields of the object.
+This defaults to all of the fields of the object.
 
 =cut
 
 sub possible_fields {
     my $self = shift;
-    return $self->record->writable_attributes;
+    return map {$_->name} grep {$_->type ne "serial"} $self->record->columns;
 }
 
 =head2 take_action

Modified: jifty/trunk/lib/Jifty/Action/Record/Create.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Create.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Create.pm	Tue Jun 20 23:15:27 2006
@@ -84,19 +84,6 @@
     return 1;
 }
 
-=head2 possible_fields
-
-Returns all of the columns on the record class.  This is because,
-unlike L<Jifty::Action::Record::Update>, columns which are marked as
-'immutable' should still be able to be set at creation time.
-
-=cut
-
-sub possible_fields {
-    my $self = shift;
-    return map {$_->name} grep {$_->type ne "serial"} $self->record->columns;
-}
-
 =head2 report_success
 
 Sets the L<Jifty::Result/message> to default success message,

Modified: jifty/trunk/lib/Jifty/Action/Record/Update.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Update.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record/Update.pm	Tue Jun 20 23:15:27 2006
@@ -33,6 +33,12 @@
     my $self = shift;
     my $arguments = $self->SUPER::arguments(@_);
 
+    for my $column ( $self->record->columns ) {
+        if ( not $column->writable and $column->readable ) {
+            $arguments->{$column->name}{'render_mode'} = 'read';
+        }
+    }
+
     for my $pk (@{ $self->record->_primary_keys }) {
         $arguments->{$pk}{'constructor'} = 1;
         $arguments->{$pk}{'mandatory'} = 1;

Modified: jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm	(original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Model/User.pm	Tue Jun 20 23:15:27 2006
@@ -10,6 +10,10 @@
 column 'email' =>
   type is 'text',
   is mandatory;
+column 'tasty' =>
+  type is 'boolean',
+  is immutable;
+
 
 package TestApp::Model::User;
 use base qw/TestApp::Record/;

Modified: jifty/trunk/t/TestApp/share/web/templates/editform
==============================================================================
--- jifty/trunk/t/TestApp/share/web/templates/editform	(original)
+++ jifty/trunk/t/TestApp/share/web/templates/editform	Tue Jun 20 23:15:27 2006
@@ -13,6 +13,7 @@
 <% Jifty->web->form->start() %>
 <% $action->form_field('name') %>
 <% $action->form_field('email') %>
+<% $action->form_field('tasty') %>
 <% Jifty->web->form->submit %>
 <% Jifty->web->form->end %>
 </&>

Modified: jifty/trunk/t/TestApp/t/05-editactions-Record.t
==============================================================================
--- jifty/trunk/t/TestApp/t/05-editactions-Record.t	(original)
+++ jifty/trunk/t/TestApp/t/05-editactions-Record.t	Tue Jun 20 23:15:27 2006
@@ -9,7 +9,7 @@
 }
 use lib '../../lib';
 
-use Jifty::Test tests => 8;
+use Jifty::Test tests => 10;
 use Jifty::Test::WWW::Mechanize;
 
 # Make sure we can load the model
@@ -21,8 +21,10 @@
 
 # Create a user
 my $o = TestApp::Model::User->new(current_user => $system_user);
-my ($id) = $o->create( name => 'edituser', email => 'someone at example.com' );
+my ($id) = $o->create( name => 'edituser', email => 'someone at example.com',
+                       tasty => 1 );
 ok($id, "User create returned success");
+is($o->tasty, 1, "User is tasty");
 
 my $server  = Jifty::Test->make_server;
 
@@ -32,13 +34,14 @@
 my $mech    = Jifty::Test::WWW::Mechanize->new();
 
 # Test action to update
-$mech->get_ok($URL.'/editform?J:A-updateuser=TestApp::Action::UpdateUser&J:A:F:F:F-id-updateuser=1&J:A:F-name-updateuser=edituser&J:A:F-email-updateuser=newemail at example.com', "Form submitted");
+$mech->get_ok($URL.'/editform?J:A-updateuser=TestApp::Action::UpdateUser&J:A:F:F:F-id-updateuser=1&J:A:F-name-updateuser=edituser&J:A:F-email-updateuser=newemail at example.com&J:A:F-tasty-updateuser=0', "Form submitted");
 undef $o;
 $o = TestApp::Model::User->new(current_user => $system_user);
 $o->load($id);
 ok($id, "Load returned success");
 
 is($o->email, 'newemail at example.com', "Email was updated by form");
+is($o->tasty, 1, "User is still tasty (was not updated since immutable)");
 
 1;
 


More information about the Jifty-commit mailing list