From cf808598d230d2fe80e3c320f822d8d7fe96b38e Mon Sep 17 00:00:00 2001 From: z9hang Date: Fri, 21 Nov 2014 14:57:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E7=AB=99=E6=90=9C=E7=B4=A2=E4=B8=8D?= =?UTF-8?q?=E5=9C=A8=E6=90=9C=E7=B4=A2=E9=9D=9E=E6=9C=AC=E4=BA=BA=E7=9A=84?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E8=B5=84=E6=BA=90=EF=BC=8C=E4=B8=94=E4=BB=96?= =?UTF-8?q?=E4=BA=BA=E7=9A=84=E5=85=AC=E5=BC=80=E8=B5=84=E6=BA=90=E4=BA=A6?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E4=BF=AE=E6=94=B9=E5=85=B6=E5=85=AC=E5=BC=80?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E5=B1=9E=E6=80=A72=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 +- app/views/files/_course_list.html.erb | 3 ++- .../20141120091234_add_column_copyfrom_to_attachment.rb | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20141120091234_add_column_copyfrom_to_attachment.rb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index ca7f8e040..6de800efc 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -69,7 +69,7 @@ class FilesController < ApplicationController # StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map # 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。 # 现在还木有思路 药丸 - resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). + resultSet = Attachment.where("attachments.container_type IS NOT NULL AND (is_public = 1 OR author_id = #{User.current.id}) AND filename LIKE :like ", like: "%#{keywords}%"). reorder("created_on DESC") end diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 554a3aea5..df0e837f2 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -21,12 +21,13 @@
<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %> - <% if is_course_teacher(User.current,@course) %> + <% if is_course_teacher(User.current,@course) && User.current.id == file.author_id %> <%= link_to "选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true %> <%= link_to (file.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"f_l re_open",:method => :post %> <% else %> + <%= link_to "选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true %> <%= link_to (file.is_public? ? "公开":"私有"),"javascript:void(0)",:class=>"f_l re_open" %> <% end %>
diff --git a/db/migrate/20141120091234_add_column_copyfrom_to_attachment.rb b/db/migrate/20141120091234_add_column_copyfrom_to_attachment.rb new file mode 100644 index 000000000..cc8444f6d --- /dev/null +++ b/db/migrate/20141120091234_add_column_copyfrom_to_attachment.rb @@ -0,0 +1,5 @@ +class AddColumnCopyfromToAttachment < ActiveRecord::Migration + def change + add_column("attachments","copy_from",:integer) + end +end