diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index e25434e6e..90cfed429 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -411,6 +411,17 @@ class Attachment < ActiveRecord::Base
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
#
# Returns a Hash of the results:
diff --git a/app/views/attachments/_form_course.html.erb b/app/views/attachments/_form_course.html.erb
index e5fbd3f82..a56c5d1d4 100644
--- a/app/views/attachments/_form_course.html.erb
+++ b/app/views/attachments/_form_course.html.erb
@@ -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;") +
link_to(' '.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"} %>
+ <%= l(:field_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}" %>
@@ -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;") +
link_to(' '.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"} %>
+ <%= l(:field_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}" %>
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 f6dc31c64..5e344d735 100644
--- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -79,9 +79,11 @@ module Redmine
if res.is_public
if( (self.class.to_s=="Project" && self.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=="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
end
@@ -120,18 +122,22 @@ module Redmine
end
if attachments.is_a?(Array)
attachments.each do |attachment|
- next unless attachment.is_a?(Hash)
- a = nil
- if file = attachment['file']
- next unless file.size > 0
- a = Attachment.create(:file => file, :author => author)
- elsif token = attachment['token']
- a = Attachment.find_by_token(token)
- next unless a
- a.filename = attachment['filename'] unless attachment['filename'].blank?
- a.content_type = attachment['content_type']
+ if attachment.is_a?(Hash)
+ a = nil
+ file = attachment['file']
+ token = attachment['token']
+ t = file && file.size > 0
+ if file && file.size > 0
+ a = Attachment.create(:file => file, :author => author)
+ elsif token
+ a = Attachment.find_by_token_only(token)
+ if a
+ a.filename = attachment['filename'] unless attachment['filename'].blank?
+ a.content_type = attachment['content_type']
+ end
+ end
end
- if !attachment[:is_public]
+ if a && !attachment[:is_public]
a.is_public = false
end
set_attachment_public(a)