diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 026a12e9a..36dd61105 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -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) } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b6cd47924..77741e5e5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 4debe668f..c79004794 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -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) diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index 52b090bd8..99ecab35d 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -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, diff --git a/app/views/courses/feedback.html.erb b/app/views/courses/feedback.html.erb index 90803fdd0..903b0b5fc 100644 --- a/app/views/courses/feedback.html.erb +++ b/app/views/courses/feedback.html.erb @@ -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 %>
diff --git a/app/views/news/_course_show.html.erb b/app/views/news/_course_show.html.erb index 7b5d17e43..727c9eb7a 100644 --- a/app/views/news/_course_show.html.erb +++ b/app/views/news/_course_show.html.erb @@ -75,7 +75,7 @@ <%= format_time(comment.created_on) %> - <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment}, + <%= 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) %> diff --git a/app/views/projects/_project.html.erb b/app/views/projects/_project.html.erb index c057202f8..3c858cce6 100644 --- a/app/views/projects/_project.html.erb +++ b/app/views/projects/_project.html.erb @@ -12,7 +12,7 @@

- <%= textilizable(project.short_description, :project => project) %> + <%= textilizable(project.short_description.strip, :project => project) %>

diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index b9e6174ae..9f85dc49f 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -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