[Cpan-forum-commit] rev 318 - in trunk: . lib/CPAN lib/CPAN/Forum/DB templates
svn at pti.co.il
svn at pti.co.il
Sun Aug 5 07:12:25 EEST 2007
Author: gabor
Date: 2007-08-05 07:12:25 +0300 (Sun, 05 Aug 2007)
New Revision: 318
Modified:
trunk/
trunk/lib/CPAN/Forum.pm
trunk/lib/CPAN/Forum/DB/Posts.pm
trunk/templates/editor.tmpl
Log:
make the flood limit work again,
check if the post is identical to the last post and don't allow such posts
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4378
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
+ 7bc34947-122d-0410-bc5a-f898d2bb5f81:/local/cpan-forum:4379
8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:12752
Modified: trunk/lib/CPAN/Forum/DB/Posts.pm
===================================================================
--- trunk/lib/CPAN/Forum/DB/Posts.pm 2007-08-05 04:12:10 UTC (rev 317)
+++ trunk/lib/CPAN/Forum/DB/Posts.pm 2007-08-05 04:12:25 UTC (rev 318)
@@ -16,6 +16,7 @@
__PACKAGE__->set_sql(count_like => "SELECT count(*) FROM __TABLE__ WHERE %s LIKE '%s'");
my $MORE_SQL = 'groups.name group_name, users.fname user_fname, users.lname user_lname, users.username user_username';
+
sub get_post {
my ($self, $post_id) = @_;
return if not $post_id;
@@ -27,7 +28,23 @@
WHERE posts.id=? AND posts.gid=groups.id";
return $self->_fetch_single_hashref($sql, $post_id);
}
+sub _get_latest_pid_by_uid {
+ my ($self, $uid) = @_;
+ my $sql = "SELECT id, text, subject FROM posts WHERE uid=? ORDER BY date DESC LIMIT 1";
+ return $self->_fetch_single_value($sql, $uid);
+}
+sub get_latest_post_by_uid {
+ my ($self, $uid) = @_;
+ Carp::croak("no uid provided") if not $uid;
+ my $post_id = $self->_get_latest_pid_by_uid($uid);
+ if ($post_id) {
+ return $self->get_post($post_id);
+ } else {
+ return;
+ }
+}
+
sub retrieve_latest {
my ($self, $limit) = @_;
Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm 2007-08-05 04:12:10 UTC (rev 317)
+++ trunk/lib/CPAN/Forum.pm 2007-08-05 04:12:25 UTC (rev 318)
@@ -1193,13 +1193,16 @@
my $button = $q->param("button");
if (not @errors and $button eq "Submit") {
- my ($last_post) = CPAN::Forum::DB::Posts->search(uid => $self->session->param("username"), {order_by => 'id DESC', limit => 1});
+ my $last_post = CPAN::Forum::DB::Posts->get_latest_post_by_uid($self->session->param('uid'));
+ # TODO, maybe also check if the post is the same as the last post to avoid duplicates
if ($last_post) {
$self->log->debug("username: " .
$self->session->param("username") .
- " last post: " . $last_post->date . " now: " . time());
- if ($last_post->date > time() - $self->config("flood_control_time_limit")) {
+ " last post: " . $last_post->{date} . " now: " . time());
+ if ($last_post->{date} > time() - $self->config("flood_control_time_limit")) {
push @errors, "flood_control";
+ } elsif ($last_post->{text} eq $new_text) {
+ push @errors, "duplicate_post";
}
}
}
Modified: trunk/templates/editor.tmpl
===================================================================
--- trunk/templates/editor.tmpl 2007-08-05 04:12:10 UTC (rev 317)
+++ trunk/templates/editor.tmpl 2007-08-05 04:12:25 UTC (rev 318)
@@ -10,10 +10,13 @@
<TMPL_IF subject_too_long>Subject must be up to 50 characters.<br /></TMPL_IF>
<TMPL_IF flood_control>Trying to submit posts too quickly.
Please wait 10 more seconds before posting again.</TMPL_IF>
- <TMPL_IF text_format>Text format is not correct. As we are still in development
- this might be either a bug or on purpose. If after reading again the rules of posting
- at the bottom of this page you still think your post should work, please send a copy of
- it to <a href="mailto:gabor at perl.org.il">szabgab</a><br /></TMPL_IF>
+ <TMPL_IF duplicate_post>Identical to your last post. You might have tried to reload the page.</TMPL_IF>
+ <TMPL_IF text_format>Text format is not correct.<br />
+ Most likely you need to replace < characters by &lt;<br />
+ or wrap your code snippets in <code></code> tags.
+ <br />
+ If that still does not work you can send the text to <a href="mailto:gabor at perl.org.il">szabgab</a> I might be
+ able to tell what is the problem.<br /></TMPL_IF>
<TMPL_IF bad_thing>Bad thing<br /></TMPL_IF>
</div>
More information about the Cpan-forum-commit
mailing list