diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/comment_controller.rb | 6 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 11 | ||||
-rw-r--r-- | app/models/comment.rb | 15 | ||||
-rw-r--r-- | app/views/comment/new.rhtml | 9 | ||||
-rw-r--r-- | app/views/request/show.rhtml | 2 |
5 files changed, 33 insertions, 10 deletions
diff --git a/app/controllers/comment_controller.rb b/app/controllers/comment_controller.rb index 7192eb84b..fe2b31daf 100644 --- a/app/controllers/comment_controller.rb +++ b/app/controllers/comment_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: comment_controller.rb,v 1.2 2008-08-26 16:03:36 francis Exp $ +# $Id: comment_controller.rb,v 1.3 2008-08-26 22:54:45 francis Exp $ class CommentController < ApplicationController @@ -20,10 +20,10 @@ class CommentController < ApplicationController end # XXX this check should theoretically be a validation rule in the model - #@existing_comment = Comment.find_by_existing_comment(params[:info_request][:title], params[:info_request][:public_body_id], params[:outgoing_message][:body]) + @existing_comment = Comment.find_by_existing_comment(@info_request.id, params[:comment][:body]) # See if values were valid or not - if !@comment.valid? || params[:reedit] + if !@existing_comment.nil? || !@comment.valid? || params[:reedit] render :action => 'new' return end diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 96e489e26..722c6a2d7 100644 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -5,7 +5,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: link_to_helper.rb,v 1.36 2008-08-13 01:39:41 francis Exp $ +# $Id: link_to_helper.rb,v 1.37 2008-08-26 22:54:46 francis Exp $ module LinkToHelper @@ -73,13 +73,16 @@ module LinkToHelper link_to h(user.name), user_url(user) end end - def user_or_you_capital_link(user) + def user_or_you_capital(user) if @user && user == @user - link_to h("You"), user_url(user) + return h("You") else - link_to h(user.name), user_url(user) + return h(user.name) end end + def user_or_you_capital_link(user) + link_to user_or_you_capital(user), user_url(user) + end def user_admin_url(user) return admin_url('user/show/' + user.id.to_s) end diff --git a/app/models/comment.rb b/app/models/comment.rb index a8e338a70..0d219a9a8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -19,7 +19,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: comment.rb,v 1.2 2008-08-22 04:18:53 francis Exp $ +# $Id: comment.rb,v 1.3 2008-08-26 22:54:46 francis Exp $ class Comment < ActiveRecord::Base belongs_to :user @@ -58,6 +58,19 @@ class Comment < ActiveRecord::Base text = text.gsub(/\n/, '<br>') return text end + + # When posting a new comment, use this to check user hasn't double submitted. + def Comment.find_by_existing_comment(info_request_id, body) + # XXX can add other databases here which have regexp_replace + if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" + # Exclude spaces from the body comparison using regexp_replace + return Comment.find(:first, :conditions => [ "info_request_id = ? and regexp_replace(body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')", info_request_id, body ]) + else + # For other databases (e.g. SQLite) not the end of the world being space-sensitive for this check + return Comment.find(:first, :conditions => [ "info_request_id = ? and body = ?", info_request_id, body ]) + end + end + end diff --git a/app/views/comment/new.rhtml b/app/views/comment/new.rhtml index 22e260c1b..b377f82fa 100644 --- a/app/views/comment/new.rhtml +++ b/app/views/comment/new.rhtml @@ -1,5 +1,14 @@ <% @title = "Make an annotation on '" + h(@info_request.title) + "'" %> +<% if @existing_comment %> + <div class="errorExplanation" id="errorExplanation"><ul> + <li> + <%= user_or_you_capital(@existing_comment.user) %> already + made this annotation on <%=simple_date(@existing_comment.created_at)%>. + </li> + </ul></div> +<% end %> + <%= foi_error_messages_for :comment %> <h1>Add an annotation</h1> diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml index e10550022..15d70a8f4 100644 --- a/app/views/request/show.rhtml +++ b/app/views/request/show.rhtml @@ -98,7 +98,6 @@ <%= render :partial => 'correspondence', :locals => { :info_request_event => info_request_event } %> <% end %> - <!-- <div id="comment_form"> <h2>Add an annotation</h2> @@ -148,7 +147,6 @@ <%= render :partial => 'comment/comment_form', :locals => { } %> </div> - --> </div> |