Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
b9fe6d6777
|
@ -257,12 +257,12 @@ class ApplicationController < ActionController::Base
|
|||
def authorize_attachment_download(ctrl = params[:controller], action = params[:action], global = false)
|
||||
if @attachment.container_type == "Memo"
|
||||
allowed = User.current.allowed_to?(:memos_attachments_download,nil,:global => true)
|
||||
elsif @attachment.container_type == "Project"
|
||||
return true
|
||||
elsif @attachment.container_type == "course"
|
||||
return true
|
||||
elsif @attachment.container_type == "Message" && !@project.nil?
|
||||
allowed = User.current.allowed_to?(:projects_attachments_download,@project,:global => false)
|
||||
elsif @attachment.container_type == "Message" && !@course.nil?
|
||||
allowed = User.current.allowed_to?(:course_attachments_download, @course, :global => false)
|
||||
elsif @attachment.container_type == "contest"
|
||||
return true
|
||||
return true
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ class AttachmentsController < ApplicationController
|
|||
before_filter :delete_authorize, :only => :destroy
|
||||
before_filter :authorize_global, :only => :upload
|
||||
before_filter :authorize_attachment_download, :only => :download
|
||||
before_filter :login_without_softapplication, only: [:download]
|
||||
#before_filter :login_without_softapplication, only: [:download]
|
||||
accept_api_auth :show, :download, :upload
|
||||
require 'iconv'
|
||||
|
||||
|
@ -68,12 +68,20 @@ class AttachmentsController < ApplicationController
|
|||
elsif @attachment.container.is_a?(Project)
|
||||
project = @attachment.container
|
||||
candown= User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
|
||||
elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
|
||||
@attachment.container.board.project
|
||||
project = @attachment.container.board.project
|
||||
candown = User.current.member_of?(project) || (project.is_public && @attachment.is_public == 1)
|
||||
elsif (@attachment.container.has_attribute?(:course) ||@attachment.container.has_attribute?(:course_id) ) && @attachment.container.course
|
||||
course = @attachment.container.course
|
||||
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
|
||||
elsif @attachment.container.is_a?(Course)
|
||||
course = @attachment.container
|
||||
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
|
||||
elsif (@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
|
||||
@attachment.container.board.course
|
||||
course = @attachment.container.board.course
|
||||
candown= User.current.member_of_course?(course) || (course.is_public==1 && @attachment.is_public == 1)
|
||||
elsif @attachment.container.class.to_s=="HomeworkAttach" && @attachment.container.bid.reward_type == 3
|
||||
candown = true
|
||||
else
|
||||
|
@ -321,8 +329,11 @@ private
|
|||
raise ActiveRecord::RecordNotFound if params[:filename] && params[:filename] != @attachment.filename
|
||||
if @attachment.container_type == 'Course'
|
||||
@course = @attachment.course
|
||||
elsif !@attachment.container.nil? && (@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course)) && @attachment.container.course
|
||||
elsif !@attachment.container.nil? && (@attachment.container.has_attribute?(:course) || @attachment.container.has_attribute?(:course_id)) && @attachment.container.course
|
||||
@course = @attachment.container.course
|
||||
elsif !@attachment.container.nil? && ((@attachment.container.has_attribute?(:board) || @attachment.container.has_attribute?(:board_id)) && @attachment.container.board &&
|
||||
@attachment.container.board.course)
|
||||
@course = @attachment.container.board.course
|
||||
else
|
||||
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication'
|
||||
@project = @attachment.project
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
|
||||
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>
|
||||
<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,attachment.is_public == 1 ? true : false,:class => 'is_public')%>
|
||||
<%= if attachment.id.nil?
|
||||
#待补充代码
|
||||
else
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
<%= 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"} %>
|
||||
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, :class => 'is_public')%>
|
||||
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
|
||||
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%>
|
||||
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
@ -18,7 +19,8 @@
|
|||
<%= 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"} %>
|
||||
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, :class => 'is_public')%>
|
||||
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
|
||||
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public')%>
|
||||
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
|
|
@ -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,19 +122,25 @@ 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_checkbox']
|
||||
a.is_public = false
|
||||
elsif a && attachment['is_public_checkbox']
|
||||
a.is_public = true
|
||||
end
|
||||
set_attachment_public(a)
|
||||
next unless a
|
||||
|
|
Loading…
Reference in New Issue