From 7f591bd4b261fbc2f919160e062b33f6603ff456 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 2 Aug 2019 17:44:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) From 8b94dc48a160381aeddad78ac096781150dfe359 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 2 Aug 2019 17:47:08 +0800 Subject: [PATCH 2/3] send tiding when create shixun --- app/models/shixun.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 82f689e3f..392807479 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -62,6 +62,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 +244,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 => self.user_id, :trigger_user_id => self.user_id, :belong_container_id => self.id, :belong_container_type =>'Shixun', :tiding_type => "System", :viewed => 0) + end + end From 1f3ca2c64eceee65acc396746c42490c7511132f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 2 Aug 2019 17:55:20 +0800 Subject: [PATCH 3/3] fix --- app/models/shixun.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 392807479..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}%") } @@ -248,7 +249,7 @@ class Shixun < ApplicationRecord private def send_tiding - self.tidings << Tiding.new(:user_id => self.user_id, :trigger_user_id => self.user_id, :belong_container_id => self.id, :belong_container_type =>'Shixun', :tiding_type => "System", :viewed => 0) + 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