annotate app/controllers/news_controller.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@441 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 class NewsController < ApplicationController
Chris@0 19 default_search_scope :news
Chris@0 20 model_object News
chris@37 21 before_filter :find_model_object, :except => [:new, :create, :index]
chris@37 22 before_filter :find_project_from_association, :except => [:new, :create, :index]
Chris@1115 23 before_filter :find_project_by_project_id, :only => [:new, :create]
chris@37 24 before_filter :authorize, :except => [:index]
Chris@0 25 before_filter :find_optional_project, :only => :index
Chris@507 26 accept_rss_auth :index
Chris@507 27 accept_api_auth :index
Chris@909 28
Chris@441 29 helper :watchers
Chris@1115 30 helper :attachments
Chris@909 31
Chris@0 32 def index
Chris@119 33 case params[:format]
Chris@119 34 when 'xml', 'json'
Chris@119 35 @offset, @limit = api_offset_and_limit
Chris@119 36 else
Chris@119 37 @limit = 10
Chris@119 38 end
Chris@909 39
Chris@119 40 scope = @project ? @project.news.visible : News.visible
Chris@909 41
Chris@119 42 @news_count = scope.count
Chris@1464 43 @news_pages = Paginator.new @news_count, @limit, params['page']
Chris@1464 44 @offset ||= @news_pages.offset
Chris@1517 45 @newss = scope.includes([:author, :project]).
Chris@1517 46 order("#{News.table_name}.created_on DESC").
Chris@1517 47 limit(@limit).
Chris@1517 48 offset(@offset).
Chris@1517 49 all
Chris@0 50 respond_to do |format|
Chris@909 51 format.html {
Chris@909 52 @news = News.new # for adding news inline
Chris@909 53 render :layout => false if request.xhr?
Chris@909 54 }
Chris@119 55 format.api
Chris@0 56 format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
Chris@0 57 end
Chris@0 58 end
Chris@909 59
Chris@0 60 def show
Chris@0 61 @comments = @news.comments
Chris@0 62 @comments.reverse! if User.current.wants_comments_in_reverse_order?
Chris@0 63 end
Chris@0 64
Chris@0 65 def new
Chris@0 66 @news = News.new(:project => @project, :author => User.current)
chris@22 67 end
chris@22 68
chris@22 69 def create
chris@22 70 @news = News.new(:project => @project, :author => User.current)
Chris@929 71 @news.safe_attributes = params[:news]
Chris@1115 72 @news.save_attachments(params[:attachments])
Chris@1115 73 if @news.save
Chris@1115 74 render_attachment_warning_if_needed(@news)
Chris@1115 75 flash[:notice] = l(:notice_successful_create)
Chris@1464 76 redirect_to project_news_index_path(@project)
Chris@1115 77 else
Chris@1115 78 render :action => 'new'
Chris@0 79 end
Chris@0 80 end
chris@22 81
chris@22 82 def edit
chris@22 83 end
Chris@909 84
chris@22 85 def update
Chris@929 86 @news.safe_attributes = params[:news]
Chris@1115 87 @news.save_attachments(params[:attachments])
Chris@1115 88 if @news.save
Chris@1115 89 render_attachment_warning_if_needed(@news)
Chris@0 90 flash[:notice] = l(:notice_successful_update)
Chris@1464 91 redirect_to news_path(@news)
chris@22 92 else
chris@22 93 render :action => 'edit'
Chris@0 94 end
Chris@0 95 end
Chris@0 96
Chris@0 97 def destroy
Chris@0 98 @news.destroy
Chris@1464 99 redirect_to project_news_index_path(@project)
Chris@0 100 end
Chris@909 101
Chris@1115 102 private
Chris@909 103
Chris@0 104 def find_optional_project
Chris@0 105 return true unless params[:project_id]
Chris@0 106 @project = Project.find(params[:project_id])
Chris@0 107 authorize
Chris@0 108 rescue ActiveRecord::RecordNotFound
Chris@0 109 render_404
Chris@0 110 end
Chris@0 111 end