Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Render votes RSS feed #180

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/discourse_topic_voting/list_controller_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module DiscourseTopicVoting
module ListControllerExtension
def self.prepended(base)
base.class_eval do
before_action :ensure_discourse_topic_voting, only: %i[voted_by]
skip_before_action :ensure_logged_in, only: %i[voted_by]
before_action :ensure_discourse_topic_voting, only: %i[voted_by votes_feed]
skip_before_action :ensure_logged_in, only: %i[voted_by votes_feed]
end
end

Expand All @@ -18,6 +18,15 @@ def voted_by
respond_with_list(list)
end

def votes_feed
category_slug_path_with_id = params.require(:category_slug_path_with_id)

@category = Category.find_by_slug_path_with_id(category_slug_path_with_id)
@topic_list = TopicQuery.new(current_user, { category: @category.id }).list_votes

render "list", formats: [:rss]
end

protected

def ensure_discourse_topic_voting
Expand Down
4 changes: 4 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ class Engine < ::Rails::Engine
get "who" => "votes#who"
end

Discourse::Application.routes.prepend do
get "c/*category_slug_path_with_id/l/votes.rss" => "list#votes_feed", :format => :rss
end

Discourse::Application.routes.append do
mount ::DiscourseTopicVoting::Engine, at: "/voting"

Expand Down
28 changes: 28 additions & 0 deletions spec/requests/lists_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,32 @@

expect(response.status).to eq(404)
end

context "in a category" do
fab!(:category1) { Fabricate(:category) }
fab!(:category2) { Fabricate(:category) }
fab!(:topic1) do
Fabricate(:topic, category: category1, title: "Topic in votes-enabled category 1")
end
fab!(:topic2) do
Fabricate(:topic, category: category2, title: "Topic in votes-enabled category 2")
end

before do
DiscourseTopicVoting::CategorySetting.create!(category: category1)
DiscourseTopicVoting::CategorySetting.create!(category: category2)
end

it "allows anons to view votes RSS feed" do
DiscourseTopicVoting::Vote.create!(user: user, topic: topic1)
DiscourseTopicVoting::Vote.create!(user: user, topic: topic2)

get "/c/#{category2.slug}/#{category2.id}/l/votes.rss"

expect(response.status).to eq(200)
expect(response.body).to include(topic2.title)
# ensure we don't include votes from other categories
expect(response.body).not_to include(topic1.title)
end
end
end