Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit ad68a82be19f44c8e9ab895075a4e932133ad6ee 1 parent 8509cf8
jplang jplang authored
98 app/controllers/feeds_controller.rb
... ... @@ -1,98 +0,0 @@
1   -# redMine - project management software
2   -# Copyright (C) 2006-2007 Jean-Philippe Lang
3   -#
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.
17   -
18   -class FeedsController < ApplicationController
19   - before_filter :find_scope
20   - session :off
21   -
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
46   -
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
66   -
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
30 app/controllers/news_controller.rb
@@ -17,8 +17,22 @@
17 17
18 18 class NewsController < ApplicationController
19 19 layout 'base'
20   - before_filter :find_project, :authorize
21   -
  20 + before_filter :find_project, :authorize, :except => :index
  21 + before_filter :find_optional_project, :only => :index
  22 + accept_key_auth :index
  23 +
  24 + def index
  25 + @news_pages, @newss = paginate :news,
  26 + :per_page => 10,
  27 + :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
  28 + :include => [:author, :project],
  29 + :order => "#{News.table_name}.created_on DESC"
  30 + respond_to do |format|
  31 + format.html { render :layout => false if request.xhr? }
  32 + format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
  33 + end
  34 + end
  35 +
22 36 def show
23 37 end
24 38
@@ -47,7 +61,7 @@ def destroy_comment
47 61
48 62 def destroy
49 63 @news.destroy
50   - redirect_to :controller => 'projects', :action => 'list_news', :id => @project
  64 + redirect_to :action => 'index', :project_id => @project
51 65 end
52 66
53 67 private
@@ -56,5 +70,13 @@ def find_project
56 70 @project = @news.project
57 71 rescue ActiveRecord::RecordNotFound
58 72 render_404
59   - end
  73 + end
  74 +
  75 + def find_optional_project
  76 + return true unless params[:project_id]
  77 + @project = Project.find(params[:project_id])
  78 + authorize
  79 + rescue ActiveRecord::RecordNotFound
  80 + render_404
  81 + end
60 82 end
12 app/controllers/projects_controller.rb
@@ -330,21 +330,11 @@ def add_news
330 330 if @news.save
331 331 flash[:notice] = l(:notice_successful_create)
332 332 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
333   - redirect_to :action => 'list_news', :id => @project
  333 + redirect_to :controller => 'news', :action => 'index', :project_id => @project
