|
|
|
@ -35,7 +35,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
:transfer_to_course_group, :delete_from_course, :export_member_scores_excel,
|
|
|
|
|
:search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup,
|
|
|
|
|
:add_teacher, :export_couser_info, :export_member_act_score,
|
|
|
|
|
:update_informs, :new_informs, :delete_informs]
|
|
|
|
|
:update_informs, :new_informs, :delete_informs, :switch_to_student]
|
|
|
|
|
before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin,
|
|
|
|
|
:set_course_group, :create_group_by_importing_file,
|
|
|
|
|
:update_task_position, :tasks_list]
|
|
|
|
@ -681,13 +681,19 @@ class CoursesController < ApplicationController
|
|
|
|
|
course_member = @course.course_members.find_by!(user_id: current_user.id, is_active: 1)
|
|
|
|
|
tip_exception("切换失败") if course_member.STUDENT?
|
|
|
|
|
|
|
|
|
|
course_student = CourseMember.find_by!(user_id: current_user.id, role: %i[STUDENT], course_id: @course.id)
|
|
|
|
|
course_member.update_attributes(is_active: 0)
|
|
|
|
|
course_student.update_attributes(is_active: 1)
|
|
|
|
|
course_student = CourseMember.find_by(user_id: current_user.id, role: %i[STUDENT], course_id: @course.id)
|
|
|
|
|
if course_student
|
|
|
|
|
course_student.update_attributes!(is_active: 1)
|
|
|
|
|
else
|
|
|
|
|
# 学生身份不存在则创建
|
|
|
|
|
CourseMember.create!(user_id: current_user.id, role: %i[STUDENT], course_id: @course.id)
|
|
|
|
|
CourseAddStudentCreateWorksJob.perform_later(@course.id, [current_user.id])
|
|
|
|
|
end
|
|
|
|
|
course_member.update_attributes!(is_active: 0)
|
|
|
|
|
normal_status(0, "切换成功")
|
|
|
|
|
rescue => e
|
|
|
|
|
uid_logger_error("switch_to_student error: #{e.message}")
|
|
|
|
|
tip_exception("切换失败")
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -1127,7 +1133,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def top_banner
|
|
|
|
|
@user = current_user
|
|
|
|
|
@is_teacher = @user_course_identity < Course::STUDENT
|
|
|
|
|
@switch_student = Course::BUSINESS < @user_course_identity < Course::STUDENT
|
|
|
|
|
@is_student = @user_course_identity == Course::STUDENT
|
|
|
|
|
@course.increment!(:visits)
|
|
|
|
|
end
|
|
|
|
|