diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 851567c92..72afb3342 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,9 @@ class CommentsController < ApplicationController # 列表 def index - disscusses = @hack.disscusses.where(:root_id => nil) - @disscuss_count = disscusses.count - @disscusses= paginate disscusses + discusses = @hack.discusses.where(root_id: nil) + @discusses_count = discusses.count + @discusses= paginate discusses end # 删除 @@ -43,10 +43,20 @@ class CommentsController < ApplicationController render_ok end + # 隐藏、取消隐藏 + def hidden + if @hack.manager?(current_user) + @discuss.update_attribute(:hidden, params[:hidden] == "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/discusses_controller.rb b/app/controllers/discusses_controller.rb index cbb19cb7f..6b21526dd 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -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/games_controller.rb b/app/controllers/games_controller.rb index d55eb9211..a5cb1ece3 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -103,7 +103,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/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0a6ec62cc..190892730 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -782,7 +782,7 @@ class ShixunsController < ApplicationController end rescue => e uid_logger_error(e.message) - tip_exception("#{e.message}") + tip_exception("服务器出现问题,请重置环境") end end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 6a9438a79..c8f2f5f57 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -214,7 +214,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? + MirrorRepository.where("type_name like '%Jupyter%'").first&.id + folder = EduSetting.get('shixun_folder') + path = "#{folder}/#{identifier}" + FileUtils.mkdir_p(path, :mode => 0777) unless File.directory?(path) + 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) diff --git a/app/models/discuss.rb b/app/models/discuss.rb index a50b18a6f..652ffea37 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) } @@ -54,9 +54,14 @@ class Discuss < ApplicationRecord def send_tiding 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' + belong_container_id: dis_id, belong_container_type: dis_type, viewed: 0, tiding_type: 'Comment' } - user_id = has_parent? ? parent.user_id : Challenge.find(challenge_id).user_id + user_id = + if dis_type == 'Shixun' + has_parent? ? parent.user_id : Challenge.find(challenge_id).user_id + elsif dis_type == 'Hack' + has_parent? ? parent.user_id : Hack.find(dis_id).user_id + end tidings.create!(base_attrs.merge(user_id: user_id)) end end diff --git a/app/models/hack.rb b/app/models/hack.rb index 506cd4942..2e2ffb9e0 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -11,6 +11,9 @@ 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 + belongs_to :user scope :published, -> { where(status: 1) } diff --git a/app/views/comments/_discuss.json.jbuilder b/app/views/comments/_discuss.json.jbuilder index e9f983a47..b634b20a8 100644 --- a/app/views/comments/_discuss.json.jbuilder +++ b/app/views/comments/_discuss.json.jbuilder @@ -1,3 +1,6 @@ +json.author do + json.partial! 'users/user', user: discuss.user +end json.id discuss.id json.content content_safe(discuss.content) json.time time_from_now(discuss.created_at) diff --git a/app/views/comments/index.json.jbuilder b/app/views/comments/index.json.jbuilder index 399b144d9..b176d00b9 100644 --- a/app/views/comments/index.json.jbuilder +++ b/app/views/comments/index.json.jbuilder @@ -1,4 +1,4 @@ -json.disscuss_count @disscuss_count +json.disscuss_count @discusses_count json.comments @discusses do |discuss| json.partial! 'comments/discuss', locals: { discuss: discuss} json.children discuss.child_discuss(current_user) do |c_d| diff --git a/app/views/comments/plus.json.jbuilder b/app/views/comments/plus.json.jbuilder new file mode 100644 index 000000000..d24dbb655 --- /dev/null +++ b/app/views/comments/plus.json.jbuilder @@ -0,0 +1 @@ +json.praise_count @praise_count \ No newline at end of file diff --git a/app/views/hack_user_lastest_codes/show.json.jbuilder b/app/views/hack_user_lastest_codes/show.json.jbuilder index cfdc87d25..be700f112 100644 --- a/app/views/hack_user_lastest_codes/show.json.jbuilder +++ b/app/views/hack_user_lastest_codes/show.json.jbuilder @@ -1,11 +1,12 @@ json.hack do - json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier, :status) + json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier, :status, :praises_count) json.language @hack.language json.username @hack.user.real_name json.code @my_hack.code json.pass_count @hack.pass_num json.submit_count @hack.submit_num json.modify_code @modify + json.comments_count @hack.discusses.count end json.test_case do diff --git a/config/routes.rb b/config/routes.rb index 2ccfe117b..de884f3c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,7 +77,10 @@ Rails.application.routes.draw do delete :delete_set end resources :comments do - post :reply + collection do + post :reply + post :hidden + end end end diff --git a/db/migrate/20191223113621_modify_task_pass_for_challenges.rb b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb new file mode 100644 index 000000000..dbbbafced --- /dev/null +++ b/db/migrate/20191223113621_modify_task_pass_for_challenges.rb @@ -0,0 +1,8 @@ +class ModifyTaskPassForChallenges < ActiveRecord::Migration[5.2] + def change + Challenge.find_each do |challenge| + task_pass = challenge.task_pass.gsub(" ", "").gsub("rac", '\frac') + challenge.update_attribute(:task_pass, task_pass) + end + end +end diff --git a/db/migrate/20191223120424_add_praises_count_for_hacks.rb b/db/migrate/20191223120424_add_praises_count_for_hacks.rb new file mode 100644 index 000000000..4c4f3a9e2 --- /dev/null +++ b/db/migrate/20191223120424_add_praises_count_for_hacks.rb @@ -0,0 +1,6 @@ +class AddPraisesCountForHacks < ActiveRecord::Migration[5.2] + def change + add_column :hacks, :praises_count, :integer, :default => 0 + add_column :hacks, :comments_count, :integer, :default => 0 + end +end diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index e05a813f4..a8f860c2d 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -14,19 +14,19 @@ namespace :excellent_course_exercise do course = Course.find_by(id: course_id) course.exercises.each_with_index do |exercise, index| - # if exercise.exercise_users.where(commit_status: 1).count == 0 + if exercise.exercise_users.where(commit_status: 1).count == 0 # 第一个试卷的参与人数和通过人数都是传的数据,后续的随机 if index == 0 members = course.students.order("id asc").limit(participant_count) update_exercise_user(exercise, members, pass_count) else - new_participant_count = rand((participant_count - 423)..participant_count) - new_pass_count = rand((new_participant_count - 113)..new_participant_count) + new_participant_count = rand((participant_count - 20)..participant_count) + new_pass_count = rand((new_participant_count - 30)..new_participant_count) members = course.students.order("id asc").limit(new_participant_count) update_exercise_user(exercise, members, new_pass_count) end - # end + end end end @@ -36,14 +36,15 @@ namespace :excellent_course_exercise do # index < pass_count 之前的学生都是通关的,之后的未通过 members.each_with_index do |member, index| exercise_user = exercise.exercise_users.where(user_id: member.user_id).take - if exercise_question_ids.length == 20 + question_length = exercise_question_ids.length + if question_length == 20 rand_num = index < pass_count - 1 ? rand(15..20) : rand(1..10) - elsif exercise_question_ids.length == 17 + elsif question_length == 17 rand_num = index < pass_count - 1 ? rand(12..17) : rand(1..9) - elsif exercise_question_ids.length == 39 + elsif question_length == 39 rand_num = index < pass_count - 1 ? rand(30..39) : rand(1..18) else - rand_num = exercise_question_ids.length + rand_num = index < pass_count - 1 ? rand((question_length-3)..question_length) : rand(1..(question_length-8)) end if exercise_user && exercise_user.commit_status == 0 diff --git a/lib/tasks/migrate_course_student.rake b/lib/tasks/migrate_course_student.rake new file mode 100644 index 000000000..913cb2562 --- /dev/null +++ b/lib/tasks/migrate_course_student.rake @@ -0,0 +1,32 @@ +# 执行示例 RAILS_ENV=production bundle exec rake migrate_course_student:student args=3835,2526,21950,1000 +# args 第一个课程 course_id,第二个参数是学校school_id,第三个参数是部门id,第四个参数是迁移数量 +# + +desc "同步学校的学生" +namespace :migrate_course_student do + if ENV['args'] + course_id = ENV['args'].split(",")[0] # 对应课堂的id + school_id = ENV['args'].split(",")[1] # 对应学校id + department_id = ENV['args'].split(",")[2] # 对应部门id + limit = ENV['args'].split(",")[3] # 限制导入的数量 + end + + task :student => :environment do + course = Course.find course_id + users = User.joins(:user_extension).where(user_extensions: {school_id: school_id, department_id: department_id, identity: 1}).limit(limit) + user_ids = [] + + users.each do |user| + if user.student_id.present? && !course.students.exists?(user_id: user.id) + begin + CourseMember.create!(course_id: course_id, user_id: user.id, role: 4) + user_ids << user.id + rescue Exception => e + Rails.logger(e.message) + end + end + end + CourseAddStudentCreateWorksJob.perform_later(course_id, user_ids) + + end +end \ No newline at end of file diff --git a/public/react/public/css/edu-all.css b/public/react/public/css/edu-all.css index 5988709eb..f628b1e5c 100644 --- a/public/react/public/css/edu-all.css +++ b/public/react/public/css/edu-all.css @@ -360,7 +360,7 @@ label.infolabel{display: block;float: left;width: 56px;text-align: right;margin- .subshaicontent a{float: left;margin-right: 20px;color: #999;cursor: pointer} -.search-new{width: 248px;height:32px;position: relative;margin-right: 35px;} +.search-new{width: 248px;height:32px;position: relative;} .search-span{display: block;position: absolute;width: 100%;height: 100%;left:0px;top:0px;background-color: #F4F4F4;border: 1px solid #EAEAEA; border-radius: 4px;z-index: 1} .search-new-input{height: 32px;padding-left: 5px;width: 225px;border: none;box-sizing: border-box;background: none;outline: none;position: absolute;left:0px;top:1px;z-index: 2} .search-new img,.search-new a,.search-new .searchicon{cursor: pointer;position: absolute;right:2px;top:2px;z-index: 2} diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index acd18e6c3..0356f25f1 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -35,7 +35,7 @@ if (isDev) { // 老师 //ebugType="teacher"; // 学生 -// debugType="student"; +//debugType="student"; window._debugType = debugType; export function initAxiosInterceptors(props) { diff --git a/public/react/src/modules/courses/busyWork/CommonWorkDetailIndex.js b/public/react/src/modules/courses/busyWork/CommonWorkDetailIndex.js index 5799110f2..5c55f8894 100644 --- a/public/react/src/modules/courses/busyWork/CommonWorkDetailIndex.js +++ b/public/react/src/modules/courses/busyWork/CommonWorkDetailIndex.js @@ -336,7 +336,7 @@ class CommonWorkDetailIndex extends Component{ } `} {this.props.isAdmin()? -
  • +
  • 导出