From ef3e0798cc527d9d21c83661c8e48ca43d899fb0 Mon Sep 17 00:00:00 2001 From: z9hang Date: Sat, 11 Oct 2014 11:06:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=AF=BE=E7=A8=8B=E3=80=81=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=AE=A8=E8=AE=BA=E5=8C=BA=E7=BC=96=E8=BE=91=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=B2=A1=E6=9C=89=E5=85=AC=E5=BC=80=E5=AD=97=E6=A0=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=822=E3=80=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E7=A7=81=E6=9C=89=E5=B1=9E=E6=80=A7=E9=81=97?= =?UTF-8?q?=E6=BC=8F=E8=AE=A8=E8=AE=BA=E5=8C=BA=E7=9A=84=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E6=B7=BB=E5=8A=A0=E3=80=823?= =?UTF-8?q?=E3=80=81=E7=BC=96=E8=BE=91=E9=99=84=E4=BB=B6=E7=9A=84=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E3=80=81=E5=85=AC=E5=BC=80=E5=B1=9E=E6=80=A7=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 11 +++++++ app/views/attachments/_form_course.html.erb | 2 ++ .../lib/acts_as_attachable.rb | 30 +++++++++++-------- 3 files changed, 31 insertions(+), 12 deletions(-) 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)