##// END OF EJS Templates
Backported r2429, r2430, r248 to r2491 and r2522 from trunk (request and controller objects added to the hooks by default.)....
Backported r2429, r2430, r248 to r2491 and r2522 from trunk (request and controller objects added to the hooks by default.). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.8-stable@2558 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r2364:bc4249e3d3ed
r2490:36b5d4f6af04
Show More
message.rb
89 lines | 3.3 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Per project forums added....
r526 # redMine - project management software
# Copyright (C) 2006-2007 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
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Message < ActiveRecord::Base
belongs_to :board
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
Jean-Philippe Lang
Merged r2116, r2117 and r2187 from trunk....
r2215 acts_as_attachable
Jean-Philippe Lang
Per project forums added....
r526 belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
Jean-Philippe Lang
Fixed: unable to migrate from an empty database....
r760 acts_as_searchable :columns => ['subject', 'content'],
Jean-Philippe Lang
Merged r2270, r2344, r2359, r2360, r2362, r2363, r2415, r2423, r2424 from trunk....
r2364 :include => {:board => :project},
Jean-Philippe Lang
Fixed: unable to migrate from an empty database....
r760 :project_key => 'project_id',
Jean-Philippe Lang
Ability to search all projects or the projects the user belongs to (#791)....
r1420 :date_column => "#{table_name}.created_on"
Jean-Philippe Lang
Search engines now supports pagination....
r755 acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
:description => :content,
Jean-Philippe Lang
Add an icon to each event on the activity view....
r1327 :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
Jean-Philippe Lang
Adds anchor to atom feed messages links....
r1574 :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
{:id => o.parent_id, :anchor => "message-#{o.id}"})}
Jean-Philippe Lang
Activity refactoring....
r1692
Jean-Philippe Lang
Display latest user's activity on account/show view....
r2064 acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
:author_key => :author_id
Jean-Philippe Lang
Adds watch/unwatch functionality at forum topic level (#1912)....
r1876 acts_as_watchable
Jean-Philippe Lang
Activity refactoring....
r1692
Jean-Philippe Lang
Forums enhancements:...
r913 attr_protected :locked, :sticky
Jean-Philippe Lang
Per project forums added....
r526 validates_presence_of :subject, :content
validates_length_of :subject, :maximum => 255
Jean-Philippe Lang
Adds watch/unwatch functionality at forum topic level (#1912)....
r1876 after_create :add_author_as_watcher
Jean-Philippe Lang
Forums enhancements:...
r913 def validate_on_create
# Can not reply to a locked topic
Jean-Philippe Lang
Fixed: can not lock a topic when creating it....
r1081 errors.add_to_base 'Topic is locked' if root.locked? && self != root
Jean-Philippe Lang
Forums enhancements:...
r913 end
Jean-Philippe Lang
Per project forums added....
r526 def after_create
board.update_attribute(:last_message_id, self.id)
board.increment! :messages_count
if parent
parent.reload.update_attribute(:last_reply_id, self.id)
else
board.increment! :topics_count
end
end
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538
Jean-Philippe Lang
Forums enhancements:...
r913 def after_destroy
# The following line is required so that the previous counter
# updates (due to children removal) are not overwritten
board.reload
board.decrement! :messages_count
board.decrement! :topics_count unless parent
end
def sticky?
sticky == 1
end
Jean-Philippe Lang
Attachments can now be added to wiki pages (original patch by Pavol Murin). Only authorized users can add/delete attachments....
r538 def project
board.project
end
Jean-Philippe Lang
Adds permissions to let users edit and/or delete their messages (#854, patch by Markus Knittig with slight changes)....
r2017
def editable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
end
def destroyable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
end
Jean-Philippe Lang
Adds watch/unwatch functionality at forum topic level (#1912)....
r1876
private
def add_author_as_watcher
Watcher.create(:watchable => self.root, :user => author)
end
Jean-Philippe Lang
Per project forums added....
r526 end