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

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

From: svn
Subject: [Yapcom checkin] rev 11 - / lib/YAPC t t/lib/YAPC/Test templates
Date: 10:28 on 24 Nov 2003
Author: gabor
Date: 2003-11-24 10:28:41 +0200 (Mon, 24 Nov 2003)
New Revision: 11

Added:
   t/11-web-admin.t
   templates/admin.tmpl
   templates/admin_list_people.tmpl
   templates/admin_list_proposals.tmpl
Modified:
   MANIFEST
   README
   lib/YAPC/Config.pm
   lib/YAPC/Organizer.pm
   t/lib/YAPC/Test/Data.pm
Log:
admin interface - administrators can view more information about people and can see the proposals as well

Modified: MANIFEST
===================================================================
--- MANIFEST	2003-11-23 16:10:43 UTC (rev 10)
+++ MANIFEST	2003-11-24 08:28:41 UTC (rev 11)
@@ -27,6 +27,7 @@
 t/05-web-proposals.t              no
 t/07-web-change-data.t            no
 t/10-use-html-template.t          no
+t/11-web-admin.t                  no
 t/lib/YAPC/Test.pm                no
 t/lib/YAPC/Test/Data.pm           no
 templates/error.tmpl
@@ -53,5 +54,15 @@
 templates/email/register.tmpl
 templates/email/register_subject.tmpl
 templates/personal_info.tmpl
+templates/admin.tmpl
+templates/admin_list_people.tmpl
+templates/admin_list_proposals.tmpl
+templates/email/password.tmpl
+templates/email_sent.tmpl
+templates/lost_password.tmpl
+templates/lost_validation.tmpl
 docs/announcement_call_for_papers_hebrew.doc
+docs/announcement_call_for_papers_english.doc
 docs/sponsorship_letter_hebrew.doc
+
+

Modified: README
===================================================================
--- README	2003-11-23 16:10:43 UTC (rev 10)
+++ README	2003-11-24 08:28:41 UTC (rev 11)
@@ -40,6 +40,8 @@
         if e-mail was not yet validated.
     - make list of proposal lengths configurable and add 180 min too
     - make list of languages configurable
+    - create admin interface to list all the people with all their properties.
+    
 
 0.07_01 2003.11.15
     - send e-mail on every registration to administrator

Modified: lib/YAPC/Config.pm
===================================================================
--- lib/YAPC/Config.pm	2003-11-23 16:10:43 UTC (rev 10)
+++ lib/YAPC/Config.pm	2003-11-24 08:28:41 UTC (rev 11)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 our (@STORAGE, $dir, $db_dir, $db_file, $TIMEOUT, $templates_dir, $email_address);
-our (@proposal_languages, @proposal_lengths);
+our (@proposal_languages, @proposal_lengths, @admins);
 
 $dir = "/home/gabor/projects/perl/perl.org.il/YAPC/dev";
 $email_address = 'yapc@xxxx.xxx.xx';
@@ -21,8 +21,8 @@
 @proposal_lengths = (5, 30, 60, 90, 180);
 @proposal_languages = qw(English Hebrew);
 
+@admins = qw(gabor@xxx.xx.xx);
 
-
 1;
 
 =head1 VERSION

Modified: lib/YAPC/Organizer.pm
===================================================================
--- lib/YAPC/Organizer.pm	2003-11-23 16:10:43 UTC (rev 10)
+++ lib/YAPC/Organizer.pm	2003-11-24 08:28:41 UTC (rev 11)
@@ -79,24 +79,45 @@
         my $t = $self->_server_page('user_account', "$templates_dir/user_account.tmpl");
         return $t->output;
     }
+    my @user_pages = qw(proposal user_account personal_info);  # 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
 
     if (not $id and 
         not $self->header_props() and   # set within this run in do_login
-        grep {$_ eq $page} qw(proposal user_account personal_info)) { # list pages that require valid login to access
-
+        grep {$_ eq $page} (@user_pages, @admin_pages)) {
         my $t = $self->_server_page('login', "$templates_dir/login.tmpl");
         $t->param(next => "$page.html");
         return $t->output;
     }
 
