##// END OF EJS Templates
set default category_id instead of the object (#11665)...
set default category_id instead of the object (#11665) Rails 2.3 still has issues with synchronizing the association_id and association attributes of an object. That means, if you set the association with an object first and then just set the id afterwards, the object wins and the setting of the id gets lost. This is not an issue in Rails >= 3.1 anymore. Contributed by Holger Just. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@10226 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r9020:2bcf9f28710b
r10043:14dcefaa97f9
Show More
board.rb
56 lines | 2.4 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726 # Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
Jean-Philippe Lang
Per project forums added....
r526 #
# 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.
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726 #
Jean-Philippe Lang
Per project forums added....
r526 # 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.
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726 #
Jean-Philippe Lang
Per project forums added....
r526 # 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 Board < ActiveRecord::Base
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a forum (#10390)....
r9020 include Redmine::SafeAttributes
Jean-Philippe Lang
Per project forums added....
r526 belongs_to :project
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
Jean-Philippe Lang
Fixed: messages attachments/watchers are not deleted when deleting a project or forum (#6966)....
r4317 has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
Jean-Philippe Lang
Per project forums added....
r526 belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
acts_as_list :scope => :project_id
Jean-Philippe Lang
Added watchers for message boards (watchers controller modified to support any watchable model)....
r527 acts_as_watchable
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726
Jean-Philippe Lang
Per project forums added....
r526 validates_presence_of :name, :description
validates_length_of :name, :maximum => 30
validates_length_of :description, :maximum => 255
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726
Jean-Philippe Lang
Wiki links for news and forums (#9600)....
r7720 named_scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a forum (#10390)....
r9020 safe_attributes 'name', 'description', 'move_to'
Jean-Philippe Lang
Makes user unwatch what he can no longer view after its permissions have changed (#3589)....
r3053 def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_messages, project)
end
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726
Jean-Philippe Lang
Adds single forum atom feed (#3181)....
r2590 def to_s
name
end
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726
Jean-Philippe Lang
Adds the ability to move threads between project forums (#2452). 'Edit message' permission is required....
r2560 def reset_counters!
self.class.reset_counters!(id)
end
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726
Jean-Philippe Lang
Adds the ability to move threads between project forums (#2452). 'Edit message' permission is required....
r2560 # Updates topics_count, messages_count and last_message_id attributes for +board_id+
def self.reset_counters!(board_id)
board_id = board_id.to_i
update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," +
" messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," +
" last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})",
["id = ?", board_id])
end
Jean-Philippe Lang
Per project forums added....
r526 end