annotate app/controllers/news_controller.rb @ 866:2cd212a468b6 bug_152

Close obsolete branch bug_152
author Chris Cannam
date Wed, 11 May 2011 10:08:34 +0100
parents 94944d00e43c
children af80e5618e9b
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class NewsController < ApplicationController
Chris@0 19 default_search_scope :news
Chris@0 20 model_object News
chris@37 21 before_filter :find_model_object, :except => [:new, :create, :index]
chris@37 22 before_filter :find_project_from_association, :except => [:new, :create, :index]
chris@37 23 before_filter :find_project, :only => [:new, :create]
chris@37 24 before_filter :authorize, :except => [:index]
Chris@0 25 before_filter :find_optional_project, :only => :index
Chris@0 26 accept_key_auth :index
Chris@0 27
Chris@0 28 def index
Chris@0 29 @news_pages, @newss = paginate :news,
Chris@0 30 :per_page => 10,
Chris@0 31 :conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project),
Chris@0 32 :include => [:author, :project],
Chris@0 33 :order => "#{News.table_name}.created_on DESC"
Chris@0 34 respond_to do |format|
Chris@0 35 format.html { render :layout => false if request.xhr? }
Chris@0 36 format.xml { render :xml => @newss.to_xml }
Chris@0 37 format.json { render :json => @newss.to_json }
Chris@0 38 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
Chris@0 39 end
Chris@0 40 end
Chris@0 41
Chris@0 42 def show
Chris@0 43 @comments = @news.comments
Chris@0 44 @comments.reverse! if User.current.wants_comments_in_reverse_order?
Chris@0 45 end
Chris@0 46
Chris@0 47 def new
Chris@0 48 @news = News.new(:project => @project, :author => User.current)
chris@22 49 end
chris@22 50
chris@22 51 def create
chris@22 52 @news = News.new(:project => @project, :author => User.current)
Chris@0 53 if request.post?
Chris@0 54 @news.attributes = params[:news]
Chris@0 55 if @news.save
Chris@0 56 flash[:notice] = l(:notice_successful_create)
Chris@0 57 redirect_to :controller => 'news', :action => 'index', :project_id => @project
chris@22 58 else
chris@22 59 render :action => 'new'
Chris@0 60 end
Chris@0 61 end
Chris@0 62 end
chris@22 63
chris@22 64 def edit
chris@22 65 end
Chris@0 66
chris@22 67 def update
chris@22 68 if request.put? and @news.update_attributes(params[:news])
Chris@0 69 flash[:notice] = l(:notice_successful_update)
Chris@0 70 redirect_to :action => 'show', :id => @news
chris@22 71 else
chris@22 72 render :action => 'edit'
Chris@0 73 end
Chris@0 74 end
Chris@0 75
Chris@0 76 def destroy
Chris@0 77 @news.destroy
Chris@0 78 redirect_to :action => 'index', :project_id => @project
Chris@0 79 end
Chris@0 80
Chris@0 81 private
Chris@0 82 def find_project
Chris@0 83 @project = Project.find(params[:project_id])
Chris@0 84 rescue ActiveRecord::RecordNotFound
Chris@0 85 render_404
Chris@0 86 end
Chris@0 87
Chris@0 88 def find_optional_project
Chris@0 89 return true unless params[:project_id]
Chris@0 90 @project = Project.find(params[:project_id])
Chris@0 91 authorize
Chris@0 92 rescue ActiveRecord::RecordNotFound
Chris@0 93 render_404
Chris@0 94 end
Chris@0 95 end