Skip to content

Commit

Permalink
Merge pull request #2415 from tvdeyen/remove-rss-feed
Browse files Browse the repository at this point in the history
Remove RSS Feed feature
  • Loading branch information
tvdeyen authored Jan 21, 2023
2 parents bef444b + 6ffa05d commit 6728310
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 211 deletions.
47 changes: 19 additions & 28 deletions app/controllers/alchemy/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ def locale_prefix_not_allowed?
# If no index page and no admin users are present we show the "Welcome to Alchemy" page.
#
def load_index_page
@page ||= begin
Alchemy::Page.
contentpages.
language_roots.
where(language: Language.current).
includes(page_includes).
first
end
@page ||= Alchemy::Page
.contentpages
.language_roots
.where(language: Language.current)
.includes(page_includes)
.first

render template: "alchemy/welcome", layout: false if signup_required?
end

Expand All @@ -127,13 +126,11 @@ def load_index_page
def load_page
page_not_found! unless Language.current

@page ||= begin
Alchemy::Page.
contentpages.
where(language: Language.current).
includes(page_includes).
find_by(urlname: params[:urlname])
end
@page ||= Alchemy::Page
.contentpages
.where(language: Language.current)
.includes(page_includes)
.find_by(urlname: params[:urlname])
end

def enforce_locale
Expand Down Expand Up @@ -178,7 +175,7 @@ def additional_params

# == Renders the page :show template
#
# Handles html and rss requests (for pages containing a feed)
# Handles html requests
#
# Omits the layout, if the request is a XHR request.
#
Expand All @@ -187,14 +184,6 @@ def render_page
format.html do
render action: :show, layout: !request.xhr?
end

format.rss do
if @page.contains_feed?
render action: :show, layout: false, handlers: [:builder]
else
render xml: { error: "Not found" }, status: 404
end
end
end
end

Expand Down Expand Up @@ -230,10 +219,12 @@ def page_etag
# or the cache is stale, because it's been republished by the user.
#
def render_fresh_page?
must_not_cache? || stale?(etag: page_etag,
last_modified: @page.published_at,
public: !@page.restricted,
template: "pages/show")
must_not_cache? || stale?(
etag: page_etag,
last_modified: @page.published_at,
public: !@page.restricted,
template: "pages/show",
)
end

# don't cache pages if we have flash message to display or the page has caching disabled
Expand Down
35 changes: 0 additions & 35 deletions app/models/alchemy/element/element_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,6 @@ def copy_contents_to(element)
end
end

# Returns the content that is marked as rss title.
#
# Mark a content as rss title in your +elements.yml+ file:
#
# - name: news
# contents:
# - name: headline
# type: EssenceText
# rss_title: true
#
def content_for_rss_title
content_for_rss_meta("title")
end

# Returns the content that is marked as rss description.
#
# Mark a content as rss description in your +elements.yml+ file:
#
# - name: news
# contents:
# - name: body
# type: EssenceRichtext
# rss_description: true
#
def content_for_rss_description
content_for_rss_meta("description")
end

# Returns the array with the hashes for all element contents in the elements.yml file
def content_definitions
return nil if definition.blank?
Expand Down Expand Up @@ -138,13 +110,6 @@ def contents_with_errors

private

def content_for_rss_meta(type)
definition = content_definitions.detect { |c| c["rss_#{type}"] }
return if definition.blank?

contents.detect { |content| content.name == definition["name"] }
end

# creates the contents for this element as described in the elements.yml
#
# If ingredients are defined as well no contents get created,
Expand Down
12 changes: 0 additions & 12 deletions app/models/alchemy/page/page_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ def element_definitions_by_name(names)
end
end

# Returns all elements that should be feeded via rss.
#
# Define feedable elements in your +page_layouts.yml+:
#
# - name: news
# feed: true
# feed_elements: [element_name, element_2_name]
#
def feed_elements
elements.named(definition["feed_elements"])
end

# Returns an array of all EssenceRichtext contents ids from not folded elements
#
def richtext_contents_ids
Expand Down
4 changes: 0 additions & 4 deletions app/models/alchemy/page/page_natures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def folded?(user_id)
folded_pages.where(user_id: user_id, folded: true).any?
end

def contains_feed?
definition["feed"]
end

# Returns an Array of Alchemy roles which are able to edit this template
#
# # config/alchemy/page_layouts.yml
Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/pages/_meta_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<%= tag(:meta, name: 'robots', content: meta_robots) %>
<%= tag(:meta, name: 'description', content: meta_description, lang: @page.language_code) if meta_description.present? %>
<%= tag(:meta, name: 'keywords', content: meta_keywords, lang: @page.language_code) if meta_keywords.present? %>
<%= auto_discovery_link_tag(:rss, show_alchemy_page_url(@page, format: :rss)) if @page.contains_feed? %>
<% end %>
21 changes: 0 additions & 21 deletions app/views/alchemy/pages/show.rss.builder

This file was deleted.

