From 6f97f3e6c94891c72bb8e813f410f9427c114478 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 09:01:05 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E5=85=B3=E5=8D=A1=E7=9A=84=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index f2a964c8d..e315ab596 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -5,8 +5,8 @@ class ChallengesController < ApplicationController before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, :edit_choose_question, :show_choose_question, :destroy_challenge_choose, :update_choose_question, :destroy, :crud_answer, :answer] - # before_action :allowed, except: [:index, :show, :edit_choose_question, :edit] - + # 权限控制 + before_action :allowed, except: [:index] include ShixunsHelper include ChallengesHelper @@ -296,8 +296,7 @@ class ChallengesController < ApplicationController end def allowed - # 实训为发布前,除实训的管理者外,其他人都不人都不允许访问 - if !current_user.manager_of_shixun?(@shixun) && (@shixun.status < 1 || @shixun.hidden == 1) + unless current_user.manager_of_shixun?(@shixun) raise Educoder::TipException.new(403, "..") end end From 0773f7fc48004fb9a7e604dfedf5d662bffeb17a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 09:36:56 +0800 Subject: [PATCH 02/17] =?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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 253bafa48..93eba89d8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -11,7 +11,7 @@ class CoursesController < ApplicationController render_error(ex.model.errors.full_messages.join(',')) end - before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups] + before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, :set_public_or_private, :search_teacher_candidate, :teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, From 6e18d221112013a4d783dea3828ce224d3be623d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 09:42:59 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E6=89=93=E5=BC=80=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d9588cb5b..290b4387d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -518,7 +518,7 @@ class ShixunsController < ApplicationController ActiveRecord::Base.transaction do begin - #cloud_bridge = edu_setting('cloud_bridge') + cloud_bridge = edu_setting('cloud_bridge') myshixun_identifier = generate_identifier Myshixun, 10 myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, From 11c7e95a4606c25f27f6a1ba081534a5cdeff73b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 09:44:00 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E5=88=A0=E9=99=A4=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise_question.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 5f456e21f..607ad1a29 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -5,11 +5,11 @@ class ExerciseQuestion < ApplicationRecord belongs_to :shixun, optional: true has_many :exercise_choices, :dependent => :destroy - has_many :exercise_answers, :dependent => :destroy + has_many :exercise_answers has_many :exercise_shixun_challenges,:dependent => :destroy - has_many :exercise_shixun_answers, :dependent => :destroy - has_many :exercise_answer_comments, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_shixun_answers + has_many :exercise_answer_comments + has_many :exercise_standard_answers scope :insert_question_ex, lambda {|k| where("question_number > ?",k)} scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 From fc2685a9d8433f36a1f2775ba5c4ed8acd607053 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:07:55 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 290b4387d..743594749 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -624,8 +624,11 @@ class ShixunsController < ApplicationController def add_collaborators raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" - condition = "%#{params[:search].strip}%".gsub(" ","") - @users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'") + user_name = "%#{params[:user_name].strip}%" + school_name = "%#{params[:school_name].strip}%" + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE + '#{school_name}' ") end def shixun_members_added From e1c40cd30d9288e6a0b3e5cb03f44c5c8f0f9d3d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:11:27 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 743594749..ecbcbf872 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -626,9 +626,13 @@ class ShixunsController < ApplicationController member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" user_name = "%#{params[:user_name].strip}%" school_name = "%#{params[:school_name].strip}%" - @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + if user_name.present? || school_name.present? + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}' ") + '#{school_name}'") + else + @users = User.none + end end def shixun_members_added From 72c304faa5707b76035221cf2812e21fd88664ec Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:22:03 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E9=9A=8F=E6=9C=BA=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions/_exercise_questions.json.jbuilder | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 7a05c2e11..9445862ba 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -6,10 +6,11 @@ json.question_type question.question_type json.question_score question.question_score.round(1).to_s if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 standard_answers_array = question.get_standard_answer_ids - exercise_choices = choices.order("choice_position ASC") ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱 if ex_choice_random_boolean - exercise_choices = exercise_choices.order("RAND()") + exercise_choices = choices.order("RAND()") + else + exercise_choices = choices.order("choice_position ASC") end json.question_choices do json.array! exercise_choices.each_with_index.to_a do |a,index| From 21c0d774e4d9e717b747dceb2de164bd6aa37210 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:26:11 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E5=8F=91=E9=80=81=E8=87=B3=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=AF=BE=E7=A8=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index ecbcbf872..f8c2fce68 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -674,14 +674,14 @@ class ShixunsController < ApplicationController limit = params[:limit] || 20 if params[:search] search = "%#{params[:search].to_s.strip.downcase}%" - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0 AND c.name like '#{search}' ").map(&:id) else - course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) end From fa9448967bc96d6b679ae28c5a6718dd2fc789b2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:32:56 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=87=B3=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f8c2fce68..e3a658d7c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -693,7 +693,7 @@ class ShixunsController < ApplicationController # 将实训发送到课程 def send_to_course @course = Course.find(params[:course_id]) - homework = HomeworksService.new.create_homework shixun, @course, nil, current_user + homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user end # 二维码扫描下载 From d4bdc7e8e2145f730875937b70917d89082c9d25 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:34:50 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=87=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/send_to_course.json.jbuilder | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/shixuns/send_to_course.json.jbuilder b/app/views/shixuns/send_to_course.json.jbuilder index dd087d3e2..b2e30f985 100644 --- a/app/views/shixuns/send_to_course.json.jbuilder +++ b/app/views/shixuns/send_to_course.json.jbuilder @@ -1,4 +1,3 @@ json.status 1 json.message "发送成功" -json.url course_homework_commons_path(@course.id, type: 4) -# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4" \ No newline at end of file +json.course_id @course.id \ No newline at end of file From 863dad51b1ab2d80da23070c020c20da2df13d53 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:37:41 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=AD=94=E9=A2=98=E5=88=97=E8=A1=A8=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=92=8C=E8=80=81=E5=B8=88=E8=A7=86=E8=A7=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7e7e1070d..fd2877cc8 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -508,15 +508,14 @@ module ExercisesHelper current_user_group_name = course_group.first.name if course_group.present? end teacher_review = ex_user.subjective_score < 0.0 ? false : true - if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 - # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 - ex_object_score = nil - ex_subject_score = nil - score = nil - else + if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看 ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s + else + ex_object_score = nil + ex_subject_score = nil + score = nil end { From 4122ccf438accbacf156baf67012c98f2041e37a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:48:23 +0800 Subject: [PATCH 12/17] fix bug --- app/helpers/exercises_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index fd2877cc8..8db7e8bfa 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -638,6 +638,9 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end + if user_score > q.question_score + user_score = q.question_score + end if ques_type <= 2 answered_content = exercise_answers.pluck(:exercise_choice_id) elsif ques_type == 3 From 76028ceca5e290dd7a620176189d6c673bd1a7cb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:59:31 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=8F=91=E9=80=81=E8=87=B3=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 4b954584b..c73fec500 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -164,8 +164,8 @@ class SubjectsController < ApplicationController end def choose_course - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) From 6f900946d79d9cf912431b02fcc66d4eeaf89680 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 11:08:15 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e3a658d7c..5f7c13964 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -622,7 +622,6 @@ class ShixunsController < ApplicationController end def add_collaborators - raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" user_name = "%#{params[:user_name].strip}%" school_name = "%#{params[:school_name].strip}%" From 2a010194578c773162e856a6812ea74adb83b667 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:23:10 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 13 ++++++++++--- app/models/exercise_answer.rb | 8 +++++++- app/models/exercise_choice.rb | 11 +++++++++-- app/models/exercise_question.rb | 10 ++++++++-- app/models/exercise_shixun_answer.rb | 7 ++++++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0c8b97ca7..af84a5c49 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,9 +3,9 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users,:dependent => :destroy - has_many :exercise_questions,:dependent => :destroy - has_many :exercise_group_settings,:dependent => :destroy + has_many :exercise_users + has_many :exercise_questions + has_many :exercise_group_settings has_many :tidings, as: :container has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy @@ -19,6 +19,13 @@ class Exercise < ApplicationRecord validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } after_create :create_exercise_list + after_destroy :destroy_other_relations + + def destroy_other_relations + exercise_users.destroy_all + exercise_questions.destroy_all + exercise_group_settings.destroy_all + end def create_exercise_list str = "" diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 465fa036b..96fbe17bb 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} @@ -11,4 +11,10 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 + after_destroy :destroy_answers_relations + + def destroy_answers_relations + exercise_answer_comments.destroy_all + end + end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index 525251ce6..f4f5c5a16 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,9 +1,16 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_answers + has_many :exercise_standard_answers scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + + after_destroy :destroy_choices_relations + + def destroy_choices_relations + exercise_answers.destroy_all + exercise_standard_answers.destroy_all + end end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 607ad1a29..c236b657c 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,9 +4,9 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices, :dependent => :destroy + has_many :exercise_choices has_many :exercise_answers - has_many :exercise_shixun_challenges,:dependent => :destroy + has_many :exercise_shixun_challenges has_many :exercise_shixun_answers has_many :exercise_answer_comments has_many :exercise_standard_answers @@ -17,6 +17,12 @@ class ExerciseQuestion < ApplicationRecord scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} + after_destroy :destroy_questions_relations + + def destroy_questions_relations + exercise_choices.destroy_all + exercise_shixun_challenges.destroy_all + end def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 8548e497d..72a6999d6 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} @@ -10,4 +10,9 @@ class ExerciseShixunAnswer < ApplicationRecord scope :shixun_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)} scope :score_reviewed, lambda {where("score is not NULL AND score >= ?",0.0)} #是否评分 + after_destroy :destroy_shixun_relations + + def destroy_shixun_relations + exercise_answer_comments.destroy_all + end end From 7a007dbd44315ea14fe384b50dedb1f6212f6404 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:38:32 +0800 Subject: [PATCH 16/17] fix bug --- app/models/exercise.rb | 15 ++++----------- app/models/exercise_answer.rb | 8 +------- app/models/exercise_choice.rb | 10 ++-------- app/models/exercise_question.rb | 11 ++--------- app/models/exercise_shixun_answer.rb | 7 +------ 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index af84a5c49..60409e51d 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,11 +3,11 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users - has_many :exercise_questions - has_many :exercise_group_settings + has_many :exercise_users, :dependent => :delete_all + has_many :exercise_questions, :dependent => :delete_all + has_many :exercise_group_settings, :dependent => :delete_all has_many :tidings, as: :container - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all scope :is_exercise_published, -> { where("exercise_status > ? ",1)} scope :unified_setting, -> { where("unified_setting = ?",true) } @@ -19,13 +19,6 @@ class Exercise < ApplicationRecord validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } after_create :create_exercise_list - after_destroy :destroy_other_relations - - def destroy_other_relations - exercise_users.destroy_all - exercise_questions.destroy_all - exercise_group_settings.destroy_all - end def create_exercise_list str = "" diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 96fbe17bb..11558f937 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments + has_many :exercise_answer_comments, :dependent => :delete_all scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} @@ -11,10 +11,4 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 - after_destroy :destroy_answers_relations - - def destroy_answers_relations - exercise_answer_comments.destroy_all - end - end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index f4f5c5a16..72dc30c9d 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,16 +1,10 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers - has_many :exercise_standard_answers + has_many :exercise_answers, :dependent => :delete_all + has_many :exercise_standard_answers, :dependent => :delete_all scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 - after_destroy :destroy_choices_relations - - def destroy_choices_relations - exercise_answers.destroy_all - exercise_standard_answers.destroy_all - end end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index c236b657c..2c9b281c3 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,9 +4,9 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices + has_many :exercise_choices, :dependent => :delete_all has_many :exercise_answers - has_many :exercise_shixun_challenges + has_many :exercise_shixun_challenges, :dependent => :delete_all has_many :exercise_shixun_answers has_many :exercise_answer_comments has_many :exercise_standard_answers @@ -15,14 +15,7 @@ class ExerciseQuestion < ApplicationRecord scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} - # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} - after_destroy :destroy_questions_relations - def destroy_questions_relations - exercise_choices.destroy_all - exercise_shixun_challenges.destroy_all - end def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 72a6999d6..a9550c024 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments + has_many :exercise_answer_comments, :dependent => :delete_all # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} @@ -10,9 +10,4 @@ class ExerciseShixunAnswer < ApplicationRecord scope :shixun_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)} scope :score_reviewed, lambda {where("score is not NULL AND score >= ?",0.0)} #是否评分 - after_destroy :destroy_shixun_relations - - def destroy_shixun_relations - exercise_answer_comments.destroy_all - end end From e233d90197bc70ef7775c364f3bdb13e2c6673a1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:48:41 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E5=92=8C=E9=97=AE=E5=8D=B7=E5=88=A0=E9=99=A4=E5=85=B3=E8=81=94?= =?UTF-8?q?=E4=B8=BAdelete=5Fall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/poll.rb | 10 +++++----- app/models/poll_answer.rb | 2 +- app/models/poll_question.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 1cead3291..f72239ba7 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -4,13 +4,13 @@ class Poll < ApplicationRecord belongs_to :exercise_bank, optional: true # belongs_to :exercise_bank - has_many :poll_questions,dependent: :destroy - has_many :poll_users, :dependent => :destroy + has_many :poll_questions,dependent: :delete_all + has_many :poll_users, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 - has_many :poll_group_settings, :dependent => :destroy - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :poll_group_settings, :dependent => :delete_all + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all - has_many :tidings, as: :container, dependent: :destroy + has_many :tidings, as: :container, dependent: :delete_all scope :publish_or_not, -> { where("polls_status > ? ",1)} scope :only_public, -> {where("is_public = ?",true)} diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 423198bbf..8e2421328 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord # include Redmine::SafeAttributes belongs_to :poll_question - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes, :dependent => :delete_all scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 1fc8e0c16..a0854aa48 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -1,9 +1,9 @@ class PollQuestion < ApplicationRecord belongs_to :poll - has_many :poll_answers, :dependent => :destroy + has_many :poll_answers, :dependent => :delete_all attr_accessor :question_answers, :question_other_anser - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_necessary, -> {where("is_necessary = ?",1)}