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

RSS feed on tagged content for author pages #2161

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,24 @@ def rss
end
end

def rss_for_tagged_with_author
@user = User.find_by(name: params[:author])
@notes = Tag.tagged_nodes_by_author([params[:tagname]], @user)
.limit(20)
respond_to do |format|
format.rss do
response.headers['Content-Type'] = 'application/xml; charset=utf-8'
response.headers['Access-Control-Allow-Origin'] = '*'
render layout: false
end
format.ics do
response.headers['Content-Disposition'] = "attachment; filename='public-lab-events.ics'"
response.headers['Content-Type'] = 'text/calendar; charset=utf-8'
render layout: false, template: 'tag/icalendar.ics', filename: 'public-lab-events.ics'
end
end
end

def contributors
set_sidebar :tags, [params[:id]], note_count: 20
@tagnames = [params[:id]]
Expand Down
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def self.tagged_nodes_by_author(tagname, user_id)
@wildcard = true
Node.where('term_data.name LIKE(?)', tagname[0..-2]+'%')
.includes(:node_tag, :tag)
.order('node.nid DESC')
.references(:term_data)
.order('node.nid DESC')
.where('node.uid = ?', user_id)
else
Node.where('term_data.name = ?', tagname)
Expand Down
38 changes: 38 additions & 0 deletions app/views/tag/rss_for_tagged_with_author.rss.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do
xml.channel do
xml.title "Research tagged '#{params[:tagname]}' by #{params[:authorname]}"
xml.description "Open source environmental science research at Public Lab"
xml.link "https://#{request.host}/feed/tag/"+params[:tagname]+"/author/"+"params[:authorname]"+".rss"

@notes.each do |node|

body = node.body
uname = node.author.username
email = node.author.email
if node.author.user.has_power_tag('twitter')
uname = node.author.user.get_value_of_power_tag('twitter')
end
author_format = "@#{uname} (#{email})"
xml.item do
xml.title " #{node.title}"
xml.author author_format
if node.power_tag('date') != ''
begin
xml.pubDate DateTime.strptime(node.power_tag('date'), "%m-%d-%Y").rfc822
rescue
xml.pubDate node.power_tag('date')
end
else
xml.pubDate node.created_at.to_s(:rfc822)
end
xml.link "https://" + request.host.to_s + node.path
if node.main_image
xml.description { xml.cdata!("<img src='#{node.main_image.path(:default)}' alt='#{node.main_image.title}'>") }
else
xml.description { xml.cdata!("<img src='https://i.publiclab.org/system/images/photos/000/000/354/medium/Boots-ground-02.png' alt='PublicLab'><p>#{body}</p>") }
end
xml.guid url_for :only_path => false, :controller => 'notes', :action => 'show', :id => node.nid
end
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
# these need precedence for tag listings
get 'feed/tag/:tagname' => 'tag#rss'
get ':node_type/tag(/:id)' => 'tag#show'
get 'feed/tag/:tagname/author/:authorname' => 'tag#rss_for_tagged_with_author'
get 'wiki/raw/:id' => 'wiki#raw'
get 'wiki/revisions/:id' => 'wiki#revisions'
get 'wiki/revert/:id' => 'wiki#revert'
Expand Down
6 changes: 6 additions & 0 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,10 @@ def setup
assert_response :success
assert_select 'table' # ensure a table is shown
end
test 'rss with tagname and authorname' do
get :rss_for_tagged_with_author, tagname: 'test*', authorname: 'jeff', format: 'rss'
assert :success
assert_not_nil :notes
assert_equal 'application/rss+xml', @response.content_type
end
end