-    my $t = $self->_server_page($page, $filename);
-    if ($page eq 'proposal') {
+    if ($id and $page eq 'proposal') {
+       my $t = $self->_server_page($page, $filename);
        $t->param(run => 'send_proposal');
        my @length_selection = map {{ value => $_, text => $_} } @YAPC::Config::proposal_lengths;
        $t->param(length => \@length_selection);
        my @language_selection = map {{ value => $_, text => $_} } @YAPC::Config::proposal_languages;
        $t->param(language => \@language_selection);
+       return $t->output;
     }
+
+    if ($id) {
+       if (grep {$_ eq $page} @admin_pages) {
+          my ($person) = YAPC::Person->search(id => $id); 
+          if (grep {$_ eq $person->email} @YAPC::Config::admins) {
+             if ($page eq 'admin_list_people') { return $self->do_admin_list_people; }
+             if ($page eq 'admin_list_proposals') { return $self->do_admin_list_proposals; }
+             my $t = $self->_server_page('admin', "$templates_dir/admin.tmpl");
+             $t->param(approved => 1);
+             return $t->output;
+          } else {
+             my $t = $self->_server_page('admin', "$templates_dir/admin.tmpl");
+             $t->param(approved => 0);
+             return $t->output;
+          }
+       }
+    }
+
+    my $t = $self->_server_page($page, $filename);
     return $t->output;
 }
 
@@ -237,7 +258,43 @@
     return $t->output;
 }
 
+sub do_admin_list_people {
+    my $self = shift;
 
+    my $ar = [];
+    foreach my $p (YAPC::Person->retrieve_all) {
+       my $url  =  $p->url;
+       $url = "http://$url"; if ($url and substr($url, 0, 7) ne 'http://');
+        push @$ar, $p;
+
+    }
+    my $t = $self->_server_page('admin_list_people', "$templates_dir/admin_list_people.tmpl");
+    my $stat = YAPC::Person->get_statistics();
+    $t->param(%$stat);
+    #warn Dumper $ar;
+    $t->param(USERS => $ar);
+    return $t->output;
+}
+
+sub do_admin_list_proposals {
+    my $self = shift;
+
+    my $ar = [];
+    foreach my $p (YAPC::Talk->retrieve_all) {
+        push @$ar, 
+           {
+           abstract => $p->abstract,
+           title  => $p->title,
+           };
+    }
+    #warn Dumper $ar;
+    my $t = $self->_server_page('admin_list_proposals', "$templates_dir/admin_list_proposals.tmpl");
+    $t->param(TALKS => $ar);
+    return $t->output;
+}
+
+
+
 sub do_login {
     my $self = shift;
     my $q = $self->query;
@@ -346,7 +403,7 @@
        my $gbr = YAPC::Person->acknowladge($q->Vars);
     };
     if ($@) {
-       warn $@;
+       #warn $@;
        my $t = $self->_server_page('validation', "$templates_dir/validation.tmpl");
        return $t->output;
     } else {

Added: t/11-web-admin.t
===================================================================
--- t/11-web-admin.t	2003-11-23 16:10:43 UTC (rev 10)
+++ t/11-web-admin.t	2003-11-24 08:28:41 UTC (rev 11)
@@ -0,0 +1,100 @@
+#!/usr/bin/perl 
+# -T
+
+
+# Testing the administrative web interface that can be reachable only by administrators
+
+use strict;
+use warnings;
+use Test::More qw(no_plan);
+use lib qw(lib);
+use lib qw(t/lib);
+use YAPC::Test 'init_db';
+use YAPC::Test::Data;
+
+#use YAPC::Person;
+use CGI; # needed for some of the tests
+
+$ENV{CGI_APP_RETURN_ONLY} = 1; # to eliminate screen output
+
+# to avoid warning caused my lack of web server in the test environment
+$ENV{HTTP_HOST}     = 'test-host';
+# $ENV{REQUEST_URI}   = 'test-uri';   #should be set for each request as we are using it
+$ENV{YAPCOM_NOMAIL} = 1;
+$ENV{REQUEST_URI}   = '/';
+
+BEGIN { use_ok( 'YAPC::Organizer' ); }
+
+###### prepare the environment: create and validate users and make them login
+my @cookies;
+
+YAPC::Test::Data::register_user(0);
+YAPC::Test::Data::register_user(1);
+push @cookies, YAPC::Test::Data::login_user(0);
+push @cookies, YAPC::Test::Data::login_user(0);
+push @cookies, YAPC::Test::Data::login_user(1);
+isnt($cookies[0], $cookies[1], 'cookies are different');
+isnt($cookies[0], $cookies[2], 'cookies are different');
+isnt($cookies[1], $cookies[2], 'cookies are different');
+YAPC::Test::Data::submit_talk(0, $cookies[0]);
+
+
+### access admin page(s)  by unauthenticated user
+{
+   local $ENV{REQUEST_URI}   = '/admin.html';
+   my $q = CGI->new();
+   my $webapp = YAPC::Organizer->new;
+   $webapp->query($q);
+   my $result = $webapp->run();
+   like($result, qr@<h2>Login</h2>@, "Access to 'admin.html' refused for unauthenticated user");
+}
+
+
+### access admin page(s)  by authenticated user who is not an admin
+foreach my $page (qw(admin admin_list_people admin_list_proposals)) {
+   local $ENV{REQUEST_URI}   = "/$page.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/Access to administrators only/, "Access to '$page.html' refused for authenticated nonadmin");
+}
+   
+
+
+### access admin page(s)  by authenticated user who is an admin
+{
+   local $ENV{REQUEST_URI}   = '/admin.html';
+   local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[2]";
+   my $q = CGI->new();
+   my $webapp = YAPC::Organizer->new;
+   $webapp->query($q);
+   my $result = $webapp->run();
+   like($result, qr/Administrators page/, 'Access approved');
+}
+
+### access admin page(s)  by authenticated user who is an admin
+{
+   local $ENV{REQUEST_URI}   = '/admin_list_people.html';
+   local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[2]";
+   my $q = CGI->new();
+   my $webapp = YAPC::Organizer->new;
+   $webapp->query($q);
+   my $result = $webapp->run();
+   like($result, qr/$YAPC::Test::Data::people[0]{fname}/, "First name listed");
+}
+
+### access admin page(s)  by authenticated user who is an admin
+{
+   local $ENV{REQUEST_URI}   = '/admin_list_proposals.html';
+   local $ENV{HTTP_COOKIE} = "Yapcom=$cookies[2]";
+   my $q = CGI->new();
+   my $webapp = YAPC::Organizer->new;
+   $webapp->query($q);
+   my $result = $webapp->run();
+   like($result, qr/$YAPC::Test::Data::talks[0]{subject}/, 'talk listed');
+}
+
+
+


Property changes on: t/11-web-admin.t
___________________________________________________________________
Name: svn:executable
   + *

Modified: t/lib/YAPC/Test/Data.pm
===================================================================
--- t/lib/YAPC/Test/Data.pm	2003-11-23 16:10:43 UTC (rev 10)
+++ t/lib/YAPC/Test/Data.pm	2003-11-24 08:28:41 UTC (rev 11)
@@ -33,6 +33,25 @@
     },
 );
 