334 334 end
335 335 end
336 336 end
337 337
338   - # Show news list of @project
339   - def list_news
340   - @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
341   -
342   - respond_to do |format|
343   - format.html { render :layout => false if request.xhr? }
344   - format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
345   - end
346   - end
347   -
348 338 def add_file
349 339 if request.post?
350 340 @version = @project.versions.find_by_id(params[:version_id])
19 app/helpers/feeds_helper.rb
... ... @@ -1,19 +0,0 @@
1   -# redMine - project management software
2   -# Copyright (C) 2006 Jean-Philippe Lang
3   -#
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.
17   -
18   -module FeedsHelper
19   -end
28 app/views/feeds/history.rxml
... ... @@ -1,28 +0,0 @@
1   -xml.instruct!
2   -xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
3   - xml.channel do
4   - xml.title @title
5   - xml.link url_for(:controller => 'welcome', :only_path => false)
6   - xml.pubDate CGI.rfc1123_date(@journals.first ? @journals.first.created_on : Time.now)
7   - xml.description l(:label_changes_details)
8   - @journals.each do |journal|
9   - issue = journal.issue
10   - xml.item do
11   - xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
12   - url = url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
13   - xml.link url
14   - xml.description do
15   - xml.text! h(journal.notes)
16   - xml.text! "<ul>"
17   - journal.details.each do |detail|
18   - xml.text! "<li>" + show_detail(detail, false) + "</li>"
19   - end
20   - xml.text! "</ul>"
21   - end
22   - xml.pubDate CGI.rfc1123_date(journal.created_on)
23   - xml.guid url
24   - xml.author h(journal.user.name)
25   - end
26   - end
27   - end
28   -end
28 app/views/feeds/history_atom.rxml
... ... @@ -1,28 +0,0 @@
1   -xml.instruct!
2   -xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3   - xml.title @title
4   - xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'history', :format => 'atom', :only_path => false)
5   - xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
6   - xml.id url_for(:controller => 'welcome', :only_path => false)
7   - xml.updated CGI.rfc1123_date(@journals.first.created_on) if @journals.any?
8   - xml.author { xml.name "#{Setting.app_title}" }
9   - @journals.each do |journal|
10   - issue = journal.issue
11   - xml.entry do
12   - xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
13   - xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
14   - xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
15   - xml.updated CGI.rfc1123_date(journal.created_on)
16   - xml.author { xml.name journal.user.name }
17   - xml.summary journal.notes
18   - xml.content "type" => "html" do
19   - xml.text! journal.notes if journal.notes
20   - xml.text! "<ul>"
21   - journal.details.each do |detail|
22   - xml.text! "<li>" + show_detail(detail, false) + "</li>"
23   - end
24   - xml.text! "</ul>"
25   - end
26   - end
27   - end
28   -end
20 app/views/feeds/issues.rxml
... ... @@ -1,20 +0,0 @@
1   -xml.instruct!
2   -xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
3   - xml.channel do
4   - xml.title @title
5   - xml.link url_for(:controller => 'welcome', :only_path => false)
6   - xml.pubDate CGI.rfc1123_date(@issues.first ? @issues.first.created_on : Time.now)
7   - xml.description l(:label_reported_issues)
8   - @issues.each do |issue|
9   - xml.item do
10   - xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
11   - url = url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
12   - xml.link url
13   - xml.description h(issue.description)
14   - xml.pubDate CGI.rfc1123_date(issue.created_on)
15   - xml.guid url
16   - xml.author h(issue.author.name)
17   - end
18   - end
19   - end
20   -end
22 app/views/feeds/issues_atom.rxml
... ... @@ -1,22 +0,0 @@
1   -xml.instruct!
2   -xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3   - xml.title @title
4   - xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'issues', :format => 'atom', :only_path => false)
5   - xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
6   - xml.id url_for(:controller => 'welcome', :only_path => false)
7   - xml.updated CGI.rfc1123_date(@issues.first.updated_on) if @issues.any?
8   - xml.author { xml.name "#{Setting.app_title}" }
9   - @issues.each do |issue|
10   - xml.entry do
11   - xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
12   - xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
13   - xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
14   - xml.updated CGI.rfc1123_date(issue.updated_on)
15   - xml.author { xml.name issue.author.name }
16   - xml.summary issue.description
17   - xml.content "type" => "html" do
18   - xml.text! issue.description
19   - end
20   - end
21   - end
22   -end
20 app/views/feeds/news.rxml
... ... @@ -1,20 +0,0 @@
1   -xml.instruct!
2   -xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
3   - xml.channel do
4   - xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"
5   - xml.link url_for(:controller => 'welcome', :only_path => false)
6   - xml.pubDate CGI.rfc1123_date(@news.first ? @news.first.created_on : Time.now)
7   - xml.description l(:label_news_latest)
8   - @news.each do |news|
9   - xml.item do
10   - xml.title "#{news.project.name}: #{news.title}"
11   - news_url = url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
12   - xml.link news_url
13   - xml.description h(news.summary)
14   - xml.pubDate CGI.rfc1123_date(news.created_on)
15   - xml.guid news_url
16   - xml.author h(news.author.name)
17   - end
18   - end
19   - end
20   -end
22 app/views/feeds/news_atom.rxml
... ... @@ -1,22 +0,0 @@
1   -xml.instruct!
2   -xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3   - xml.title "#{Setting.app_title}: #{l(:label_news_latest)}"
4   - xml.link "rel" => "self", "href" => url_for(:controller => 'feeds', :action => 'news', :format => 'atom', :only_path => false)
5   - xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false)
6   - xml.id url_for(:controller => 'welcome', :only_path => false)
7   - xml.updated CGI.rfc1123_date(@news.first.created_on) if @news.any?
8   - xml.author { xml.name "#{Setting.app_title}" }
9   - @news.each do |news|
10   - xml.entry do
11   - xml.title news.title
12   - xml.link "rel" => "alternate", "href" => url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
13   - xml.id url_for(:controller => 'news' , :action => 'show', :id => news, :only_path => false)
14   - xml.updated CGI.rfc1123_date(news.created_on)
15   - xml.author { xml.name news.author.name }
16   - xml.summary h(news.summary)
17   - xml.content "type" => "html" do
18   - xml.text! news.description
19   - end
20   - end
21   - end
22   -end
11 app/views/projects/list_news.rhtml → app/views/news/index.rhtml
... ... @@ -1,17 +1,17 @@
1 1 <div class="contextual">
2   -<%= link_to_if_authorized l(:label_news_new),
  2 +<%= link_to_if_authorized(l(:label_news_new),
3 3 {:controller => 'projects', :action => 'add_news', :id => @project},
4 4 :class => 'icon icon-add',
5   - :onclick => 'Element.show("add-news"); return false;' %>
  5 + :onclick => 'Element.show("add-news"); return false;') if @project %>
