Skip to content

Commit

Permalink
Move browse#note to notes#show
Browse files Browse the repository at this point in the history
This allows a more resourceful routing approach.
  • Loading branch information
gravitystorm committed Feb 1, 2023
1 parent b5046fd commit 9748ce3
Show file tree
Hide file tree
Showing 22 changed files with 175 additions and 138 deletions.
4 changes: 2 additions & 2 deletions app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Ability

def initialize(user)
can [:relation, :relation_history, :way, :way_history, :node, :node_history,
:changeset, :note, :query], :browse
can [:new], Note
:changeset, :query], :browse
can [:show, :new], Note
can :search, :direction
can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
can [:finish, :embed], :export
Expand Down
14 changes: 0 additions & 14 deletions app/controllers/browse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,5 @@ def changeset
render :action => "not_found", :status => :not_found
end

def note
@type = "note"

if current_user&.moderator?
@note = Note.find(params[:id])
@note_comments = @note.comments.unscope(:where => :visible)
else
@note = Note.visible.find(params[:id])
@note_comments = @note.comments
end
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end

def query; end
end
14 changes: 14 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,19 @@ def index
end
end

def show
@type = "note"

if current_user&.moderator?
@note = Note.find(params[:id])
@note_comments = @note.comments.unscope(:where => :visible)
else
@note = Note.visible.find(params[:id])
@note_comments = @note.comments
end
rescue ActiveRecord::RecordNotFound
render :template => "browse/not_found", :status => :not_found
end

def new; end
end
2 changes: 1 addition & 1 deletion app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def redirect_browse_params
elsif params[:relation]
redirect_to relation_path(params[:relation])
elsif params[:note]
redirect_to browse_note_path(params[:note])
redirect_to note_path(params[:note])
elsif params[:query]
redirect_to search_path(:query => params[:query])
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/issues_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def reportable_url(reportable)
when DiaryComment
diary_entry_url(reportable.diary_entry.user, reportable.diary_entry, :anchor => "comment#{reportable.id}")
when Note
url_for(:controller => :browse, :action => :note, :id => reportable.id)
note_url(reportable)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/note_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module NoteHelper