6 changes: 3 additions & 3 deletions lib/alchemy/routing_constraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Alchemy
# Alchemy has a very strong catch all route.
# But we don't want to handle all requests.
#
# For instance we only want to handle html and rss requests and
# For instance we only want to handle html requests and
# don't want to swallow the rails/info routes in development mode.
#
class RoutingConstraints
Expand All @@ -21,13 +21,13 @@ def matches?(request)

private

# We only want html and rss requests to be handled by us.
# We only want html requests to be handled by us.
#
# If an unknown format is requested we want to handle this,
# because it could be a legacy route that needs to be redirected.
#
def handable_format?
@request.format.symbol.nil? || (@request.format.symbol == :html) || (@request.format.symbol == :rss)
@request.format.symbol.nil? || (@request.format.symbol == :html)
end

# We don't want to handle the Rails info routes.
Expand Down
22 changes: 0 additions & 22 deletions spec/controllers/alchemy/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,6 @@ module Alchemy
end
end

context "requested for a page containing a feed" do
render_views

it "should render a rss feed" do
get :show, params: { urlname: page.urlname, format: :rss }
expect(response.media_type).to eq("application/rss+xml")
end

it "should include content" do
page.elements.first.content_by_name("news_headline").essence.update_columns(body: "Peters Petshop")
get :show, params: { urlname: "news", format: :rss }
expect(response.body).to match /Peters Petshop/
end
end

context "requested for a page that does not contain a feed" do
it "should render xml 404 error" do
get :show, params: { urlname: default_language_root.urlname, format: :rss }
expect(response.status).to eq(404)
end
end

describe "Layout rendering" do
context "with ajax request" do
it "should not render a layout" do
Expand Down
2 changes: 0 additions & 2 deletions spec/dummy/config/alchemy/elements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@
type: EssenceDate
- name: news_headline
type: EssenceText
rss_title: true
- name: body
type: EssenceRichtext
rss_description: true

- name: download
contents:
Expand Down
2 changes: 0 additions & 2 deletions spec/dummy/config/alchemy/page_layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
autogenerate: [all_you_can_eat, right_column, left_column]

- name: news
feed: true
unique: true
insert_elements_at: top
elements: [headline, news]
autogenerate: [news]
feed_elements: [news]

- name: contact
unique: true
Expand Down
24 changes: 0 additions & 24 deletions spec/models/alchemy/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,30 +823,6 @@ module Alchemy
end
end
end

it "should return the content for rss title" do
expect(element.content_for_rss_title).to eq(element.contents.find_by_name("news_headline"))
end

it "should return the content for rss descdefinitionription" do
expect(element.content_for_rss_description).to eq(element.contents.find_by_name("body"))
end

context "if no content is defined as rss title" do
before { expect(element).to receive(:content_definitions).and_return([]) }

it "should return nil" do
expect(element.content_for_rss_title).to be_nil
end
end

context "if no content is defined as rss description" do
before { expect(element).to receive(:content_definitions).and_return([]) }

it "should return nil" do
expect(element.content_for_rss_description).to be_nil
end
end
end

describe "#update_contents" do
Expand Down
14 changes: 0 additions & 14 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1029,20 +1029,6 @@ class AnotherUrlPathClass; end
end
end

describe "#feed_elements" do
let(:news_page) { create(:alchemy_page, :public, name: "News", page_layout: "news") }
let(:news_element) { create(:alchemy_element, name: "news", page: news_page, page_version: news_page.public_version) }
let(:unpublic_news_element) { create(:alchemy_element, name: "news", public: false, page: news_page, page_version: news_page.draft_version) }

it "should return all published rss feed elements" do
expect(news_page.feed_elements).to eq([news_element])
end

it "should not return unpublished rss feed elements" do
expect(news_page.feed_elements).not_to include(unpublic_news_element)
end
end

describe "#find_elements" do
subject { page.find_elements(options) }

Expand Down
2 changes: 0 additions & 2 deletions spec/models/alchemy/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ module Alchemy
"headline",
"news",
],
"feed" => true,
"feed_elements" => ["news"],
"insert_elements_at" => "top",
"unique" => true,
},
Expand Down
15 changes: 1 addition & 14 deletions spec/routing/routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,6 @@
end
end

describe "rss feed requests" do
it "should be handled by alchemy/pages controller" do
expect({
get: "/news.rss",
}).to route_to(
controller: "alchemy/pages",
action: "show",
urlname: "news",
format: "rss",
)
end
end

describe "unknown formats" do
it "should be handled by alchemy/pages controller" do
expect({
Expand Down Expand Up @@ -232,7 +219,7 @@
context "customized" do
before(:all) do
Alchemy.admin_path = "backend"
Alchemy.admin_constraints = {subdomain: "hidden"}
Alchemy.admin_constraints = { subdomain: "hidden" }
Rails.application.reload_routes!
end

Expand Down
Loading

0 comments on commit 6728310

Please sign in to comment.