# 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
# 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
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
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
# 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
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
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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
-xml.instruct!\r
-xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do\r
- xml.channel do\r
- xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"\r
- xml.link url_for(:controller => 'welcome', :only_path => false)\r
- xml.pubDate CGI.rfc1123_date(@news.first ? @news.first.created_on : Time.now)\r
- xml.description l(:label_news_latest)\r
- @news.each do |news|\r
- xml.item do\r
- xml.title "#{news.project.name}: #{news.title}"\r
- news_url = url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)\r
- xml.link news_url \r
- xml.description h(news.summary)\r
- xml.pubDate CGI.rfc1123_date(news.created_on)\r
- xml.guid news_url\r
- xml.author h(news.author.name)\r
- end\r
- end\r
- end\r
+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
--- /dev/null
+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
--- /dev/null
+<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"> <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
+<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">
--- /dev/null
+class AddProjectsFeedsPermissions < ActiveRecord::Migration
+ def self.up
+ Permission.create :controller => "projects", :action => "feeds", :description => "label_feed_plural", :sort => 132, :is_public => true, :mail_option => 0, :mail_enabled => 0
+ end
+
+ def self.down
+ Permission.find_by_controller_and_action('projects', 'feeds').destroy
+ end
+end
label_page_index: Index\r
label_current_version: Gegenwärtige Version\r
label_preview: Vorbetrachtung\r
+label_feed_plural: Feeds\r
+label_changes_details: Details of all changes\r
\r
button_login: Einloggen\r
button_submit: Einreichen\r
label_page_index: Index\r
label_current_version: Current version\r
label_preview: Preview\r
+label_feed_plural: Feeds\r
+label_changes_details: Details of all changes\r
\r
button_login: Login\r
button_submit: Submit\r
label_page_index: Índice\r
label_current_version: Versión actual\r
label_preview: Previo\r
+label_feed_plural: Feeds\r
+label_changes_details: Detalles de todos los cambios\r
\r
button_login: Conexión\r
button_submit: Someter\r
label_page_index: Index\r
label_current_version: Version actuelle\r
label_preview: Prévisualisation\r
+label_feed_plural: Flux RSS\r
+label_changes_details: Détails de tous les changements\r
\r
button_login: Connexion\r
button_submit: Soumettre\r
label_page_index: Indice\r
label_current_version: Versione corrente\r
label_preview: Previsione\r
+label_feed_plural: Feeds\r
+label_changes_details: Particolari di tutti i cambiamenti\r
\r
button_login: Login\r
button_submit: Invia\r
label_page_index: 索引\r
label_current_version: 最近版\r
label_preview: 下検分\r
+label_feed_plural: Feeds\r
+label_changes_details: Details of all changes\r
\r
button_login: ログイン\r
button_submit: 変更\r
.icon-attachment { background-image: url(../images/attachment.png); }\r
.icon-index { background-image: url(../images/index.png); }\r
.icon-history { background-image: url(../images/history.png); }\r
+.icon-feed { background-image: url(../images/feed.png); }\r
\r
.icon22-projects { background-image: url(../images/22x22/projects.png); }\r
.icon22-users { background-image: url(../images/22x22/users.png); }\r
.even {background-color: #fff;}\r
hr { border:0; border-top: dotted 1px #fff; border-bottom: dotted 1px #c0c0c0; }\r
table p {margin:0; padding:0;}\r
+table td {padding-right: 1em;}\r
\r
.highlight { background-color: #FCFD8D;}\r
\r
role_id: 2\r
id: 2\r
user_id: 3\r
+members_003: \r
+ created_on: 2006-07-19 19:35:36 +02:00\r
+ project_id: 2\r
+ role_id: 2\r
+ id: 3\r
+ user_id: 2\r
+
\ No newline at end of file
--- /dev/null
+# redMine - project management software
+# 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
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'feeds_controller'
+
+# Re-raise errors caught by the controller.
+class FeedsController; def rescue_action(e) raise e end; end
+
+class FeedsControllerTest < Test::Unit::TestCase
+ fixtures :projects, :users, :members, :roles
+
+ def setup
+ @controller = FeedsController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ def test_news
+ get :news
+ assert_response :success
+ assert_template 'news'
+ assert_not_nil assigns(:news)
+ end
+
+ def test_issues
+ get :issues
+ assert_response :success
+ assert_template 'issues'
+ assert_not_nil assigns(:issues)
+ end
+
+ def test_history
+ get :history
+ assert_response :success
+ assert_template 'history'
+ assert_not_nil assigns(:journals)
+ end
+
+ def test_project_privacy
+ get :news, :project_id => 2
+ assert_response 403
+ end
+
+ def test_rss_key
+ user = User.find(2)
+ key = user.get_or_create_rss_key.value
+
+ get :news, :project_id => 2, :key => key
+ assert_response :success
+ end
+end
user = User.try_to_login("jsmith", "jsmith")
assert_equal nil, user
end
+
+ def test_rss_key
+ assert_nil @jsmith.rss_key
+ key = @jsmith.get_or_create_rss_key
+ assert_kind_of Token, key
+ assert_equal 40, key.value.length
+
+ @jsmith.reload
+ assert_equal key.value, @jsmith.get_or_create_rss_key.value
+
+ @jsmith.reload
+ assert_equal key.value, @jsmith.rss_key.value
+ end
end