[Yapcom checkin] rev 71 - lib/YAPC t t/lib/YAPC/Test templates

[prev] [thread] [next] [lurker] [Date index for 2003/11/26]

From: svn
Subject: [Yapcom checkin] rev 71 - lib/YAPC t t/lib/YAPC/Test templates
Date: 21:43 on 26 Nov 2003
Author: gabor
Date: 2003-11-26 21:43:35 +0200 (Wed, 26 Nov 2003)
New Revision: 71

Modified:
   lib/YAPC/Organizer.pm
   lib/YAPC/Talk.pm
   t/13-change-proposal.t
   t/lib/YAPC/Test/Data.pm
   templates/login.tmpl
   templates/message.tmpl
   templates/proposal.tmpl
Log:
logged in users can now list and change their own proposals

Modified: lib/YAPC/Organizer.pm
===================================================================
--- lib/YAPC/Organizer.pm	2003-11-26 17:32:25 UTC (rev 70)
+++ lib/YAPC/Organizer.pm	2003-11-26 19:43:35 UTC (rev 71)
@@ -1,6 +1,6 @@
 package YAPC::Organizer;
 
-our $VERSION = '0.08_02';
+our $VERSION = '0.08_03';
 
 use strict;
 use warnings;
@@ -18,8 +18,15 @@
 use base 'CGI::Application';
 use Data::Dumper;  # for playing with debugging
 
-my @user_pages = qw(proposal personal_info change_password user_account logout list_my_proposals);  # list pages that require valid login to access
-my @admin_pages = qw(admin admin_list_people admin_list_proposals); # list of pages accessible to administrators only
+
+# list pages that require valid login to access
+my @user_pages = qw(proposal personal_info change_password 
+                   user_account logout list_my_proposals edit_my_proposal);  
+
+# list of pages accessible to administrators only
+my @admin_pages = qw(admin admin_list_people admin_list_proposals); 
+
+# other pages that can be directly access but which don't need any authentication
 my @other_pages = qw(list_people login registration validation lost_validation lost_password);
 
 my @run_modes = map {$_, $_} @user_pages, @admin_pages, @other_pages;
