This commit is contained in:
z9hang 2014-07-28 13:53:57 +08:00
commit 9bf8abd03b
8 changed files with 30 additions and 6 deletions

View File

@ -174,7 +174,9 @@ class AttachmentsController < ApplicationController
respond_to do |format|
# modify by nwb
if !@attachment.container.nil? && (@attachment.container.is_a?(Course) || @attachment.container.course)
if @course.nil?
if @attachment.container.is_a?(News)
format.html { redirect_to_referer_or news_path(@attachment.container) }
elsif @course.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
else
format.html { redirect_to_referer_or course_path(@course) }

View File

@ -68,6 +68,10 @@ module ApplicationHelper
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
end
def link_to_if_authorized_course(name, options = {}, html_options = nil, *parameters_for_method_reference)
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_course(options[:controller] || params[:controller], options[:action])
end
def link_to_if_authorized_contest(name, options = {}, html_options = nil, *parameters_for_method_reference)
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_contest(options[:controller] || params[:controller], options[:action])
end

View File

@ -68,6 +68,7 @@ class JournalsForMessage < ActiveRecord::Base
return true
end
end
def self.remove_by_user? user
if( self.user == user ||
@ -87,6 +88,15 @@ class JournalsForMessage < ActiveRecord::Base
def reference_user
User.find(reply_id)
end
def delete_by_user?user
# 用户可删除自己的留言
if self.user.id == user.id || user.admin?
return true
else
return false
end
end
def self.reference_message(user_id)
@user = User.find(user_id)

View File

@ -15,7 +15,7 @@
:method => :delete,
:class => 'delete',
:title => l(:button_delete) %>
<% else %>
<% else %>
<%= link_to image_tag('delete.png'), attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,

View File

@ -78,6 +78,9 @@ function checkMaxLength() {
'#{l(:label_reply_plural)} #{journal.user.name}: ');
return false;"} %>
<% end %>
<% if journal.delete_by_user?(User.current) %>
<%= link_to(l(:button_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => journal.user}, :method => :delete,:remote => true)%>
<% end %>
</span>
</span>
<div style="clear: both;"></div>

View File

@ -75,7 +75,7 @@
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= format_time(comment.created_on) %></span></td>
<td width="200" align="right" class="a"><%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
<td width="200" align="right" class="a"><%= link_to_if_authorized_course image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %></td>
</tr>
</table></td>

View File

@ -12,7 +12,7 @@
</div>
<div class="wiki-description">
<p>
<%= textilizable(project.short_description, :project => project) %>
<%= textilizable(project.short_description.strip, :project => project) %>
</p>
</div>

View File

@ -48,8 +48,13 @@ module Redmine
end
def attachments_deletable?(user=User.current)
(respond_to?(:visible?) ? visible?(user) : true) &&
user.allowed_to?(self.class.attachable_options[:delete_permission], self.project)
if (self.has_attribute?(:course) ||self.has_attribute?(:course_id)) && self.course
(respond_to?(:visible?) ? visible?(user) : true) &&
user.allowed_to?(self.class.attachable_options[:delete_permission], self.course)
else
(respond_to?(:visible?) ? visible?(user) : true) &&
user.allowed_to?(self.class.attachable_options[:delete_permission], self.project)
end
end
def saved_attachments