ProjectsController#list_issues, #export_issues_csv and #export_issues_pdf merged...
[gitredmine.git] / app / controllers / feeds_controller.rb
blob0601b8a5ef34d693d0f0ce5513d5616dd6c641a7
1 # redMine - project management software
2 # Copyright (C) 2006-2007  Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 class FeedsController < ApplicationController
19   before_filter :find_scope
20   session :off
22   helper :issues
23   include IssuesHelper
24   helper :custom_fields
25   include CustomFieldsHelper
26     
27   # news feeds
28   def news
29     News.with_scope(:find => @find_options) do
30       @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ]
31     end
32     headers["Content-Type"] = "application/rss+xml"
33     render :action => 'news_atom' if 'atom' == params[:format]
34   end
35   
36   # issue feeds
37   def issues
38     if @project && params[:query_id]
39       query = Query.find(params[:query_id])
40       query.executed_by = @user
41       # ignore query if it's not valid
42       query = nil unless query.valid?
43       # override with query conditions
44       @find_options[:conditions] = query.statement if query.valid? and @project == query.project
45     end
47     Issue.with_scope(:find => @find_options) do
48       @issues = Issue.find :all, :include => [:project, :author, :tracker, :status], 
49                                  :order => "#{Issue.table_name}.created_on DESC"
50     end
51     @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_reported_issues))
52     headers["Content-Type"] = "application/rss+xml"
53     render :action => 'issues_atom' if 'atom' == params[:format]
54   end
55   
56   # issue changes feeds
57   def history    
58     if @project && params[:query_id]
59       query = Query.find(params[:query_id])
60       query.executed_by = @user
61       # ignore query if it's not valid
62       query = nil unless query.valid?
63       # override with query conditions
64       @find_options[:conditions] = query.statement if query.valid? and @project == query.project
65     end
67     Journal.with_scope(:find => @find_options) do
68       @journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], 
69                                      :order => "#{Journal.table_name}.created_on DESC"
70     end
71     
72     @title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_changes_details))
73     headers["Content-Type"] = "application/rss+xml"
74     render :action => 'history_atom' if 'atom' == params[:format]
75   end
76    
77 private
78   # override for feeds specific authentication
79   def check_if_login_required
80     @user = User.find_by_rss_key(params[:key])
81     render(:nothing => true, :status => 403) and return false if !@user && Setting.login_required?
82   end
83   
84   def find_scope
85     if params[:project_id]
86       # project feed
87       # check if project is public or if the user is a member
88       @project = Project.find(params[:project_id])
89       render(:nothing => true, :status => 403) and return false unless @project.is_public? || (@user && @user.role_for_project(@project))
90       scope = ["#{Project.table_name}.id=?", params[:project_id].to_i]
91     else
92       # global feed
93       scope = ["#{Project.table_name}.is_public=?", true]
94     end
95     @find_options = {:conditions => scope, :limit => Setting.feeds_limit.to_i}
96     return true
97   end
98 end