diff options
Diffstat (limited to 'app/controllers/feeds_controller.rb')
-rw-r--r-- | app/controllers/feeds_controller.rb | 81 |
1 files changed, 78 insertions, 3 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 |