Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/4576'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Mar 14, 2024
2 parents 5ba71f9 + d87d06f commit 3b143dc
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 235 deletions.
4 changes: 2 additions & 2 deletions app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Ability
include CanCan::Ability

def initialize(user)
can [:relation, :relation_history, :way, :way_history, :node, :node_history, :query], :browse
can [:show], [OldNode, OldWay, OldRelation]
can [:relation, :way, :node, :query], :browse
can [:index, :show], [OldNode, OldWay, OldRelation]
can [:show, :new], Note
can :search, :direction
can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
Expand Down
31 changes: 0 additions & 31 deletions app/controllers/browse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class BrowseController < ApplicationController
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth
before_action :update_totp, :only => [:query]
before_action :require_moderator_for_unredacted_history, :only => [:relation_history, :way_history, :node_history]
around_action :web_timeout
authorize_resource :class => false

Expand All @@ -18,14 +17,6 @@ def relation
render :action => "not_found", :status => :not_found
end

def relation_history
@type = "relation"
@feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end

def way
@type = "way"
@feature = Way.preload(:way_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :nodes => [:node_tags, { :ways => :way_tags }]).find(params[:id])
Expand All @@ -34,14 +25,6 @@ def way
render :action => "not_found", :status => :not_found
end

def way_history
@type = "way"
@feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end

def node
@type = "node"
@feature = Node.preload(:node_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :ways => :way_tags).find(params[:id])
Expand All @@ -50,19 +33,5 @@ def node
render :action => "not_found", :status => :not_found
end

def node_history
@type = "node"
@feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end

def query; end

private

def require_moderator_for_unredacted_history
deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
end
end
8 changes: 8 additions & 0 deletions app/controllers/old_nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class OldNodesController < ApplicationController
before_action :require_moderator_for_unredacted_history
around_action :web_timeout

def index
@type = "node"
@feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
render "browse/history"
rescue ActiveRecord::RecordNotFound
render "browse/not_found", :status => :not_found
end

def show
@type = "node"
@feature = OldNode.preload(:old_tags, :changeset => [:changeset_tags, :user]).find([params[:id], params[:version]])
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/old_relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class OldRelationsController < ApplicationController
before_action :require_moderator_for_unredacted_history
around_action :web_timeout

def index
@type = "relation"
@feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
render "browse/history"
rescue ActiveRecord::RecordNotFound
render "browse/not_found", :status => :not_found
end

def show
@type = "relation"
@feature = OldRelation.preload(:old_tags, :changeset => [:changeset_tags, :user], :old_members => :member).find([params[:id], params[:version]])
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/old_ways_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class OldWaysController < ApplicationController
before_action :require_moderator_for_unredacted_history
around_action :web_timeout

def index
@type = "way"
@feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
render "browse/history"
rescue ActiveRecord::RecordNotFound
render "browse/not_found", :status => :not_found
end

def show
@type = "way"
@feature = OldWay.preload(:old_tags, :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] }).find([params[:id], params[:version]])
Expand Down
2 changes: 1 addition & 1 deletion app/views/browse/_version_actions.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<% end %>
&middot;
<% end %>
<%= link_to t("browse.view_history"), :controller => :browse, :action => "#{@type}_history" %>
<%= link_to t("browse.view_history"), :action => :index %>
<% unless @feature.latest_version? %>
&middot;
<%= link_to({ :version => @feature.version + 1 }, { :class => "icon-link" }) do %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/browse/feature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<% end %>
&middot;
<% end %>
<%= link_to t("browse.view_history"), :action => "#{@type}_history" %>
<%= link_to t("browse.view_history"), :controller => "old_#{@type.pluralize}" %>
<% if current_user&.moderator? %>
&middot;
<%= link_to(t("browse.view_unredacted_history"), :action => "#{@type}_history", :params => { :show_redactions => true }) %>
<%= link_to(t("browse.view_unredacted_history"), :controller => "old_#{@type.pluralize}", :params => { :show_redactions => true }) %>
<% end %>
<% if @feature.version > 1 %>
&middot;
Expand Down
10 changes: 5 additions & 5 deletions app/views/browse/history.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

<%= render "sidebar_header", :title => t("browse.#{@type}.history_title_html", :name => printable_element_name(@feature)) %>

<%= render :partial => @type, :collection => @feature.send(:"old_#{@type}s").reverse %>
<%= render :partial => "browse/#{@type}", :collection => @feature.send(:"old_#{@type}s").reverse %>

<div class='secondary-actions'>
<%= link_to(t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => "history") %>
<%= link_to t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => "history" %>
&middot;
<%= link_to(t("browse.view_details"), :action => @type) %>
<%= link_to t("browse.view_details"), :controller => "browse", :action => @type %>
<% if params[:show_redactions] %>
&middot;
<%= link_to(t("browse.view_history"), :action => "#{@type}_history") %>
<%= link_to t("browse.view_history") %>
<% elsif current_user&.moderator? %>
&middot;
<%= link_to(t("browse.view_unredacted_history"), :action => "#{@type}_history", :params => { :show_redactions => true }) %>
<%= link_to t("browse.view_unredacted_history"), :params => { :show_redactions => true } %>
<% end %>
</div>
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@

# Data browsing
get "/way/:id" => "browse#way", :id => /\d+/, :as => :way
get "/way/:id/history" => "browse#way_history", :id => /\d+/, :as => :way_history
get "/way/:id/history" => "old_ways#index", :id => /\d+/, :as => :way_history
resources :old_ways, :path => "/way/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "/node/:id" => "browse#node", :id => /\d+/, :as => :node
get "/node/:id/history" => "browse#node_history", :id => /\d+/, :as => :node_history
get "/node/:id/history" => "old_nodes#index", :id => /\d+/, :as => :node_history
resources :old_nodes, :path => "/node/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "/relation/:id" => "browse#relation", :id => /\d+/, :as => :relation
get "/relation/:id/history" => "browse#relation_history", :id => /\d+/, :as => :relation_history
get "/relation/:id/history" => "old_relations#index", :id => /\d+/, :as => :relation_history
resources :old_relations, :path => "/relation/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
resources :changesets, :path => "changeset", :id => /\d+/, :only => :show
get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" }
Expand Down
Loading

0 comments on commit 3b143dc

Please sign in to comment.