From e944ce97c74a63cc5a98e5c3c9ec6523d6f1caff Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 12:56:34 +0800 Subject: [PATCH 01/12] =?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/shixuns_controller.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 74942446e..8a59477c3 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -563,15 +563,15 @@ class ShixunsController < ApplicationController # end # 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 - if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) - subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take - course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take - if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) - # 为了不影响后续操作,用create而不是create! - CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) - CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) - end - end + # if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) + # subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take + # course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take + # if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) + # # 为了不影响后续操作,用create而不是create! + # CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) + # CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) + # end + # end ActiveRecord::Base.transaction do begin From ac66f683f28221178d55251d2bbe2246cff57fed Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 12:57:32 +0800 Subject: [PATCH 02/12] =?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/shixuns_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8a59477c3..c9b56bb98 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -555,12 +555,12 @@ class ShixunsController < ApplicationController # 判断实训是否全为选择题 is_choice_type = (min_challenges.size == min_challenges.select{|challenge| challenge.last == 1}.count) - # if !is_choice_type - # commit = GitService.commits(repo_path: @repo_path).try(:first) - # uid_logger("First comit########{commit}") - # tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? - # commit_id = commit["id"] - # end + if !is_choice_type + commit = GitService.commits(repo_path: @repo_path).try(:first) + uid_logger("First comit########{commit}") + tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? + commit_id = commit["id"] + end # 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 # if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) From 031b93f7cfb0db09cf14eb270b34a80c327d039b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 13:48:41 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 9d61984db..8d6ce4f72 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -38,7 +38,12 @@ class DuplicateCourseService < ApplicationService def copy_course_modules! origin_course.course_modules.each do |course_module| attrs = course_module.as_json(only: %i[module_type position hidden module_name]) - CourseModule.create!(attrs.merge(course_id: course.id)) + new_course_module = CourseModule.create!(attrs.merge(course_id: course.id)) + # 复制子目录 + course_module.course_second_categories.each do |second_category| + category_attr = second_category.as_json(only: %i[category_type name position]) + CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id)) + end end end From 8299c443ab5130f14aef33e8079386f949895b13 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 14:21:15 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 8d6ce4f72..acff0a726 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -36,13 +36,16 @@ class DuplicateCourseService < ApplicationService end def copy_course_modules! + @second_category_list = {} origin_course.course_modules.each do |course_module| attrs = course_module.as_json(only: %i[module_type position hidden module_name]) new_course_module = CourseModule.create!(attrs.merge(course_id: course.id)) # 复制子目录 course_module.course_second_categories.each do |second_category| category_attr = second_category.as_json(only: %i[category_type name position]) - CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id)) + new_second_category = + CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id)) + @second_category_list[second_category.id] = new_second_category.id end end end @@ -55,7 +58,10 @@ class DuplicateCourseService < ApplicationService origin_course.homework_commons.where(homework_type: %i[normal group practice]).find_each do |origin_homework| homework_attrs = origin_homework.as_json(only: %i[name description homework_type homework_bank_id reference_answer]) - homework = HomeworkCommon.create!(homework_attrs.merge(user_id: user.id, course_id: course.id)) + course_second_category_id = @second_category_list[origin_homework.course_second_category_id] + + homework = HomeworkCommon.create!(homework_attrs.merge(user_id: user.id, course_id: course.id, + course_second_category_id:course_second_category_id)) origin_homework.attachments.find_each do |origin_attachment| attachment = origin_attachment.copy @@ -76,6 +82,7 @@ class DuplicateCourseService < ApplicationService HomeworksService.new.create_shixun_homework_cha_setting(homework, origin_homework.shixuns.first) end + origin_homework.increment!(:quotes) origin_homework.homework_bank.increment!(:quotes) if origin_homework.homework_bank end @@ -143,9 +150,9 @@ class DuplicateCourseService < ApplicationService attachment.copy_from = origin_attachment.copy_from || origin_attachment.id attachment.is_publish = 0 attachment.attachtype ||= 4 + attachment.course_second_category_id = @second_category_list[origin_attachment.course_second_category_id] attachment.save! - origin_course.update_quotes(attachment) end end From cc29cb619419ff4325004c6a0bab5bd43d233fe4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 14:27:00 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index acff0a726..2456c81ff 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -11,7 +11,7 @@ class DuplicateCourseService < ApplicationService @course = copy_course! copy_course_modules! - + logger.info("###########second_category_list#{@second_category_list}") join_course! copy_homework_commons! From b81ddf1d0d31d3a1e921b3bd8a54fa14d6b40bdb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 14:28:01 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 2456c81ff..27ae2f784 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -11,7 +11,7 @@ class DuplicateCourseService < ApplicationService @course = copy_course! copy_course_modules! - logger.info("###########second_category_list#{@second_category_list}") + Rails.logger.info("###########second_category_list#{@second_category_list}") join_course! copy_homework_commons! From 4103d471aa197a83acb5f68ddc12d6b496d6ca8b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 14:39:20 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/excellent_course_exercise.rake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index c68cf6348..9f1484027 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -16,7 +16,16 @@ namespace :excellent_course_exercise do exercise_1884 = course.exercises.find_by(id: 1884) members_1.each_with_index do |member, index| if index < 821 - + exercise_1884.exercise_questions.where.not(question_type: 5).each do |question| + answer_option = { + :user_id => current_user.id, + :exercise_question_id => @exercise_question.id, + :exercise_choice_id => choice_id, + :answer_text => "" + } + ex_a = ExerciseAnswer.new(answer_option) + ex_a.save! + end else end From c0a4766dab4c7519661875ca532aacc15ac48ce3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 14:41:34 +0800 Subject: [PATCH 08/12] tz --- app/controllers/subjects_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 6a381b258..55f8722a2 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -86,6 +86,16 @@ class SubjectsController < ApplicationController @shixuns = @subject.shixuns.published.pluck(:id) @courses = @subject.courses if @subject.excellent + @members = @subject.subject_members.includes(:user) + shixuns = @subject.shixuns.published.pluck(:id) + challenge_ids = Challenge.where(shixun_id: shixuns).pluck(:id) + # 实训路径中的所有实训标签 + @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq + # 用户获取的实训标签 + # @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + @user_tags = user_shixun_tags challenge_ids, @user.id + @my_subject_progress = @subject.my_subject_progress + # 访问数变更 @subject.increment!(:visits) end From 6716cd9938736c3e33e13065a07bdb43f8bcc1d3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 14:42:34 +0800 Subject: [PATCH 09/12] tz --- app/views/subjects/show.json.jbuilder | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/views/subjects/show.json.jbuilder b/app/views/subjects/show.json.jbuilder index bf179b86d..93fa105a6 100644 --- a/app/views/subjects/show.json.jbuilder +++ b/app/views/subjects/show.json.jbuilder @@ -22,4 +22,26 @@ if @subject.excellent json.course_identity @user.course_identity(course) json.course_status subject_course_status course end +end + + +json.members @members do |member| + json.partial! 'subject_member', locals: { user: member.user } + json.role member.role +end + +# 技能标签 +json.tags @tags do |tag| + unless tag.blank? + json.tag_name tag + json.status @user_tags.include?(tag) + end +end + +# 我的进展 +json.progress do + json.my_score @subject.my_subject_score + json.all_score @subject.all_score + json.learned @subject.my_subject_progress + json.time @subject.my_consume_time end \ No newline at end of file From 32bb3c60442e692f6e778e07098e01d8271e1fd7 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 15:05:09 +0800 Subject: [PATCH 10/12] video feature add teacher check --- app/controllers/users/base_controller.rb | 6 ++++++ app/controllers/users/video_auths_controller.rb | 2 +- app/controllers/users/videos_controller.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 706b77802..7dd5ae024 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -26,6 +26,12 @@ class Users::BaseController < ApplicationController render_forbidden end + def require_auth_teacher! + return if user.admin_or_business? || observed_user.certification_teacher? + + render_forbidden + end + def page_value params[:page].to_i <= 0 ? 1 : params[:page].to_i end diff --git a/app/controllers/users/video_auths_controller.rb b/app/controllers/users/video_auths_controller.rb index d7950f873..0eec4dffb 100644 --- a/app/controllers/users/video_auths_controller.rb +++ b/app/controllers/users/video_auths_controller.rb @@ -1,5 +1,5 @@ class Users::VideoAuthsController < Users::BaseController - before_action :private_user_resources! + before_action :private_user_resources!, :require_auth_teacher! def create result = Videos::CreateAuthService.call(observed_user, create_params) diff --git a/app/controllers/users/videos_controller.rb b/app/controllers/users/videos_controller.rb index e4dffec23..1df726c0c 100644 --- a/app/controllers/users/videos_controller.rb +++ b/app/controllers/users/videos_controller.rb @@ -1,5 +1,5 @@ class Users::VideosController < Users::BaseController - before_action :private_user_resources! + before_action :private_user_resources!, :require_auth_teacher! helper_method :current_video From 43d8f62f0fcec73b1872d90bafc6133fce3b6602 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 15:28:24 +0800 Subject: [PATCH 11/12] fix --- app/controllers/users/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 7dd5ae024..eb6b98048 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -27,7 +27,7 @@ class Users::BaseController < ApplicationController end def require_auth_teacher! - return if user.admin_or_business? || observed_user.certification_teacher? + return if current_user.admin_or_business? || observed_user.certification_teacher? render_forbidden end From 7b99a1a5c5f85a8adf74c9430f05cd2bfedd8307 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 15:55:22 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E7=9A=84pdf=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 7 +------ app/models/attachment.rb | 11 +++++++++++ .../_attachment_history.json.jbuilder | 1 + app/views/attachments/_attachment_small.json.jbuilder | 3 ++- app/views/files/histories.json.jbuilder | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index bcfed25dd..2cfa61cc9 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -260,12 +260,7 @@ class FilesController < ApplicationController return normal_status(-2, "该课程下没有id为 #{params[:id]}的资源") if @file.nil? return normal_status(403, "您没有权限进行该操作") if @user != @file.author && !@user.teacher_of_course?(@course) && !@file.public? - @is_pdf = false - file_content_type = @file.content_type - file_ext_type = File.extname(@file.filename).strip.downcase[1..-1] - if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) - @is_pdf = true - end + @attachment_histories = @file.attachment_histories end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index bdd749108..3a512278a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -115,4 +115,15 @@ class Attachment < ApplicationRecord end end + #判断是否为pdf文件 + def is_pdf? + is_pdf = false + file_content_type = content_type + file_ext_type = File.extname(filename).strip.downcase[1..-1] + if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) + is_pdf = true + end + is_pdf + end + end diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 37b8b95c1..65ca1e887 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -7,3 +7,4 @@ json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.url attachment_path(attachment, type: 'history') +json.is_pdf attachment.is_pdf? diff --git a/app/views/attachments/_attachment_small.json.jbuilder b/app/views/attachments/_attachment_small.json.jbuilder index d9a976bde..97cbee120 100644 --- a/app/views/attachments/_attachment_small.json.jbuilder +++ b/app/views/attachments/_attachment_small.json.jbuilder @@ -2,4 +2,5 @@ json.id attachment.id json.title attachment.title json.filesize number_to_human_size(attachment.filesize) json.url download_url(attachment) -json.created_on attachment.created_on \ No newline at end of file +json.created_on attachment.created_on +json.is_pdf attachment.is_pdf? \ No newline at end of file diff --git a/app/views/files/histories.json.jbuilder b/app/views/files/histories.json.jbuilder index 9dfec4fd4..7039752e7 100644 --- a/app/views/files/histories.json.jbuilder +++ b/app/views/files/histories.json.jbuilder @@ -1,3 +1,3 @@ -json.is_pdf @is_pdf + json.partial! 'attachments/attachment_small', attachment: @file json.partial! "attachment_histories/list", attachment_histories: @attachment_histories