annotate .svn/pristine/f9/f9a3c2fc35d351c140eb4c5c08fb19d887d2a468.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +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 News < ActiveRecord::Base
Chris@1517 19 include Redmine::SafeAttributes
Chris@1517 20 belongs_to :project
Chris@1517 21 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
Chris@1517 22 has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
Chris@1517 23
Chris@1517 24 validates_presence_of :title, :description
Chris@1517 25 validates_length_of :title, :maximum => 60
Chris@1517 26 validates_length_of :summary, :maximum => 255
Chris@1517 27
Chris@1517 28 acts_as_attachable :delete_permission => :manage_news
Chris@1517 29 acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project
Chris@1517 30 acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
Chris@1517 31 acts_as_activity_provider :find_options => {:include => [:project, :author]},
Chris@1517 32 :author_key => :author_id
Chris@1517 33 acts_as_watchable
Chris@1517 34
Chris@1517 35 after_create :add_author_as_watcher
Chris@1517 36 after_create :send_notification
Chris@1517 37
Chris@1517 38 scope :visible, lambda {|*args|
Chris@1517 39 includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
Chris@1517 40 }
Chris@1517 41
Chris@1517 42 safe_attributes 'title', 'summary', 'description'
Chris@1517 43
Chris@1517 44 def visible?(user=User.current)
Chris@1517 45 !user.nil? && user.allowed_to?(:view_news, project)
Chris@1517 46 end
Chris@1517 47
Chris@1517 48 # Returns true if the news can be commented by user
Chris@1517 49 def commentable?(user=User.current)
Chris@1517 50 user.allowed_to?(:comment_news, project)
Chris@1517 51 end
Chris@1517 52
Chris@1517 53 def recipients
Chris@1517 54 project.users.select {|user| user.notify_about?(self) && user.allowed_to?(:view_news, project)}.map(&:mail)
Chris@1517 55 end
Chris@1517 56
Chris@1517 57 # Returns the email addresses that should be cc'd when a new news is added
Chris@1517 58 def cc_for_added_news
Chris@1517 59 cc = []
Chris@1517 60 if m = project.enabled_module('news')
Chris@1517 61 cc = m.notified_watchers
Chris@1517 62 unless project.is_public?
Chris@1517 63 cc = cc.select {|user| project.users.include?(user)}
Chris@1517 64 end
Chris@1517 65 end
Chris@1517 66 cc.map(&:mail)
Chris@1517 67 end
Chris@1517 68
Chris@1517 69 # returns latest news for projects visible by user
Chris@1517 70 def self.latest(user = User.current, count = 5)
Chris@1517 71 visible(user).includes([:author, :project]).order("#{News.table_name}.created_on DESC").limit(count).all
Chris@1517 72 end
Chris@1517 73
Chris@1517 74 private
Chris@1517 75
Chris@1517 76 def add_author_as_watcher
Chris@1517 77 Watcher.create(:watchable => self, :user => author)
Chris@1517 78 end
Chris@1517 79
Chris@1517 80 def send_notification
Chris@1517 81 if Setting.notified_events.include?('news_added')
Chris@1517 82 Mailer.news_added(self).deliver
Chris@1517 83 end
Chris@1517 84 end
Chris@1517 85 end