diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb index f90c8a1ed..0451b77d1 100644 --- a/app/controllers/admins/base_controller.rb +++ b/app/controllers/admins/base_controller.rb @@ -6,10 +6,10 @@ class Admins::BaseController < ApplicationController layout 'admin' skip_before_action :verify_authenticity_token - before_action :require_login, :require_admin! after_action :rebind_event_if_ajax_render_partial + skip_before_action :check_sign private diff --git a/app/controllers/admins/shixun_settings_controller.rb b/app/controllers/admins/shixun_settings_controller.rb index 6dbbc077a..37ca45674 100644 --- a/app/controllers/admins/shixun_settings_controller.rb +++ b/app/controllers/admins/shixun_settings_controller.rb @@ -5,9 +5,10 @@ class Admins::ShixunSettingsController < Admins::BaseController shixun_settings = Admins::ShixunSettingsQuery.call(params) @editing_shixuns = shixun_settings.where(status:0).size - @pending_shixuns = shixun_settings.where(status:1).size - @processed_shixuns = shixun_settings.where(status:2).size + @processed_shixuns = shixun_settings.where(status:2, public: 0).size @closed_shixuns = shixun_settings.where(status:3).size + @pending_public_shixuns = shixun_settings.where(public:1).size + @processed_pubic_shixuns = shixun_settings.where(public:2).size @sort_json = { can_copy: params[:can_copy].present? ? params[:can_copy] : false, @@ -83,9 +84,9 @@ class Admins::ShixunSettingsController < Admins::BaseController sheet1[count_row, 6] = shixun.myshixuns_count sheet1[count_row, 7] = shixun.myshixuns.select{|m| m.status == 1}.size sheet1[count_row, 8] = shixun.shixun_status - sheet1[count_row, 9] = shixun.user.show_real_name - sheet1[count_row, 10] = shixun.user.school_name - sheet1[count_row, 11] = shixun.user.identity + sheet1[count_row, 9] = shixun.user&.show_real_name + sheet1[count_row, 10] = shixun.user&.school_name + sheet1[count_row, 11] = shixun.user&.identity shixun.challenges.each do |challenge| sheet1[count_row, 12] = "第#{challenge.position}关" sheet1[count_row, 13] = challenge.subject @@ -112,13 +113,16 @@ class Admins::ShixunSettingsController < Admins::BaseController sheet1[count_row, 2] = shixun.mirror_repositories.select{|mr| mr.main_type == "1"}.first&.type_name sheet1[count_row, 3] = shixun.fork_from sheet1[count_row, 4] = shixun.shixun_status - sheet1[count_row, 5] = shixun.user.show_real_name - sheet1[count_row, 6] = shixun.user.school_name - sheet1[count_row, 7] = shixun.user.identity - shixun.challenges.each do |challenge| + sheet1[count_row, 5] = shixun.user&.show_real_name + sheet1[count_row, 6] = shixun.user&.school_name + sheet1[count_row, 7] = shixun.user&.identity + challenge_count = shixun.challenges.count + shixun.challenges.each_with_index do |challenge, index| sheet1[count_row, 8] = "第#{challenge.position}关" sheet1[count_row, 9] = challenge.subject - count_row += 1 + if index + 1 != challenge_count + count_row += 1 + end end count_row += 1 end diff --git a/app/controllers/admins/shixuns_controller.rb b/app/controllers/admins/shixuns_controller.rb index 6593f27c2..86cb9b45f 100644 --- a/app/controllers/admins/shixuns_controller.rb +++ b/app/controllers/admins/shixuns_controller.rb @@ -5,10 +5,8 @@ class Admins::ShixunsController < Admins::BaseController params[:sort_direction] = params[:sort_direction].presence || 'desc' shixuns = Admins::ShixunQuery.call(params) @editing_shixuns = shixuns.where(status:0).size - @pending_shixuns = shixuns.where(status:1).size - @processed_shixuns = shixuns.where(status:2).size + @processed_shixuns = shixuns.where(status:2, public: 0).size @closed_shixuns = shixuns.where(status:3).size - @none_public_shixuns = shixuns.where(public:0).size @pending_public_shixuns = shixuns.where(public:1).size @processed_pubic_shixuns = shixuns.where(public:2).size @shixuns_type_check = MirrorRepository.pluck(:type_name,:id) diff --git a/app/controllers/admins/users_controller.rb b/app/controllers/admins/users_controller.rb index 9630394b4..b9a07ba1e 100644 --- a/app/controllers/admins/users_controller.rb +++ b/app/controllers/admins/users_controller.rb @@ -61,7 +61,7 @@ class Admins::UsersController < Admins::BaseController private def update_params - params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id + params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker mail phone location location_city school_id department_id admin business is_test password professional_certification authentication]) end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9630caaec..254d04cfd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base protect_from_forgery prepend: true, unless: -> { request.format.json? } + before_action :check_sign before_action :user_setup #before_action :check_account @@ -20,12 +21,37 @@ class ApplicationController < ActionController::Base helper_method :current_user + # 所有请求必须合法签名 + def check_sign + Rails.logger.info("66666 #{params}") + suffix = request.url.split(".").last.split("?").first + suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释 + unless suffix_arr.include?(suffix) + if params[:client_key].present? + randomcode = params[:randomcode] + # tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5) + + sign = Digest::MD5.hexdigest("#{OPENKEY}#{randomcode}") + Rails.logger.info("2222 #{sign}") + tip_exception(501, "请求不合理") if sign != params[:client_key] + else + tip_exception(501, "请求不合理") + end + end + end + # 全局配置参数 # 返回name对应的value def edu_setting(name) EduSetting.get(name) end + def shixun_marker + unless current_user.is_shixun_marker? || current_user.admin_or_business? + tip_exception(403, "..") + end + end + # 实训的访问权限 def shixun_access_allowed if !current_user.shixun_permission(@shixun) @@ -256,9 +282,10 @@ class ApplicationController < ActionController::Base end def user_setup - # reacct静态资源加载不需要走这一步 + # # reacct静态资源加载不需要走这一步 return if params[:controller] == "main" # Find the current user + #Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}") User.current = find_current_user uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) @@ -400,7 +427,7 @@ class ApplicationController < ActionController::Base end rescue Exception => e uid_logger("--uri_exec: exception #{e.message}") - raise Educoder::TipException.new("实训平台繁忙(繁忙等级:84)") + raise Educoder::TipException.new(message) end end @@ -603,7 +630,7 @@ class ApplicationController < ActionController::Base end def paginate(relation) - limit = params[:limit].to_i.zero? ? 20 : params[:limit].to_i + limit = (params[:limit].to_i.zero? || params[:limit].to_i > 20) ? 20 : params[:limit].to_i page = params[:page].to_i.zero? ? 1 : params[:page].to_i offset = (page - 1) * limit @@ -678,4 +705,5 @@ class ApplicationController < ActionController::Base HotSearchKeyword.add(keyword) end + end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 5fc81c5d5..e0dd71467 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -5,6 +5,7 @@ class AttachmentsController < ApplicationController before_action :require_login, :check_auth, except: [:show] before_action :find_file, only: %i[show destroy] before_action :attachment_candown, only: [:show] + skip_before_action :check_sign, only: [:show, :create] include ApplicationHelper diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 851567c92..c5d3082ba 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -22,7 +22,7 @@ class CommentsController < ApplicationController @discuss = @hack.discusses.new(reply_params) @discuss.hidden = false @discuss.user_id = current_user.id - @discuss.root_id = params[:parent_id] + @discuss.root_id = params[:comments][:parent_id] @discuss.save! rescue Exception => e uid_logger_error("reply discuss failed : #{e.message}") @@ -32,9 +32,14 @@ class CommentsController < ApplicationController # 列表 def index - disscusses = @hack.disscusses.where(:root_id => nil) - @disscuss_count = disscusses.count - @disscusses= paginate disscusses + discusses = + if current_user.admin_or_business? + @hack.discusses.where(root_id: nil) + else + @hack.discusses.where(root_id: nil, hidden: false) + end + @discusses_count = discusses.count + @discusses= paginate discusses end # 删除 @@ -43,10 +48,21 @@ class CommentsController < ApplicationController render_ok end + # 隐藏、取消隐藏 + def hidden + if current_user.admin_or_business? + @discuss = @hack.discusses.where(id: params[:id]).first + @discuss.update_attribute(:hidden, params[:hidden].to_i == 1) + sucess_status + else + Educoder::TipException(403, "..") + end + end + private def find_hack - @hack = Hack.find_by_identifier params[:identifier] + @hack = Hack.find_by_identifier(params[:hack_identifier]) end def comment_params diff --git a/app/controllers/cooperative/base_controller.rb b/app/controllers/cooperative/base_controller.rb index 51af05ed2..5d21598aa 100644 --- a/app/controllers/cooperative/base_controller.rb +++ b/app/controllers/cooperative/base_controller.rb @@ -10,13 +10,14 @@ class Cooperative::BaseController < ApplicationController before_action :laboratory_exist!, :require_login, :require_cooperative_manager! after_action :rebind_event_if_ajax_render_partial + skip_before_action :check_sign helper_method :current_laboratory, :current_setting_or_default private def current_laboratory - @_current_laboratory ||= Laboratory.find_by_subdomain(request.subdomain) + @_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.first) # @_current_laboratory ||= Laboratory.find 1 end diff --git a/app/controllers/departments_controller.rb b/app/controllers/departments_controller.rb index 5e82b2c51..73cb19156 100644 --- a/app/controllers/departments_controller.rb +++ b/app/controllers/departments_controller.rb @@ -1,4 +1,6 @@ class DepartmentsController < ApplicationController + skip_before_action :check_sign + def for_option render_ok(departments: current_school.departments.without_deleted.select(:id, :name).as_json) end diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index cbb19cb7f..e7d692de5 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -14,14 +14,14 @@ class DiscussesController < ApplicationController @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil) - @discusses = disscusses.limit(LIMIT).joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id") - .select("discusses.*, games.identifier").includes(:user, :praise_treads).offset(offset) + @discusses = disscusses.joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id") + .select("discusses.*, games.identifier").includes(:user, :praise_treads) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (discusses.hidden = :hidden or discusses.user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) @disscuss_count = disscusses.count("discusses.id") - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) + @discusses = disscusses.includes(:user, :praise_treads).limit(LIMIT).offset(offset) end @current_user = current_user @@ -117,13 +117,13 @@ class DiscussesController < ApplicationController # 0 取消赞; def plus pt = PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type], - :user_id => current_user, :praise_or_tread => 1).first + :user_id => current_user, :praise_or_tread => 1) # 如果当前用户已赞过,则不能重复赞 if params[:type] == 1 && pt.blank? PraiseTread.create!(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type], - :user_id => current_user.id, :praise_or_tread => 1) if pt.blank? + :user_id => current_user.id, :praise_or_tread => 1) else - pt.destroy if pt.present? # 如果已赞过,则删掉这条赞(取消);如果没赞过,则为非法请求不处理 + pt.destroy_all if pt.present? # 如果已赞过,则删掉这条赞(取消);如果没赞过,则为非法请求不处理 end @praise_count = PraiseTread.where(:praise_tread_object_id => params[:id], :praise_tread_object_type => params[:container_type], diff --git a/app/controllers/edu_settings_controller.rb b/app/controllers/edu_settings_controller.rb index 6baf38e5b..d3b796da7 100644 --- a/app/controllers/edu_settings_controller.rb +++ b/app/controllers/edu_settings_controller.rb @@ -1,7 +1,7 @@ class EduSettingsController < ApplicationController before_action :require_admin before_action :set_edu_setting, only: [:show, :edit, :update, :destroy] - + skip_before_action :check_sign # GET /edu_settings # GET /edu_settings.json def index diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d55eb9211..938d42c2f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -10,9 +10,6 @@ class GamesController < ApplicationController include GamesHelper include ApplicationHelper - - - def show uid_logger("--games show start") # 防止评测中途ajaxE被取消;3改成0是为了处理首次进入下一关的问题 @@ -91,7 +88,6 @@ class GamesController < ApplicationController end end - def jupyter # Jupyter没有challenge @myshixun = Myshixun.find_by_identifier params[:identifier] @@ -103,7 +99,7 @@ class GamesController < ApplicationController begin @tpm_modified = @myshixun.repository_is_modified(@shixun.repo_path) # 判断TPM和TPI的版本库是否被改了 rescue - uid_logger("实训平台繁忙,繁忙等级(81)") + uid_logger("服务器出现问题,请重置刷新页面") end end diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index bbb0e293e..0767eab02 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -1,5 +1,5 @@ class GitsController < ApplicationController - + skip_before_action :check_sign # 说明: # 以下Git认证只针对新版git,Gitlab的Git认证不走该控制器 # 思路: @@ -39,7 +39,7 @@ class GitsController < ApplicationController # 用户是否对对象拥有权限 system_user = User.find_by_login(input_username) || User.find_by_mail(input_username) || User.find_by_phone(input_username) # 如果用户名密码错误 - if system_user && !system_user.check_password?(input_password) + if system_user.blank? || system_user && !system_user.check_password?(input_password) uid_logger_error("git start: password is wrong") result = false else diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 0e6135e8c..de707d7c7 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -171,8 +171,8 @@ class GraduationTopicsController < ApplicationController unless teacher_group.present? member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first tip_exception("分班名称不能为空") if params[:course_group_name].blank? - course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id) - teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :course_member_id => member.try(:id), + course_group = CourseGroup.find_or_create_by!(:name => params[:course_group_name], :course_id => @course.id) + teacher_group = TeacherCourseGroup.find_or_create_by!(:course_id => @course.id, :course_member_id => member.try(:id), :user_id => @graduation_topic.tea_id, :course_group_id => course_group.try(:id)) end diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index 814d16d51..38238fea7 100644 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ b/app/controllers/hack_user_lastest_codes_controller.rb @@ -1,10 +1,10 @@ class HackUserLastestCodesController < ApplicationController before_action :require_login, except: [:listen_result] - before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, + before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code, :add_notes, :listen_result, :result, :submit_records, :restore_initial_code] before_action :update_user_hack_status, only: [:code_debug, :code_submit] - before_action :require_auth_identity, only: [:update_code, :restore_initial_code, :sync_code] - before_action :require_manager_identity, only: [:update_code] + before_action :require_auth_identity, only: [:add_notes] + before_action :require_manager_identity, only: [:show, :update_code, :restore_initial_code, :sync_code] def show @my_hack.update_attribute(:submit_status, 0) if @my_hack.submit_status == 1 @@ -61,13 +61,18 @@ class HackUserLastestCodesController < ApplicationController # 提交记录 def submit_records - @records = @my_hack.hack_user_codes.created_order - end + records = @my_hack.hack_user_codes + @records_count = records.count + @records = paginate records.created_order + end # 提交记录详情 def record_detail @hack_user = HackUserCode.find params[:id] + set = HackSet.find_by(id: @hack_user.error_test_set_id) + @pass_set_count = set ? set.position - 1 : 0 + @set_count = @hack_user.hack.hack_sets.count @my_hack = @hack_user.hack_user_lastest_code end @@ -80,7 +85,7 @@ class HackUserLastestCodesController < ApplicationController testCase = ojEvaResult['testCase'] # 只有编译出错时,才正则匹配错误行数 error_line= - if params[:status] == "-4" + if ojEvaResult['status'] == "4" || ojEvaResult['status'] == "5" regular_match_error_line ojEvaResult['outPut'], @my_hack.hack.language end # debug 与submit 公用的参数 @@ -94,7 +99,8 @@ class HackUserLastestCodesController < ApplicationController if ojEvaResult['execMode'] == "debug" save_debug_data ds_params elsif ojEvaResult['execMode'] == "submit" - save_submit_data ds_params.merge(expected_output: testCase['expectedOutput']) + save_submit_data ds_params.merge(expected_output: testCase['expectedOutput'], + error_test_set_id: ojEvaResult['failCaseNum']) end # 评测完成后,还原评测中的状态 @my_hack.update_attribute(:submit_status, 0) @@ -106,6 +112,11 @@ class HackUserLastestCodesController < ApplicationController end + def add_notes + @my_hack.update_attribute(:notes, params[:notes]) + render_ok + end + private def find_my_hack @my_hack = HackUserLastestCode.find_by(identifier: params[:identifier]) @@ -137,11 +148,12 @@ class HackUserLastestCodesController < ApplicationController # 正则错误行数 def regular_match_error_line content, language content = Base64.decode64(content).force_encoding("utf-8") + logger.info("######content: #{content}") case language when 'Java' content.scan(/.java.\d+/).map{|s| s.match(/\d+/)[0].to_i}.min when 'C', 'C++' - content.scan(/\d:\d+: error/).map{|s| s.match(/\d+/)[0]}.min + content.scan(/\d:\d+:/).map{|s| s.match(/\d+/)[0].to_i}.min when 'Python' content.scan(/line \d+/).map{|s| s.match(/\d+/)[0].to_i}.min end @@ -163,12 +175,12 @@ class HackUserLastestCodesController < ApplicationController # 通关 if submit_params[:status] == "0" # 编程题已经发布,且之前未通关奖励积分 + @hack.increment!(:pass_num) if @hack.status == 1 && !@my_hack.passed? - reward_attrs = { container_id: game.id, container_type: 'Hack', score: @hack.score } + reward_attrs = { container_id: @hack.id, container_type: 'Hack', score: @hack.score } RewardGradeService.call(@my_hack.user, reward_attrs) RewardExperienceService.call(@my_hack.user, reward_attrs) # 评测完成更新通过数 - @hack.increment!(:pass_num) @my_hack.update_attributes(passed: true, passed_time: Time.now) end end diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index b7f6a30a2..3eaac0648 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -44,12 +44,13 @@ class HacksController < ApplicationController begin logger.info("##########{hack_params}") hack = Hack.new(hack_params) + hack.user_id = current_user.id + hack.identifier = generate_identifier Hack, 8 ActiveRecord::Base.transaction do - hack.user_id = current_user.id - hack.identifier = generate_identifier Hack, 8 hack.save! # 创建测试集与代码 hack.hack_sets.create!(hack_sets_params) + # 新建知识点 hack_codes = hack.hack_codes.new(hack_code_params) hack_codes.modify_time = Time.now hack_codes.save! @@ -98,12 +99,22 @@ class HacksController < ApplicationController # 发布功能 def publish @hack.update_attribute(:status, 1) + base_attrs = { + trigger_user_id: current_user.id, viewed: 0, tiding_type: 'System', user_id: @hack.user_id, + parent_container_type: "HackPublish", extra: @hack.identifier + } + @hack.tidings.create!(base_attrs) render_ok end # 取消发布 def cancel_publish @hack.update_attribute(:status, 0) + base_attrs = { + trigger_user_id: current_user.id, viewed: 0, tiding_type: 'System', user_id: @hack.user_id, + parent_container_type: "HackUnPublish", extra: @hack.identifier + } + @hack.tidings.create!(base_attrs) render_ok end @@ -121,8 +132,19 @@ class HacksController < ApplicationController def new;end def destroy - @hack.destroy - render_ok + begin + base_attrs = { + user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, + parent_container_type: "HackDelete", extra: "#{@hack.name}" + } + @hack.tidings.create!(base_attrs) + @hack.destroy + render_ok + rescue => e + logger.error("####hack_delete_error: #{e.message}") + render_error("删除失败") + end + end private @@ -167,10 +189,13 @@ class HacksController < ApplicationController def param_update_sets sets, all_sets_id delete_set_ids = all_sets_id - sets.map{|set|set[:id]} @hack.hack_sets.where(id: delete_set_ids).destroy_all + logger.info("#######sets:#{sets}") sets.each do |set| + logger.info("###set[:id]: #{set[:id]}") + logger.info("###all_sets: #{all_sets_id.include?(set[:id])}") if all_sets_id.include?(set[:id]) update_attrs = {input: set[:input], output: set[:output], position: set[:position]} - @hack.hack_sets.find_by!(id: set[:id]).update_attributes(update_attrs) + @hack.hack_sets.find_by!(id: set[:id]).update_attributes!(update_attrs) end end end @@ -208,6 +233,11 @@ class HacksController < ApplicationController hacks = hacks.where(category: params[:category]) end + # 语言 + if params[:language] + hacks = hacks.joins(:hack_codes).where(hack_codes: {language: params[:language]}) + end + # 排序 sort_by = params[:sort_by] || "hack_user_lastest_codes_count" sort_direction = params[:sort_direction] || "desc" diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3a60dcde5..a4d34a1c8 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -11,7 +11,7 @@ class HomeworkCommonsController < ApplicationController before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, - :update_score, :update_student_score] + :update_score, :update_student_score, :batch_comment] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] @@ -19,7 +19,7 @@ class HomeworkCommonsController < ApplicationController :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :update_explanation, :update_settings, - :add_to_homework_bank, :publish_groups, :end_groups] + :add_to_homework_bank, :publish_groups, :end_groups, :batch_comment] before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category, :add_to_homework_bank] before_action :course_manager, only: [:alter_name] @@ -214,7 +214,7 @@ class HomeworkCommonsController < ApplicationController limit = params[:limit] || 20 @student_works = @student_works.page(page).per(limit) if @homework.homework_type == "practice" - @student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games) + @student_works = @student_works.includes(:student_works_scores, :shixun_work_comments, user: :user_extension, myshixun: :games) else @student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension) end @@ -453,105 +453,8 @@ class HomeworkCommonsController < ApplicationController # 课堂结束后不能再更新 unless @course.is_end + # 发布设置 UpdateHomeworkPublishSettingService.call(@homework, publish_params) - # 作业未发布时,unified_setting参数不能为空 -=begin - if @homework.publish_time.nil? || @homework.publish_time > Time.now - tip_exception("缺少统一设置的参数") if params[:unified_setting].nil? - if params[:unified_setting] || @course.course_groups_count == 0 - tip_exception("发布时间不能为空") if params[:publish_time].blank? - tip_exception("截止时间不能为空") if params[:end_time].blank? - tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") - tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") - tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time] - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day - - @homework.unified_setting = 1 - @homework.homework_group_settings.destroy_all - @homework.publish_time = params[:publish_time] - # 截止时间为空时取发布时间后一个月 - @homework.end_time = params[:end_time] - - else - tip_exception("分班发布设置不能为空") if params[:group_settings].blank? - # 创建作业的分班设置 - create_homework_group_settings @homework - - setting_group_ids = [] - - params[:group_settings].each do |setting| - tip_exception("分班id不能为空") if setting[:group_id].length == 0 - tip_exception("发布时间不能为空") if setting[:publish_time].blank? - tip_exception("截止时间不能为空") if setting[:end_time].blank? - tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) - tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day - - - publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time] - # 截止时间为空时取发布时间后一个月 - end_time = setting[:end_time] - HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id]). - update_all(publish_time: publish_time, end_time: end_time) - setting_group_ids << setting[:group_id] - end - - # 未设置的分班:发布时间和截止时间都为nil - HomeworkGroupSetting.where.not(course_group_id: setting_group_ids).where(homework_common_id: @homework.id). - update_all(publish_time: nil, end_time: nil) - - # 记录已发布需要发消息的分班 - publish_group_ids = HomeworkGroupSetting.where(homework_common_id: @homework.id).group_published.pluck(:course_group_id) - - @homework.unified_setting = 0 - @homework.publish_time = @homework.min_group_publish_time - @homework.end_time = @homework.max_group_end_time - end - - # 如果作业立即发布则更新状态、发消息 - if @homework.publish_time <= Time.now and @homework_detail_manual.comment_status == 0 - @homework_detail_manual.comment_status = 1 - send_tiding = true - end - - # 作业在"提交中"状态时 - else - if @homework.end_time > Time.now && @homework.unified_setting - tip_exception("截止时间不能为空") if params[:end_time].blank? - tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) - - @homework.end_time = params[:end_time] - - elsif !@homework.unified_setting - create_homework_group_settings @homework - tip_exception("分班发布设置不能为空") if params[:group_settings].blank? - params[:group_settings].each do |setting| - group_settings = HomeworkGroupSetting.where(homework_common_id: @homework.id, course_group_id: setting[:group_id]) - - tip_exception("分班id不能为空") if setting[:group_id].length == 0 - tip_exception("发布时间不能为空") if setting[:publish_time].blank? - tip_exception("截止时间不能为空") if setting[:end_time].blank? - # 如果该发布规则 没有已发布的分班则需判断发布时间 - tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0 - - tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) && group_settings.none_end.count > 0 - tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if - @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day) - - group_settings.none_published.update_all(publish_time: setting[:publish_time]) - group_settings.none_end.update_all(end_time: setting[:end_time]) - end - - @homework.end_time = @homework.max_group_end_time - end - end -=end # 补交设置 tip_exception("缺少allow_late参数") if params[:allow_late].nil? @@ -880,69 +783,6 @@ class HomeworkCommonsController < ApplicationController ## 分页参数 page = params[:page] || 1 @shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10) - - # 新版用下面的代码 - # ## 我的实训 - # @shixuns = - # if params[:order_by] == 'mine' - # current_user.my_shixuns.unhidden - # else - # if current_user.admin? - # Shixun.unhidden - # else - # none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) - # - # @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden - # end - # end - # - # ## 方向 - # if params[:tag_level].present? && params[:tag_id].present? - # @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) - # case params[:tag_level].to_i - # when 1 #大类 - # @search_tags = Repertoire.find(params[:tag_id].to_i).name - # when 2 #子类 - # @search_tags = SubRepertoire.find(params[:tag_id].to_i).name - # when 3 #tag - # tag = TagRepertoire.find(params[:tag_id].to_i) - # @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" - # end - # end - # - # ## 搜索关键字创建者、实训名称、院校名称 - # if params[:keyword].present? - # keyword = params[:keyword].strip - # @shixuns = @shixuns.joins(user: [user_extenison: :school]). - # where("schools.name like '%#{keyword}%' - # or concat(lastname, firstname) like '%#{keyword}%' - # or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct - # end - # - # ## 筛选 难度 - # if params[:diff].present? && params[:diff].to_i != 0 - # @shixuns = @shixuns.where(trainee: params[:diff]) - # end - # - # ## 排序参数 - # bsort = params[:sort] || 'desc' - # case params[:order_by] || 'hot' - # when 'hot' - # @shixuns = @shixuns.order("myshixuns_count #{bsort}") - # when 'mine' - # @shixuns = @shixuns.order("shixuns.created_at #{bsort}") - # else - # @shixuns = @shixuns.order("myshixuns_count #{bsort}") - # end - # - # @total_count = @shixuns.count - # - # ## 分页参数 - # page = params[:page] || 1 - # limit = params[:limit] || 15 - # - # @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) - # end def create_shixun_homework @@ -1046,7 +886,7 @@ class HomeworkCommonsController < ApplicationController course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) # 去掉不对当前用户的单位公开的实训,已发布的实训 - stage.shixuns.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun| + stage.shixuns.no_jupyter.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun| homework = HomeworksService.new.create_homework shixun, @course, category, current_user @homework_ids << homework.id CreateStudentWorkJob.perform_later(homework.id) @@ -1248,31 +1088,6 @@ class HomeworkCommonsController < ApplicationController # homework_challenge_settings = homework.homework_challenge_settings unless student_works.blank? student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if homework.allow_late - -=begin - student_works.where("work_status != 0").includes(:myshixun).each do |student_work| - unless student_work.myshixun.is_complete? - student_work.update_attributes(work_status: 2, late_penalty: homework.late_penalty) - student_work.late_penalty = homework.late_penalty - end - HomeworksService.new.set_shixun_final_score student_work, student_work.myshixun, homework_detail_manual.answer_open_evaluation, - homework_challenge_settings - end - - student_works.where("work_status = 0").each do |student_work| - myshixun = Myshixun.where(shixun_id: shixun.id, user_id: student_work.user_id).first - if myshixun.present? - student_work.update_attributes(work_status: (myshixun.is_complete? ? 1 : 2), - late_penalty: myshixun.is_complete? ? 0 : homework.late_penalty, - commit_time: myshixun.created_at, myshixun_id: myshixun.id) - student_work.late_penalty = myshixun.is_complete? ? 0 : homework.late_penalty - HomeworksService.new.set_shixun_final_score student_work, myshixun, homework_detail_manual.answer_open_evaluation, - homework_challenge_settings - end - end -=end - - # 更新所有学生的效率分(重新取homework确保是更新后的) end end homework.save! @@ -1558,6 +1373,21 @@ class HomeworkCommonsController < ApplicationController end + def batch_comment + tip_exception(-1, "作业还未发布,不能评阅") if @homework_detail_manual.comment_status == 0 + tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank? + ActiveRecord::Base.transaction do + work_ids = @homework.student_works.where(work_status: [1, 2], user_id: @course.teacher_group_user_ids(current_user.id)).pluck(:id) + has_comment_ids = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 0).pluck(:student_work_id) + batch_comment_works = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 1) + batch_comment_works.update_all(comment: params[:comment], hidden_comment: params[:hidden_comment]) + work_ids = work_ids - has_comment_ids - batch_comment_works.pluck(:student_work_id) + # @homework.student_works.where(work_status: 0, id: work_ids).update_all(work_status: 1, commit_time: @homework.end_time, update_time: Time.now, work_score: 0, final_score: 0) + HomeworkBatchCommentJob.perform_later(params[:comment], params[:hidden_comment], work_ids, @homework.id, current_user.id) + normal_status("评阅成功") + end + end + private def find_homework diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 0e2628c3e..e8554300c 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,4 +1,10 @@ class MainController < ApplicationController + skip_before_action :check_sign + + def first_stamp + render :json => { status: 0, message: Time.now.to_i } + end + def index render file: 'public/react/build/index.html', :layout => false end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 255c0f42e..67bec877b 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -3,6 +3,7 @@ class MyshixunsController < ApplicationController before_action :find_myshixun, :except => [:training_task_status, :code_runinng_message] before_action :find_repo_name, :except => [:training_task_status, :code_runinng_message] skip_before_action :verify_authenticity_token, :only => [:html_content] + skip_before_action :check_sign, only: [:training_task_status, :code_runinng_message] ## TPI关卡列表 def challenges diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 0c442a613..3e6914dee 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -46,8 +46,8 @@ class PollsController < ApplicationController @polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id - not_poll_ids = @course.poll_group_settings.poll_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id) - @polls = member_show_polls.where.not(id: not_poll_ids) + publish_poll_ids = @course.poll_group_settings.poll_group_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id) + @polls = member_show_polls.unified_setting.or(member_show_polls.where(id: publish_poll_ids)) end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 @@ -722,19 +722,16 @@ class PollsController < ApplicationController un_anonymous = params[:un_anonymous] ? true : false # 统一设置或者分班为0,则更新问卷,并删除问卷分组 if unified_setting || (course_group_ids.size == 0) - params_publish_time = params[:publish_time].present? ? params[:publish_time].to_time : nil - params_end_time = nil - if params[:end_time].blank? - if params_publish_time.present? - params_end_time = params_publish_time + 30.days - end - else - params_end_time = params[:end_time].to_time - end - # params_end_time = params[:end_time].present? ? params[:end_time].to_time : nil - if poll_status == 2 && @poll.publish_time != params_publish_time - normal_status(-1,"不允许修改发布时间") - elsif poll_status == 3 && (@poll.end_time != params_end_time || @poll.publish_time != params_publish_time) + tip_exception("发布时间不能为空") if params[:publish_time].blank? + tip_exception("截止时间不能为空") if params[:end_time].blank? + tip_exception("截止时间不能早于发布时间") if params[:publish_time].to_time > params[:end_time].to_time + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && params[:end_time].to_time > @course.end_date.end_of_day + + params_publish_time = params[:publish_time].to_time + params_end_time = params[:end_time].to_time + + if poll_status != 1 && @poll.publish_time != params_publish_time normal_status(-1,"不允许修改发布时间") elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time normal_status(-1,"截止时间不能小于发布时间") @@ -761,24 +758,25 @@ class PollsController < ApplicationController total_common_group = poll_groups_ids & total_common #传入的分班与问卷已存在的分班的交集 old_poll_groups = poll_groups_ids - total_common_group #后来传入的分班里,没有了的班级,即需要删除 params_times.each do |t| - course_id = t[:course_group_id] #为数组,可能会设置分班为各个班级id的数组 - poll_publish_time = t[:publish_time].present? ? t[:publish_time].to_time : nil - # poll_end_time = t[:end_time].present? ? t[:end_time].to_time : nil - poll_end_time = nil - if t[:end_time].blank? - if poll_publish_time.present? - poll_end_time = poll_publish_time + 30.days - end - else - poll_end_time = t[:end_time].to_time - end + tip_exception("发布时间不能为空") if t[:publish_time].blank? + tip_exception("截止时间不能为空") if t[:end_time].blank? + tip_exception("截止时间不能早于发布时间") if t[:publish_time].to_time > t[:end_time].to_time + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && t[:end_time].to_time > @course.end_date.end_of_day + + course_id = t[:course_group_id] + poll_publish_time = t[:publish_time].to_time + poll_end_time = t[:end_time].to_time + poll_group = poll_groups.find_in_poll_group("course_group_id",course_id) #判断该分班是否存在 - if poll_group.present? && poll_group.first.end_time <= Time.now && (poll_end_time != poll_group.first.end_time || poll_publish_time != poll_group.first.publish_time) #已截止且时间改变的,则提示错误 + + if poll_group.present? && (poll_group.first.publish_time < Time.now) && (poll_publish_time != poll_group.first.publish_time) error_count += 1 end - if poll_group.present? && poll_group.first.publish_time < Time.now && poll_publish_time != poll_group.first.publish_time + if poll_group.present? && (poll_group.first.publish_time < Time.now && poll_group.first.end_time > Time.now) && (poll_end_time < Time.now) error_count += 1 end + if error_count == 0 common_group = poll_groups_ids & course_id #传入的班级与问卷已存在的班级的交集,即表示已有分班的 new_group_ids = course_id - common_group #新传入的班级id @@ -794,12 +792,12 @@ class PollsController < ApplicationController if the_group_setting_status == 2 poll_group_params = { :publish_time => the_group_setting.publish_time, - :end_time => poll_end_time + :end_time => poll_end_time < Time.now ? the_group_setting.end_time : poll_end_time } elsif the_group_setting_status == 3 poll_group_params = { :publish_time => the_group_setting.publish_time, - :end_time => the_group_setting.end_time + :end_time => poll_end_time } end the_group_setting.update_attributes(poll_group_params) diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 99ca62b4c..ae0315cdd 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -1,4 +1,5 @@ class SchoolsController < ApplicationController + skip_before_action :check_sign def school_list schools = School.all @@ -14,7 +15,6 @@ class SchoolsController < ApplicationController schools = School.all keyword = params[:keyword].to_s.strip schools = schools.where('name LIKE ?', "%#{keyword}%") if keyword - render_ok(schools: schools.select(:id, :name).as_json) end diff --git a/app/controllers/shixun_lists_controller.rb b/app/controllers/shixun_lists_controller.rb index d0bfe3d88..c77da46e0 100644 --- a/app/controllers/shixun_lists_controller.rb +++ b/app/controllers/shixun_lists_controller.rb @@ -4,7 +4,8 @@ class ShixunListsController < ApplicationController end private + def search_params - params.permit(:keyword, :type, :page, :limit, :order, :status, :diff) + params.permit(:keyword, :type, :page, :limit, :order, :status, :diff, :sort, :no_jupyter) end end \ No newline at end of file diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 7c5964962..3de5970b6 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -19,11 +19,12 @@ class ShixunsController < ApplicationController :add_file, :jupyter_exec] before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish, :apply_public, - :shixun_members_added, :change_manager, :collaborators_delete, + :shixun_members_added, :change_manager, :collaborators_delete, :upload_git_file, :cancel_apply_public, :cancel_publish, :add_collaborators, :add_file] before_action :portion_allowed, only: [:copy] before_action :special_allowed, only: [:send_to_course, :search_user_courses] + before_action :shixun_marker, only: [:new, :create] ## 获取课程列表 def index @@ -215,7 +216,8 @@ class ShixunsController < ApplicationController if @shixun.shixun_info.present? ShixunInfo.create!(shixun_id: @new_shixun.id, description: @shixun.description, - evaluate_script: @shixun.evaluate_script) + evaluate_script: @shixun.evaluate_script, + fork_reason: params[:reason].to_s.strip) end # 同步私密版本库 @@ -265,8 +267,20 @@ class ShixunsController < ApplicationController # 如果是jupyter,先创建一个目录,为了挂载(因为后续数据集,开启Pod后环境在没销毁前,你上传数据集是挂载不上目录的,因此要先创建目录,方便中间层挂载) if @new_shixun.is_jupyter? folder = EduSetting.get('shixun_folder') + raise "存储目录未定义" unless folder.present? path = "#{folder}/#{@new_shixun.identifier}" FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path) + # 复制数据集 + save_path = File.join(folder, @shixun.identifier) + @shixun.data_sets.each do |set| + new_date_set = Attachment.new + new_date_set.attributes = set.attributes.dup.except("id", "container_id", "disk_directory") + new_date_set.container_id = @new_shixun.id + new_date_set.disk_directory = @new_shixun.identifier + new_date_set.save! + FileUtils.cp("#{save_path}/#{set.relative_path_filename}", path) + end + end # 同步复制关卡 if @shixun.challenges.present? @@ -350,7 +364,7 @@ class ShixunsController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 10 @member_count = @shixun.shixun_members.count - @members = @shixun.shixun_members.includes(:user).page(page).per(limit) + @members = @shixun.shixun_members.order("role = 1 desc, created_at asc").includes(:user).page(page).per(limit) end def fork_list @@ -454,7 +468,13 @@ class ShixunsController < ApplicationController def update_learn_setting begin ActiveRecord::Base.transaction do - @shixun.update_attributes!(shixun_params) + update_params = + if params[:shixun][:vnc] + shixun_params.merge(vnc_evaluate: 1) + else + shixun_params + end + @shixun.update_attributes!(update_params) end rescue => e uid_logger_error("实训学习页面设置失败--------#{e.message}") @@ -753,7 +773,7 @@ class ShixunsController < ApplicationController # jupyter开启挑战 def jupyter_exec - begin + if is_shixun_opening? tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") end @@ -767,22 +787,23 @@ class ShixunsController < ApplicationController commit_id = commit["id"] cloud_bridge = edu_setting('cloud_bridge') myshixun_identifier = generate_identifier Myshixun, 10 - ActiveRecord::Base.transaction do - @myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, - modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, - onclick_time: Time.now, commit_id: commit_id) - # fork仓库 - project_fork(@myshixun, @repo_path, current_user.login) - rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path) - uri = "#{cloud_bridge}/bridge/game/openGameInstance" - params = {tpiID: "#{@myshixun.id}", tpmGitURL: rep_url, tpiRepoName: @myshixun.repo_name.split("/").last} - interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" + begin + ActiveRecord::Base.transaction do + @myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, + modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, + onclick_time: Time.now, commit_id: commit_id) + # fork仓库 + project_fork(@myshixun, @repo_path, current_user.login) + rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path) + uri = "#{cloud_bridge}/bridge/game/openGameInstance" + params = {tpiID: "#{@myshixun.id}", tpmGitURL: rep_url, tpiRepoName: @myshixun.repo_name.split("/").last} + interface_post uri, params, 83, "服务器出现问题,请重置环境" + end + rescue => e + uid_logger_error(e.message) + tip_exception("服务器出现问题,请重置环境") end end - rescue => e - uid_logger_error(e.message) - tip_exception("#{e.message}") - end end def publish @@ -862,7 +883,18 @@ class ShixunsController < ApplicationController author_name = current_user.real_name author_email = current_user.git_mail @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" - end + end + + def upload_git_file + upload_file = params["file"] + uid_logger("#########################file_params####{params["#{params[:file]}"]}") + raise "未上传文件" unless upload_file + content = upload_file.tempfile.read + author_name = current_user.real_name + author_email = current_user.git_mail + update_file_content(content, @repo_path, author_email, author_name, "upload file by browser") + render_ok + end def add_collaborators member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" @@ -896,16 +928,20 @@ class ShixunsController < ApplicationController # 搜索成员 if request.get? @collaborators = @shixun.shixun_members.where("user_id != #{@shixun.user_id}") - else - if params[:user_id] - man_member = ShixunMember.where(:shixun_id => @shixun.id, :user_id => @shixun.user_id).first - cha_member = ShixunMember.where(:user_id => params[:user_id], :shixun_id => @shixun.id).first - if man_member && cha_member - man_member.update_attribute(:role, 2) - cha_member.update_attribute(:role, 1) - @shixun.update_attribute(:user_id, cha_member.user_id) - end - end + else + begin + raise("请先选择成员") if params[:user_id].blank? + man_member = ShixunMember.where(:shixun_id => @shixun.id, :user_id => @shixun.user_id).first + cha_member = ShixunMember.where(:user_id => params[:user_id], :shixun_id => @shixun.id).first + if man_member && cha_member + man_member.update_attribute(:role, 2) + cha_member.update_attribute(:role, 1) + @shixun.update_attribute(:user_id, cha_member.user_id) + end + rescue => e + logger.error("######change_manager_error: #{e.message}") + render_error(e.message) + end end end @@ -1127,4 +1163,5 @@ private end md5.hexdigest end + end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 6a9438a79..7df9aae89 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -7,6 +7,8 @@ class SubjectsController < ApplicationController :search_members, :add_subject_members, :statistics, :shixun_report, :school_report, :up_member_position, :down_member_position, :update_team_title] before_action :require_admin, only: [:copy_subject] + before_action :shixun_marker, only: [:new, :create, :add_shixun_to_stage] + include ApplicationHelper include SubjectsHelper @@ -214,7 +216,15 @@ class SubjectsController < ApplicationController GitService.add_repository(repo_path: repo_path) # todo: 为什么保存的时候要去除后面的.git呢?? @shixun.update_column(:repo_name, repo_path.split(".")[0]) - mirror_id = MirrorRepository.find_by(type_name: 'Python3.6')&.id + mirror_id = + if @shixun.is_jupyter? + folder = EduSetting.get('shixun_folder') + path = "#{folder}/#{identifier}" + FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path) + MirrorRepository.where("type_name like '%Jupyter%'").first&.id + else + MirrorRepository.find_by(type_name: 'Python3.6')&.id + end if mirror_id ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror_id) @shixun.shixun_service_configs.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror_id) @@ -247,7 +257,7 @@ class SubjectsController < ApplicationController CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework", course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) - stage.shixuns.where(id: params[:shixun_ids], status: 2).each do |shixun| + stage.shixuns.no_jupyter.where(id: params[:shixun_ids], status: 2).each do |shixun| homework = HomeworksService.new.create_homework shixun, @course, category, current_user homework_ids << homework.id end diff --git a/app/decorators/grade_decorator.rb b/app/decorators/grade_decorator.rb index ffffa11c9..5e2b9deed 100644 --- a/app/decorators/grade_decorator.rb +++ b/app/decorators/grade_decorator.rb @@ -31,6 +31,9 @@ module GradeDecorator when 'check_ta_answer' then game = Game.find_by(id: container_id) game.present? ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的TA人解答消耗的金币" : '' + when 'hack' then + hack = Hack.find_by(id: container_id) + hack.present? ? "完成了题目解答“#{hack.name}”,获得金币奖励:#{hack.score}" : '' end end end \ No newline at end of file diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb index 130e7f4b8..58345b601 100644 --- a/app/decorators/tiding_decorator.rb +++ b/app/decorators/tiding_decorator.rb @@ -220,11 +220,14 @@ module TidingDecorator when 'Journal' then message = parent_container&.notes.present? ? ':' + message_content_helper(parent_container.notes) : '' I18n.t(locale_format(parent_container_type)) % message + when 'Hack' then + I18n.t(locale_format(parent_container_type)) % parent_container.name end end def discuss_content - I18n.t(locale_format(container.parent_id.present?)) % message_content_helper(container.content) + I18n.t(locale_format(parent_container_type, container.parent_id.present?)) % + (parent_container_type == 'Hack' ? container.content : message_content_helper(container.content)) end def grade_content @@ -250,6 +253,9 @@ module TidingDecorator when 'shixunPublish' then name = Shixun.find_by(id: parent_container_id)&.name || '---' I18n.t(locale_format(parent_container_type)) % [name, container.score] + when 'Hack' then + name = Hack.find_by(id: container_id)&.name || '---' + I18n.t(locale_format(parent_container_type)) % [name, container.score] else I18n.t(locale_format(parent_container_type)) % container.score end @@ -405,4 +411,8 @@ module TidingDecorator def subject_start_course_content I18n.t(locale_format) % belong_container&.name end + + def hack_content + I18n.t(locale_format(parent_container_type)) % (container&.name || extra) + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cabf8d244..40e6cb365 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -64,7 +64,7 @@ module ApplicationHelper shixun_id = shixun_id.blank? ? -1 : shixun_id.join(",") Shixun.select([:id, :name, :user_id, :challenges_count, :myshixuns_count, :trainee, :identifier]).where("id - in(#{shixun_id})").unhidden.order("homepage_show asc, myshixuns_count desc").limit(3) + in(#{shixun_id})").unhidden.publiced.order("homepage_show asc, myshixuns_count desc").limit(3) end diff --git a/app/jobs/homework_batch_comment_job.rb b/app/jobs/homework_batch_comment_job.rb new file mode 100644 index 000000000..b9baa8557 --- /dev/null +++ b/app/jobs/homework_batch_comment_job.rb @@ -0,0 +1,20 @@ +# 作业的一键评阅 +class HomeworkBatchCommentJob < ApplicationJob + queue_as :default + + def perform(comment, hidden_comment, work_ids, homework_id, user_id) + # Do something later + homework = HomeworkCommon.find_by(id: homework_id) + return if homework.blank? + + attrs = %i[student_work_id challenge_id user_id comment hidden_comment batch_comment created_at updated_at] + + same_attrs = {challenge_id: 0, user_id: user_id, comment: comment, hidden_comment: hidden_comment, batch_comment: 1} + + ShixunWorkComment.bulk_insert(*attrs) do |worker| + work_ids.each do |work_id| + worker.add same_attrs.merge(student_work_id: work_id) + end + end + end +end diff --git a/app/models/course_group.rb b/app/models/course_group.rb index d57edf497..9486c9043 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -2,13 +2,15 @@ class CourseGroup < ApplicationRecord default_scope { order("course_groups.position ASC") } belongs_to :course, counter_cache: true has_many :course_members - has_many :exercise_group_settings,:dependent => :destroy has_many :attachment_group_settings, :dependent => :destroy has_many :homework_group_reviews, :dependent => :destroy + has_many :teacher_course_groups, :dependent => :destroy + has_many :homework_group_settings, :dependent => :destroy scope :by_group_ids, lambda { |ids| where(id: ids)} validates :name, length: { maximum: 60 } + validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班" after_create :generate_invite_code diff --git a/app/models/discuss.rb b/app/models/discuss.rb index a50b18a6f..4e6cd617c 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -10,7 +10,7 @@ class Discuss < ApplicationRecord has_one :praise_tread_cache, as: :object, dependent: :destroy belongs_to :dis, polymorphic: true - belongs_to :challenge + belongs_to :challenge, optional: true after_create :send_tiding scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) } @@ -52,11 +52,21 @@ class Discuss < ApplicationRecord private def send_tiding + if dis_type == 'Shixun' + send_user_id = has_parent? ? parent.user_id : Challenge.find(challenge_id).user_id + parent_container_type = 'Challenge' + challenge_id = challenge_id + extra = '' + elsif dis_type == 'Hack' + send_user_id = has_parent? ? parent.user_id : Hack.find(dis_id).user_id + parent_container_type = 'Hack' + challenge_id = dis_id + extra = HackUserLastestCode.where(user_id: user_id, hack_id: dis_id).first&.identifier + end base_attrs = { - trigger_user_id: user_id, parent_container_id: challenge_id, parent_container_type: 'Challenge', - belong_container_id: dis_id, belong_container_type: 'Shixun', viewed: 0, tiding_type: 'Comment' + trigger_user_id: user_id, parent_container_id: challenge_id, parent_container_type: parent_container_type, + belong_container_id: dis_id, belong_container_type: dis_type, viewed: 0, tiding_type: 'Comment', extra: extra } - user_id = has_parent? ? parent.user_id : Challenge.find(challenge_id).user_id - tidings.create!(base_attrs.merge(user_id: user_id)) + tidings.create!(base_attrs.merge(user_id: send_user_id)) end end diff --git a/app/models/hack.rb b/app/models/hack.rb index 506cd4942..37e1f239d 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -11,6 +11,11 @@ class Hack < ApplicationRecord has_many :hack_codes, :dependent => :destroy has_many :hack_user_lastest_codes, :dependent => :destroy has_many :discusses, as: :dis, dependent: :destroy + # 点赞 + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy + # 消息 + has_many :tidings, as: :container + belongs_to :user scope :published, -> { where(status: 1) } diff --git a/app/models/hack_set.rb b/app/models/hack_set.rb index 6afe05663..9e2186fb5 100644 --- a/app/models/hack_set.rb +++ b/app/models/hack_set.rb @@ -1,5 +1,5 @@ class HackSet < ApplicationRecord - #validates :input, presence: { message: "测试集输入不能为空" } + validates :input, presence: { message: "测试集输入不能为空" } validates :output, presence: { message: "测试集输出不能为空" } validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同" # 编程题测试集 diff --git a/app/models/hack_user_code.rb b/app/models/hack_user_code.rb index eee394e39..1e13f8bfb 100644 --- a/app/models/hack_user_code.rb +++ b/app/models/hack_user_code.rb @@ -1,4 +1,5 @@ class HackUserCode < ApplicationRecord + # error_test_set_id: 错误的测试集id # 用户编程题的信息 belongs_to :hack belongs_to :hack_user_lastest_code diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 830f16dde..99582af41 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -12,4 +12,6 @@ class HackUserLastestCode < ApplicationRecord scope :mine_hack, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} + validates_length_of :notes, maximum: 5000, message: "笔记不能超过5000个字" + end diff --git a/app/models/poll.rb b/app/models/poll.rb index 5c1a9a64c..365e46008 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -19,6 +19,7 @@ class Poll < ApplicationRecord scope :poll_by_ids, lambda { |ids| where(id: ids) unless ids.blank? } scope :poll_by_status, lambda { |s| where(polls_status: s) unless s.blank? } scope :poll_group_ended, -> {where("end_time is NOT NULL AND end_time <= ?",Time.now)} + scope :unified_setting, -> { where("unified_setting = ?",true) } scope :poll_search, lambda { |keywords| where("polls_name LIKE ?", "%#{keywords}%") unless keywords.blank?} @@ -103,7 +104,7 @@ class Poll < ApplicationRecord if course.is_end status = 4 else - if user.present? && user.student_of_course?(course) + if user.present? && user.course_identity(course) == Course::STUDENT ex_time = get_poll_times(user.id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 58ec965b4..8e96b7d47 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -12,7 +12,7 @@ class PraiseTread < ApplicationRecord case self.praise_tread_object_type when "Memo","Message","Issue" self.tidings << Tiding.new(:trigger_user_id => self.user_id, :user_id => self.praise_tread_object.author_id, :parent_container_id => self.praise_tread_object_id, :parent_container_type => self.praise_tread_object_type, :viewed => 0, :tiding_type => "Praise") - when "Discuss","Challenge","HomeworkCommon","JournalsForMessage","Journal","GraduationTopic","GraduationTask" + when "Discuss","Challenge","HomeworkCommon","JournalsForMessage","Journal","GraduationTopic","GraduationTask", "Hack" self.tidings << Tiding.new(:trigger_user_id => self.user_id, :user_id => self.praise_tread_object.user_id, :parent_container_id => self.praise_tread_object_id, :parent_container_type => self.praise_tread_object_type, :viewed => 0, :tiding_type => "Praise") end end diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index 359b8b4dc..e01920490 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -16,7 +16,9 @@ module Searchable::Shixun name: name, description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH], status: status, - myshixuns_count: myshixuns_count + myshixuns_count: myshixuns_count, + created_at: created_at, + publish_time: publish_time }.merge!(searchable_user_data) .merge!(searchable_challenge_data) end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index de014f87b..d8a41ba6a 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -83,6 +83,7 @@ class Shixun < ApplicationRecord scope :publiced, lambda{ where(public: 2) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :find_by_ids,lambda{|k| where(id:k)} + scope :no_jupyter, -> { where(is_jupyter: false) } after_create :send_tiding #同步到trustie @@ -103,6 +104,19 @@ class Shixun < ApplicationRecord shixun_info.try(:evaluate_script) end + def fork_reason + case shixun_info.try(:fork_reason) + when 'Shixun' + '实训内容升级' + when 'Course' + '课堂教学使用' + when 'Subject' + '实践课程使用' + else + shixun_info.try(:fork_reason) + end + end + def fork_identifier self.fork_from.nil? ? "--" : fork_shixuns.first&.identifier end diff --git a/app/models/shixun_info.rb b/app/models/shixun_info.rb index 321b4c44a..7f7aa364e 100644 --- a/app/models/shixun_info.rb +++ b/app/models/shixun_info.rb @@ -1,6 +1,7 @@ class ShixunInfo < ApplicationRecord belongs_to :shixun validates_uniqueness_of :shixun_id + validates_length_of :fork_reason, maximum: 60 after_commit :create_diff_record private diff --git a/app/models/teacher_course_group.rb b/app/models/teacher_course_group.rb index fbf9849ac..769026366 100644 --- a/app/models/teacher_course_group.rb +++ b/app/models/teacher_course_group.rb @@ -8,6 +8,8 @@ class TeacherCourseGroup < ApplicationRecord scope :find_teacher_group_ids, lambda { |ids| where(course_group_id: ids) unless ids.blank?} scope :get_user_groups,lambda {|ids| where(user_id:ids)} + validates_uniqueness_of :course_group_id, scope: :course_member_id + def course_members self.course_group.course_members end diff --git a/app/queries/admins/shixun_query.rb b/app/queries/admins/shixun_query.rb index 0f8523599..29e087332 100644 --- a/app/queries/admins/shixun_query.rb +++ b/app/queries/admins/shixun_query.rb @@ -13,25 +13,24 @@ class Admins::ShixunQuery < ApplicationQuery all_shixuns = Shixun.all status = case params[:status] - when "editing" then [0] - when "pending" then [1] - when "processed" then [2] - when "closed" then [3] - else - [0,1,2,3] + when "editing" then {status: 0} + when "processed" then {status: 2, public: 0} + when "pending" then {public: 1} + when "publiced" then {public: 2} + when "closed" then {status: 3} end - public = - case params[:public] - when "editing" then [0] - when "pending" then [1] - when "processed" then [2] - else - [0,1,2] - end + all_shixuns = all_shixuns.where(status) if status.present? - all_shixuns = all_shixuns.where(status: status) if status.present? - all_shixuns = all_shixuns.where(public: public) if public.present? + if params[:fork_status].present? + all_shixuns = all_shixuns.where.not(fork_from: nil) + case params[:fork_status] + when 'Shixun', 'Course', 'Subject' + all_shixuns = all_shixuns.joins(:shixun_info).where(shixun_infos: {fork_reason: params[:fork_status]}) + when 'Other' + all_shixuns = all_shixuns.joins(:shixun_info).where("fork_reason is null or fork_reason not in ('Shixun', 'Course', 'Subject')") + end + end if params[:tag].present? all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i) diff --git a/app/queries/admins/shixun_settings_query.rb b/app/queries/admins/shixun_settings_query.rb index 377e7bf60..1e45952bf 100644 --- a/app/queries/admins/shixun_settings_query.rb +++ b/app/queries/admins/shixun_settings_query.rb @@ -15,16 +15,15 @@ class Admins::ShixunSettingsQuery < ApplicationQuery all_shixuns = all_shixuns.where(id: params[:id]) if params[:id].present? status = - case params[:status] - when "editing" then [0] - when "pending" then [1] - when "processed" then [2] - when "closed" then [3] - else - [0,1,2,3] - end - - all_shixuns = all_shixuns.where(status: status) if status.present? + case params[:status] + when "editing" then {status: 0} + when "processed" then {status: 2, public: 0} + when "pending" then {public: 1} + when "publiced" then {public: 2} + when "closed" then {status: 3} + end + + all_shixuns = all_shixuns.where(status) if status.present? if params[:tag].present? all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i) diff --git a/app/services/admins/identity_auths/agree_apply_service.rb b/app/services/admins/identity_auths/agree_apply_service.rb index d75a6d7db..4528debb4 100644 --- a/app/services/admins/identity_auths/agree_apply_service.rb +++ b/app/services/admins/identity_auths/agree_apply_service.rb @@ -10,7 +10,6 @@ class Admins::IdentityAuths::AgreeApplyService < ApplicationService ActiveRecord::Base.transaction do apply.update!(status: 1) user.update!(authentication: true) - RewardGradeService.call(user, container_id: user.id, container_type: 'Authentication', score: 500) deal_tiding! diff --git a/app/services/admins/professional_auths/agree_apply_service.rb b/app/services/admins/professional_auths/agree_apply_service.rb index 1ca2da2fc..3d723412b 100644 --- a/app/services/admins/professional_auths/agree_apply_service.rb +++ b/app/services/admins/professional_auths/agree_apply_service.rb @@ -10,7 +10,7 @@ class Admins::ProfessionalAuths::AgreeApplyService < ApplicationService ActiveRecord::Base.transaction do apply.update!(status: 1) user.update!(professional_certification: true) - + user.update!(is_shixun_marker: true) if user.is_teacher? RewardGradeService.call(user, container_id: user.id, container_type: 'Professional', score: 500) deal_tiding! diff --git a/app/services/admins/update_user_service.rb b/app/services/admins/update_user_service.rb index 41b5065d0..6b1c0c857 100644 --- a/app/services/admins/update_user_service.rb +++ b/app/services/admins/update_user_service.rb @@ -25,6 +25,7 @@ class Admins::UpdateUserService < ApplicationService ActiveRecord::Base.transaction do user.save! user.user_extension.save! + user.update!(is_shixun_marker: true) if user.is_certification_teacher update_gitlab_password if params[:password].present? end @@ -36,7 +37,7 @@ class Admins::UpdateUserService < ApplicationService def user_attributes params.slice(*%i[lastname nickname mail phone admin business is_test - professional_certification authentication]) + professional_certification authentication is_shixun_marker]) end def user_extension_attributes diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb index 015aac29b..6caf37f8f 100644 --- a/app/services/concerns/elasticsearch_able.rb +++ b/app/services/concerns/elasticsearch_able.rb @@ -9,7 +9,7 @@ module ElasticsearchAble highlight: highlight_options, body_options: body_options, page: page, - per_page: per_page + per_page: 20 } end @@ -37,7 +37,7 @@ module ElasticsearchAble def per_page per_page = params[:per_page].to_s.strip.presence || params[:limit].to_s.strip.presence - per_page.to_i <= 0 ? 20 : per_page.to_i + per_page.to_i <= 0 || per_page.to_i > 20 ? 20 : per_page.to_i end def page diff --git a/app/services/private_messages/create_service.rb b/app/services/private_messages/create_service.rb index 88f3a084f..89365c4a7 100644 --- a/app/services/private_messages/create_service.rb +++ b/app/services/private_messages/create_service.rb @@ -30,6 +30,6 @@ class PrivateMessages::CreateService < ApplicationService def validate! raise Error, '内容不能为空' if content.blank? - raise Error, '内容太长' if content.size > 255 + raise Error, '内容太长' if content.size > 500 end end \ No newline at end of file diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index f5af69179..32488a7c3 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -33,6 +33,10 @@ class ShixunSearchService < ApplicationService @shixuns = status == "published" ? @shixuns.where(status: 2) : @shixuns.where(status: [0, 1]) end + if params[:no_jupyter] + @shixuns = @shixuns.where(is_jupyter: 0) + end + ## 筛选 难度 if params[:diff].present? && params[:diff].to_i != 0 @shixuns = @shixuns.where(trainee: params[:diff]) @@ -49,12 +53,16 @@ class ShixunSearchService < ApplicationService includes: [ :shixun_info, :challenges, :subjects, user: { user_extension: :school } ] } model_options.merge!(where: { id: @shixuns.pluck(:id) }) - model_options.merge!(order: {"myshixuns_count" => sort_str}) + model_options.merge!(order: {sort_str => order_str}) model_options.merge!(default_options) model_options end - def sort_str + def order_str params[:order] || "desc" end + + def sort_str + params[:sort] || "myshixuns_count" + end end \ No newline at end of file diff --git a/app/services/subjects/copy_subject_service.rb b/app/services/subjects/copy_subject_service.rb index f44191fda..4715a8bad 100644 --- a/app/services/subjects/copy_subject_service.rb +++ b/app/services/subjects/copy_subject_service.rb @@ -79,7 +79,7 @@ class Subjects::CopySubjectService < ApplicationService copy_shixun_service_configs_data!(shixun, to_shixun) copy_challenges_data!(shixun, to_shixun) copy_shixun_members_data!(to_shixun) - + copy_jupyter_data_sets(shixun, to_shixun) if shixun.is_jupyter? # 云上实验室 if laboratory laboratory.laboratory_shixuns.create(shixun: to_shixun) @@ -87,6 +87,25 @@ class Subjects::CopySubjectService < ApplicationService to_shixun end + # 复制jupyter的数据集 + def copy_jupyter_data_sets(shixun, to_shixun) + return unless shixun.is_jupyter? + folder = EduSetting.get('shixun_folder') + raise "存储目录未定义" unless folder.present? + path = "#{folder}/#{to_shixun.identifier}" + FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path) + # 复制数据集 + save_path = File.join(folder, shixun.identifier) + shixun.data_sets.each do |set| + new_date_set = Attachment.new + new_date_set.attributes = set.attributes.dup.except("id", "container_id", "disk_directory") + new_date_set.container_id = to_shixun.id + new_date_set.disk_directory = to_shixun.identifier + new_date_set.save! + FileUtils.cp("#{save_path}/#{set.relative_path_filename}", path) + end + end + # 创建实训长字段内容 def copy_shixun_info_data!(shixun, to_shixun) to_shixun_info = ShixunInfo.new diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb index 279d147f4..b13b0ab1f 100644 --- a/app/services/users/shixun_service.rb +++ b/app/services/users/shixun_service.rb @@ -65,13 +65,18 @@ class Users::ShixunService end def manage_shixun_status_filter(relations) - status = case params[:status] - when 'editing' then 0 - when 'applying' then 1 - when 'published' then 2 - when 'closed' then 3 - end - relations = relations.where(status: status) if status + if params[:status] == "publiced" + relations = relations.where(public: 2) + elsif params[:status] == "applying" + relations = relations.where(public: 1) + else + status = case params[:status] + when 'editing' then 0 + when 'published' then 2 + when 'closed' then 3 + end + relations = relations.where(status: status) if status + end relations end diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 4b84068e7..09c115b06 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -2,7 +2,7 @@