<% note.comments.forEach(function (comment) { %>
<p>
<small class="deemphasize">
- <%- I18n.t('javascripts.notes.show.event', {
- action: comment.action, user: comment.user, time: comment.date
- }) %>
+ <% if (comment.user) { %>
+ <%- I18n.t('javascripts.notes.show.event', {
+ action: comment.action, user: comment.user, time: comment.date
+ }) %>
+ <% } else { %>
+ <%- I18n.t('javascripts.notes.show.anonymous_event', {
+ action: comment.action, time: comment.date
+ }) %>
+ <% } %>
</small>
<br/>
<%- comment.text %>
lon = params[:lon].to_f
lat = params[:lat].to_f
comment = params[:text]
- name = params[:name]
# Include in a transaction to ensure that there is always a note_comment for every note
Note.transaction do
@note.save!
# Add a comment to the note
- add_comment(@note, comment, name, "opened")
+ add_comment(@note, comment, "opened")
end
# Return a copy of the new note
# Extract the arguments
id = params[:id].to_i
comment = params[:text]
- name = params[:name] or "NoName"
# Find the note and check it is valid
@note = Note.find(id)
# Add a comment to the note
Note.transaction do
- add_comment(@note, comment, name, "commented")
+ add_comment(@note, comment, "commented")
end
# Return a copy of the updated note
# Extract the arguments
id = params[:id].to_i
comment = params[:text]
- name = params[:name]
# Find the note and check it is valid
@note = Note.find_by_id(id)
Note.transaction do
@note.close
- add_comment(@note, comment, name, "closed")
+ add_comment(@note, comment, "closed")
end
# Return a copy of the updated note
# Extract the arguments
id = params[:id].to_i
- name = params[:name]
# Find the note and check it is valid
note = Note.find(id)
note.status = "hidden"
note.save
- add_comment(note, nil, name, "hidden")
+ add_comment(note, nil, "hidden")
end
# Render the result
##
# Add a comment to a note
- def add_comment(note, text, name, event)
- name = "NoName" if name.nil?
-
+ def add_comment(note, text, event)
attributes = { :visible => true, :event => event, :body => text }
if @user
attributes[:author_id] = @user.id
- attributes[:author_name] = @user.display_name
else
attributes[:author_ip] = request.remote_ip
- attributes[:author_name] = name + " (a)"
end
comment = note.comments.create(attributes, :without_protection => true)
def note_author(object, link_options = {})
if object.author.nil?
- h(object.author_name)
+ ""
else
- link_to h(object.author_name), link_options.merge({:controller => "user", :action => "view", :display_name => object.author_name})
+ link_to h(object.author.display_name), link_options.merge({:controller => "user", :action => "view", :display_name => object.author.display_name})
end
end
end
resp += (comment_no == 1 ? "" : separator_char)
resp += comment.body if comment.body
resp += " [ "
- resp += comment.author_name if comment.author_name
+ resp += comment.author.display_name if comment.author
resp += " " + comment.created_at.to_s + " ]"
comment_no += 1
end
self.comments.first.author_ip
end
- # Return the author id, derived from the first comment
- def author_id
- self.comments.first.author_id
- end
-
- # Return the author name, derived from the first comment
- def author_name
- self.comments.first.author_name
- end
-
private
# Fill in default values for new notes
validates_associated :author
validates_inclusion_of :event, :in => [ "opened", "closed", "reopened", "commented", "hidden" ]
- # Return the author name
- def author_name
- if self.author_id.nil?
- self.read_attribute(:author_name)
- else
- self.author.display_name
- end
- end
-
# Return the comment text
def body
RichText.new("text", read_attribute(:body))
def signup_confirm(user, token)
@locale = user.preferred_language_from(I18n.available_locales)
-
+
# If we are passed an email address verification token, create
# the confirumation URL for account activation.
#
:display_name => user.display_name,
:confirm_string => token.token)
end
-
+
mail :to => user.email,
:subject => I18n.t('notifier.signup_confirm.subject', :locale => @locale)
end
mail :to => trace.user.email,
:subject => I18n.t('notifier.gpx_notification.failure.subject', :locale => @locale)
end
-
+
def message_notification(message)
@locale = message.recipient.preferred_language_from(I18n.available_locales)
@to_user = message.recipient.display_name
@place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, @locale)
@comment = comment.body
@owner = recipient == comment.note.author
- @commenter = comment.author_name
- subject = I18n.t('notifier.note_comment_notification.subject_own', :commenter => comment.author_name) if @owner
- subject = I18n.t('notifier.note_comment_notification.subject_other', :commenter => comment.author_name) unless @owner
+ if comment.author
+ @commenter = comment.author.display_name
+ else
+ @commenter = I18n.t("notifier.note_comment_notification.anonymous")
+ end
+
+ if @owner
+ subject = I18n.t('notifier.note_comment_notification.subject_own', :commenter => @commenter)
+ else
+ subject = I18n.t('notifier.note_comment_notification.subject_other', :commenter => @commenter)
+ end
mail :to => recipient.email, :subject => subject
end
json.comments(note.comments) do |comment|
json.date comment.created_at
- json.uid comment.author_id unless comment.author_id.nil?
- json.user comment.author_name
+ json.uid comment.author.id unless comment.author.nil?
+ json.user comment.author.display_name unless comment.author.nil?
json.action comment.event
json.text comment.body unless comment.body.nil?
end
xml.link browse_note_url(note)
xml.guid note_url(note)
xml.description render(:partial => "description", :object => note, :formats => [ :html ])
- xml.author note.comments.first.author_name
+
+ if note.author
+ xml.author note.author_display_name
+ end
+
xml.pubDate note.updated_at.to_s(:rfc822)
xml.geo :lat, note.lat
xml.geo :long, note.lon
note.comments.each do |comment|
xml.comment do
xml.date comment.created_at
- xml.uid comment.author_id unless comment.author_id.nil?
- xml.user comment.author_name
+ xml.uid comment.author.id unless comment.author.nil?
+ xml.user comment.author.display_name unless comment.author.nil?
xml.text comment.body
end
end
description_text += comment.note.flatten_comment("<br>", comment.created_at)
xml.description description_text
- xml.author comment.author_name
+
+ if comment.author
+ xml.author comment.author.display_name
+ end
+
xml.pubDate comment.created_at.to_s(:rfc822)
xml.geo :lat, comment.note.lat
xml.geo :long, comment.note.lon
</td>
<td><%= link_to note.id.to_s, :controller => "browse", :action => "note", :id => note.id %></td>
<% if note.author.nil? %>
- <td> <%= note.author_name %> </td>
+ <td></td>
<% else %>
- <td><%= link_to h(note.author_name), :controller => "user", :action => "view", :display_name => note.author_name %></td>
+ <td><%= link_to h(note.author.display_name), user_url(:display_name => note.author.display_name) %></td>
<% end %>
<td> <%= note.comments.first.body.to_html %> </td>
<td><%= l note.created_at %></td>
hopefully_you: "Someone (possibly you) has asked for the password to be reset on this email address's openstreetmap.org account."
click_the_link: "If this is you, please click the link below to reset your password."
note_comment_notification:
+ anonymous: An anonymous user
subject_own: "[OpenStreetMap] %{commenter} has commented on one of your notes"
subject_other: "[OpenStreetMap] %{commenter} has commented on a note you are interested in"
greeting: "Hi,"
show:
title: Note %{id}
event: "%{action} by %{user} at %{time}"
+ anonymous_event: "%{action} by anonymous at %{time}"
close: Close
comment_and_close: Comment & Close
comment: Comment
--- /dev/null
+class RemoveAuthorNameFromNoteComment < ActiveRecord::Migration
+ def up
+ remove_column :note_comments, :author_name
+ end
+
+ def down
+ add_column :note_comments, :author_name, :string
+ end
+end
note_id bigint NOT NULL,
visible boolean NOT NULL,
created_at timestamp without time zone NOT NULL,
- author_name character varying(255),
author_ip character varying(255),
author_id bigint,
body text,
tile bigint NOT NULL,
updated_at timestamp without time zone NOT NULL,
created_at timestamp without time zone NOT NULL,
- nearby_place character varying(255),
status note_status_enum NOT NULL,
closed_at timestamp without time zone
);
INSERT INTO schema_migrations (version) VALUES ('20121012044047');
+INSERT INTO schema_migrations (version) VALUES ('20121119165817');
+
+INSERT INTO schema_migrations (version) VALUES ('20121202155309');
+
INSERT INTO schema_migrations (version) VALUES ('21');
INSERT INTO schema_migrations (version) VALUES ('22');
note_id: 1
visible: true
created_at: 2007-01-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'This is the initial description of the note 1'
note_id: 2
visible: true
created_at: 2007-01-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'This is the initial description of the note 2'
note_id: 2
visible: true
created_at: 2007-02-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'This is an additional comment for note 2'
note_id: 3
visible: true
created_at: 2007-01-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'This is the initial comment for note 3'
note_id: 4
visible: true
created_at: 2007-01-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'Spam for note 4'
note_id: 5
visible: true
created_at: 2007-01-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'Valid comment for note 5'
note_id: 5
visible: false
created_at: 2007-02-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'Spam for note 5'
note_id: 5
visible: true
created_at: 2007-02-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'Another valid comment for note 5'
visible: true
event: opened
created_at: 2007-01-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'Initial note description'
visible: true
event: commented
created_at: 2007-02-01 00:00:00
- author_name: 'testname'
author_ip: '192.168.1.1'
body: 'A comment description'
def test_note_create_success
assert_difference('Note.count') do
assert_difference('NoteComment.count') do
- post :create, {:lat => -1.0, :lon => -1.0, :name => "new_tester", :text => "This is a comment", :format => "json"}
+ post :create, {:lat => -1.0, :lon => -1.0, :text => "This is a comment", :format => "json"}
end
end
assert_response :success
assert_equal 1, js["properties"]["comments"].count
assert_equal "opened", js["properties"]["comments"].last["action"]
assert_equal "This is a comment", js["properties"]["comments"].last["text"]
- assert_equal "new_tester (a)", js["properties"]["comments"].last["user"]
+ assert_nil js["properties"]["comments"].last["user"]
id = js["properties"]["id"]
get :show, {:id => id, :format => "json"}
assert_equal 1, js["properties"]["comments"].count
assert_equal "opened", js["properties"]["comments"].last["action"]
assert_equal "This is a comment", js["properties"]["comments"].last["text"]
- assert_equal "new_tester (a)", js["properties"]["comments"].last["user"]
+ assert_nil js["properties"]["comments"].last["user"]
end
def test_note_create_fail
assert_no_difference('Note.count') do
assert_no_difference('NoteComment.count') do
- post :create, {:lon => -1.0, :name => "new_tester", :text => "This is a comment"}
+ post :create, {:lon => -1.0, :text => "This is a comment"}
end
end
assert_response :bad_request
assert_no_difference('Note.count') do
assert_no_difference('NoteComment.count') do
- post :create, {:lat => -1.0, :name => "new_tester", :text => "This is a comment"}
+ post :create, {:lat => -1.0, :text => "This is a comment"}
end
end
assert_response :bad_request
assert_no_difference('Note.count') do
assert_no_difference('NoteComment.count') do
- post :create, {:lat => -1.0, :lon => -1.0, :name => "new_tester"}
+ post :create, {:lat => -1.0, :lon => -1.0}
end
end
assert_response :bad_request
assert_no_difference('Note.count') do
assert_no_difference('NoteComment.count') do
- post :create, {:lat => -100.0, :lon => -1.0, :name => "new_tester", :text => "This is a comment"}
+ post :create, {:lat => -100.0, :lon => -1.0, :text => "This is a comment"}
end
end
assert_response :bad_request
assert_no_difference('Note.count') do
assert_no_difference('NoteComment.count') do
- post :create, {:lat => -1.0, :lon => -200.0, :name => "new_tester", :text => "This is a comment"}
+ post :create, {:lat => -1.0, :lon => -200.0, :text => "This is a comment"}
end
end
assert_response :bad_request
def test_note_comment_create_success
assert_difference('NoteComment.count') do
- post :comment, {:id => notes(:open_note_with_comment).id, :name => "new_tester2", :text => "This is an additional comment", :format => "json"}
+ post :comment, {:id => notes(:open_note_with_comment).id, :text => "This is an additional comment", :format => "json"}
end
assert_response :success
js = ActiveSupport::JSON.decode(@response.body)
assert_equal 3, js["properties"]["comments"].count
assert_equal "commented", js["properties"]["comments"].last["action"]
assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
- assert_equal "new_tester2 (a)", js["properties"]["comments"].last["user"]
+ assert_nil js["properties"]["comments"].last["user"]
get :show, {:id => notes(:open_note_with_comment).id, :format => "json"}
assert_response :success
assert_equal 3, js["properties"]["comments"].count
assert_equal "commented", js["properties"]["comments"].last["action"]
assert_equal "This is an additional comment", js["properties"]["comments"].last["text"]
- assert_equal "new_tester2 (a)", js["properties"]["comments"].last["user"]
+ assert_nil js["properties"]["comments"].last["user"]
end
def test_note_comment_create_fail
assert_no_difference('NoteComment.count') do
- post :comment, {:name => "new_tester2", :text => "This is an additional comment"}
+ post :comment, {:text => "This is an additional comment"}
end
assert_response :bad_request
assert_no_difference('NoteComment.count') do
- post :comment, {:id => notes(:open_note_with_comment).id, :name => "new_tester2"}
+ post :comment, {:id => notes(:open_note_with_comment).id}
end
assert_response :bad_request
assert_no_difference('NoteComment.count') do
- post :comment, {:id => 12345, :name => "new_tester2", :text => "This is an additional comment"}
+ post :comment, {:id => 12345, :text => "This is an additional comment"}
end
assert_response :not_found
assert_no_difference('NoteComment.count') do
- post :comment, {:id => notes(:hidden_note_with_comment).id, :name => "new_tester2", :text => "This is an additional comment"}
+ post :comment, {:id => notes(:hidden_note_with_comment).id, :text => "This is an additional comment"}
end
assert_response :gone
end
assert_equal 3, js["properties"]["comments"].count
assert_equal "closed", js["properties"]["comments"].last["action"]
assert_equal "This is a close comment", js["properties"]["comments"].last["text"]
- assert_equal "NoName (a)", js["properties"]["comments"].last["user"]
+ assert_nil js["properties"]["comments"].last["user"]
get :show, {:id => notes(:open_note_with_comment).id, :format => "json"}
assert_response :success
assert_equal 3, js["properties"]["comments"].count
assert_equal "closed", js["properties"]["comments"].last["action"]
assert_equal "This is a close comment", js["properties"]["comments"].last["text"]
- assert_equal "NoName (a)", js["properties"]["comments"].last["user"]
+ assert_nil js["properties"]["comments"].last["user"]
end
def test_note_close_fail