@@ -50,13 +50,10 class MessagesController < ApplicationController | |||||
50 |
|
50 | |||
51 | # Create a new topic |
|
51 | # Create a new topic | |
52 | def new |
|
52 | def new | |
53 |
@message = Message.new |
|
53 | @message = Message.new | |
54 | @message.author = User.current |
|
54 | @message.author = User.current | |
55 | @message.board = @board |
|
55 | @message.board = @board | |
56 | if params[:message] && User.current.allowed_to?(:edit_messages, @project) |
|
56 | @message.safe_attributes = params[:message] | |
57 | @message.locked = params[:message]['locked'] |
|
|||
58 | @message.sticky = params[:message]['sticky'] |
|
|||
59 | end |
|
|||
60 | if request.post? |
|
57 | if request.post? | |
61 | @message.save_attachments(params[:attachments]) |
|
58 | @message.save_attachments(params[:attachments]) | |
62 | if @message.save |
|
59 | if @message.save | |
@@ -69,9 +66,10 class MessagesController < ApplicationController | |||||
69 |
|
66 | |||
70 | # Reply to a topic |
|
67 | # Reply to a topic | |
71 | def reply |
|
68 | def reply | |
72 |
@reply = Message.new |
|
69 | @reply = Message.new | |
73 | @reply.author = User.current |
|
70 | @reply.author = User.current | |
74 | @reply.board = @board |
|
71 | @reply.board = @board | |
|
72 | @reply.safe_attributes = params[:reply] | |||
75 | @topic.children << @reply |
|
73 | @topic.children << @reply | |
76 | if !@reply.new_record? |
|
74 | if !@reply.new_record? | |
77 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) |
|
75 | call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply}) | |
@@ -84,11 +82,8 class MessagesController < ApplicationController | |||||
84 | # Edit a message |
|
82 | # Edit a message | |
85 | def edit |
|
83 | def edit | |
86 | (render_403; return false) unless @message.editable_by?(User.current) |
|
84 | (render_403; return false) unless @message.editable_by?(User.current) | |
87 |
|
|
85 | @message.safe_attributes = params[:message] | |
88 | @message.locked = params[:message]['locked'] |
|
86 | if request.post? && @message.save | |
89 | @message.sticky = params[:message]['sticky'] |
|
|||
90 | end |
|
|||
91 | if request.post? && @message.update_attributes(params[:message]) |
|
|||
92 | attachments = Attachment.attach_files(@message, params[:attachments]) |
|
87 | attachments = Attachment.attach_files(@message, params[:attachments]) | |
93 | render_attachment_warning_if_needed(@message) |
|
88 | render_attachment_warning_if_needed(@message) | |
94 | flash[:notice] = l(:notice_successful_update) |
|
89 | flash[:notice] = l(:notice_successful_update) |
@@ -16,6 +16,7 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Message < ActiveRecord::Base |
|
18 | class Message < ActiveRecord::Base | |
|
19 | include Redmine::SafeAttributes | |||
19 | belongs_to :board |
|
20 | belongs_to :board | |
20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
21 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | |
21 | acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" |
|
22 | acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" | |
@@ -48,6 +49,12 class Message < ActiveRecord::Base | |||||
48 | named_scope :visible, lambda {|*args| { :include => {:board => :project}, |
|
49 | named_scope :visible, lambda {|*args| { :include => {:board => :project}, | |
49 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } |
|
50 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } | |
50 |
|
51 | |||
|
52 | safe_attributes 'subject', 'content' | |||
|
53 | safe_attributes 'locked', 'sticky', | |||
|
54 | :if => lambda {|message, user| | |||
|
55 | user.allowed_to?(:edit_messages, message.project) | |||
|
56 | } | |||
|
57 | ||||
51 | def visible?(user=User.current) |
|
58 | def visible?(user=User.current) | |
52 | !user.nil? && user.allowed_to?(:view_messages, project) |
|
59 | !user.nil? && user.allowed_to?(:view_messages, project) | |
53 | end |
|
60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now