##// END OF EJS Templates
Fixed: News from a project with 'news' module disabled, are still diplayed in the cross-project news list (#4333)....
Jean-Philippe Lang -
r3006:8bc0f7888bdd
parent child
Show More
@@ -1,109 +1,109
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class NewsController < ApplicationController
18 class NewsController < ApplicationController
19 default_search_scope :news
19 default_search_scope :news
20 before_filter :find_news, :except => [:new, :index, :preview]
20 before_filter :find_news, :except => [:new, :index, :preview]
21 before_filter :find_project, :only => [:new, :preview]
21 before_filter :find_project, :only => [:new, :preview]
22 before_filter :authorize, :except => [:index, :preview]
22 before_filter :authorize, :except => [:index, :preview]
23 before_filter :find_optional_project, :only => :index
23 before_filter :find_optional_project, :only => :index
24 accept_key_auth :index
24 accept_key_auth :index
25
25
26 def index
26 def index
27 @news_pages, @newss = paginate :news,
27 @news_pages, @newss = paginate :news,
28 :per_page => 10,
28 :per_page => 10,
29 :conditions => (@project ? {:project_id => @project.id} : Project.visible_by(User.current)),
29 :conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project),
30 :include => [:author, :project],
30 :include => [:author, :project],
31 :order => "#{News.table_name}.created_on DESC"
31 :order => "#{News.table_name}.created_on DESC"
32 respond_to do |format|
32 respond_to do |format|
33 format.html { render :layout => false if request.xhr? }
33 format.html { render :layout => false if request.xhr? }
34 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
34 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
35 end
35 end
36 end
36 end
37
37
38 def show
38 def show
39 @comments = @news.comments
39 @comments = @news.comments
40 @comments.reverse! if User.current.wants_comments_in_reverse_order?
40 @comments.reverse! if User.current.wants_comments_in_reverse_order?
41 end
41 end
42
42
43 def new
43 def new
44 @news = News.new(:project => @project, :author => User.current)
44 @news = News.new(:project => @project, :author => User.current)
45 if request.post?
45 if request.post?
46 @news.attributes = params[:news]
46 @news.attributes = params[:news]
47 if @news.save
47 if @news.save
48 flash[:notice] = l(:notice_successful_create)
48 flash[:notice] = l(:notice_successful_create)
49 redirect_to :controller => 'news', :action => 'index', :project_id => @project
49 redirect_to :controller => 'news', :action => 'index', :project_id => @project
50 end
50 end
51 end
51 end
52 end
52 end
53
53
54 def edit
54 def edit
55 if request.post? and @news.update_attributes(params[:news])
55 if request.post? and @news.update_attributes(params[:news])
56 flash[:notice] = l(:notice_successful_update)
56 flash[:notice] = l(:notice_successful_update)
57 redirect_to :action => 'show', :id => @news
57 redirect_to :action => 'show', :id => @news
58 end
58 end
59 end
59 end
60
60
61 def add_comment
61 def add_comment
62 @comment = Comment.new(params[:comment])
62 @comment = Comment.new(params[:comment])
63 @comment.author = User.current
63 @comment.author = User.current
64 if @news.comments << @comment
64 if @news.comments << @comment
65 flash[:notice] = l(:label_comment_added)
65 flash[:notice] = l(:label_comment_added)
66 redirect_to :action => 'show', :id => @news
66 redirect_to :action => 'show', :id => @news
67 else
67 else
68 show
68 show
69 render :action => 'show'
69 render :action => 'show'
70 end
70 end
71 end
71 end
72
72
73 def destroy_comment
73 def destroy_comment
74 @news.comments.find(params[:comment_id]).destroy
74 @news.comments.find(params[:comment_id]).destroy
75 redirect_to :action => 'show', :id => @news
75 redirect_to :action => 'show', :id => @news
76 end
76 end
77
77
78 def destroy
78 def destroy
79 @news.destroy
79 @news.destroy
80 redirect_to :action => 'index', :project_id => @project
80 redirect_to :action => 'index', :project_id => @project
81 end
81 end
82
82
83 def preview
83 def preview
84 @text = (params[:news] ? params[:news][:description] : nil)
84 @text = (params[:news] ? params[:news][:description] : nil)
85 render :partial => 'common/preview'
85 render :partial => 'common/preview'
86 end
86 end
87
87
88 private
88 private
89 def find_news
89 def find_news
90 @news = News.find(params[:id])
90 @news = News.find(params[:id])
91 @project = @news.project
91 @project = @news.project
92 rescue ActiveRecord::RecordNotFound
92 rescue ActiveRecord::RecordNotFound
93 render_404
93 render_404
94 end
94 end
95
95
96 def find_project
96 def find_project
97 @project = Project.find(params[:project_id])
97 @project = Project.find(params[:project_id])
98 rescue ActiveRecord::RecordNotFound
98 rescue ActiveRecord::RecordNotFound
99 render_404
99 render_404
100 end
100 end
101
101
102 def find_optional_project
102 def find_optional_project
103 return true unless params[:project_id]
103 return true unless params[:project_id]
104 @project = Project.find(params[:project_id])
104 @project = Project.find(params[:project_id])
105 authorize
105 authorize
106 rescue ActiveRecord::RecordNotFound
106 rescue ActiveRecord::RecordNotFound
107 render_404
107 render_404
108 end
108 end
109 end
109 end
General Comments 0
You need to be logged in to leave comments. Login now