annotate .svn/pristine/c9/c931f2d34cca31d2bb57a53ae8694c7f520ff6e5.svn-base @ 929:5f33065ddc4b redmine-1.3

Update to Redmine SVN rev 9414 on 1.3-stable branch
author Chris Cannam
date Wed, 27 Jun 2012 14:54:18 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 class News < ActiveRecord::Base
Chris@909 19 belongs_to :project
Chris@909 20 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
Chris@909 21 has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
Chris@909 22
Chris@909 23 validates_presence_of :title, :description
Chris@909 24 validates_length_of :title, :maximum => 60
Chris@909 25 validates_length_of :summary, :maximum => 255
Chris@909 26
Chris@909 27 acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project
Chris@909 28 acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
Chris@909 29 acts_as_activity_provider :find_options => {:include => [:project, :author]},
Chris@909 30 :author_key => :author_id
Chris@909 31 acts_as_watchable
Chris@909 32
Chris@909 33 after_create :add_author_as_watcher
Chris@909 34
Chris@909 35 named_scope :visible, lambda {|*args| {
Chris@909 36 :include => :project,
Chris@909 37 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args)
Chris@909 38 }}
Chris@909 39
Chris@909 40 def visible?(user=User.current)
Chris@909 41 !user.nil? && user.allowed_to?(:view_news, project)
Chris@909 42 end
Chris@909 43
Chris@909 44 # returns latest news for projects visible by user
Chris@909 45 def self.latest(user = User.current, count = 5)
Chris@909 46 find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
Chris@909 47 end
Chris@909 48
Chris@909 49 private
Chris@909 50
Chris@909 51 def add_author_as_watcher
Chris@909 52 Watcher.create(:watchable => self, :user => author)
Chris@909 53 end
Chris@909 54 end