diff app/models/news.rb @ 1339:c03a6c3c4db9 luisf

Merge
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 20 Jun 2013 14:34:42 +0100
parents bb32da3bea34
children 4f746d8966dd 51364c0cd58f
line wrap: on
line diff
--- a/app/models/news.rb	Wed Nov 21 18:16:32 2012 +0000
+++ b/app/models/news.rb	Thu Jun 20 14:34:42 2013 +0100
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  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
@@ -25,6 +25,7 @@
   validates_length_of :title, :maximum => 60
   validates_length_of :summary, :maximum => 255
 
+  acts_as_attachable :delete_permission => :manage_news
   acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project
   acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
   acts_as_activity_provider :find_options => {:include => [:project, :author]},
@@ -33,7 +34,7 @@
 
   after_create :add_author_as_watcher
 
-  named_scope :visible, lambda {|*args| {
+  scope :visible, lambda {|*args| {
     :include => :project,
     :conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args)
   }}
@@ -44,9 +45,14 @@
     !user.nil? && user.allowed_to?(:view_news, project)
   end
 
+  # Returns true if the news can be commented by user
+  def commentable?(user=User.current)
+    user.allowed_to?(:comment_news, project)
+  end
+
   # returns latest news for projects visible by user
   def self.latest(user = User.current, count = 5)
-    find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")	
+    visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all
   end
 
   private