+our @talks = (
+    {
+      subject    => 'Name of the first one',
+      'length'   => 30,
+      language   => 'English',
+      abstract   => 'This is the body of the proposal',
+      comment    => 'My comment',
+    },
+    {
+      'subject'  => "Nice talk",
+      'length'   => 5,
+      'language' => 'English',
+      'abstract' => 'This is my abstract',
+      'comment'  => 'There can be a comment, no ?',
+    }
+
+);
+
+
 =head2 prepare
 
 Prepare the test environment
@@ -106,4 +125,24 @@
    return $logins[-1]->cookie;
 }
 
+sub submit_talk {
+    my $t = shift; # talk id
+    my $cookie = shift; 
+   
+    local $ENV{REQUEST_URI}   = '/proposal.html';
+    local $ENV{HTTP_COOKIE} = "Yapcom=$cookie";
+    my %prop = %{$talks[$t]};
+    $prop{run} = 'send_proposal';
+    my $q = CGI->new(\%prop);
+    my $webapp = YAPC::Organizer->new;
+    $webapp->query($q);
+    my $result = $webapp->run();
+}
+
+
+
+
 1;
+
+
+

Added: templates/admin.tmpl
===================================================================
--- templates/admin.tmpl	2003-11-23 16:10:43 UTC (rev 10)
+++ templates/admin.tmpl	2003-11-24 08:28:41 UTC (rev 11)
@@ -0,0 +1,24 @@
+<TMPL_VALUE NAME="title" VALUE="My YAPC Admin">
+<TMPL_INCLUDE NAME="header.tmpl">
+     <td valign="top">
+
+<TMPL_IF NAME="approved">
+<h2>Administrators page</h2>
+<a href=admin_list_people.html>List people</a><br>
+<a href=admin_list_proposals.html>List proposals</a><br>
+<a href=logout.html>Logout</a><br>
+<TMPL_ELSE>
+Access to administrators only
+</TMPL_IF>
+
+         <br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br />
+         <hr />
+
+         <p class="bottomtext">
+            Please send comments, questions etc. to
+            <a href="mailto:yapc-organizers@xxxx.xxx.xx">yapc-organizers@xxxx.xxx.xx</a>;
+         </p>
+
+      </td>
+<TMPL_INCLUDE NAME="footer.tmpl">
+

