authorize_resource
+ before_action :require_moderator_for_unredacted_history
around_action :web_timeout
def show
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
+
+ private
+
+ def require_moderator_for_unredacted_history
+ deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+ end
end
authorize_resource
+ before_action :require_moderator_for_unredacted_history
around_action :web_timeout
def show
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
+
+ private
+
+ def require_moderator_for_unredacted_history
+ deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+ end
end
authorize_resource
+ before_action :require_moderator_for_unredacted_history
around_action :web_timeout
def show
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
+
+ private
+
+ def require_moderator_for_unredacted_history
+ deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+ end
end
end
def test_redacted
- node = create(:node, :with_history, :deleted, :version => 2)
- node_v1 = node.old_nodes.find_by(:version => 1)
- node_v1.redact!(create(:redaction))
+ node = create_redacted_node
get old_node_path(node, 1)
assert_response :success
assert_template "old_nodes/show"
assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
end
+ test "don't show redacted versions to anonymous users" do
+ node = create_redacted_node
+ get old_node_path(node, 1, :params => { :show_redactions => true })
+ assert_response :redirect
+ end
+
+ test "don't show redacted versions to regular users" do
+ session_for(create(:user))
+ node = create_redacted_node
+ get old_node_path(node, 1, :params => { :show_redactions => true })
+ assert_response :redirect
+ end
+
+ test "show redacted versions to moderators" do
+ session_for(create(:moderator_user))
+ node = create_redacted_node
+ get old_node_path(node, 1, :params => { :show_redactions => true })
+ assert_response :success
+ end
+
def test_not_found
get old_node_path(0, 0)
assert_response :not_found
assert_template :layout => "map"
assert_select "#sidebar_content", /node #0 version 0 could not be found/
end
+
+ private
+
+ def create_redacted_node
+ create(:node, :with_history, :deleted, :version => 2) do |node|
+ node_v1 = node.old_nodes.find_by(:version => 1)
+ node_v1.redact!(create(:redaction))
+ end
+ end
end
end
def test_redacted
- relation = create(:relation, :with_history, :deleted, :version => 2)
- relation_v1 = relation.old_relations.find_by(:version => 1)
- relation_v1.redact!(create(:redaction))
+ relation = create_redacted_relation
get old_relation_path(relation, 1)
assert_response :success
assert_template "old_relations/show"
assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 0
end
+ test "don't show redacted versions to anonymous users" do
+ relation = create_redacted_relation
+ get old_relation_path(relation, 1, :params => { :show_redactions => true })
+ assert_response :redirect
+ end
+
+ test "don't show redacted versions to regular users" do
+ session_for(create(:user))
+ relation = create_redacted_relation
+ get old_relation_path(relation, 1, :params => { :show_redactions => true })
+ assert_response :redirect
+ end
+
+ test "show redacted versions to moderators" do
+ session_for(create(:moderator_user))
+ relation = create_redacted_relation
+ get old_relation_path(relation, 1, :params => { :show_redactions => true })
+ assert_response :success
+ end
+
def test_not_found
get old_relation_path(0, 0)
assert_response :not_found
assert_template :layout => "map"
assert_select "#sidebar_content", /relation #0 version 0 could not be found/
end
+
+ private
+
+ def create_redacted_relation
+ create(:relation, :with_history, :deleted, :version => 2) do |relation|
+ relation_v1 = relation.old_relations.find_by(:version => 1)
+ relation_v1.redact!(create(:redaction))
+ end
+ end
end
end
def test_redacted
- way = create(:way, :with_history, :deleted, :version => 2)
- way_v1 = way.old_ways.find_by(:version => 1)
- way_v1.redact!(create(:redaction))
+ way = create_redacted_way
get old_way_path(way, 1)
assert_response :success
assert_template "old_ways/show"
assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
end
+ test "don't show redacted versions to anonymous users" do
+ way = create_redacted_way
+ get old_way_path(way, 1, :params => { :show_redactions => true })
+ assert_response :redirect
+ end
+
+ test "don't show redacted versions to regular users" do
+ session_for(create(:user))
+ way = create_redacted_way
+ get old_way_path(way, 1, :params => { :show_redactions => true })
+ assert_response :redirect
+ end
+
+ test "show redacted versions to moderators" do
+ session_for(create(:moderator_user))
+ way = create_redacted_way
+ get old_way_path(way, 1, :params => { :show_redactions => true })
+ assert_response :success
+ end
+
def test_not_found
get old_way_path(0, 0)
assert_response :not_found
assert_template :layout => "map"
assert_select "#sidebar_content", /way #0 version 0 could not be found/
end
+
+ private
+
+ def create_redacted_way
+ create(:way, :with_history, :deleted, :version => 2) do |way|
+ way_v1 = way.old_ways.find_by(:version => 1)
+ way_v1.redact!(create(:redaction))
+ end
+ end
end