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