Added: templates/admin_list_people.tmpl
===================================================================
--- templates/admin_list_people.tmpl	2003-11-23 16:10:43 UTC (rev 10)
+++ templates/admin_list_people.tmpl	2003-11-24 08:28:41 UTC (rev 11)
@@ -0,0 +1,42 @@
+<TMPL_VALUE NAME="title" VALUE="Administrative List of People">
+<TMPL_INCLUDE NAME="header.tmpl">
+     <td valign="top">
+<p>
+
+Total number of registered people: <b><TMPL_VAR NAME="total"></b><br>
+Number of people who have also validated their e-mail: <b><TMPL_VAR NAME="validated"></b><p> 
+<table>
+<TMPL_LOOP NAME="users">
+<tr><td colspan=3><hr></td></tr>
+<tr>
+  <td>
+  <TMPL_IF NAME="url">
+     <a href="<TMPL_VAR NAME="url">"><TMPL_VAR NAME="fname"> <TMPL_VAR NAME="lname"></a>
+  <TMPL_ELSE>
+     <TMPL_VAR NAME="fname"> <TMPL_VAR NAME="lname">
+  </TMPL_IF>
+  </a></td>
+  <td><TMPL_VAR NAME="mongers"></td>
+  <td><a href="http://search.cpan.org/author/<TMPL_VAR NAME="pauseid">"><TMPL_VAR NAME="pauseid"></a></td>
+</tr>
+<tr>
+  <td><TMPL_IF NAME="acked">Validated<TMPL_ELSE>NOT Validated</TMPL_IF></td>
+  <td><TMPL_VAR NAME="company"></td>
+  <td><TMPL_VAR NAME="email"></td>
+</tr>
+<tr><td colspan=3><TMPL_VAR NAME="bio"></td></tr>
+
+</TMPL_LOOP>
+</table>
+
+<br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br />
+<hr />
+
+<p class="bottomtext">
+           Please send comments, questions etc. to
+            <a href="mailto:yapc-organizers@xxxx.xxx.xx">yapc-organizers@xxxx.xxx.xx</a>;
+         </p>
+
+      </td>
+<TMPL_INCLUDE NAME="footer.tmpl">
+

Added: templates/admin_list_proposals.tmpl
===================================================================
--- templates/admin_list_proposals.tmpl	2003-11-23 16:10:43 UTC (rev 10)
+++ templates/admin_list_proposals.tmpl	2003-11-24 08:28:41 UTC (rev 11)
@@ -0,0 +1,33 @@
+<TMPL_VALUE NAME="title" VALUE="Administrative List of Proposals">
+<TMPL_INCLUDE NAME="header.tmpl">
+     <td valign="top">
+<p>
+<table>
+<TMPL_LOOP NAME="talks">
+<tr><td colspan=3><hr></td></tr>
+<tr>
+  <td><TMPL_VAR NAME="title"></td>
+  <td><TMPL_VAR NAME="length"></td>
+  <td><TMPL_VAR NAME="language"></td>
+</tr>
+<tr>
+  <td colspan=3><TMPL_VAR NAME="abstract"></td>
+</tr>
+<tr>
+  <td><TMPL_VAR NAME="other"></td>
+</tr>  
+<tr><td><hr></td></tr>  
+</TMPL_LOOP>
+</table>
+
+<br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br /><br />&nbsp;<br />
+<hr />
+
+<p class="bottomtext">
+           Please send comments, questions etc. to
+            <a href="mailto:yapc-organizers@xxxx.xxx.xx">yapc-organizers@xxxx.xxx.xx</a>;
+         </p>
+
+      </td>
+<TMPL_INCLUDE NAME="footer.tmpl">
+

Generated at 13:06 on 24 Nov 2003 by mariachi 0.51