diff app/controllers/news_controller.rb @ 511:107d36338b70 live

Merge from branch "cannam"
author Chris Cannam
date Thu, 14 Jul 2011 10:43:07 +0100
parents 0c939c159af4
children cbb26bc654de
line wrap: on
line diff
--- a/app/controllers/news_controller.rb	Thu Jun 09 16:51:06 2011 +0100
+++ b/app/controllers/news_controller.rb	Thu Jul 14 10:43:07 2011 +0100
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006  Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -23,18 +23,32 @@
   before_filter :find_project, :only => [:new, :create]
   before_filter :authorize, :except => [:index]
   before_filter :find_optional_project, :only => :index
-  accept_key_auth :index
+  accept_rss_auth :index
+  accept_api_auth :index
+  
+  helper :watchers
   
   def index
-    @news_pages, @newss = paginate :news,
-                                   :per_page => 10,
-                                   :conditions => Project.allowed_to_condition(User.current, :view_news, :project => @project),
-                                   :include => [:author, :project],
-                                   :order => "#{News.table_name}.created_on DESC"    
+    case params[:format]
+    when 'xml', 'json'
+      @offset, @limit = api_offset_and_limit
+    else
+      @limit =  10
+    end
+    
+    scope = @project ? @project.news.visible : News.visible
+    
+    @news_count = scope.count
+    @news_pages = Paginator.new self, @news_count, @limit, params['page']
+    @offset ||= @news_pages.current.offset
+    @newss = scope.all(:include => [:author, :project],
+                                       :order => "#{News.table_name}.created_on DESC",
+                                       :offset => @offset,
+                                       :limit => @limit)
+    
     respond_to do |format|
       format.html { render :layout => false if request.xhr? }
-      format.xml { render :xml => @newss.to_xml }
-      format.json { render :json => @newss.to_json }
+      format.api
       format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
     end
   end