diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 6c2eb5299..d49e28d80 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -911,6 +911,7 @@ class CoursesController < ApplicationController CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id) end + student_role = 1 end # 创建教师身份 @@ -940,9 +941,9 @@ class CoursesController < ApplicationController teacher_role = 1 end - if teacher_role && current_user.student_of_course?(course) + if teacher_role && student_role render json: { status: 0, message: message, course_id: course.id} - elsif current_user.student_of_course?(course) + elsif student_role render json: { status: 0, message: "加入成功", course_id: course.id} else normal_status(message) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 82f689e3f..61d15de55 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -38,6 +38,7 @@ class Shixun < ApplicationRecord belongs_to :user # 实训服务配置 has_many :shixun_service_configs, :dependent => :destroy + has_many :tidings, as: :container, dependent: :destroy scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", "%#{keyword}%", "%#{keyword}%") } @@ -62,6 +63,8 @@ class Shixun < ApplicationRecord scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :find_by_ids,lambda{|k| where(id:k)} + after_create :send_tiding + # REDO:  def propaedeutics shixun_info.try(:propaedeutics) @@ -242,4 +245,11 @@ class Shixun < ApplicationRecord def finished_challenges_count(user) Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count end + + private + + def send_tiding + self.tidings << Tiding.new(:user_id => user_id, :trigger_user_id => 1, :belong_container_id => id, :belong_container_type =>'Shixun', :tiding_type => "System", :viewed => 0) + end + end