个人资源库搜索不到组织资源

This commit is contained in:
lizanle 2015-12-31 09:08:07 +08:00
parent a85a3339bb
commit b132e8483c
2 changed files with 3 additions and 2 deletions

View File

@ -1953,7 +1953,7 @@ class UsersController < ApplicationController
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
@attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
@attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
" or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).order("created_on desc")
else
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中

View File

@ -356,8 +356,9 @@ class Attachment < ActiveRecord::Base
end
#有了历史记录的数据记录是不能被删除的。
#true 能被删除 false 不能被删除
def destroyable
Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0
self.attachment_histories.count == 0
end
# Returns file's location on disk