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 %>