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