diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 35a60f692..baa8b0d85 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -749,8 +749,8 @@ class CoursesController < ApplicationController ActiveRecord::Base.transaction do course_student.destroy! course_teacher.update!(is_active: 1) + CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) end - CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) normal_status(0, "切换成功") rescue => e uid_logger_error(e.message) @@ -761,12 +761,15 @@ class CoursesController < ApplicationController # 切换为助教 def switch_to_assistant begin - course_member = @course.course_members.find_by!(user_id: current_user.id, is_active: 1) - tip_exception("切换失败") unless course_member.STUDENT? + course_student = @course.course_members.find_by!(user_id: current_user.id, is_active: 1) + tip_exception("切换失败") unless course_student.present? course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[ASSISTANT_PROFESSOR], course_id: @course.id) - course_member.update!(is_active: 0) - course_teacher.update!(is_active: 1) + ActiveRecord::Base.transaction do + course_student.destroy! + course_teacher.update!(is_active: 1) + CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) + end normal_status(0, "切换成功") rescue => e uid_logger_error(e.message)