diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 2bdd88566..a916f5351 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -263,12 +263,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/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 74942446e..c9b56bb98 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -555,23 +555,23 @@ 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)) - 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 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 diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 706b77802..eb6b98048 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 current_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 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/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 9d61984db..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! - + Rails.logger.info("###########second_category_list#{@second_category_list}") join_course! copy_homework_commons! @@ -36,9 +36,17 @@ 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]) - 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]) + 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 @@ -50,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 @@ -71,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 @@ -138,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 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 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 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