To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / news_controller.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (3.37 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2 1295:622f24f53b42 Chris
# Copyright (C) 2006-2013  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# 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 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# 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 37:94944d00e43c chris
  before_filter :find_model_object, :except => [:new, :create, :index]
22
  before_filter :find_project_from_association, :except => [:new, :create, :index]
23 1115:433d4f72a19b Chris
  before_filter :find_project_by_project_id, :only => [:new, :create]
24 37:94944d00e43c chris
  before_filter :authorize, :except => [:index]
25 0:513646585e45 Chris
  before_filter :find_optional_project, :only => :index
26 507:0c939c159af4 Chris
  accept_rss_auth :index
27
  accept_api_auth :index
28 909:cbb26bc654de Chris
29 441:cbce1fd3b1b7 Chris
  helper :watchers
30 1115:433d4f72a19b Chris
  helper :attachments
31 909:cbb26bc654de Chris
32 0:513646585e45 Chris
  def index
33 119:8661b858af72 Chris
    case params[:format]
34
    when 'xml', 'json'
35
      @offset, @limit = api_offset_and_limit
36
    else
37
      @limit =  10
38
    end
39 909:cbb26bc654de Chris
40 119:8661b858af72 Chris
    scope = @project ? @project.news.visible : News.visible
41 909:cbb26bc654de Chris
42 119:8661b858af72 Chris
    @news_count = scope.count
43 1295:622f24f53b42 Chris
    @news_pages = Paginator.new @news_count, @limit, params['page']
44
    @offset ||= @news_pages.offset
45 119:8661b858af72 Chris
    @newss = scope.all(:include => [:author, :project],
46
                                       :order => "#{News.table_name}.created_on DESC",
47
                                       :offset => @offset,
48
                                       :limit => @limit)
49 909:cbb26bc654de Chris
50 0:513646585e45 Chris
    respond_to do |format|
51 909:cbb26bc654de Chris
      format.html {
52
        @news = News.new # for adding news inline
53
        render :layout => false if request.xhr?
54
      }
55 119:8661b858af72 Chris
      format.api
56 0:513646585e45 Chris
      format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
57
    end
58
  end
59 909:cbb26bc654de Chris
60 0:513646585e45 Chris
  def show
61
    @comments = @news.comments
62
    @comments.reverse! if User.current.wants_comments_in_reverse_order?
63
  end
64
65
  def new
66
    @news = News.new(:project => @project, :author => User.current)
67 22:40f7cfd4df19 chris
  end
68
69
  def create
70
    @news = News.new(:project => @project, :author => User.current)
71 929:5f33065ddc4b Chris
    @news.safe_attributes = params[:news]
72 1115:433d4f72a19b Chris
    @news.save_attachments(params[:attachments])
73
    if @news.save
74
      render_attachment_warning_if_needed(@news)
75
      flash[:notice] = l(:notice_successful_create)
76 1295:622f24f53b42 Chris
      redirect_to project_news_index_path(@project)
77 1115:433d4f72a19b Chris
    else
78
      render :action => 'new'
79 0:513646585e45 Chris
    end
80
  end
81 22:40f7cfd4df19 chris
82
  def edit
83
  end
84 909:cbb26bc654de Chris
85 22:40f7cfd4df19 chris
  def update
86 929:5f33065ddc4b Chris
    @news.safe_attributes = params[:news]
87 1115:433d4f72a19b Chris
    @news.save_attachments(params[:attachments])
88
    if @news.save
89
      render_attachment_warning_if_needed(@news)
90 0:513646585e45 Chris
      flash[:notice] = l(:notice_successful_update)
91 1295:622f24f53b42 Chris
      redirect_to news_path(@news)
92 22:40f7cfd4df19 chris
    else
93
      render :action => 'edit'
94 0:513646585e45 Chris
    end
95
  end
96
97
  def destroy
98
    @news.destroy
99 1295:622f24f53b42 Chris
    redirect_to project_news_index_path(@project)
100 0:513646585e45 Chris
  end
101 909:cbb26bc654de Chris
102 1115:433d4f72a19b Chris
  private
103 909:cbb26bc654de Chris
104 0:513646585e45 Chris
  def find_optional_project
105
    return true unless params[:project_id]
106
    @project = Project.find(params[:project_id])
107
    authorize
108
  rescue ActiveRecord::RecordNotFound
109
    render_404
110
  end
111
end