1、课程、项目讨论区编辑附件没有公开字样问题。2、设置附件私有属性遗漏讨论区的附件的情况添加。3、编辑附件的描述、公开属性无效的问题,原因编辑保存逻辑存在问题,修正

This commit is contained in:
z9hang 2014-10-11 11:06:37 +08:00
parent 0633d5661e
commit ef3e0798cc
3 changed files with 31 additions and 12 deletions

View File

@ -411,6 +411,17 @@ class Attachment < ActiveRecord::Base
end end
end end
# Finds an attachment that matches the given token
def self.find_by_token_only(token)
if token.to_s =~ /^(\d+)\.([0-9a-f]+)$/
attachment_id, attachment_digest = $1, $2
attachment = Attachment.where(:id => attachment_id, :digest => attachment_digest).first
if attachment
attachment
end
end
end
# Bulk attaches a set of files to an object # Bulk attaches a set of files to an object
# #
# Returns a Hash of the results: # Returns a Hash of the results:

View File

@ -7,6 +7,7 @@
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") +
link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
<%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, :class => 'is_public')%> <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, :class => 'is_public')%>
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
</span> </span>
@ -18,6 +19,7 @@
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") +
link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
<%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, :class => 'is_public')%> <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, :class => 'is_public')%>
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
</span> </span>

View File

@ -79,9 +79,11 @@ module Redmine
if res.is_public if res.is_public
if( (self.class.to_s=="Project" && self.is_public == false) || if( (self.class.to_s=="Project" && self.is_public == false) ||
(self.has_attribute?(:project) && self.project && self.project.is_public == false) || (self.has_attribute?(:project) && self.project && self.project.is_public == false) ||
(self.has_attribute?(:board) && self.board.project && self.board.project.is_public == false) ||
(self.class.to_s=="HomeworkAttach" && self.bid.reward_type == 3) || (self.class.to_s=="HomeworkAttach" && self.bid.reward_type == 3) ||
(self.class.to_s=="Course" && self.is_public == false) || (self.class.to_s=="Course" && self.is_public == false) ||
(self.has_attribute?(:course) && self.course && self.course.is_public == false) (self.has_attribute?(:course) && self.course && self.course.is_public == false) ||
(self.has_attribute?(:board) && self.board.course && self.board.course.is_public == false)
) )
res.is_public = false res.is_public = false
end end
@ -120,18 +122,22 @@ module Redmine
end end
if attachments.is_a?(Array) if attachments.is_a?(Array)
attachments.each do |attachment| attachments.each do |attachment|
next unless attachment.is_a?(Hash) if attachment.is_a?(Hash)
a = nil a = nil
if file = attachment['file'] file = attachment['file']
next unless file.size > 0 token = attachment['token']
a = Attachment.create(:file => file, :author => author) t = file && file.size > 0
elsif token = attachment['token'] if file && file.size > 0
a = Attachment.find_by_token(token) a = Attachment.create(:file => file, :author => author)
next unless a elsif token
a.filename = attachment['filename'] unless attachment['filename'].blank? a = Attachment.find_by_token_only(token)
a.content_type = attachment['content_type'] if a
a.filename = attachment['filename'] unless attachment['filename'].blank?
a.content_type = attachment['content_type']
end
end
end end
if !attachment[:is_public] if a && !attachment[:is_public]
a.is_public = false a.is_public = false
end end
set_attachment_public(a) set_attachment_public(a)