summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-03-17 15:18:50 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-03-17 15:18:50 +0000
commit10cf1ccc1abe1c6ffdf21259b54292f9068b569c (patch)
treed43c2fd622b2126f72672d177f482e4934106e3d /app
parent22b42dc90a86b16904224bf638054fffd062b53f (diff)
downloadredmine-10cf1ccc1abe1c6ffdf21259b54292f9068b569c.tar.gz
redmine-10cf1ccc1abe1c6ffdf21259b54292f9068b569c.zip
added rss/atom feeds at project levels for:
* news * new issues reported * details of issue changes issue cutom queries can be used as feeds git-svn-id: http://redmine.rubyforge.org/svn/trunk@339 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/feeds_controller.rb81
-rw-r--r--app/controllers/projects_controller.rb5
-rw-r--r--app/models/journal.rb4
-rw-r--r--app/models/token.rb2
-rw-r--r--app/models/user.rb10
-rw-r--r--app/views/feeds/history.rxml28
-rw-r--r--app/views/feeds/history_atom.rxml28
-rw-r--r--app/views/feeds/issues.rxml20
-rw-r--r--app/views/feeds/issues_atom.rxml22
-rw-r--r--app/views/feeds/news.rxml38
-rw-r--r--app/views/feeds/news_atom.rxml22
-rw-r--r--app/views/projects/feeds.rhtml33
-rw-r--r--app/views/projects/show.rhtml4
13 files changed, 274 insertions, 23 deletions
diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb
index 7a454d80a..46e8ae05c 100644
--- a/app/controllers/feeds_controller.rb
+++ b/app/controllers/feeds_controller.rb
@@ -1,5 +1,5 @@
# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,10 +16,85 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class FeedsController < ApplicationController
+ before_filter :find_scope
session :off
-
+
+ helper :issues
+ include IssuesHelper
+ helper :custom_fields
+ include CustomFieldsHelper
+
+ # news feeds
def news
- @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :limit => 10, :include => [ :author, :project ]
+ News.with_scope(:find => @find_options) do
+ @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :limit => 10, :include => [ :author, :project ]
+ end
headers["Content-Type"] = "application/rss+xml"
+ render :action => 'news_atom' if 'atom' == params[:format]
+ end
+
+ # issue feeds
+ def issues
+ conditions = nil
+
+ if params[:query_id]
+ query = Query.find(params[:query_id])
+ # ignore query if it's not valid
+ query = nil unless query.valid?
+ conditions = query.statement if query
+ end
+
+ Issue.with_scope(:find => @find_options) do
+ @issues = Issue.find :all, :include => [:project, :author, :tracker, :status],
+ :order => "#{Issue.table_name}.created_on DESC",
+ :conditions => conditions
+ end
+ @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues))
+ headers["Content-Type"] = "application/rss+xml"
+ render :action => 'issues_atom' if 'atom' == params[:format]
+ end
+
+ # issue changes feeds
+ def history
+ conditions = nil
+
+ if params[:query_id]
+ query = Query.find(params[:query_id])
+ # ignore query if it's not valid
+ query = nil unless query.valid?
+ conditions = query.statement if query
+ end
+
+ Journal.with_scope(:find => @find_options) do
+ @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ],
+ :order => "#{Journal.table_name}.created_on DESC",
+ :conditions => conditions
+ end
+
+ @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues))
+ headers["Content-Type"] = "application/rss+xml"
+ render :action => 'history_atom' if 'atom' == params[:format]
+ end
+
+private
+ # override for feeds specific authentication
+ def check_if_login_required
+ @user = User.find_by_rss_key(params[:key])
+ render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required?
+ end
+
+ def find_scope
+ if params[:project_id]
+ # project feed
+ # check if project is public or if the user is a member
+ @project = Project.find(params[:project_id])
+ render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project.id))
+ scope = ["#{Project.table_name}.id=?", params[:project_id].to_i]
+ else
+ # global feed
+ scope = ["#{Project.table_name}.is_public=?", true]
+ end
+ @find_options = {:conditions => scope, :limit => 10}
+ return true
end
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index fe4836811..61b772194 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -575,6 +575,11 @@ class ProjectsController < ApplicationController
end
end
+ def feeds
+ @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
+ @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
+ end
+
private
# Find project of id params[:id]
# if not found, redirect to project list
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 18a6ec083..f70a69863 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -17,6 +17,10 @@
class Journal < ActiveRecord::Base
belongs_to :journalized, :polymorphic => true
+ # added as a quick fix to allow eager loading of the polymorphic association
+ # since always associated to an issue, for now
+ belongs_to :issue, :foreign_key => :journalized_id
+
belongs_to :user
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
end
diff --git a/app/models/token.rb b/app/models/token.rb
index 98745d29e..0e8c2c3e2 100644
--- a/app/models/token.rb
+++ b/app/models/token.rb
@@ -31,7 +31,7 @@ class Token < ActiveRecord::Base
# Delete all expired tokens
def self.destroy_expired
- Token.delete_all ["created_on < ?", Time.now - @@validity_time]
+ Token.delete_all ["action <> 'feeds' AND created_on < ?", Time.now - @@validity_time]
end
private
diff --git a/app/models/user.rb b/app/models/user.rb
index 3a315239c..869be920e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -22,6 +22,7 @@ class User < ActiveRecord::Base
has_many :projects, :through => :memberships
has_many :custom_values, :dependent => :delete_all, :as => :customized
has_one :preference, :dependent => :destroy, :class_name => 'UserPreference'
+ has_one :rss_key, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
belongs_to :auth_source
attr_accessor :password, :password_confirmation
@@ -133,6 +134,15 @@ class User < ActiveRecord::Base
def pref
self.preference ||= UserPreference.new(:user => self)
end
+
+ def get_or_create_rss_key
+ self.rss_key || Token.create(:user => self, :action => 'feeds')
+ end
+
+ def self.find_by_rss_key(key)
+ token = Token.find_by_value(key)
+ token && token.user.active? ? token.user : nil
+ end
private
# Return password digest
diff --git a/app/views/feeds/history.rxml b/app/views/feeds/history.rxml
new file mode 100644
index 000000000..b7e5a3509
--- /dev/null
+++ b/app/views/feeds/history.rxml
@@ -0,0 +1,28 @@
+xml.instruct!
+xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
+ xml.channel do
+ xml.title @title
+ xml.link url_for(:controller => 'welcome', :only_path => false)
+ xml.pubDate CGI.rfc1123_date(@journals.first ? @journals.first.created_on : Time.now)
+ xml.description l(:label_reported_issues)
+ @journals.each do |journal|
+ issue = journal.issue
+ xml.item do
+ xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
+ url = url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
+ xml.link url
+ xml.description do
+ xml.text! h(journal.notes)
+ xml.text! "<ul>"
+ journal.details.each do |detail|
+ xml.text! "<li>" + show_detail(detail, false) + "</li>"
+ end
+ xml.text! "</ul>"
+ end
+ xml.pubDate CGI.rfc1123_date(journal.created_on)
+ xml.guid url
+ xml.author h(journal.user.name)
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/feeds/history_atom.rxml b/app/views/feeds/history_atom.rxml
new file mode 100644
index 000000000..9d82ef606
--- /dev/null
+++ b/app/views/feeds/history_atom.rxml
@@ -0,0 +1,28 @@
+xml.instruct!
+xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
+ xml.title @title
+ xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'history', :format => 'atom', :only_path => false)
+ xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
+ xml.id url_for(:controller => 'welcome', :only_path => false)
+ xml.updated CGI.rfc1123_date(@journals.first.created_on) if @journals.any?
+ xml.author { xml.name "#{Setting.app_title}" }
+ @journals.each do |journal|
+ issue = journal.issue
+ xml.entry do
+ xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
+ xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
+ xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
+ xml.updated CGI.rfc1123_date(journal.created_on)
+ xml.author { xml.name journal.user.name }
+ xml.summary journal.notes
+ xml.content "type" => "html" do
+ xml.text! journal.notes
+ xml.text! "<ul>"
+ journal.details.each do |detail|
+ xml.text! "<li>" + show_detail(detail, false) + "</li>"
+ end
+ xml.text! "</ul>"
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/feeds/issues.rxml b/app/views/feeds/issues.rxml
new file mode 100644
index 000000000..fb120b7cb
--- /dev/null
+++ b/app/views/feeds/issues.rxml
@@ -0,0 +1,20 @@
+xml.instruct!
+xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
+ xml.channel do
+ xml.title @title
+ xml.link url_for(:controller => 'welcome', :only_path => false)
+ xml.pubDate CGI.rfc1123_date(@issues.first ? @issues.first.created_on : Time.now)
+ xml.description l(:label_reported_issues)
+ @issues.each do |issue|
+ xml.item do
+ xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
+ url = url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
+ xml.link url
+ xml.description h(issue.description)
+ xml.pubDate CGI.rfc1123_date(issue.created_on)
+ xml.guid url
+ xml.author h(issue.author.name)
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/feeds/issues_atom.rxml b/app/views/feeds/issues_atom.rxml
new file mode 100644
index 000000000..bb15fc493
--- /dev/null
+++ b/app/views/feeds/issues_atom.rxml
@@ -0,0 +1,22 @@
+xml.instruct!
+xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
+ xml.title @title
+ xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'issues', :format => 'atom', :only_path => false)
+ xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
+ xml.id url_for(:controller => 'welcome', :only_path => false)
+ xml.updated CGI.rfc1123_date(@issues.first.updated_on) if @issues.any?
+ xml.author { xml.name "#{Setting.app_title}" }
+ @issues.each do |issue|
+ xml.entry do
+ xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
+ xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
+ xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
+ xml.updated CGI.rfc1123_date(issue.updated_on)
+ xml.author { xml.name issue.author.name }
+ xml.summary issue.description
+ xml.content "type" => "html" do
+ xml.text! issue.description
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/feeds/news.rxml b/app/views/feeds/news.rxml
index a85d86715..d7248b6cb 100644
--- a/app/views/feeds/news.rxml
+++ b/app/views/feeds/news.rxml
@@ -1,20 +1,20 @@
-xml.instruct!
-xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
- xml.channel do
- xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"
- xml.link url_for(:controller => 'welcome', :only_path => false)
- xml.pubDate CGI.rfc1123_date(@news.first ? @news.first.created_on : Time.now)
- xml.description l(:label_news_latest)
- @news.each do |news|
- xml.item do
- xml.title "#{news.project.name}: #{news.title}"
- news_url = url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
- xml.link news_url
- xml.description h(news.summary)
- xml.pubDate CGI.rfc1123_date(news.created_on)
- xml.guid news_url
- xml.author h(news.author.name)
- end
- end
- end
+xml.instruct!
+xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
+ xml.channel do
+ xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"
+ xml.link url_for(:controller => 'welcome', :only_path => false)
+ xml.pubDate CGI.rfc1123_date(@news.first ? @news.first.created_on : Time.now)
+ xml.description l(:label_news_latest)
+ @news.each do |news|
+ xml.item do
+ xml.title "#{news.project.name}: #{news.title}"
+ news_url = url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
+ xml.link news_url
+ xml.description h(news.summary)
+ xml.pubDate CGI.rfc1123_date(news.created_on)
+ xml.guid news_url
+ xml.author h(news.author.name)
+ end
+ end
+ end
end \ No newline at end of file
diff --git a/app/views/feeds/news_atom.rxml b/app/views/feeds/news_atom.rxml
new file mode 100644
index 000000000..2550341c8
--- /dev/null
+++ b/app/views/feeds/news_atom.rxml
@@ -0,0 +1,22 @@
+xml.instruct!
+xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
+ xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"
+ xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'news', :format => 'atom', :only_path => false)
+ xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
+ xml.id url_for(:controller => 'welcome', :only_path => false)
+ xml.updated CGI.rfc1123_date(@news.first.created_on) if @news.any?
+ xml.author { xml.name "#{Setting.app_title}" }
+ @news.each do |news|
+ xml.entry do
+ xml.title news.title
+ xml.link "rel" => "alternate", "href" => url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
+ xml.id url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
+ xml.updated CGI.rfc1123_date(news.created_on)
+ xml.author { xml.name news.author.name }
+ xml.summary h(news.summary)
+ xml.content "type" => "html" do
+ xml.text! news.description
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/projects/feeds.rhtml b/app/views/projects/feeds.rhtml
new file mode 100644
index 000000000..037469a8a
--- /dev/null
+++ b/app/views/projects/feeds.rhtml
@@ -0,0 +1,33 @@
+<h2><%= l(:label_feed_plural) %> (<%=h @project.name %>)</h2>
+
+<table>
+
+<tr><td colspan="3"><h3><%= l(:label_issue_plural) %></h3></td></tr>
+<tr><td><%= l(:label_reported_issues) %></td>
+<td><%= link_to 'RSS', {:controller => 'feeds', :action => 'issues', :project_id => @project, :key => @key}, :class => 'icon icon-feed' %></td>
+<td><%= link_to 'Atom', {:controller => 'feeds', :action => 'issues', :project_id => @project, :key => @key, :format => 'atom'}, :class => 'icon icon-feed' %></td>
+</tr>
+<tr><td><%= l(:label_changes_details) %></td>
+<td><%= link_to 'RSS', {:controller => 'feeds', :action => 'history', :project_id => @project, :key => @key}, :class => 'icon icon-feed' %></td>
+<td><%= link_to 'Atom', {:controller => 'feeds', :action => 'history', :project_id => @project, :key => @key, :format => 'atom'}, :class => 'icon icon-feed' %></td>
+</tr>
+
+<% @queries.each do |query| %>
+<tr><td colspan="3"><h4><%=h query.name %></h4></td></tr>
+<tr><td><%= l(:label_reported_issues) %></td>
+<td><%= link_to 'RSS', {:controller => 'feeds', :action => 'issues', :project_id => @project, :query_id => query, :key => @key}, :class => 'icon icon-feed' %></td>
+<td><%= link_to 'Atom', {:controller => 'feeds', :action => 'issues', :project_id => @project, :query_id => query, :key => @key, :format => 'atom'}, :class => 'icon icon-feed' %></td>
+</tr>
+<tr><td><%= l(:label_changes_details) %></td>
+<td><%= link_to 'RSS', {:controller => 'feeds', :action => 'history', :project_id => @project, :query_id => query, :key => @key}, :class => 'icon icon-feed' %></td>
+<td><%= link_to 'Atom', {:controller => 'feeds', :action => 'history', :project_id => @project, :query_id => query, :key => @key, :format => 'atom'}, :class => 'icon icon-feed' %></td>
+</tr>
+<% end %>
+
+<tr><td colspan="3">&nbsp;<h3><%= l(:label_news_plural) %></h3></td></tr>
+<tr><td><%= l(:label_news_latest) %></td>
+<td><%= link_to 'RSS', {:controller => 'feeds', :action => 'news', :project_id => @project, :key => @key}, :class => 'icon icon-feed' %></td>
+<td><%= link_to 'Atom', {:controller => 'feeds', :action => 'news', :project_id => @project, :key => @key, :format => 'atom'}, :class => 'icon icon-feed' %></td>
+</tr>
+
+</table> \ No newline at end of file
diff --git a/app/views/projects/show.rhtml b/app/views/projects/show.rhtml
index b38eceaac..9ecbbb663 100644
--- a/app/views/projects/show.rhtml
+++ b/app/views/projects/show.rhtml
@@ -1,3 +1,7 @@
+<div class="contextual">
+<%= link_to l(:label_feed_plural), {:action => 'feeds', :id => @project}, :class => 'icon icon-feed' %>
+</div>
+
<h2><%=l(:label_overview)%></h2>
<div class="splitcontentleft">