diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb
deleted file mode 100644
index 0601b8a5..00000000
--- a/app/controllers/feeds_controller.rb
+++ /dev/null
@@ -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
diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 6b143dde..c41c5844 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -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
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 4356ec77..8db55ba0 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -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])
diff --git a/app/helpers/feeds_helper.rb b/app/helpers/feeds_helper.rb
deleted file mode 100644
index 850bd44f..00000000
--- a/app/helpers/feeds_helper.rb
+++ /dev/null
@@ -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
diff --git a/app/views/feeds/history.rxml b/app/views/feeds/history.rxml
deleted file mode 100644
index 9894412c..00000000
--- a/app/views/feeds/history.rxml
+++ /dev/null
@@ -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! "
"
- journal.details.each do |detail|
- xml.text! "- " + show_detail(detail, false) + "
"
- end
- xml.text! "
"
- 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
diff --git a/app/views/feeds/history_atom.rxml b/app/views/feeds/history_atom.rxml
deleted file mode 100644
index 8c01fe4e..00000000
--- a/app/views/feeds/history_atom.rxml
+++ /dev/null
@@ -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! ""
- journal.details.each do |detail|
- xml.text! "- " + show_detail(detail, false) + "
"
- end
- xml.text! "
"
- end
- end
- end
-end
\ No newline at end of file
diff --git a/app/views/feeds/issues.rxml b/app/views/feeds/issues.rxml
deleted file mode 100644
index 70398f42..00000000
--- a/app/views/feeds/issues.rxml
+++ /dev/null
@@ -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
diff --git a/app/views/feeds/issues_atom.rxml b/app/views/feeds/issues_atom.rxml
deleted file mode 100644
index bb15fc49..00000000
--- a/app/views/feeds/issues_atom.rxml
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/app/views/feeds/news.rxml b/app/views/feeds/news.rxml
deleted file mode 100644
index d7248b6c..00000000
--- a/app/views/feeds/news.rxml
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/app/views/feeds/news_atom.rxml b/app/views/feeds/news_atom.rxml
deleted file mode 100644
index 2550341c..00000000
--- a/app/views/feeds/news_atom.rxml
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/app/views/projects/list_news.rhtml b/app/views/news/index.rhtml
similarity index 70%
rename from app/views/projects/list_news.rhtml
rename to app/views/news/index.rhtml
index 8a353784..a956f86d 100644
--- a/app/views/projects/list_news.rhtml
+++ b/app/views/news/index.rhtml
@@ -1,17 +1,17 @@
-<%= 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 %>
<%=l(:label_news_new)%>
-<% 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 %>
<%=l(:label_news_plural)%>
@@ -20,7 +20,8 @@
<%= l(:label_no_data) %>
<% else %>
<% @newss.each do |news| %>
- <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
+ <%= 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 %>
<%= authoring news.created_on, news.author %>
<%= textilizable(news.description) %>
diff --git a/app/views/projects/show.rhtml b/app/views/projects/show.rhtml
index 88178cb5..94df0bf3 100644
--- a/app/views/projects/show.rhtml
+++ b/app/views/projects/show.rhtml
@@ -46,11 +46,11 @@
<% end %>
- <% if @news.any? && authorize_for('projects', 'list_news') %>
+ <% if @news.any? && authorize_for('news', 'index') %>
<%=l(:label_news_latest)%>
<%= render :partial => 'news/news', :collection => @news %>
-
<%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %>
+
<%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %>
<% end %>
diff --git a/app/views/welcome/index.rhtml b/app/views/welcome/index.rhtml
index 4b9b5909..af09eea9 100644
--- a/app/views/welcome/index.rhtml
+++ b/app/views/welcome/index.rhtml
@@ -2,10 +2,13 @@
<%= textilizable Setting.welcome_text %>
+ <% if @news.any? %>
<%=l(:label_news_latest)%>
<%= render :partial => 'news/news', :collection => @news %>
-
+ <%= link_to l(:label_issue_view_all), :controller => 'news' %>
+
+ <% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 3b4767a3..c3637304 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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'
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 3e9569ac..959cfc0c 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -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? }
diff --git a/test/functional/feeds_controller_test.rb b/test/functional/news_controller_test.rb
similarity index 57%
rename from test/functional/feeds_controller_test.rb
rename to test/functional/news_controller_test.rb
index c41fa2c6..8a02345f 100644
--- a/test/functional/feeds_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -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
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 28f826b8..002dc1e4 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -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