@@ -503,6 +510,8 @@
 
 sub proposal {
     my $self = shift;
+    my $update = shift;
+
     my $q = $self->query;
     my $talk;
     my $id = $self->is_logged_in;
@@ -510,10 +519,14 @@
     my $t = $self->_server_page('proposal');
 
 # See logic in &lost_validation
-    return $self->_build_prop_page($t) unless $q->param('submit');
+    return $self->_build_prop_page($t) if not $q->param('submit');
 
     eval {
-      $talk = YAPC::Talk->propose($q->Vars, user_id => $id);
+      if ($update) {
+         $talk = YAPC::Talk->change_talk($q->Vars, user_id => $id);
+      } else {
+         $talk = YAPC::Talk->propose($q->Vars, user_id => $id);
+      }
     };
 
     if ($@) {
@@ -528,7 +541,35 @@
     return $t->output;
 }
 
+sub edit_my_proposal {
+   my $self = shift;
+   my $q = $self->query;
 
+   $self->send_message('no_such_proposal') if not $q->param('id');
+
+#    return $self->_build_prop_page($t) unless $q->param('submit');
+
+
+    my $user_id = $self->is_logged_in;
+    my $t;
+    eval {
+       ($t) = YAPC::Talk->search(user_id => $user_id, id => $q->param('id'));
+    };
+    return $self->send_message('no_such_proposal') if not $t;
+
+    return $self->proposal('update') if $q->param('submit');
+    
+    $self->query->param(abstract => $t->abstract);
+    $self->query->param(subject  => $t->title);
+    $self->query->param('length'  => $t->length);
+    $self->query->param(language  => $t->language);
+    $self->query->param(comment  => $t->other);
+    $self->query->param(id  => $t->id);
+
+    $self->proposal('update');
+}
+
+
 sub send_new_proposal_to_admin {
     my $self = shift;
     my $talk = shift;
@@ -627,7 +668,14 @@
     return $t->output;
 }
 
+sub send_message {
+   my $t = $_[0]->_server_page('message');
+   $t->param($_[1] => 1);
+   return $t->output;
+}
 
+
+
 1;
 
 

Modified: lib/YAPC/Talk.pm
===================================================================
--- lib/YAPC/Talk.pm	2003-11-26 17:32:25 UTC (rev 70)
+++ lib/YAPC/Talk.pm	2003-11-26 19:43:35 UTC (rev 71)
@@ -16,25 +16,42 @@
 =cut
 sub propose {
     my $self = shift;
-    my %args = @_; # cookie =>    subject =>  language => 	 length =>   abstract =>  comment =>
-#   delete $args{run};    # was added for CGI::Application
-#   delete $args{submit};    # was added for CGI::Application
+    my %args = $self->_check_values(@_); 
 
-#   $args{user_id} = YAPC::Login->get_user_id(cookie => $args{cookie});
-#   delete $args{cookie};
+    croak("id should not be defined\n") if defined $args{id};
 
+    __PACKAGE__->create(\%args);
+}
+
+sub change_talk {
+    my $self = shift;
+    my %args = $self->_check_values(@_); 
+
+    croak("id should be defined\n") if not defined $args{id};
+    my ($t) = __PACKAGE__->search(id => $args{id});
+    my @valid_args = qw(id user_id title language length abstract other accepted);
+    foreach my $a (@valid_args) {
+       next if( $a eq 'user_id' or $a eq 'id' or $a eq 'accepted');
+       $t->set($a => $args{$a});
+    }
+    $t->update;
+    return $t;
+}
+
+
+sub _check_values {
+    my $self = shift;
+    my %args = @_; 
+
     croak("Only authenticated users can submit proposals\n") if not $args{user_id};
-    croak("id should not be defined\n") if defined $args{id};
     croak("No title provided\n") if not $args{subject};
     $args{title} = $args{subject};
-#   delete $args{subject};
     croak("No length provided\n") if not $args{'length'};
     croak("No abstract provided\n") if not $args{abstract};
     $args{accepted} = 0; # no trick from the outside please !
 
     # the form will have comment field and now we use the other field for our purposes
     $args{other} = $args{comment};
-#   delete $args{comment};
 
     if (not grep {$args{language} eq $_} @YAPC::Config::proposal_languages) {
        croak("Incorrect language\n");
@@ -44,14 +61,14 @@
        croak("Incorrect length\n");
     }
 
-    my @valid_args = qw(user_id title language length abstract other accepted);
+    my @valid_args = qw(id user_id title language length abstract other accepted);
     my %passed_args;
     @passed_args{@valid_args}= @args{@valid_args};
-
-    __PACKAGE__->create(\%passed_args);
+    return %passed_args;
 }
 
 
+
 =head2 VERSION
 
 $Id:$

Modified: t/13-change-proposal.t
===================================================================
--- t/13-change-proposal.t	2003-11-26 17:32:25 UTC (rev 70)
+++ t/13-change-proposal.t	2003-11-26 19:43:35 UTC (rev 71)
@@ -38,6 +38,7 @@
 isnt($cookies[0], $cookies[2], 'cookies are different');
 isnt($cookies[1], $cookies[2], 'cookies are different');
 YAPC::Test::Data::submit_talk(0, $cookies[0]);
+YAPC::Test::Data::submit_talk(1, $cookies[2]);
 
 
 
@@ -63,109 +64,102 @@
    my $result = $webapp->run();
    like($result, qr@<h2>My Proposals</h2>@, 'proposals listed');
    like($result, qr@\Q<a href="edit_my_proposal.html?id=1">$talks[0]{subject}</a>@, '1st proposal listed');
+   unlike($result, qr@\Q$talks[1]{subject}@, '2nd proposal NOT listed');
 
 }
- 
 