def note_event(event, at, by)
if by.nil?
t("browse.note.#{event}_by_anonymous_html",
t("notes.show.#{event}_by_anonymous_html",
:when => friendly_date_ago(at),
:exact_time => l(at))
else
t("browse.note.#{event}_by_html",
t("notes.show.#{event}_by_html",
:when => friendly_date_ago(at),
:exact_time => l(at),
:user => note_author(by))
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def friendship_notification(friendship)

def note_comment_notification(comment, recipient)
with_recipient_locale recipient do
@noteurl = browse_note_url(comment.note)
@noteurl = note_url(comment.note)
@place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
@comment = comment.body
@owner = recipient == comment.note.author
Expand Down
4 changes: 2 additions & 2 deletions app/views/api/notes/_note.gpx.builder
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
xml.wpt("lon" => note.lon, "lat" => note.lat) do
xml.time note.created_at.to_fs(:iso8601)
xml.name t("browse.note.title", :id => note.id)
xml.name t("notes.show.title", :id => note.id)

xml.desc do
xml.cdata! render(:partial => "description", :object => note, :formats => [:html])
end

xml.link("href" => browse_note_url(note, :only_path => false))
xml.link("href" => note_url(note, :only_path => false))

xml.extensions do
xml.id note.id
Expand Down
2 changes: 1 addition & 1 deletion app/views/api/notes/_note.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ xml.item do
xml.title t("api.notes.rss.opened", :place => location)
end

xml.link browse_note_url(note)
xml.link note_url(note)
xml.guid api_note_url(note)
xml.description render(:partial => "description", :object => note, :formats => [:html])

Expand Down
4 changes: 2 additions & 2 deletions app/views/api/notes/feed.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ xml.rss("version" => "2.0",
xml.item do
xml.title t("api.notes.rss.#{comment.event}", :place => location)

xml.link url_for(:controller => "/browse", :action => "note", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false)
xml.guid url_for(:controller => "/browse", :action => "note", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false)
xml.link url_for(:controller => "/notes", :action => "show", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false)
xml.guid url_for(:controller => "/notes", :action => "show", :id => comment.note.id, :anchor => "c#{comment.id}", :only_path => false)

xml.description do
xml.cdata! render(:partial => "entry", :object => comment, :formats => [:html])
Expand Down
2 changes: 1 addition & 1 deletion app/views/notes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<%= image_tag("open_note_marker.png", :alt => "open", :size => "25x40") %>
<% end %>
</td>
<td><%= link_to note.id, browse_note_path(note) %></td>
<td><%= link_to note.id, note %></td>
<td><%= note_author(note.author) %></td>
<td><%= note.comments.first.body.to_html %></td>
<td><%= friendly_date_ago(note.created_at) %></td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notes/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% set_title(t("browse.note.new_note")) %>
<% set_title(t(".title")) %>
<%= render "sidebar_header", :title => t("browse.note.new_note") %>
<%= render "sidebar_header", :title => t(".title") %>

<div class="note">
<p class="alert alert-info"><%= t("javascripts.notes.new.intro") %></p>
Expand Down
File renamed without changes.
37 changes: 19 additions & 18 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,24 +407,6 @@ en:
telephone_link: "Call %{phone_number}"
colour_preview: "Colour %{colour_value} preview"
email_link: "Email %{email}"
note:
title: "Note: %{id}"
new_note: "New Note"
description: "Description"
open_title: "Unresolved note #%{note_name}"
closed_title: "Resolved note #%{note_name}"
hidden_title: "Hidden note #%{note_name}"
opened_by_html: "Created by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
opened_by_anonymous_html: "Created by anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
commented_by_html: "Comment from %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
commented_by_anonymous_html: "Comment from anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
closed_by_html: "Resolved by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
closed_by_anonymous_html: "Resolved by anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
reopened_by_html: "Reactivated by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
reopened_by_anonymous_html: "Reactivated by anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
hidden_by_html: "Hidden by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
report: report this note
coordinates_html: "%{latitude}, %{longitude}"
query:
title: "Query Features"
introduction: "Click on the map to find nearby features."
Expand Down Expand Up @@ -2837,6 +2819,25 @@ en:
description: "Description"
created_at: "Created at"
last_changed: "Last changed"
show:
title: "Note: %{id}"
description: "Description"
open_title: "Unresolved note #%{note_name}"
closed_title: "Resolved note #%{note_name}"
hidden_title: "Hidden note #%{note_name}"
opened_by_html: "Created by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
opened_by_anonymous_html: "Created by anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
commented_by_html: "Comment from %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
commented_by_anonymous_html: "Comment from anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
closed_by_html: "Resolved by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
closed_by_anonymous_html: "Resolved by anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
reopened_by_html: "Reactivated by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
reopened_by_anonymous_html: "Reactivated by anonymous <abbr title='%{exact_time}'>%{when}</abbr>"
hidden_by_html: "Hidden by %{user} <abbr title='%{exact_time}'>%{when}</abbr>"
report: report this note
coordinates_html: "%{latitude}, %{longitude}"
new:
title: "New Note"
javascripts:
close: Close
share:
Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@
get "/relation/:id/history" => "browse#relation_history", :id => /\d+/, :as => :relation_history
get "/changeset/:id" => "browse#changeset", :as => :changeset, :id => /\d+/
get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" }
get "/note/:id" => "browse#note", :id => /\d+/, :as => "browse_note"
resources :notes, :path => "note", :only => [:new]
resources :notes, :path => "note", :only => [:show, :new]

get "/user/:display_name/history" => "changesets#index"
get "/user/:display_name/history/feed" => "changesets#feed", :defaults => { :format => :atom }
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/api/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_show_success
assert_select "rss", :count => 1 do
assert_select "channel", :count => 1 do
assert_select "item", :count => 1 do
assert_select "link", browse_note_url(open_note)
assert_select "link", note_url(open_note)
assert_select "guid", api_note_url(open_note)
assert_select "pubDate", open_note.created_at.to_fs(:rfc822)
assert_select "geo|lat", open_note.lat.to_s
Expand Down
76 changes: 0 additions & 76 deletions test/controllers/browse_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def test_routes
{ :path => "/changeset/1", :method => :get },
{ :controller => "browse", :action => "changeset", :id => "1" }
)
assert_routing(
{ :path => "/note/1", :method => :get },
{ :controller => "browse", :action => "note", :id => "1" }
)
assert_routing(
{ :path => "/query", :method => :get },
{ :controller => "browse", :action => "query" }
Expand Down Expand Up @@ -102,78 +98,6 @@ def test_read_changeset_hidden_comments
assert_select "div.changeset-comments ul li", :count => 4
end

def test_read_note
open_note = create(:note_with_comments)

browse_check :browse_note_path, open_note.id, "browse/note"
end

def test_read_hidden_note
hidden_note_with_comment = create(:note_with_comments, :status => "hidden")

get browse_note_path(:id => hidden_note_with_comment)
assert_response :not_found
assert_template "browse/not_found"
assert_template :layout => "map"

get browse_note_path(:id => hidden_note_with_comment), :xhr => true
assert_response :not_found
assert_template "browse/not_found"
assert_template :layout => "xhr"

session_for(create(:moderator_user))

browse_check :browse_note_path, hidden_note_with_comment.id, "browse/note"
end

def test_read_note_hidden_comments
note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
create(:note_comment, :note => note, :visible => false)
end

browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1

session_for(create(:moderator_user))

browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 2
end

def test_read_note_hidden_user_comment
hidden_user = create(:user, :deleted)
note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note|
create(:note_comment, :note => note, :author => hidden_user)
end

browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1

session_for(create(:moderator_user))

browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1
end

def test_read_closed_note
user = create(:user)
closed_note = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc, :comments_count => 2) do |note|
create(:note_comment, :event => "closed", :note => note, :author => user)
end

browse_check :browse_note_path, closed_note.id, "browse/note"
assert_select "div.note-comments ul li", :count => 2
assert_select "div.details", /Resolved by #{user.display_name}/

user.soft_destroy!

reset!

browse_check :browse_note_path, closed_note.id, "browse/note"
assert_select "div.note-comments ul li", :count => 1
assert_select "div.details", /Resolved by deleted/
end

##
# Methods to check redaction.
#
Expand Down

0 comments on commit 9748ce3

Please sign in to comment.