parent
97707ea44a
commit
80bd535b4f
|
@ -103,7 +103,11 @@ class MessagesController < ApplicationController
|
||||||
|
|
||||||
# Edit a message
|
# Edit a message
|
||||||
def edit
|
def edit
|
||||||
|
if @project
|
||||||
(render_403; return false) unless @message.editable_by?(User.current)
|
(render_403; return false) unless @message.editable_by?(User.current)
|
||||||
|
else
|
||||||
|
(render_403; return false) unless @message.course_editable_by?(User.current)
|
||||||
|
end
|
||||||
@message.safe_attributes = params[:message]
|
@message.safe_attributes = params[:message]
|
||||||
if request.post? && @message.save
|
if request.post? && @message.save
|
||||||
attachments = Attachment.attach_files(@message, params[:attachments])
|
attachments = Attachment.attach_files(@message, params[:attachments])
|
||||||
|
@ -124,7 +128,11 @@ class MessagesController < ApplicationController
|
||||||
|
|
||||||
# Delete a messages
|
# Delete a messages
|
||||||
def destroy
|
def destroy
|
||||||
|
if @project
|
||||||
(render_403; return false) unless @message.destroyable_by?(User.current)
|
(render_403; return false) unless @message.destroyable_by?(User.current)
|
||||||
|
else
|
||||||
|
(render_403; return false) unless @message.course_destroyable_by?(User.current)
|
||||||
|
end
|
||||||
r = @message.to_param
|
r = @message.to_param
|
||||||
@message.destroy
|
@message.destroy
|
||||||
# modify by nwb
|
# modify by nwb
|
||||||
|
|
|
@ -127,6 +127,14 @@ class Message < ActiveRecord::Base
|
||||||
board.course
|
board.course
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def course_editable_by?(usr)
|
||||||
|
usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course)))
|
||||||
|
end
|
||||||
|
|
||||||
|
def course_destroyable_by?(usr)
|
||||||
|
usr && usr.logged? && (usr.allowed_to?(:delete_messages, course) || (self.author == usr && usr.allowed_to?(:delete_own_messages, course)))
|
||||||
|
end
|
||||||
|
|
||||||
def editable_by?(usr)
|
def editable_by?(usr)
|
||||||
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
|
usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
|
||||||
end
|
end
|
||||||
|
|
|
@ -148,7 +148,7 @@
|
||||||
"编辑",
|
"编辑",
|
||||||
{:action => 'edit', :id => message},
|
{:action => 'edit', :id => message},
|
||||||
:title => l(:button_edit)
|
:title => l(:button_edit)
|
||||||
) if message.editable_by?(User.current) %>
|
) if message.course_editable_by?(User.current) %>
|
||||||
<%= link_to(
|
<%= link_to(
|
||||||
#image_tag('delete.png'),
|
#image_tag('delete.png'),
|
||||||
"删除",
|
"删除",
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
:method => :post,
|
:method => :post,
|
||||||
:data => {:confirm => l(:text_are_you_sure)},
|
:data => {:confirm => l(:text_are_you_sure)},
|
||||||
:title => l(:button_delete)
|
:title => l(:button_delete)
|
||||||
) if message.destroyable_by?(User.current) %>
|
) if message.course_destroyable_by?(User.current) %>
|
||||||
</div></td>
|
</div></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in New Issue