diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b76673945..01ce1f6e8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -913,7 +913,7 @@ class CoursesController < ApplicationController def left_banner @user = current_user @is_teacher = @user.teacher_of_course?(@course) - @course_modules = @course.course_modules.where.not(module_type: "activity").where(hidden: 0) + @course_modules = @course.course_modules.where(hidden: 0) @hidden_modules = @course.course_modules.where(hidden: 1) @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"] end diff --git a/app/models/course.rb b/app/models/course.rb index a2f5add51..7729a2650 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,7 +7,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 - has_many :course_modules, -> {where hidden: 0}, dependent: :destroy + has_many :course_modules, dependent: :destroy has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/models/course_module.rb b/app/models/course_module.rb index 7b96a044f..641c70425 100644 --- a/app/models/course_module.rb +++ b/app/models/course_module.rb @@ -7,6 +7,7 @@ class CourseModule < ApplicationRecord validates :module_name, length: { maximum: 20 } + scope :not_hidden, -> { where(hidden: 0) } scope :graduation_module, -> { where(module_type: "graduation") } scope :graduation_module_not_hidden, -> { graduation_module.where(hidden: 0) } scope :board_module, -> { where(module_type: 'board') } diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 1993851e8..5a128a0b7 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -12,7 +12,7 @@ json.courses do json.is_public course.is_public json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end - json.first_category_url module_url(course.course_modules.first, course) + json.first_category_url module_url(course.course_modules.not_hidden.first, course) end end json.courses_count @courses_count diff --git a/app/views/users/courses/shared/_course.json.jbuilder b/app/views/users/courses/shared/_course.json.jbuilder index e5823212e..629f47264 100644 --- a/app/views/users/courses/shared/_course.json.jbuilder +++ b/app/views/users/courses/shared/_course.json.jbuilder @@ -4,7 +4,7 @@ json.members_count course.members_count json.homework_commons_count course.homework_commons_count json.attachments_count course.attachments.count -json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course) +json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course) json.is_public course.is_public json.can_visited observed_logged_user? || course.can_visited?