-
-
-__END__
-
-=pod
-# update personal_information fails if not authenticated
+# access edit_my_proposal should fail for unauthenticated
 {
-   local $ENV{REQUEST_URI}   = '/personal_info.html';
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
    #local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
    my $q = CGI->new();
    my $webapp = YAPC::Organizer->new;
    $webapp->query($q);
    my $result = $webapp->run();
    like($result, qr@<h2>Login</h2>@, 'Redirected to login page');
-   like($result, qr@$talks[0]{title}
 }
-=cut
 
-
-# access to personl_info page is successful when authenticated
+# access edit_my_proposal without an id should give an error message
 {
-   local $ENV{REQUEST_URI}   = '/personal_info.html';
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
    local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
    my $q = CGI->new();
    my $webapp = YAPC::Organizer->new;
    $webapp->query($q);
    my $result = $webapp->run();
-   like($result, qr@<h2>Change Personal Information</h2>@, 'personal_info page accessed');
-   like($result, qr@\Q<tr><td>First Name:</td><td><input size=40 name="fname" value="$people[0]{fname}" /> *</td></tr>@, 'old fname filled in correclty');
-   like($result, qr@\Q<tr><td>Last Name:</td><td><input size=40 name="lname" value="$people[0]{lname}" /> *</td></tr>@, 'old lname filled in correclty');
-   like($result, qr@\Q<tr><td>Phone:</td><td><input  size=40 name="phone" value="$people[0]{phone}" /> *</td></tr>@, 'old phone filled in correclty');
-   like($result, qr@\Q<tr><td>Company:</td><td><input  size=40 name="company" value="" /></td></tr>@, 'old company filled in correclty');
-             # $people[0]{company}
+   like($result, qr@We could not find this proposal.@, 'proposals refused');
+
 }
 
-
-# submit change to personl_info page when not authenticated
-# no value submitted:
+# access edit_my_proposal with an id that does not belong to the user should give an error message
 {
-   local $ENV{REQUEST_URI}   = '/personal_info.html';
-#   local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
-   my $q = CGI->new({submit => 1});
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
+   local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+   my $q = CGI->new({id => 2});
    my $webapp = YAPC::Organizer->new;
    $webapp->query($q);
    my $result = $webapp->run();
-   like($result, qr@<h2>Login</h2>@, 'Redirected to login page');
+   like($result, qr@We could not find this proposal.@, 'proposals refused');
 }
 
 
-#   like($result, qr@<h2>Change Personal Information</h2>@, 'personal_info page accessed');
+# show details of a proposal
+{
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
+   local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
+   my $q = CGI->new({id => 1});
+   my $webapp = YAPC::Organizer->new;
+   $webapp->query($q);
+   my $result = $webapp->run();
+   like($result, qr@Proposal@, 'proposal title');
+   like($result, qr@\Q$talks[0]{subject}@, 'proposal displayed');
+   like($result, qr@\Q"$talks[0]{language}" selected@, 'proposal displayed');
+   like($result, qr@\Q"$talks[0]{'length'}" selected@, 'proposal displayed');
+}
 
-# submit change to personl_info page gives error when authenticated but not enough data provided.
+# submit new data without an id
 {
-   local $ENV{REQUEST_URI}   = '/personal_info.html';
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
    local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
-   my $q = CGI->new({submit => 1});
+   my %talk = %{$talks[2]};
+   $talk{submit} = 1;
+   my $q = CGI->new(\%talk);
    my $webapp = YAPC::Organizer->new;
    $webapp->query($q);
    my $result = $webapp->run();
-   like($result, qr@Error@, 'Error');
-   like($result, qr@<h2>Change Personal Information</h2>@, 'personal_info page accessed');
-   like($result, qr@\Q<tr><td>First Name:</td><td><input size=40 name="fname" value="" /> *</td></tr>@, 'old fname filled in correclty');
-   like($result, qr@\Q<tr><td>Last Name:</td><td><input size=40 name="lname" value="" /> *</td></tr>@, 'old lname filled in correclty');
-   like($result, qr@\Q<tr><td>Phone:</td><td><input  size=40 name="phone" value="" /> *</td></tr>@, 'old phone filled in correclty');
-   like($result, qr@\Q<tr><td>Company:</td><td><input  size=40 name="company" value="" /></td></tr>@, 'old company filled in correclty');
+   like($result, qr@We could not find this proposal.@, 'proposals refused');
 }
+
+# submit new data to the wrong id
 {
-   local $ENV{REQUEST_URI}   = '/personal_info.html';
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
    local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
-   my $q = CGI->new({submit => 1, fname => $people[3]{fname}, lname => $people[3]{lname}, company=>$people[3]{company}});
+   my %talk = %{$talks[2]};
+   $talk{submit} = 1;
+   $talk{id} = 2;
+   my $q = CGI->new(\%talk);
    my $webapp = YAPC::Organizer->new;
    $webapp->query($q);
    my $result = $webapp->run();
-   like($result, qr@Error@, 'Error');
-   like($result, qr@<h2>Change Personal Information</h2>@, 'personal_info page accessed');
-   like($result, qr@\Q<tr><td>First Name:</td><td><input size=40 name="fname" value="$people[3]{fname}" /> *</td></tr>@, 'old fname filled in correclty');
-   like($result, qr@\Q<tr><td>Last Name:</td><td><input size=40 name="lname" value="$people[3]{lname}" /> *</td></tr>@, 'old lname filled in correclty');
-   like($result, qr@\Q<tr><td>Phone:</td><td><input  size=40 name="phone" value="" /> *</td></tr>@, 'old phone filled in correclty');
-   like($result, qr@\Q<tr><td>Company:</td><td><input  size=40 name="company" value="$people[3]{company}" /></td></tr>@, 'old company filled in correclty');
+   like($result, qr@We could not find this proposal.@, 'proposals refused');
 }
 
-##### submitted data gets updated in the database
+# submit new data with good id
 {
-   local $ENV{REQUEST_URI}   = '/personal_info.html';
+   local $ENV{REQUEST_URI}   = '/edit_my_proposal.html';
    local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[0]";
-   my $q = CGI->new({submit => 1, fname => $people[3]{fname}, lname => $people[3]{lname}, phone => $people[3]{phone}, company=>$people[3]{company}});
+   my %talk = %{$talks[2]};
+   $talk{submit} = 1;
+   $talk{id} = 1;
+   my $q = CGI->new(\%talk);
    my $webapp = YAPC::Organizer->new;
    $webapp->query($q);
    my $result = $webapp->run();
-   like($result, qr@Your personal information has been successfully updated.@, 'updated');
+   like($result, qr@Thank you for proposing to talk on the conference.@, 'change accepted');
 
-   # check data in database
-   my ($p) = YAPC::Person->search(email => $people[0]->{email});  # we did not change the e-mail so it is still the same e-mail address 
-   is($p->get('fname'), $people[3]{fname}, 'fname was updated correctly');
+   # test if it was recorded correctly
+   # test if no other proposal was changed
 }
 
 
 
-
-
-
-

Modified: t/lib/YAPC/Test/Data.pm
===================================================================
--- t/lib/YAPC/Test/Data.pm	2003-11-26 17:32:25 UTC (rev 70)
+++ t/lib/YAPC/Test/Data.pm	2003-11-26 19:43:35 UTC (rev 71)
@@ -45,7 +45,7 @@
 
 our @talks = (
     {
-      subject    => 'Name of the first one',
+      subject    => 'Name of the first one, is it ?',
       'length'   => 30,
       language   => 'English',
       abstract   => 'This is the body of the proposal',
@@ -54,11 +54,19 @@
     {
       'subject'  => "Nice talk",
       'length'   => 5,
-      'language' => 'English',
+      'language' => 'Hebrew',
       'abstract' => 'This is my abstract',
       'comment'  => 'There can be a comment, no ?',
-    }
+    },
+    {
+      'subject'  => "Bad talk",
+      'length'   => 60,
+      'language' => 'Hebrew',
+      'abstract' => "lajdlsafsvsdkvkds\n\n\nkhadasd adkah #%^#!^vv\n adlafJ\n dksfh",
+      'comment'  => "aldadadfkaf a\n\n akdahkhsfakd\n\n\t\nasdkahdk",
+    },
 
+
 );
 
 

Modified: templates/login.tmpl
===================================================================
--- templates/login.tmpl	2003-11-26 17:32:25 UTC (rev 70)
+++ templates/login.tmpl	2003-11-26 19:43:35 UTC (rev 71)
@@ -13,7 +13,8 @@
 <tr><td></td><td><input type="submit" name="submitbtn" value="Login"></td></tr>
 </table>
 Not yet registered ? <a href=registration.html>Register here</a><br>
-Already registered but <a href=lost_validation.html>lost validation code ?</a><br>
+Already registered but <a href=lost_validation.html>lost validation code ?</a> 
+ and then <a href="validation.html">validate it</a><br>
 Already registered but <a href=lost_password.html>lost your password ?</a><br>
 </form>
 

Modified: templates/message.tmpl
===================================================================
--- templates/message.tmpl	2003-11-26 17:32:25 UTC (rev 70)
+++ templates/message.tmpl	2003-11-26 19:43:35 UTC (rev 71)
@@ -12,8 +12,12 @@
 <TMPL_IF NAME="personal_info_changed">
 Your personal information has been successfully updated.
 </TMPL_IF>
+<TMPL_IF NAME="no_such_proposal">
+We could not find this proposal.
+</TMPL_IF>
 
 
+
          <br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br />
          <hr />
 

Modified: templates/proposal.tmpl
===================================================================
--- templates/proposal.tmpl	2003-11-26 17:32:25 UTC (rev 70)
+++ templates/proposal.tmpl	2003-11-26 19:43:35 UTC (rev 71)
@@ -9,6 +9,7 @@
 <p>
 <form method="post">
 <input type="hidden" name="submit" value="Submit">
+<input type="hidden" name="id" value="<TMPL_VAR NAME=id>" />
 <table>
 <tr><td>Title:</td><td><input size=40 name="subject" value="<TMPL_VAR NAME=subject>" /></td></tr>
 <tr><td>Language:</td><td><select name="language">

Generated at 09:06 on 27 Nov 2003 by mariachi 0.51