Mercurial > hg > soundsoftware-site
comparison app/controllers/news_controller.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | 5f33065ddc4b |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
18 class NewsController < ApplicationController | 18 class NewsController < ApplicationController |
19 default_search_scope :news | 19 default_search_scope :news |
20 model_object News | 20 model_object News |
21 before_filter :find_model_object, :except => [:new, :create, :index] | 21 before_filter :find_model_object, :except => [:new, :create, :index] |
22 before_filter :find_project_from_association, :except => [:new, :create, :index] | 22 before_filter :find_project_from_association, :except => [:new, :create, :index] |
23 before_filter :find_project, :only => [:new, :create] | 23 before_filter :find_project_by_project_id, :only => [:new, :create] |
24 before_filter :authorize, :except => [:index] | 24 before_filter :authorize, :except => [:index] |
25 before_filter :find_optional_project, :only => :index | 25 before_filter :find_optional_project, :only => :index |
26 accept_rss_auth :index | 26 accept_rss_auth :index |
27 accept_api_auth :index | 27 accept_api_auth :index |
28 | 28 |
29 helper :watchers | 29 helper :watchers |
30 helper :attachments | |
30 | 31 |
31 def index | 32 def index |
32 case params[:format] | 33 case params[:format] |
33 when 'xml', 'json' | 34 when 'xml', 'json' |
34 @offset, @limit = api_offset_and_limit | 35 @offset, @limit = api_offset_and_limit |
66 end | 67 end |
67 | 68 |
68 def create | 69 def create |
69 @news = News.new(:project => @project, :author => User.current) | 70 @news = News.new(:project => @project, :author => User.current) |
70 @news.safe_attributes = params[:news] | 71 @news.safe_attributes = params[:news] |
71 if request.post? | 72 @news.save_attachments(params[:attachments]) |
72 if @news.save | 73 if @news.save |
73 flash[:notice] = l(:notice_successful_create) | 74 render_attachment_warning_if_needed(@news) |
74 redirect_to :controller => 'news', :action => 'index', :project_id => @project | 75 flash[:notice] = l(:notice_successful_create) |
75 else | 76 redirect_to :controller => 'news', :action => 'index', :project_id => @project |
76 render :action => 'new' | 77 else |
77 end | 78 render :action => 'new' |
78 end | 79 end |
79 end | 80 end |
80 | 81 |
81 def edit | 82 def edit |
82 end | 83 end |
83 | 84 |
84 def update | 85 def update |
85 @news.safe_attributes = params[:news] | 86 @news.safe_attributes = params[:news] |
86 if request.put? and @news.save | 87 @news.save_attachments(params[:attachments]) |
88 if @news.save | |
89 render_attachment_warning_if_needed(@news) | |
87 flash[:notice] = l(:notice_successful_update) | 90 flash[:notice] = l(:notice_successful_update) |
88 redirect_to :action => 'show', :id => @news | 91 redirect_to :action => 'show', :id => @news |
89 else | 92 else |
90 render :action => 'edit' | 93 render :action => 'edit' |
91 end | 94 end |
94 def destroy | 97 def destroy |
95 @news.destroy | 98 @news.destroy |
96 redirect_to :action => 'index', :project_id => @project | 99 redirect_to :action => 'index', :project_id => @project |
97 end | 100 end |
98 | 101 |
99 private | 102 private |
100 def find_project | |
101 @project = Project.find(params[:project_id]) | |
102 rescue ActiveRecord::RecordNotFound | |
103 render_404 | |
104 end | |
105 | 103 |
106 def find_optional_project | 104 def find_optional_project |
107 return true unless params[:project_id] | 105 return true unless params[:project_id] |
108 @project = Project.find(params[:project_id]) | 106 @project = Project.find(params[:project_id]) |
109 authorize | 107 authorize |