##// END OF EJS Templates
Adds the date format for ambiguous dates (#19243)....
Adds the date format for ambiguous dates (#19243). git-svn-id: http://svn.redmine.org/redmine/trunk@14048 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r13490:000124f44f53
r13666:f821eaf7221c
Show More
board.rb
96 lines | 3.1 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r13490 # Copyright (C) 2006-2015 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
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 has_many :messages, lambda {order("#{Message.table_name}.created_on DESC")}, :dependent => :destroy
Jean-Philippe Lang
Removed unneeded :foreign_key option on belongs_to associations....
r13102 belongs_to :last_message, :class_name => 'Message'
Jean-Philippe Lang
Support for subforums (#3831)....
r9959 acts_as_tree :dependent => :nullify
acts_as_list :scope => '(project_id = #{project_id} AND parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"})'
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
Jean-Philippe Lang
Support for subforums (#3831)....
r9959 validate :validate_board
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 attr_protected :id
Toshi MARUYAMA
remove trailing white-spaces from app/models/board.rb....
r6726
Toshi MARUYAMA
remove trailing white-space from app/models/board.rb...
r11108 scope :visible, lambda {|*args|
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 joins(:project).
where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
Jean-Philippe Lang
Rewrites named scopes with ARel queries....
r10723 }
Jean-Philippe Lang
Wiki links for news and forums (#9600)....
r7720
Jean-Philippe Lang
Support for subforums (#3831)....
r9959 safe_attributes 'name', 'description', 'parent_id', 'move_to'
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a forum (#10390)....
r9020
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
Support for subforums (#3831)....
r9959 def reload(*args)
@valid_parents = nil
super
end
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
Replaced Board#topics with a regular method....
r13109 # Returns a scope for the board topics (messages without parent)
def topics
messages.where(:parent_id => nil)
end
Jean-Philippe Lang
Support for subforums (#3831)....
r9959 def valid_parents
@valid_parents ||= project.boards - self_and_descendants
end
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
Jean-Philippe Lang
Code cleanup, use array instead of handcrafted update....
r13103 Board.where(:id => board_id).
update_all(["topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=:id AND parent_id IS NULL)," +
" messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=:id)," +
" last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=:id)", :id => board_id])
Jean-Philippe Lang
Adds the ability to move threads between project forums (#2452). 'Edit message' permission is required....
r2560 end
Jean-Philippe Lang
Support for subforums (#3831)....
r9959
def self.board_tree(boards, parent_id=nil, level=0)
tree = []
boards.select {|board| board.parent_id == parent_id}.sort_by(&:position).each do |board|
tree << [board, level]
tree += board_tree(boards, board.id, level+1)
end
if block_given?
tree.each do |board, level|
yield board, level
end
end
tree
end
protected
def validate_board
if parent_id && parent_id_changed?
errors.add(:parent_id, :invalid) unless valid_parents.include?(parent)
end
end
Jean-Philippe Lang
Per project forums added....
r526 end