maoxian
This commit is contained in:
parent
b841f0c78a
commit
e9373991d2
|
@ -16,7 +16,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class AttachmentsController < ApplicationController
|
||||
before_filter :find_project, :except => :upload
|
||||
before_filter :find_project, :except => [:upload, :autocomplete]
|
||||
before_filter :file_readable, :read_authorize, :only => [:show, :thumbnail]#Modified by young
|
||||
before_filter :delete_authorize, :only => :destroy
|
||||
before_filter :authorize_global, :only => :upload
|
||||
|
@ -131,6 +131,12 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def autocomplete
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@attachment = Attachment.find(params[:id])
|
||||
|
|
|
@ -85,4 +85,17 @@ module AttachmentsHelper
|
|||
Attachment.tagged_with(tag_name).order('created_on desc')
|
||||
end
|
||||
|
||||
def render_attachments_for_new_project(project)
|
||||
# 查询条件
|
||||
filename_condition = "trustie" #params[:q]
|
||||
# 当前项目所有资源
|
||||
# attachments = Attachment.find_all_by_container_type_and_container_id(project.class, project.id)
|
||||
attachments = Attachment.where("container_type = '#{project.class}' and container_id = #{project.id}")
|
||||
# 除去当前项目的所有资源
|
||||
nobelong_attach = Attachment.where("container_type <> '#{project.class}' and container_id <> #{project.id}")
|
||||
# 搜索到的资源
|
||||
searched_attach = nobelong_attach.where("filename like '%#{filename_condition}%' ")
|
||||
|
||||
return searched_attach.to_yaml
|
||||
end
|
||||
end
|
||||
|
|
|
@ -169,7 +169,7 @@ class Attachment < ActiveRecord::Base
|
|||
|
||||
def deletable?(user=User.current)
|
||||
if container_id
|
||||
container && container.attachments_deletable?(user)
|
||||
container && (container.is_a?(Project) ? container.attachments_deletable?(user) : true )
|
||||
else
|
||||
author == user
|
||||
end
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
||||
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||||
<% if options[:deletable] %>
|
||||
<% unless attachment.container_type == 'HomeworkAttach' %>
|
||||
<%= link_to image_tag('delete.png'), attachment_path(attachment),
|
||||
<% if attachment.container_type == 'HomeworkAttach' %>
|
||||
<%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id},
|
||||
:data => {:confirm => l(:text_are_you_sure)},
|
||||
:method => :delete,
|
||||
:class => 'delete',
|
||||
:title => l(:button_delete) %>
|
||||
<% else %>
|
||||
<%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id},
|
||||
<%= link_to image_tag('delete.png'), attachment_path(attachment),
|
||||
:data => {:confirm => l(:text_are_you_sure)},
|
||||
:method => :delete,
|
||||
:class => 'delete',
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
<% a= render_attachments_for_new_project(Project.find(2)) %>
|
||||
<%=a%>
|
|
@ -385,6 +385,8 @@ RedmineApp::Application.routes.draw do
|
|||
get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment'
|
||||
get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
|
||||
get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail'
|
||||
get 'attachments/autocomplete'
|
||||
match 'attachments/autocomplete', :to => 'attachments#autocomplete', via: [:get, :post]
|
||||
resources :attachments, :only => [:show, :destroy]
|
||||
|
||||
resources :groups do
|
||||
|
|
|
@ -267,3 +267,31 @@ attachments_020:
|
|||
filename: root_attachment.txt
|
||||
filesize: 54
|
||||
author_id: 2
|
||||
attachments_021:
|
||||
content_type: text/plain
|
||||
downloads: 0
|
||||
created_on: 2012-05-12 16:14:50 +09:00
|
||||
disk_filename: 120512161450_project_test.txt
|
||||
disk_directory:
|
||||
container_id: 2
|
||||
digest: b0fe2abdb2599743d554a61d7da7ff74
|
||||
id: 21
|
||||
container_type: Project
|
||||
description: ""
|
||||
filename: project_test.txt
|
||||
filesize: 54
|
||||
author_id: 2
|
||||
attachments_022:
|
||||
content_type: text/plain
|
||||
downloads: 0
|
||||
created_on: 2012-05-12 16:14:50 +09:00
|
||||
disk_filename: 120512161450_course_test.txt
|
||||
disk_directory:
|
||||
container_id: 1
|
||||
digest: b0fe2abdb2599743d554a61d7da7ff74
|
||||
id: 22
|
||||
container_type: Project
|
||||
description: ""
|
||||
filename: course_test.txt
|
||||
filesize: 54
|
||||
author_id: 2
|
|
@ -0,0 +1,20 @@
|
|||
# encoding: utf-8
|
||||
require 'test_helper'
|
||||
|
||||
class AttachmentsTest < ActiveSupport::TestCase
|
||||
include AttachmentsHelper
|
||||
|
||||
def setup
|
||||
@file_belong_to = attachments(:attachments_021)
|
||||
@file_not_belong_to = attachments(:attachments_022)
|
||||
@project = @file_belong_to.container
|
||||
end
|
||||
|
||||
test "can be find file not belong to project" do
|
||||
params = {:q => @file_not_belong_to}
|
||||
found_file = render_attachments_for_new_project(@project)
|
||||
assert found_file.include?(@file_not_belong_to)
|
||||
assert_not found_file.include?(@file_belong_to)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue