[Cpan-forum-commit] rev 323 - in trunk: . lib/CPAN lib/CPAN/Forum lib/CPAN/Forum/DB templates

svn at pti.co.il svn at pti.co.il
Fri Aug 10 17:15:31 EEST 2007


Author: gabor
Date: 2007-08-10 17:15:31 +0300 (Fri, 10 Aug 2007)
New Revision: 323

Modified:
   trunk/
   trunk/lib/CPAN/Forum.pm
   trunk/lib/CPAN/Forum/DB/Groups.pm
   trunk/lib/CPAN/Forum/DBI.pm
   trunk/templates/admin.tmpl
   trunk/templates/notes.tmpl
Log:
temporarily disable manually adding groups by the admin



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4383
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
   + 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4390
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752

Modified: trunk/lib/CPAN/Forum/DB/Groups.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Groups.pm	2007-08-05 04:13:15 UTC (rev 322)
+++ trunk/lib/CPAN/Forum/DB/Groups.pm	2007-08-10 14:15:31 UTC (rev 323)
@@ -57,11 +57,17 @@
 
 sub add {
     my ($self, %args) = @_;
-    my $sql = "INSERT INTO groups (name, version, gtype, pauseid) VALUES (?, ?, ?, ?)";
+
+    Carp::croak("DB::Groups->add requires name and gtype fields") 
+        if not $args{name} or not defined $args{gtype} or not $args{pauseid};  #version
+
+    my ($fields, $placeholders, @values) = $self->_prep_insert(\%args);
+    my $sql = "INSERT INTO groups ($fields) VALUES ($placeholders)";
     my $dbh = CPAN::Forum::DBI::db_Main();
-    $dbh->do($sql, undef, @args{qw(name version gtype pauseid)});
+    $dbh->do($sql, undef, @values);
 
     return $self->info_by(name => $args{name});
 }
+
 1;
 

Modified: trunk/lib/CPAN/Forum/DBI.pm
===================================================================
--- trunk/lib/CPAN/Forum/DBI.pm	2007-08-05 04:13:15 UTC (rev 322)
+++ trunk/lib/CPAN/Forum/DBI.pm	2007-08-10 14:15:31 UTC (rev 323)
@@ -215,6 +215,15 @@
     #return ($where, @{ $args->{@fields} }); 
 }
 
+
+# gets a hash reference of  field names mapped to values
+# return 
+#    a partial SQL statement of the fieldnames
+#    a partial SQL statement of the placeholders
+#    list of values matching
+#
+#    $obj->_prep_insert({ fname => "Foo", lname => "Bar" })
+#    returns( "fname, lname",   "?, ?",    "Foo", "Bar" );
 sub _prep_insert {
     my ($self, $args) = @_;
 

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2007-08-05 04:13:15 UTC (rev 322)
+++ trunk/lib/CPAN/Forum.pm	2007-08-10 14:15:31 UTC (rev 323)
@@ -1193,7 +1193,7 @@
                 
     my $button = $q->param("button");
     if (not @errors and $button eq "Submit") {
-        my $last_post = CPAN::Forum::DB::Posts->get_latest_post_by_uid($self->session->param('uid'));
+        my $last_post = CPAN::Forum::DB::Posts->get_latest_post_by_uid($self->session->param('uid')); # SQL
         # TODO, maybe also check if the post is the same as the last post to avoid duplicates
         if ($last_post) {
             $self->log->debug("username: " . 
@@ -1410,12 +1410,21 @@
     }
     my $q = $self->query;
     my $group_name = $q->param("group");
+    # TODO pausid is currently free text on the form
+    # but it has been disabled for now
+    # we will have to provide the full list of PAUSEID on the form
+    # or check the id from the string
+    my $pauseid    = $q->param("pauseid");
+    if ($group_name !~ /^[\w-]+$/) {
+        return $self->notes("invalid_group_name");
+    }
+
     $self->log->debug("Adding group with name: '$group_name'");
     my $group = eval {
-            CPAN::Forum::DB::Groups->create({
+            CPAN::Forum::DB::Groups->add(   # SQL
                 name  => $group_name,
                 gtype => 3,
-                });
+                );
             };
     if ($@) {
         $self->log->debug("Failed to add group with name: '$group_name'");

Modified: trunk/templates/admin.tmpl
===================================================================
--- trunk/templates/admin.tmpl	2007-08-05 04:13:15 UTC (rev 322)
+++ trunk/templates/admin.tmpl	2007-08-10 14:15:31 UTC (rev 323)
@@ -8,20 +8,24 @@
 Data updated. <a href="/admin/">look at it again</a>
 <TMPL_ELSE>
 
+<!--
 <hr />
 <form method="POST" action="/admin/">
 <p>
 <input type="hidden" name="rm" value="add_new_group" />
 </p>
 <table>
-<tr><td>Group name:</td><td><input name="group" value="" size="50"></td></tr>
+<tr>
+ <td>Group name:</td><td><input name="group" value="" size="50"></td>
+ <td>PAUSEID:</td><td><input name="pauseid" value="" size="20"></td>
+</tr>
 </table>
 <p>
 <input type="submit" value="Add new group" />
 </p>
 </form>
+-->
 
-
 <hr />
 
 

Modified: trunk/templates/notes.tmpl
===================================================================
--- trunk/templates/notes.tmpl	2007-08-05 04:13:15 UTC (rev 322)
+++ trunk/templates/notes.tmpl	2007-08-10 14:15:31 UTC (rev 323)
@@ -55,5 +55,13 @@
 you can retrieve your password using the <a href="/">password reminder</a>
 </TMPL_IF>
 
+<TMPL_IF invalid_group_name>
+<p class="error">
+Group names are restricted to Alphanumeric characters and dash (-).
+<br />
+Press back, correct the value and submit it again.
+</p>
+</TMPL_IF>
+
 <TMPL_INCLUDE NAME="footer.tmpl">
 



More information about the Cpan-forum-commit mailing list