feeds_controller.rb
96 lines
| 3.7 KiB
| text/x-ruby
|
RubyLexer
|
r118 | # redMine - project management software | ||
|
r336 | # Copyright (C) 2006-2007 Jean-Philippe Lang | ||
|
r118 | # | ||
# 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. | ||||
class FeedsController < ApplicationController | ||||
|
r336 | before_filter :find_scope | ||
|
r118 | session :off | ||
|
r336 | |||
helper :issues | ||||
include IssuesHelper | ||||
helper :custom_fields | ||||
include CustomFieldsHelper | ||||
# news feeds | ||||
|
r118 | def news | ||
|
r336 | News.with_scope(:find => @find_options) do | ||
|
r343 | @news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ] | ||
|
r336 | end | ||
|
r191 | headers["Content-Type"] = "application/rss+xml" | ||
|
r336 | render :action => 'news_atom' if 'atom' == params[:format] | ||
end | ||||
# issue feeds | ||||
def issues | ||||
|
r355 | if @project && params[:query_id] | ||
|
r336 | query = Query.find(params[:query_id]) | ||
# ignore query if it's not valid | ||||
query = nil unless query.valid? | ||||
|
r355 | # override with query conditions | ||
@find_options[:conditions] = query.statement if query.valid? and @project == query.project | ||||
|
r336 | end | ||
Issue.with_scope(:find => @find_options) do | ||||
@issues = Issue.find :all, :include => [:project, :author, :tracker, :status], | ||||
|
r355 | :order => "#{Issue.table_name}.created_on DESC" | ||
|
r336 | 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 | ||||
|
r355 | def history | ||
if @project && params[:query_id] | ||||
|
r336 | query = Query.find(params[:query_id]) | ||
# ignore query if it's not valid | ||||
query = nil unless query.valid? | ||||
|
r355 | # override with query conditions | ||
@find_options[:conditions] = query.statement if query.valid? and @project == query.project | ||||
|
r336 | end | ||
Journal.with_scope(:find => @find_options) do | ||||
@journals = Journal.find :all, :include => [ :details, :user, {:issue => [:project, :author, :tracker, :status]} ], | ||||
|
r355 | :order => "#{Journal.table_name}.created_on DESC" | ||
|
r336 | 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 | ||||
|
r343 | @find_options = {:conditions => scope, :limit => Setting.feeds_limit} | ||
|
r336 | return true | ||
|
r118 | end | ||
end | ||||