annotate .svn/pristine/bf/bf0d465ef5c11d88a518f88080f61e4860e106e8.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 Message < ActiveRecord::Base
Chris@1517 19 include Redmine::SafeAttributes
Chris@1517 20 belongs_to :board
Chris@1517 21 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
Chris@1517 22 acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
Chris@1517 23 acts_as_attachable
Chris@1517 24 belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
Chris@1517 25
Chris@1517 26 acts_as_searchable :columns => ['subject', 'content'],
Chris@1517 27 :include => {:board => :project},
Chris@1517 28 :project_key => "#{Board.table_name}.project_id",
Chris@1517 29 :date_column => "#{table_name}.created_on"
Chris@1517 30 acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
Chris@1517 31 :description => :content,
Chris@1517 32 :group => :parent,
Chris@1517 33 :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
Chris@1517 34 :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
Chris@1517 35 {:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
Chris@1517 36
Chris@1517 37 acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
Chris@1517 38 :author_key => :author_id
Chris@1517 39 acts_as_watchable
Chris@1517 40
Chris@1517 41 validates_presence_of :board, :subject, :content
Chris@1517 42 validates_length_of :subject, :maximum => 255
Chris@1517 43 validate :cannot_reply_to_locked_topic, :on => :create
Chris@1517 44
Chris@1517 45 after_create :add_author_as_watcher, :reset_counters!
Chris@1517 46 after_update :update_messages_board
Chris@1517 47 after_destroy :reset_counters!
Chris@1517 48 after_create :send_notification
Chris@1517 49
Chris@1517 50 scope :visible, lambda {|*args|
Chris@1517 51 includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
Chris@1517 52 }
Chris@1517 53
Chris@1517 54 safe_attributes 'subject', 'content'
Chris@1517 55 safe_attributes 'locked', 'sticky', 'board_id',
Chris@1517 56 :if => lambda {|message, user|
Chris@1517 57 user.allowed_to?(:edit_messages, message.project)
Chris@1517 58 }
Chris@1517 59
Chris@1517 60 def visible?(user=User.current)
Chris@1517 61 !user.nil? && user.allowed_to?(:view_messages, project)
Chris@1517 62 end
Chris@1517 63
Chris@1517 64 def cannot_reply_to_locked_topic
Chris@1517 65 # Can not reply to a locked topic
Chris@1517 66 errors.add :base, 'Topic is locked' if root.locked? && self != root
Chris@1517 67 end
Chris@1517 68
Chris@1517 69 def update_messages_board
Chris@1517 70 if board_id_changed?
Chris@1517 71 Message.where(["id = ? OR parent_id = ?", root.id, root.id]).update_all({:board_id => board_id})
Chris@1517 72 Board.reset_counters!(board_id_was)
Chris@1517 73 Board.reset_counters!(board_id)
Chris@1517 74 end
Chris@1517 75 end
Chris@1517 76
Chris@1517 77 def reset_counters!
Chris@1517 78 if parent && parent.id
Chris@1517 79 Message.where({:id => parent.id}).update_all({:last_reply_id => parent.children.maximum(:id)})
Chris@1517 80 end
Chris@1517 81 board.reset_counters!
Chris@1517 82 end
Chris@1517 83
Chris@1517 84 def sticky=(arg)
Chris@1517 85 write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
Chris@1517 86 end
Chris@1517 87
Chris@1517 88 def sticky?
Chris@1517 89 sticky == 1
Chris@1517 90 end
Chris@1517 91
Chris@1517 92 def project
Chris@1517 93 board.project
Chris@1517 94 end
Chris@1517 95
Chris@1517 96 def editable_by?(usr)
Chris@1517 97 usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
Chris@1517 98 end
Chris@1517 99
Chris@1517 100 def destroyable_by?(usr)
Chris@1517 101 usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
Chris@1517 102 end
Chris@1517 103
Chris@1517 104 private
Chris@1517 105
Chris@1517 106 def add_author_as_watcher
Chris@1517 107 Watcher.create(:watchable => self.root, :user => author)
Chris@1517 108 end
Chris@1517 109
Chris@1517 110 def send_notification
Chris@1517 111 if Setting.notified_events.include?('message_posted')
Chris@1517 112 Mailer.message_posted(self).deliver
Chris@1517 113 end
Chris@1517 114 end
Chris@1517 115 end