| 
									
										
										
										
											2011-03-04 14:32:58 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2013-01-12 09:29:31 +00:00
										 |  |  | # Copyright (C) 2006-2013  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # 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. | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # 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. | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  | # 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 NewsController < ApplicationController | 
					
						
							| 
									
										
										
										
											2009-10-21 17:07:18 +00:00
										 |  |  |   default_search_scope :news | 
					
						
							| 
									
										
										
										
											2010-03-17 15:41:58 +00:00
										 |  |  |   model_object News | 
					
						
							| 
									
										
										
										
											2010-09-24 16:26:46 +00:00
										 |  |  |   before_filter :find_model_object, :except => [:new, :create, :index] | 
					
						
							|  |  |  |   before_filter :find_project_from_association, :except => [:new, :create, :index] | 
					
						
							| 
									
										
										
										
											2012-03-10 13:44:52 +00:00
										 |  |  |   before_filter :find_project_by_project_id, :only => [:new, :create] | 
					
						
							| 
									
										
										
										
											2010-09-24 16:26:46 +00:00
										 |  |  |   before_filter :authorize, :except => [:index] | 
					
						
							| 
									
										
										
										
											2007-11-05 22:22:51 +00:00
										 |  |  |   before_filter :find_optional_project, :only => :index | 
					
						
							| 
									
										
										
										
											2011-07-09 08:56:07 +00:00
										 |  |  |   accept_rss_auth :index | 
					
						
							|  |  |  |   accept_api_auth :index | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-04 14:32:58 +00:00
										 |  |  |   helper :watchers | 
					
						
							| 
									
										
										
										
											2012-01-29 22:39:06 +00:00
										 |  |  |   helper :attachments | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-05 22:22:51 +00:00
										 |  |  |   def index | 
					
						
							| 
									
										
										
										
											2010-12-12 17:00:52 +00:00
										 |  |  |     case params[:format] | 
					
						
							|  |  |  |     when 'xml', 'json' | 
					
						
							|  |  |  |       @offset, @limit = api_offset_and_limit | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       @limit =  10
 | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-12 17:00:52 +00:00
										 |  |  |     scope = @project ? @project.news.visible : News.visible | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-12 17:00:52 +00:00
										 |  |  |     @news_count = scope.count | 
					
						
							| 
									
										
										
										
											2013-01-08 20:18:12 +00:00
										 |  |  |     @news_pages = Paginator.new @news_count, @limit, params['page'] | 
					
						
							|  |  |  |     @offset ||= @news_pages.offset | 
					
						
							| 
									
										
										
										
											2014-01-10 08:13:47 +00:00
										 |  |  |     @newss = scope.includes([:author, :project]). | 
					
						
							|  |  |  |                       order("#{News.table_name}.created_on DESC"). | 
					
						
							|  |  |  |                       limit(@limit). | 
					
						
							|  |  |  |                       offset(@offset). | 
					
						
							|  |  |  |                       all | 
					
						
							| 
									
										
										
										
											2007-11-05 22:22:51 +00:00
										 |  |  |     respond_to do |format| | 
					
						
							| 
									
										
										
										
											2011-11-23 20:09:57 +00:00
										 |  |  |       format.html { | 
					
						
							|  |  |  |         @news = News.new # for adding news inline | 
					
						
							|  |  |  |         render :layout => false if request.xhr? | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-12-12 17:00:52 +00:00
										 |  |  |       format.api | 
					
						
							| 
									
										
										
										
											2007-11-05 22:22:51 +00:00
										 |  |  |       format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def show | 
					
						
							| 
									
										
										
										
											2008-03-05 15:41:54 +00:00
										 |  |  |     @comments = @news.comments | 
					
						
							|  |  |  |     @comments.reverse! if User.current.wants_comments_in_reverse_order? | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-03 14:38:04 +00:00
										 |  |  |   def new | 
					
						
							|  |  |  |     @news = News.new(:project => @project, :author => User.current) | 
					
						
							| 
									
										
										
										
											2010-09-20 15:13:48 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							|  |  |  |     @news = News.new(:project => @project, :author => User.current) | 
					
						
							| 
									
										
										
										
											2012-03-06 19:50:10 +00:00
										 |  |  |     @news.safe_attributes = params[:news] | 
					
						
							| 
									
										
										
										
											2012-02-23 13:07:27 +00:00
										 |  |  |     @news.save_attachments(params[:attachments]) | 
					
						
							| 
									
										
										
										
											2012-02-23 13:05:10 +00:00
										 |  |  |     if @news.save | 
					
						
							|  |  |  |       render_attachment_warning_if_needed(@news) | 
					
						
							|  |  |  |       flash[:notice] = l(:notice_successful_create) | 
					
						
							| 
									
										
										
										
											2012-12-11 19:39:47 +00:00
										 |  |  |       redirect_to project_news_index_path(@project) | 
					
						
							| 
									
										
										
										
											2012-02-23 13:05:10 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       render :action => 'new' | 
					
						
							| 
									
										
										
										
											2008-02-03 14:38:04 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-21 15:20:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2010-09-21 15:20:37 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-21 15:20:37 +00:00
										 |  |  |   def update | 
					
						
							| 
									
										
										
										
											2012-03-06 19:50:10 +00:00
										 |  |  |     @news.safe_attributes = params[:news] | 
					
						
							| 
									
										
										
										
											2012-02-23 13:07:27 +00:00
										 |  |  |     @news.save_attachments(params[:attachments]) | 
					
						
							| 
									
										
										
										
											2012-03-06 19:50:10 +00:00
										 |  |  |     if @news.save | 
					
						
							| 
									
										
										
										
											2012-01-29 22:39:06 +00:00
										 |  |  |       render_attachment_warning_if_needed(@news) | 
					
						
							| 
									
										
										
										
											2006-07-30 10:47:02 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_update) | 
					
						
							| 
									
										
										
										
											2012-12-11 19:39:47 +00:00
										 |  |  |       redirect_to news_path(@news) | 
					
						
							| 
									
										
										
										
											2010-09-21 15:20:37 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       render :action => 'edit' | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-21 15:20:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-28 00:00:21 +00:00
										 |  |  |   def destroy | 
					
						
							|  |  |  |     @news.destroy | 
					
						
							| 
									
										
										
										
											2012-12-11 19:39:47 +00:00
										 |  |  |     redirect_to project_news_index_path(@project) | 
					
						
							| 
									
										
										
										
											2007-03-12 17:59:02 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-10 13:44:52 +00:00
										 |  |  |   private | 
					
						
							| 
									
										
										
										
											2011-08-30 14:13:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-05 22:22:51 +00:00
										 |  |  |   def find_optional_project | 
					
						
							|  |  |  |     return true unless params[:project_id] | 
					
						
							|  |  |  |     @project = Project.find(params[:project_id]) | 
					
						
							|  |  |  |     authorize | 
					
						
							|  |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | end |