6 6 </div>
7 7
8 8 <div id="add-news" style="display:none;">
9 9 <h2><%=l(:label_news_new)%></h2>
10   -<% labelled_tabular_form_for :news, @news, :url => { :action => "add_news", :id => @project } do |f| %>
  10 +<% labelled_tabular_form_for :news, @news, :url => { :controller => 'projects', :action => "add_news", :id => @project } do |f| %>
11 11 <%= render :partial => 'news/form', :locals => { :f => f } %>
12 12 <%= submit_tag l(:button_create) %>
13 13 <%= link_to l(:button_cancel), "#", :onclick => 'Element.hide("add-news")' %>
14   -<% end %>
  14 +<% end if @project %>
15 15 </div>
16 16
17 17 <h2><%=l(:label_news_plural)%></h2>
@@ -20,7 +20,8 @@
20 20 <p class="nodata"><%= l(:label_no_data) %></p>
21 21 <% else %>
22 22 <% @newss.each do |news| %>
23   - <h3><%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
  23 + <h3><%= link_to(h(news.project.name), :controller => 'projects', :action => 'show', :id => news.project) + ': ' unless news.project == @project %>
  24 + <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %>
24 25 <%= "(#{news.comments_count} #{lwr(:label_comment, news.comments_count).downcase})" if news.comments_count > 0 %></h3>
25 26 <p class="author"><%= authoring news.created_on, news.author %></p>
26 27 <%= textilizable(news.description) %>
4 app/views/projects/show.rhtml
@@ -46,11 +46,11 @@
46 46 </div>
47 47 <% end %>
48 48
49   - <% if @news.any? && authorize_for('projects', 'list_news') %>
  49 + <% if @news.any? && authorize_for('news', 'index') %>
50 50 <div class="box">
51 51 <h3><%=l(:label_news_latest)%></h3>
52 52 <%= render :partial => 'news/news', :collection => @news %>
53   - <p><%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %></p>
  53 + <p><%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %></p>
54 54 </div>
55 55 <% end %>
56 56 </div>
5 app/views/welcome/index.rhtml
@@ -2,10 +2,13 @@
2 2
3 3 <div class="splitcontentleft">
4 4 <%= textilizable Setting.welcome_text %>
  5 + <% if @news.any? %>
5 6 <div class="box">
6 7 <h3><%=l(:label_news_latest)%></h3>
7 8 <%= render :partial => 'news/news', :collection => @news %>
8   - </div>
  9 + <%= link_to l(:label_issue_view_all), :controller => 'news' %>
  10 + </div>
  11 + <% end %>
