Permalink
Browse files

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...
1 parent 8509cf8 commit ad68a82be19f44c8e9ab895075a4e932133ad6ee @jplang jplang committed Nov 5, 2007
@@ -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
@@ -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 @@ def destroy_comment
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 @@ def find_project
@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
@@ -330,21 +330,11 @@ def add_news
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])
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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) %>
@@ -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>
Oops, something went wrong.

0 comments on commit ad68a82

Please sign in to comment.