To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / news_controller.rb @ 418:a9921f3e9088
History | View | Annotate | Download (3.15 KB)
| 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 |
class NewsController < ApplicationController |
| 19 |
default_search_scope :news
|
| 20 |
model_object News
|
| 21 |
before_filter :find_model_object, :except => [:new, :create, :index] |
| 22 |
before_filter :find_project_from_association, :except => [:new, :create, :index] |
| 23 |
before_filter :find_project, :only => [:new, :create] |
| 24 |
before_filter :authorize, :except => [:index] |
| 25 |
before_filter :find_optional_project, :only => :index |
| 26 |
accept_key_auth :index
|
| 27 |
|
| 28 |
def index |
| 29 |
@news_pages, @newss = paginate :news, |
| 30 |
:per_page => 10, |
| 31 |
:conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project), |
| 32 |
:include => [:author, :project], |
| 33 |
:order => "#{News.table_name}.created_on DESC" |
| 34 |
respond_to do |format|
|
| 35 |
format.html { render :layout => false if request.xhr? }
|
| 36 |
format.xml { render :xml => @newss.to_xml }
|
| 37 |
format.json { render :json => @newss.to_json }
|
| 38 |
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
|
| 39 |
end
|
| 40 |
end
|
| 41 |
|
| 42 |
def show |
| 43 |
@comments = @news.comments |
| 44 |
@comments.reverse! if User.current.wants_comments_in_reverse_order? |
| 45 |
end
|
| 46 |
|
| 47 |
def new |
| 48 |
@news = News.new(:project => @project, :author => User.current) |
| 49 |
end
|
| 50 |
|
| 51 |
def create |
| 52 |
@news = News.new(:project => @project, :author => User.current) |
| 53 |
if request.post?
|
| 54 |
@news.attributes = params[:news] |
| 55 |
if @news.save |
| 56 |
flash[:notice] = l(:notice_successful_create) |
| 57 |
redirect_to :controller => 'news', :action => 'index', :project_id => @project |
| 58 |
else
|
| 59 |
render :action => 'new' |
| 60 |
end
|
| 61 |
end
|
| 62 |
end
|
| 63 |
|
| 64 |
def edit |
| 65 |
end
|
| 66 |
|
| 67 |
def update |
| 68 |
if request.put? and @news.update_attributes(params[:news]) |
| 69 |
flash[:notice] = l(:notice_successful_update) |
| 70 |
redirect_to :action => 'show', :id => @news |
| 71 |
else
|
| 72 |
render :action => 'edit' |
| 73 |
end
|
| 74 |
end
|
| 75 |
|
| 76 |
def destroy |
| 77 |
@news.destroy
|
| 78 |
redirect_to :action => 'index', :project_id => @project |
| 79 |
end
|
| 80 |
|
| 81 |
private |
| 82 |
def find_project |
| 83 |
@project = Project.find(params[:project_id]) |
| 84 |
rescue ActiveRecord::RecordNotFound |
| 85 |
render_404 |
| 86 |
end
|
| 87 |
|
| 88 |
def find_optional_project |
| 89 |
return true unless params[:project_id] |
| 90 |
@project = Project.find(params[:project_id]) |
| 91 |
authorize |
| 92 |
rescue ActiveRecord::RecordNotFound |
| 93 |
render_404 |
| 94 |
end
|
| 95 |
end
|