9 12 </div>
10 13
11 14 <div class="splitcontentright">
1  config/routes.rb
@@ -15,6 +15,7 @@
15 15
16 16 map.connect 'issues/:issue_id/relations/:action/:id', :controller => 'issue_relations'
17 17 map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
  18 + map.connect 'projects/:project_id/news/:action', :controller => 'news'
18 19 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
19 20 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
20 21
4 lib/redmine.rb
@@ -52,7 +52,7 @@
52 52
53 53 map.project_module :news do |map|
54 54 map.permission :manage_news, {:projects => :add_news, :news => [:edit, :destroy, :destroy_comment]}, :require => :member
55   - map.permission :view_news, {:projects => :list_news, :news => :show}, :public => true
  55 + map.permission :view_news, {:news => [:index, :show]}, :public => true
56 56 map.permission :comment_news, {:news => :add_comment}, :require => :loggedin
57 57 end
58 58
@@ -93,7 +93,7 @@
93 93 menu.push :label_activity, :controller => 'projects', :action => 'activity'
94 94 menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap'
95 95 menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id
96   - menu.push :label_news_plural, :controller => 'projects', :action => 'list_news'
  96 + menu.push :label_news_plural, { :controller => 'news', :action => 'index' }, :param => :project_id
97 97 menu.push :label_document_plural, :controller => 'projects', :action => 'list_documents'
98 98 menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
99 99 menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? }
52 test/functional/feeds_controller_test.rb → test/functional/news_controller_test.rb
@@ -16,51 +16,33 @@
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19   -require 'feeds_controller'
  19 +require 'news_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22   -class FeedsController; def rescue_action(e) raise e end; end
23   -
24   -class FeedsControllerTest < Test::Unit::TestCase
25   - fixtures :projects, :users, :members, :roles
  22 +class NewsController; def rescue_action(e) raise e end; end
26 23
  24 +class NewsControllerTest < Test::Unit::TestCase
  25 + fixtures :projects, :users, :roles, :members, :enabled_modules
  26 +
27 27 def setup
28   - @controller = FeedsController.new
  28 + @controller = NewsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31   - end
32   -
33   - def test_news
34   - get :news
35   - assert_response :success
36   - assert_template 'news'
37   - assert_not_nil assigns(:news)
38   - end
39   -
40   - def test_issues
41   - get :issues
42   - assert_response :success
43   - assert_template 'issues'
44   - assert_not_nil assigns(:issues)
  31 + User.current = nil
45 32 end
46 33
47   - def test_history
48   - get :history
  34 + def test_index
  35 + get :index
49 36 assert_response :success
50   - assert_template 'history'
51   - assert_not_nil assigns(:journals)
52   - end
53   -
54   - def test_project_privacy
55   - get :news, :project_id => 2
56   - assert_response 403
  37 + assert_template 'index'
  38 + assert_not_nil assigns(:newss)
  39 + assert_nil assigns(:project)
57 40 end
58   -
59   - def test_rss_key
60   - user = User.find(2)
61   - key = user.rss_key
62   -
63   - get :news, :project_id => 2, :key => key
  41 +
  42 + def test_index_with_project
  43 + get :index, :project_id => 1
64 44 assert_response :success
  45 + assert_template 'index'
  46 + assert_not_nil assigns(:newss)
65 47 end
66 48 end
7 test/functional/projects_controller_test.rb
@@ -65,13 +65,6 @@ def test_bulk_edit_issues
65 65 # check that the issues were updated
66 66 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
67 67 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
68   - end
69   -
70   - def test_list_news
71   - get :list_news, :id => 1
72   - assert_response :success
73   - assert_template 'list_news'
74   - assert_not_nil assigns(:newss)
75 68 end
76 69
77 70 def test_list_files

0 comments on commit ad68a82

Please sign in to comment.
Something went wrong with that request. Please try again.