diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index a81446cea..db55a9511 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -1,5 +1,6 @@ class Weapps::CoursesController < Weapps::BaseController before_action :require_login + before_action :user_course_identity, except: [:create] before_action :teacher_allowed, except: [:create, :show, :shixun_homework_category] def create @@ -30,6 +31,25 @@ class Weapps::CoursesController < Weapps::BaseController @categories = current_course.shixun_course_modules.first&.course_second_categories end + # 教师列表 + def teachers + @course = current_course + if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 + @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3)") + else + @teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} + and course_members.role = 2))") + end + + @teacher_list_size = @teacher_list.size + + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size + + @teacher_list = @teacher_list.preload(user: [user_extension: :school]).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci asc") + end + + + private def course_params @@ -45,6 +65,6 @@ class Weapps::CoursesController < Weapps::BaseController end def teacher_allowed - return render_forbidden unless current_user.course_identity(current_course) < Course::STUDENT + return render_forbidden unless @user_course_identity < Course::STUDENT end end \ No newline at end of file diff --git a/app/views/courses/apply_teachers.json.jbuilder b/app/views/courses/apply_teachers.json.jbuilder index aee0803b4..bd88d5fbe 100644 --- a/app/views/courses/apply_teachers.json.jbuilder +++ b/app/views/courses/apply_teachers.json.jbuilder @@ -8,6 +8,7 @@ json.application_list do json.name application.application_user.real_name json.name_link user_path(application.application_user) json.login application.application_user.login + json.image_url url_to_avatar(application.application_user) json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" end end \ No newline at end of file diff --git a/app/views/courses/search_teacher_candidate.json.jbuilder b/app/views/courses/search_teacher_candidate.json.jbuilder index af3310fb7..cfe781165 100644 --- a/app/views/courses/search_teacher_candidate.json.jbuilder +++ b/app/views/courses/search_teacher_candidate.json.jbuilder @@ -7,6 +7,8 @@ json.candidates do json.school_name user.user_extension.school.try(:name) json.school_id user.user_extension.school.try(:id) json.added @course.course_member?(user.id, [1, 2, 3]) + json.image_url url_to_avatar(user) + json.phone user.hidden_phone end end json.candidates_count @users_size \ No newline at end of file diff --git a/app/views/weapps/courses/teachers.json.jbuilder b/app/views/weapps/courses/teachers.json.jbuilder new file mode 100644 index 000000000..0d89ca814 --- /dev/null +++ b/app/views/weapps/courses/teachers.json.jbuilder @@ -0,0 +1,16 @@ +json.teacher_list do + json.array! @teacher_list do |teacher| + json.course_member_id teacher.id + json.name teacher.user.real_name + json.login teacher.user.login + json.user_id teacher.user.id + json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教" + json.school teacher.user&.school_name + json.image_url url_to_avatar(teacher.user) + # if @user_course_identity < Course::ASSISTANT_PROFESSOR + # json.member_roles teacher.user.course_role(@course) + # end + end +end +json.teacher_list_size @teacher_list_size +json.apply_size @applications_size \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 356f6393c..7c7b95820 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -883,6 +883,7 @@ Rails.application.routes.draw do resources :courses, only: [:create, :update, :edit, :show] do member do get :shixun_homework_category + get :teachers end end end