From f6b01b300d0b9398f55c32e7bf6a547fcf27bb8f Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 21 Aug 2015 16:36:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=20=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E9=87=8C=E8=83=BD=E7=9C=8B=E5=88=B0=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=B5=84=E6=BA=90=EF=BC=8C=E4=BD=86=E6=98=AF=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E9=87=8C=E8=BE=B9=E5=8D=B4=E6=B2=A1=E6=9C=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 9 ++++++--- app/views/layouts/base_users_new.html.erb | 12 ++++++------ db/schema.rb | 10 ---------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8f69642f7..3c163fada 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -967,7 +967,8 @@ class UsersController < ApplicationController end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') ").order("created_on desc") + user_course_ids = User.current.courses.map { |c| c.id} + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.join(',')})) ").order("created_on desc") else user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course')"+ @@ -1382,7 +1383,8 @@ class UsersController < ApplicationController end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') ").order("created_on desc") + user_course_ids = User.current.courses.map { |c| c.id} + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.join(',')})) ").order("created_on desc") else user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 @attachments = Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course')"+ @@ -1432,7 +1434,8 @@ class UsersController < ApplicationController end elsif params[:type] == "2" #课程资源 if User.current.id.to_i == params[:id].to_i - @attachments = Attachment.where("author_id = #{params[:id]} and container_type = 'Course' and (filename like '%#{search}%')").order("created_on desc") + user_course_ids = User.current.courses.map { |c| c.id} + @attachments = Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.join(',')})) ").order("created_on desc") else user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中 @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type = 'Course') "+ diff --git a/app/views/layouts/base_users_new.html.erb b/app/views/layouts/base_users_new.html.erb index be75f53f1..e9b7ddb12 100644 --- a/app/views/layouts/base_users_new.html.erb +++ b/app/views/layouts/base_users_new.html.erb @@ -166,12 +166,12 @@ (<%=@user.projects.visible.count%>) -
+ + + + + + <% end %>