Moved ProjectsController#list_news to NewsController#index.

Removed FeedsController, issues and news feeds are now handled by issues and news controllers.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@888 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-11-05 22:22:51 +00:00
parent 8509cf80f0
commit ad68a82be1
17 changed files with 61 additions and 326 deletions

View File

@ -1,98 +0,0 @@
# 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.
class FeedsController < ApplicationController
before_filter :find_scope
session :off
helper :issues
include IssuesHelper
helper :custom_fields
include CustomFieldsHelper
# news feeds
def news
News.with_scope(:find => @find_options) do
@news = News.find :all, :order => "#{News.table_name}.created_on DESC", :include => [ :author, :project ]
end
headers["Content-Type"] = "application/rss+xml"
render :action => 'news_atom' if 'atom' == params[:format]
end
# issue feeds
def issues
if @project && params[:query_id]
query = Query.find(params[:query_id])
query.executed_by = @user
# ignore query if it's not valid
query = nil unless query.valid?
# override with query conditions
@find_options[:conditions] = query.statement if query.valid? and @project == query.project
end
Issue.with_scope(:find => @find_options) do
@issues = Issue.find :all, :include => [:project, :author, :tracker, :status],
:order => "#{Issue.table_name}.created_on DESC"
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
if @project && params[:query_id]
query = Query.find(params[:query_id])
query.executed_by = @user
# ignore query if it's not valid
query = nil unless query.valid?
# override with query conditions
@find_options[:conditions] = query.statement if query.valid? and @project == query.project
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"
end
@title = (@project ? @project.name : Setting.app_title) + ": " + (query ? query.name : l(:label_changes_details))
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))
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 => Setting.feeds_limit.to_i}
return true
end
end

View File

@ -17,8 +17,22 @@
class NewsController < ApplicationController
layout 'base'
before_filter :find_project, :authorize
before_filter :find_project, :authorize, :except => :index
before_filter :find_optional_project, :only => :index
accept_key_auth :index
def index
@news_pages, @newss = paginate :news,
:per_page => 10,
:conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
:include => [:author, :project],
:order => "#{News.table_name}.created_on DESC"
respond_to do |format|
format.html { render :layout => false if request.xhr? }
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
end
def show
end
@ -47,7 +61,7 @@ class NewsController < ApplicationController
def destroy
@news.destroy
redirect_to :controller => 'projects', :action => 'list_news', :id => @project
redirect_to :action => 'index', :project_id => @project
end
private
@ -56,5 +70,13 @@ private
@project = @news.project
rescue ActiveRecord::RecordNotFound
render_404
end
end
def find_optional_project
return true unless params[:project_id]
@project = Project.find(params[:project_id])
authorize
rescue ActiveRecord::RecordNotFound
render_404
end
end

View File

@ -330,21 +330,11 @@ class ProjectsController < ApplicationController
if @news.save
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
redirect_to :action => 'list_news', :id => @project
redirect_to :controller => 'news', :action => 'index', :project_id => @project
end
end
end
# Show news list of @project
def list_news
@news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
respond_to do |format|
format.html { render :layout => false if request.xhr? }
format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
end
end
def add_file
if request.post?
@version = @project.versions.find_by_id(params[:version_id])

View File

@ -1,19 +0,0 @@
# redMine - project management software
# Copyright (C) 2006 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.
module FeedsHelper
end

View File

@ -1,28 +0,0 @@
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_changes_details)
@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

View File

@ -1,28 +0,0 @@
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 if 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

View File

@ -1,20 +0,0 @@
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

View File

@ -1,22 +0,0 @@
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

View File

@ -1,20 +0,0 @@
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

View File

@ -1,22 +0,0 @@
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

View File

@ -1,17 +1,17 @@
<div class="contextual">
<%= link_to_if_authorized l(:label_news_new),
<%= link_to_if_authorized(l(:label_news_new),
{:controller => 'projects', :action => 'add_news', :id => @project},
:class => 'icon icon-add',
:onclick => 'Element.show("add-news"); return false;' %>
:onclick => 'Element.show("add-news"); return false;') if @project %>
</div>
<div id="add-news" style="display:none;">
<h2><%=l(:label_news_new)%></h2>
<% labelled_tabular_form_for :news, @news, :url => { :action => "add_news", :id => @project } do |f| %>
<% labelled_tabular_form_for :news, @news, :url => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
<% end %>
<% end if @project %>
</div>
<h2><%=l(:label_news_plural)%></h2>
@ -20,7 +20,8 @@
<p class="nodata"><%= l(:label_no_data) %></p>
<% else %>
<% @newss.each do |news| %>
<h3><%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
<h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
<%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
<%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3>
<p class="author"><%= authoring news.created_on, news.author %></p>
<%= textilizable(news.description) %>

View File

@ -46,11 +46,11 @@
</div>
<% end %>
<% if @news.any? && authorize_for('projects', 'list_news') %>
<% if @news.any? && authorize_for('news', 'index') %>
<div class="box">
<h3><%=l(:label_news_latest)%></h3>
<%= render :partial => 'news/news', :collection => @news %>
<p><%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %></p>
<p><%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %></p>
</div>
<% end %>
</div>

View File

@ -2,10 +2,13 @@
<div class="splitcontentleft">
<%= textilizable Setting.welcome_text %>
<% if @news.any? %>
<div class="box">
<h3><%=l(:label_news_latest)%></h3>
<%= render :partial => 'news/news', :collection => @news %>
</div>
<%= link_to l(:label_issue_view_all), :controller => 'news' %>
</div>
<% end %>
</div>
<div class="splitcontentright">

View File

@ -15,6 +15,7 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
map.connect 'projects/:project_id/news/:action', :controller => 'news'
map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'

View File

@ -52,7 +52,7 @@ Redmine::AccessControl.map do |map|
map.project_module :news do |map|
map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
map.permission :view_news, {:projects => :list_news, :news => :show}, :public => true
map.permission :view_news, {:news => [:index, :show]}, :public => true
map.permission :comment_news, {:news => :add_comment}, :require => :loggedin
end
@ -93,7 +93,7 @@ Redmine::MenuManager.map :project_menu do |menu|
menu.push :label_activity, :controller => 'projects', :action => 'activity'
menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap'
menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id
menu.push :label_news_plural, :controller => 'projects', :action => 'list_news'
menu.push :label_news_plural, { :controller => 'news', :action => 'index' }, :param => :project_id
menu.push :label_document_plural, :controller => 'projects', :action => 'list_documents'
menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? }

View File

@ -16,51 +16,33 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../test_helper'
require 'feeds_controller'
require 'news_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
class NewsController; def rescue_action(e) raise e end; end
class NewsControllerTest < Test::Unit::TestCase
fixtures :projects, :users, :roles, :members, :enabled_modules
def setup
@controller = FeedsController.new
@controller = NewsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
end
def test_index
get :index
assert_response :success
assert_template 'index'
assert_not_nil assigns(:newss)
assert_nil assigns(:project)
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.rss_key
get :news, :project_id => 2, :key => key
def test_index_with_project
get :index, :project_id => 1
assert_response :success
assert_template 'index'
assert_not_nil assigns(:newss)
end
end

View File

@ -65,13 +65,6 @@ class ProjectsControllerTest < Test::Unit::TestCase
# check that the issues were updated
assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
end
def test_list_news
get :list_news, :id => 1
assert_response :success
assert_template 'list_news'
assert_not_nil assigns(:newss)
end
def test_list_files