Merge branch 'dev_aliyun' into dev_daiao

dev_daiao
daiao 5 years ago
commit 0b0c9bf12e

@ -26,6 +26,15 @@ $(document).on('turbolinks:load', function() {
});
});
// 清空
searchForm.on('click', '.clear-btn', function () {
searchForm.find('select[name="status"]').val('');
searchForm.find('.school-select').val('').trigger('change');
searchForm.find('input[name="keyword"]').val('');
searchForm.find('#homepage_show').attr('checked', false);
searchForm.find('input[type="submit"]').trigger('click');
});
// ************** 学校选择 *************
searchForm.find('.school-select').select2({
theme: 'bootstrap4',

@ -65,7 +65,7 @@ $(document).on('turbolinks:load', function() {
},
matcher: matcherFunc
});
}
};
$.ajax({
url: '/api/schools/for_option.json',
@ -171,5 +171,19 @@ $(document).on('turbolinks:load', function() {
data: json
})
});
$(".laboratory-list-container").on("change", '.laboratory-sync-form', function () {
var s_id = $(this).attr("data-id");
var s_value = $(this).val();
var s_name = $(this).attr("name");
var json = {};
json[s_name] = s_value;
$.ajax({
url: "/admins/laboratories/" + s_id,
type: "PUT",
dataType:'script',
data: json
});
});
}
});

@ -107,7 +107,7 @@ $(document).on('turbolinks:load', function() {
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
var ele = '<span>'
var ele = '<span>';
ele += '<span>' + item.name + '</span>';
ele += '<span class="font-12"> -- ' + item.creator_name + '</span>';
ele += '<span class="font-12"> -- ' + item.status_text+ '</span>';
@ -116,9 +116,8 @@ $(document).on('turbolinks:load', function() {
return $(ele);
},
templateSelection: function(item){
if (item.id) {
}
var ele = '<span>' + (item.name || item.text) + '<span class="font-12"> -- ' + item.creator_name + '</span></span>'
if(!item.id || item.id === '') return item.text;
var ele = '<span>' + (item.name || item.text) + '<span class="font-12"> -- ' + item.creator_name + '</span></span>';
return $(ele);
}
});

@ -0,0 +1,11 @@
$(document).on('turbolinks:load', function () {
if ($('body.admins-projects-index-page').length > 0) {
var $form = $('.search-form');
// 清空
$form.on('click', '.clear-btn', function () {
$form.find('input[name="search"]').val('');
$form.find('input[type="submit"]').trigger('click');
});
}
});

@ -1,12 +1,14 @@
$(document).on('turbolinks:load', function(){
if ($('body.admins-shixun-feedback-messages-index-page').length > 0) {
$(".content-img img").addClass("w-20").addClass("preview-image");
var baseOptions = {
autoclose: true,
language: 'zh-CN',
format: 'yyyy-mm-dd 00:00:00',
startDate: '2017-04-01'
}
};
var defineDateRangeSelect = function(element){
var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, baseOptions);
@ -14,9 +16,9 @@ $(document).on('turbolinks:load', function(){
$(element).find('.start-date').datepicker().on('changeDate', function(e){
$(element).find('.end-date').datepicker('setStartDate', e.date);
})
});
};
defineDateRangeSelect('.grow-date-input-daterange');
}
})
});

@ -0,0 +1,12 @@
$(document).on('turbolinks:load', function () {
if ($('body.admins-shixun-modify-records-index-page').length > 0) {
var $form = $('.search-form');
// 清空
$form.on('click', '.clear-btn', function () {
$form.find('select[name="date"]').val('weekly');
$form.find('input[name="user_name"]').val('');
$form.find('input[type="submit"]').trigger('click');
});
}
});

@ -0,0 +1,14 @@
.diff{overflow:auto;}
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0 1rem;display:table;width:100%;}
.diff del, .diff ins{display:block;text-decoration:none;}
.diff li{padding:0; display:table-row;margin: 0;height:1em;}
.diff li.ins{background:#dfd; color:#080}
.diff li.del{background:#fee; color:#b00}
.diff li:hover{background:#ffc}
/* try 'whitespace:pre;' if you don't want lines to wrap */
.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
.diff del strong{font-weight:normal;background:#fcc;}
.diff ins strong{font-weight:normal;background:#9f9;}
.diff li.diff-comment { display: none; }
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }

@ -0,0 +1,7 @@
.admins-shixun-feedback-messages-index-page {
.content-img {
img {
height: 60px;
}
}
}

@ -1,7 +1,8 @@
class AdminConstraint
def matches?(request)
return false unless request.session[:user_id]
user = User.find request.session[:user_id]
laboratory = Laboratory.first
return false unless request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user = User.find request.session[:"#{laboratory.try(:identifier).split('.').first}_user_id"]
user && user.admin?
end
end

@ -38,6 +38,8 @@ class AccountsController < ApplicationController
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
end
return normal_status(-1, "8~16位密码支持字母数字和符号") unless params[:password] =~ CustomRegexp::PASSWORD
code = generate_identifier User, 8, pre
login = pre + code
@user = User.new(admin: false, login: login, mail: email, phone: phone, type: "User")
@ -114,6 +116,7 @@ class AccountsController < ApplicationController
end
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
return normal_status(-1, "8~16位密码支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
ActiveRecord::Base.transaction do
@ -123,7 +126,7 @@ class AccountsController < ApplicationController
sucess_status
rescue Exception => e
uid_logger_error(e.message)
tip_exception("密码重置失败")
tip_exception(e.message)
end
end

@ -29,9 +29,7 @@ class Admins::CoursesController < Admins::BaseController
end
def update
if @course.update_attributes(setting_params)
render_ok
else
unless @course.update_attributes!(setting_params)
redirect_to admins_courses_path
flash[:danger] = "更新失败"
end

@ -61,6 +61,14 @@ class Admins::LaboratoriesController < Admins::BaseController
@laboratory = current_laboratory
end
def update
@laboratory = current_laboratory
unless @laboratory.update_attributes!(setting_params)
redirect_to admins_laboratories_path
flash[:danger] = "更新失败"
end
end
private
def current_laboratory
@ -70,4 +78,8 @@ class Admins::LaboratoriesController < Admins::BaseController
def create_params
params.permit(:school_id)
end
def setting_params
params.permit(:sync_course, :sync_subject, :sync_shixun)
end
end

@ -16,7 +16,7 @@ class Admins::LaboratorySettingsController < Admins::BaseController
def form_params
params.permit(:identifier, :name,
:nav_logo, :login_logo, :tab_logo,
:nav_logo, :login_logo, :tab_logo, :oj_banner,
:subject_banner, :course_banner, :competition_banner, :moop_cases_banner,
:footer, navbar: %i[name link hidden])
end

@ -0,0 +1,9 @@
class Admins::ShixunModifyRecordsController < Admins::BaseController
def index
records = Admins::ShixunModifyRecordQuery.call(params)
@records = paginate records.includes(:diff_record_content)
end
end

@ -18,9 +18,9 @@ class AttachmentsController < ApplicationController
pdf_attachment = params[:disposition] || "attachment"
if pdf_attachment == "inline"
send_file absolute_path(local_path(@file)),filename: @file.filename, disposition: 'inline',type: 'application/pdf'
send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf'
else
send_file(absolute_path(local_path(@file)), filename: @file.filename,stream:false, type: @file.content_type.presence || 'application/octet-stream')
send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream')
end
update_downloads(@file)
end

@ -4,7 +4,6 @@ class ExerciseAnswersController < ApplicationController
include ExercisesHelper
def create #每一次答案的点击,请求一次,实训题不在这里回答
ActiveRecord::Base.transaction do
begin
q_type = @exercise_question.question_type #试卷的类型
choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : ""
@ -31,8 +30,8 @@ class ExerciseAnswersController < ApplicationController
ea_ids = ea.pluck(:exercise_choice_id)
common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id
new_ids = choice_ids - common_answer_ids # 新增的id
old_ids = ea_ids - common_answer_ids #没有选择的,则删掉
new_ids = (choice_ids - common_answer_ids).uniq # 新增的id
old_ids = (ea_ids - common_answer_ids).uniq #没有选择的,则删掉
if new_ids.size > 0
new_ids.each do |e|
answer_option = {
@ -84,7 +83,6 @@ class ExerciseAnswersController < ApplicationController
raise ActiveRecord::Rollback
end
end
end
private

@ -1,13 +1,14 @@
class HackUserLastestCodesController < ApplicationController
before_action :require_login, except: [:listen_result]
before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code,
before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :sync_code,
: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]
before_action :require_auth_identity, only: [:update_code, :restore_initial_code, :sync_code]
before_action :require_manager_identity, only: [:update_code]
def show
@my_hack.update_attribute(:submit_status, 0) if @my_hack.submit_status == 1
@modify = @my_hack.modify_time.to_i < @hack.hack_codes.first.modify_time.to_i
end
def update_code
@ -15,10 +16,14 @@ class HackUserLastestCodesController < ApplicationController
render_ok
end
# 复初始代码
# 复初始代码
def restore_initial_code
@my_hack.update_attribute(:code, @hack.code)
render_ok
end
# 同步代码
def sync_code
@my_hack.update_attributes(code: @hack.code, modify_time: @hack.modify_time)
end
# 调试代码
@ -55,7 +60,9 @@ class HackUserLastestCodesController < ApplicationController
end
# 提交记录
def submit_records;end
def submit_records
@records = @my_hack.hack_user_codes.created_order
end
# 提交记录详情

@ -1,7 +1,7 @@
class HacksController < ApplicationController
before_action :require_login, except: [:index]
before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set]
before_action :require_teacher_identity, only: [:create, :update_set]
before_action :require_teacher_identity, only: [:create, :update_set, :edit, :update]
before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set]
@ -15,7 +15,7 @@ class HacksController < ApplicationController
user_hack.identifier
else
user_identifier = generate_identifier HackUserLastestCode, 12
user_code = {user_id: current_user.id, code: @hack.code,
user_code = {user_id: current_user.id, code: @hack.code, modify_time: Time.now,
identifier: user_identifier, language: @hack.language}
@hack.hack_user_lastest_codes.create!(user_code)
user_identifier
@ -47,10 +47,10 @@ class HacksController < ApplicationController
hack.identifier = generate_identifier Hack, 8
hack.save!
# 创建测试集与代码
logger.info("hack_sets_params:#{hack_sets_params}")
logger.info("hack_code_params:#{hack_code_params}")
hack.hack_sets.create!(hack_sets_params)
hack.hack_codes.create!(hack_code_params)
hack_codes = hack.hack_codes.new(hack_code_params)
hack_codes.modify_time = Time.now
hack_codes.save!
end
render_ok({identifier: hack.identifier})
rescue Exception => e
@ -69,7 +69,8 @@ class HacksController < ApplicationController
# 新建
@hack.hack_sets.create!(hack_sets_params)
# 更新代码
@hack.hack_codes.create!(hack_code_params)
code_params = params[:hack_codes][:code] != @hack.code ? hack_code_params.merge(modify_time: Time.now) : hack_code_params
@hack.hack_codes.first.update_attributes!(code_params)
end
render_ok
rescue Exception => e
@ -109,6 +110,8 @@ class HacksController < ApplicationController
def edit;end
def new;end
private
# 实名认证老师,管理员与运营人员权限
def require_teacher_identity
@ -199,7 +202,7 @@ class HacksController < ApplicationController
end
def start_hack_auth
return true if @hack == 1
return true if @hack.status == 1
require_auth_identity
end

@ -20,8 +20,8 @@ class HomeController < ApplicationController
shixuns = shixuns.where(homepage_show: true)
subjects = subjects.where(homepage_show: true)
else
shixuns = shixuns.where(laboratory_shixuns: { homepage: true })
subjects = subjects.where(laboratory_subjects: { homepage: true })
shixuns = shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { homepage: true, laboratory_id: current_laboratory.id})
subjects = subjects.joins(:laboratory_subjects).where(laboratory_subjects: { homepage: true, laboratory_id: current_laboratory.id})
end
@shixuns = shixuns.includes(:tag_repertoires, :challenges).limit(8)

@ -294,7 +294,7 @@ class HomeworkCommonsController < ApplicationController
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
normal_status("更新成功")
else
normal_status("开启挑战,暂不能更新成绩")
normal_status("开启挑战,暂不能更新成绩")
end
rescue Exception => e
uid_logger(e.message)
@ -453,7 +453,9 @@ 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
@ -549,6 +551,7 @@ class HomeworkCommonsController < ApplicationController
@homework.end_time = @homework.max_group_end_time
end
end
=end
# 补交设置
tip_exception("缺少allow_late参数") if params[:allow_late].nil?
@ -582,8 +585,8 @@ class HomeworkCommonsController < ApplicationController
tip_exception("缺少answer_open_evaluation参数") if params[:answer_open_evaluation].nil?
tip_exception("缺少work_efficiency参数") if params[:work_efficiency].nil?
tip_exception("缺少eff_score参数") if params[:work_efficiency] && params[:eff_score].blank?
tip_exception("效率分不能小于等于0") if params[:eff_score] && params[:eff_score].to_f <= 0
tip_exception("效率分不能大于总分值") if params[:eff_score] && params[:eff_score].to_f.round(2) > params[:total_score].to_f.round(2)
tip_exception("效率分不能小于等于0") if params[:work_efficiency] && params[:eff_score] && params[:eff_score].to_f <= 0
tip_exception("效率分不能大于总分值") if params[:work_efficiency] && params[:eff_score] && params[:eff_score].to_f.round(2) > params[:total_score].to_f.round(2)
tip_exception("缺少shixun_evaluation参数") if params[:shixun_evaluation].blank?
tip_exception("缺少challenge_settings参数") if params[:challenge_settings].blank?
# tip_exception("缺少challenge_id参数") if params[:challenge_settings][:challenge_id].blank?
@ -591,6 +594,10 @@ class HomeworkCommonsController < ApplicationController
# tip_exception("challenge_id参数的长度与challenge_score参数的长度不匹配") if
# params[:challenge_settings][:challenge_score].length != params[:challenge_settings][:challenge_id].length
sum_challenge_score = params[:challenge_settings].pluck(:challenge_score).reject(&:blank?).map{|score| score.to_f}.sum
total_score = params[:work_efficiency] ? (params[:eff_score].to_f + sum_challenge_score) : sum_challenge_score
tip_exception("分值之和必须等于总分值:#{params[:total_score]}") if params[:total_score].to_f.round(2) != total_score.to_f.round(2)
current_eff_score = @homework.eff_score.to_f.round(2)
@homework.total_score = params[:total_score]
@homework.work_efficiency = params[:work_efficiency]
@ -631,7 +638,7 @@ class HomeworkCommonsController < ApplicationController
@homework.save!
if score_change && @homework.end_or_late_none_group
UpdateShixunWorkScoreJob.perform_now(@homework.id)
UpdateShixunWorkScoreJob.perform_later(@homework.id)
elsif update_eff_score && (@homework.end_or_late_none_group || @homework.max_efficiency > 0)
# 更新所有学生的效率分(作业允许补交且补交已截止 或者 作业不允许补交且提交已截止 或者作业已计算过效率分)
HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: @homework.id)
@ -822,12 +829,16 @@ class HomeworkCommonsController < ApplicationController
end
end
HomeworkCommonPushNotifyJob.perform_later(@homework.id, publish_group_ids) if send_tiding
normal_status(0, "更新成功")
else
tip_exception("课堂已结束不能再更新")
end
# rescue ActiveRecord::RecordInvalid
# render_error("保存失败")
# rescue ApplicationService::Error => ex
# uid_logger(ex.message)
# render_error(ex.message)
# raise ActiveRecord::Rollback
rescue Exception => e
uid_logger(e.backtrace)
tip_exception(e.message)
@ -1097,7 +1108,7 @@ class HomeworkCommonsController < ApplicationController
else
homework.unified_setting = false
# 创建作业分班设置homework_group_setting
create_homework_group_settings(homework)
homework.create_homework_group_settings
# 选中的分班设置的发布时间改为当前时间,截止时间改为传的截止时间参数
if params[:detail]
@ -1133,7 +1144,7 @@ class HomeworkCommonsController < ApplicationController
# 发消息
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
else
create_homework_group_settings(homework)
homework.create_homework_group_settings
none_publish_settings = homework.homework_group_settings.where(course_group_id: publish_groups).none_published
if params[:detail]
@ -1207,7 +1218,7 @@ class HomeworkCommonsController < ApplicationController
# 分组设置
if !params[:group_ids].blank?
# 确保之前是统一设置或者有新创建的分班的数据一致性
create_homework_group_settings(homework)
homework.create_homework_group_settings
homework.unified_setting = false if homework.unified_setting && end_groups.length != @course.course_groups_count
@ -1578,15 +1589,6 @@ class HomeworkCommonsController < ApplicationController
end
def create_homework_group_settings homework
if homework.homework_group_settings.size != @course.course_groups.size
@course.course_groups.where.not(id: homework.homework_group_settings.pluck(:course_group_id)).each do |group|
homework.homework_group_settings << HomeworkGroupSetting.new(course_group_id: group.id, course_id: @course.id,
publish_time: homework.publish_time, end_time: homework.end_time)
end
end
end
def get_new_code_reviews_result homework
if homework.code_reviews_new_results?
# 获取最新的查询id
@ -1649,4 +1651,8 @@ class HomeworkCommonsController < ApplicationController
homework_bank
end
def publish_params
params.permit(:unified_setting, :publish_time, :end_time, group_settings: [:publish_time, :end_time, group_id: []])
end
end

@ -6,11 +6,10 @@ class PollVotesController < ApplicationController
def create #每一次答案的点击,请求一次
ActiveRecord::Base.transaction do
begin
question_votes = @poll_question.poll_votes
question_type = @poll_question.question_type
question_answer_id = params[:poll_answer_id] ? params[:poll_answer_id] : nil #该答案的id
question_answer_id = params[:poll_answer_id] ? params[:poll_answer_id] : -1 #该答案的id
question_answer_text = params[:vote_text].present? ? params[:vote_text] : nil #其他选项的内容
user_votes = question_votes.find_current_vote("user_id",current_user.id) #当前用户的答案,可能有多个
# 当前用户的当前答案,如果已存在,当再次点击的时候,取消答案,即删除该答案
@ -120,7 +119,6 @@ class PollVotesController < ApplicationController
raise ActiveRecord::Rollback
end
end
end
private

@ -1409,16 +1409,21 @@ class PollsController < ApplicationController
poll_questions.each do |q|
user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id)
if user_poll_votes.present?
if q.question_type < 3
user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?)
user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?)
if user_poll_answer_ids.count > 0
answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids)
if user_poll_answer_ids.count >1
u_answer = answer_content.pluck(:answer_text).join(";")
else
u_answer = answer_content.first.answer_text
u_answer = answer_content.first&.answer_text
end
else
u_answer = "--"
end
elsif user_poll_vote_texts.count > 0
else
user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?)
if user_poll_vote_texts.count > 0
if user_poll_vote_texts.count > 1
u_answer = user_poll_vote_texts.join(";")
else
@ -1427,6 +1432,7 @@ class PollsController < ApplicationController
else
u_answer = "--"
end
end
else
u_answer = "--"
end

@ -26,22 +26,7 @@ class ShixunsController < ApplicationController
## 获取课程列表
def index
## 我的实训
@shixuns =
if params[:order_by] == 'mine'
tip_exception(401, "..") unless current_user.logged?
current_user.my_shixuns
else
Shixun.unhidden
end
## 云上实验室过滤
unless current_laboratory.main_site?
@shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id })
else
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{current_laboratory.id}")
@shixuns = @shixuns.where.not(id: not_shixun_ids)
end
@shixuns = current_laboratory.shixuns.unhidden
## 方向
if params[:tag_level].present? && params[:tag_id].present?

@ -25,15 +25,9 @@ class SubjectsController < ApplicationController
# 最热排序
if reorder == "myshixun_count"
if current_laboratory.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{current_laboratory.id}").pluck(:id)
not_subject_ids = not_subject_ids.length > 0 ? "(" + not_subject_ids.join(",") + ")" : "(-1)"
laboratory_join = " AND subjects.id not in #{not_subject_ids} "
else
subject_ids = Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id }).pluck(:id)
subject_ids = current_laboratory.subjects.pluck(:id)
subject_ids = subject_ids.length > 0 ? "(" + subject_ids.join(",") + ")" : "(-1)"
laboratory_join = " AND subjects.id in #{subject_ids} "
end
if select
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
@ -49,6 +43,7 @@ class SubjectsController < ApplicationController
GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
end
else
@subjects = current_laboratory.subjects
# 我的路径
if reorder == "mine"
tip_exception(401, "..") unless current_user.logged?
@ -57,19 +52,11 @@ class SubjectsController < ApplicationController
(select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id)
manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id)
total_subject_id = (mine_subject_id + manage_subject_id).uniq
@subjects = Subject.where(id: total_subject_id)
@subjects = @subjects.where(id: total_subject_id)
elsif reorder == "publish_time"
@subjects = Subject.unhidden
else
@subjects = Subject.visible.unhidden
end
# 云上实验室过滤
unless current_laboratory.main_site?
@subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id })
@subjects = @subjects.unhidden
else
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{current_laboratory.id}")
@subjects = @subjects.where.not(id: not_subject_ids)
@subjects = @subjects.visible.unhidden
end
# 类型

@ -1,5 +1,6 @@
class Users::AuthenticationAppliesController < Users::BaseAccountController
before_action :private_user_resources!
before_action :check_account, only: [:create]
def create
Users::ApplyAuthenticationService.call(observed_user, create_params)

@ -1,5 +1,6 @@
class Users::ProfessionalAuthAppliesController < Users::BaseAccountController
before_action :private_user_resources!
before_action :check_account, only: [:create]
def create
Users::ApplyProfessionalAuthService.call(observed_user, create_params)

@ -1,14 +1,6 @@
class Users::ShixunsController < Users::BaseController
def index
shixuns = Users::ShixunService.new(observed_user, query_params).call
## 云上实验室过滤
if current_laboratory.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{current_laboratory.id}")
shixuns = shixuns.where.not(id: not_shixun_ids)
else
shixuns = shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id })
end
shixuns = Users::ShixunService.new(observed_user, query_params, current_laboratory).call
@count = shixuns.count
@shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: observed_user.is_teacher?)

@ -2,13 +2,7 @@ class Users::SubjectsController < Users::BaseController
def index
subjects = Users::SubjectService.new(observed_user, query_params).call
## 云上实验室过滤
if current_laboratory.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{current_laboratory.id}")
subjects = subjects.where.not(id: not_subject_ids)
else
subjects = subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id })
end
subjects = subjects.where(id: current_laboratory.subjects)
@count = subjects.count
@subjects = paginate(subjects.includes(:user, :repertoire), special: observed_user.is_teacher?)

@ -6,7 +6,9 @@ class Weapps::CodeSessionsController < Weapps::BaseController
logged = false
result = Wechat::Weapp.jscode2session(params[:code])
Rails.logger.info("###########result: #{result}")
Rails.logger.info("###########result: #{result['session_key']}")
Rails.logger.info("###########result: #{result['unionid']}")
# 能根据 code 拿到 unionid
open_user = OpenUsers::Wechat.find_by(uid: result['unionid'])
if open_user.present? && open_user.user

@ -1,11 +1,12 @@
class Weapps::CoursesController < Weapps::BaseController
before_action :require_login
before_action :set_course, :user_course_identity, except: [:create]
before_action :check_account, only: [:create]
before_action :teacher_allowed, only: [:edit, :update]
before_action :teacher_or_admin_allowed, only: [:change_member_roles, :delete_course_teachers]
def create
return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
# return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
course = Course.new(tea_id: current_user.id)
Weapps::CreateCourseService.call(course, course_params)
render_ok
@ -106,7 +107,7 @@ class Weapps::CoursesController < Weapps::BaseController
# 批量修改角色
def change_member_roles
@course = current_course
tip_exception("请至少选择一个角色") if params[:roles].blank?
tip_exception("请至少选择一个角色") if params[:roles].reject(&:blank?).blank?
tip_exception("不能具有老师、助教两种角色") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR")
params[:user_ids].each do |user_id|
@ -149,13 +150,13 @@ class Weapps::CoursesController < Weapps::BaseController
new_student.is_active = 0 if correspond_teacher_exist
new_student.save!
CourseAddStudentCreateWorksJob.perform_later(@course.id, user_id)
CourseAddStudentCreateWorksJob.perform_later(@course.id, [user_id])
# StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id)
elsif !params[:roles].include?("STUDENT") && student_member.present?
# 删除学生身份时激活老师身份
teacher_member.update_attributes!(is_active: 1) if student_member.is_active && teacher_member.present?
student_member.destroy!
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, user_id)
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [user_id])
# CourseDeleteStudentNotifyJob.perform_later(@course.id, [params[:user_id]], current_user.id)
elsif params[:roles].include?("STUDENT") && student_member.present? && !params[:roles].include?("PROFESSOR") && !params[:roles].include?("ASSISTANT_PROFESSOR")
# 学生身份存在且学生没有教师身份时更新is_active

@ -0,0 +1,38 @@
class Weapps::HomeworkCommonsController < Weapps::BaseController
before_action :require_login
before_action :find_homework, :user_course_identity
before_action :teacher_allowed
def update_settings
begin
# 课堂结束后不能再更新
unless @course.is_end
UpdateHomeworkPublishSettingService.call(@homework, publish_params)
render_ok
else
tip_exception("课堂已结束不能再更新")
end
rescue Exception => e
uid_logger(e.backtrace)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
private
def teacher_allowed
return render_forbidden unless @user_course_identity < Course::STUDENT
end
def find_homework
@homework = HomeworkCommon.find_by!(id: params[:id])
@course = @homework.course
@homework_detail_manual = @homework.homework_detail_manual
end
def publish_params
params.permit(:unified_setting, :publish_time, :end_time, group_settings: [:publish_time, :end_time, group_id: []])
end
end

@ -3,7 +3,7 @@ class Users::ApplyAuthenticationForm
attr_accessor :name, :show_realname, :id_number, :gender, :upload_image, :attachment_ids
validates :name, presence: true
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "2-10位中英文、数字" }
validate :validate_ID_number
validate :validate_attachment_ids

@ -5,8 +5,8 @@ class Users::UpdateAccountForm
attr_accessor :nickname, :name, :show_realname, :gender, :location, :location_city,
:identity, :student_id, :technical_title, :school_id, :department_id
validates :nickname, presence: true, length: { maximum: 20 }
validates :name, presence: true, length: { maximum: 10 }
validates :nickname, presence: true, length: { minimum: 2, maximum: 20 }, format: { with: CustomRegexp::NICKNAME, message: "2-20位中英文、数字及下划线" }
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "2-10位中英文、数字" }
validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] }
validates :location, presence: true
validates :location_city, presence: true

@ -3,5 +3,5 @@ class Users::UpdatePasswordForm
attr_accessor :password, :old_password
validates :password, presence: true
validates :password, presence: true, length: { minimum: 8, maximum: 16 }, format: { with: CustomRegexp::PASSWORD, message: "8~16位密码支持字母数字和符号" }
end

@ -1,4 +1,7 @@
module CustomRegexp
PHONE = /1\d{10}/
EMAIL = /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/
EMAIL = /\A[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/
LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/
NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/
PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{8,16}\z/
end

@ -27,12 +27,21 @@ class Attachment < ApplicationRecord
validates_length_of :description, maximum: 100
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
def diskfile
File.join(File.join(Rails.root, "files"), disk_directory.to_s, disk_filename.to_s)
end
def title
filename
title = filename
if container.is_a?(StudentWork) && author_id != User.current.id
course = container&.homework_common&.course
unless User.current.teacher_of_course?(course)
title = "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{DCODES.sample(8).join}" + File.extname(filename)
end
end
title
end
def downloads_count

@ -165,7 +165,7 @@ class Competition < ApplicationRecord
def get_module_name type
case type
when 'home' then '首页'
when 'home' then '赛制介绍'
when 'enroll' then '报名'
when 'inform' then '通知公告'
when 'chart' then '排行榜'

@ -3,6 +3,8 @@ class Hack < ApplicationRecord
# diffcult: 难度 1简单2中等 3困难
# 编程题
validates_length_of :name, maximum: 60
validates :description, presence: { message: "描述不能为空" }
validates :name, presence: { message: "名称不能为空" }
# 测试集
has_many :hack_sets, ->{order("position asc")}, :dependent => :destroy
# 代码
@ -39,4 +41,9 @@ class Hack < ApplicationRecord
hack_sets.first&.input
end
# 管理员
def manager?(user)
user_id == user.id || user.admin_or_business?
end
end

@ -1,6 +1,7 @@
class HackSet < ApplicationRecord
validates :input, presence: { message: "测试集输入不能为空" }
#validates :input, presence: { message: "测试集输入不能为空" }
validates :output, presence: { message: "测试集输出不能为空" }
validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同"
# 编程题测试集
belongs_to :hack
end

@ -1,4 +1,6 @@
class HackUserCode < ApplicationRecord
# 用户编程题的信息
belongs_to :hack
scope :created_order, ->{ order("created_at desc")}
end

@ -285,6 +285,15 @@ class HomeworkCommon < ApplicationRecord
homework_challenge_settings.find_by(challenge_id: challenge_id)&.score.to_f
end
def create_homework_group_settings
if homework_group_settings.size != course.course_groups.size
course.course_groups.where.not(id: homework_group_settings.pluck(:course_group_id)).each do |group|
homework_group_settings << HomeworkGroupSetting.new(course_group_id: group.id, course_id: course.id,
publish_time: publish_time, end_time: end_time)
end
end
end
def update_homework_work_score
if unified_setting
works = student_works

@ -47,11 +47,31 @@ class Laboratory < ApplicationRecord
end
def shixuns
main_site? ? Shixun.all : Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id })
if main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{Laboratory.current.id}")
Shixun.where.not(id: not_shixun_ids.pluck(:shixun_id))
elsif sync_shixun
laboratory_shixun_ids = laboratory_shixuns.pluck(:shixun_id)
school_shixun_ids = Shixun.joins("join user_extensions on shixuns.user_id=user_extensions.user_id").where(user_extensions: { school_id: school_id }).pluck(:id)
shixun_ids = laboratory_shixun_ids + school_shixun_ids
Shixun.where(id: shixun_ids.uniq)
else
Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id })
end
end
def subjects
main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id })
if main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{Laboratory.current.id}")
Subject.where.not(id: not_subject_ids.pluck(:subject_id))
elsif sync_subject
laboratory_subject_ids = laboratory_subjects.pluck(:subject_id)
school_subject_ids = Subject.joins("join user_extensions on subjects.user_id=user_extensions.user_id").where(user_extensions: { school_id: school_id }).pluck(:id)
subject_ids = laboratory_subject_ids + school_subject_ids
Subject.where(id: subject_ids.uniq)
else
Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id })
end
end
def all_courses

@ -42,6 +42,10 @@ class LaboratorySetting < ApplicationRecord
image_url('_moop_cases_banner')
end
def oj_banner_url
image_url('_oj_banner')
end
def default_navbar
self.class.default_config[:navbar]
end

@ -21,7 +21,7 @@ class User < ApplicationRecord
VALID_EMAIL_REGEX = /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/i
VALID_PHONE_REGEX = /^1\d{10}$/
# 身份证
VALID_NUMBER_REGEX = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
VALID_NUMBER_REGEX = /(^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^([A-Z]\d{6,10}(\(\w{1}\))?)$)/
LOGIN_LENGTH_LIMIT = 30
MAIL_LENGTH_LMIT = 60

@ -0,0 +1,33 @@
class Admins::ShixunModifyRecordQuery < ApplicationQuery
attr_reader :params
def initialize(params)
@params = params
end
def call
if params[:user_name].blank? || params[:date].blank?
records = DiffRecord.none
else
records = DiffRecord.joins(:user).where("concat(users.lastname, users.firstname) like ?", "%#{params[:user_name].strip}%")
if time_range.present?
records = records.where(created_at: time_range)
end
end
records.order("diff_records.created_at desc")
end
private
def time_range
@_time_range ||= begin
case params[:date]
when 'weekly' then 1.weeks.ago..Time.now
when 'monthly' then 1.months.ago..Time.now
when 'quarterly' then 3.months.ago..Time.now
when 'yearly' then 1.years.ago..Time.now
else ''
end
end
end
end

@ -75,13 +75,12 @@ class Admins::CheckShixunMirrorsService < ApplicationService
def bridge_images
@_bridge_images ||= begin
url = EduSetting.get('cloud_bridge')
url = "#{EduSetting.get('cloud_bridge')}/bridge/docker/images"
res = Faraday.get(url)
res_body = JSON.parse(res.body)
res = JSON.parse(res.body)
raise Error, '拉取镜像信息异常' if res && res['code'] != 0
raise Error, '拉取镜像信息异常' if res_body && res_body['code'].to_i != 0
res_body
res
rescue => e
Rails.logger.error("get response failed ! #{e.message}")
raise Error, '实训云平台繁忙繁忙等级84'

@ -43,6 +43,7 @@ class Admins::SaveLaboratorySettingService < ApplicationService
save_image_file(params[:course_banner], '_course_banner')
save_image_file(params[:competition_banner], '_competition_banner')
save_image_file(params[:moop_cases_banner], '_moop_cases_banner')
save_image_file(params[:oj_banner], '_oj_banner')
end
def save_image_file(file, type)

@ -25,6 +25,7 @@ class CreateDiffRecordService < ApplicationService
index = 0
fragment_size = 1
Diffy::Diff.new(before, after).each do |line|
unless line.include?("\\ 文件尾没有 newline 字符")
unless line =~ /^[\+-]/
if arr.empty? && index < fragment_size
content += line
@ -41,6 +42,7 @@ class CreateDiffRecordService < ApplicationService
content += line
arr.clear
end
end
content
end
end

@ -40,23 +40,11 @@ class SearchService < ApplicationService
def extra_options
case params[:type].to_s.strip
when 'shixun' then
if Laboratory.current.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{Laboratory.current.id}")
shixun_ids = Shixun.where.not(id: not_shixun_ids).pluck(:id)
else
shixun_ids = Laboratory.current.shixuns.pluck(:id)
end
{ where: { id: shixun_ids } }
{ where: { id: Laboratory.current.shixuns.pluck(:id) } }
when 'subject' then
if Laboratory.current.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{Laboratory.current.id}")
subject_ids = Subject.where.not(id: not_subject_ids).pluck(:id)
else
subject_ids = Laboratory.current.subjects.pluck(:id)
end
{ where: { id: subject_ids } }
{ where: { id: Laboratory.current.subjects.pluck(:id) } }
when 'course' then
{ where: { laboratory_id: Laboratory.current.id } }
{ where: { id: Laboratory.current.all_courses.pluck(:id) } }
else
{}
end

@ -14,16 +14,18 @@ class ShixunSearchService < ApplicationService
# 状态:已发布/未发布
status = params[:status] || "all"
@shixuns = laboratory.shixuns.none_closed
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
if type == "mine"
@shixuns = User.current.shixuns.none_closed
@shixuns = @shixuns.where(id: User.current.shixuns)
else
if User.current.admin? || User.current.business?
@shixuns = Shixun.none_closed.where(hidden: 0)
if User.current.admin? || User.current.business? || !User.current.school_id
@shixuns = @shixuns.where(hidden: 0)
else
none_shixun_ids = ShixunSchool.where("school_id != #{User.current.school_id}").pluck(:shixun_id)
@shixuns = Shixun.where.not(id: none_shixun_ids).none_closed.where(hidden: 0)
@shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0)
end
end
@ -36,17 +38,6 @@ class ShixunSearchService < ApplicationService
@shixuns = @shixuns.where(trainee: params[:diff])
end
## 云上实验室过滤
if laboratory.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{laboratory.id}")
@shixuns = @shixuns.where.not(id: not_shixun_ids)
else
@shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: laboratory.id })
end
# laboratory = Laboratory.find_by_subdomain(subdomain)
# @shixuns = @shixuns.where(id: laboratory.shixuns) if laboratory
Shixun.search(keyword, search_options)
end

@ -12,21 +12,12 @@ class SubjectSearchService < ApplicationService
# 全部实训/我的实训
type = params[:type] || "all"
if type == "mine"
@subjects = User.current.subjects.visible.unhidden
else
@subjects = Subject.visible.unhidden
end
@subjects = laboratory.subjects
# laboratory = Laboratory.find_by_subdomain(subdomain)
# @subjects = @subjects.where(id: laboratory.subjects) if laboratory
## 云上实验室过滤
if laboratory.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{laboratory.id}")
@subjects = @subjects.where.not(id: not_subject_ids)
if type == "mine"
@subjects = @subjects.where(id: User.current.subjects).visible.unhidden
else
@subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: laboratory.id })
@subjects = @subjects.visible.unhidden
end
Subject.search(keyword, search_options)

@ -0,0 +1,116 @@
class UpdateHomeworkPublishSettingService < ApplicationService
attr_reader :homework, :params
def initialize(homework, params)
@params = params
@homework = homework
end
def call
puts params
course = homework.course
# 作业未发布时unified_setting参数不能为空
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?
# 创建作业的分班设置
homework.create_homework_group_settings
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].to_time <= Time.now
tip_exception("截止时间不能早于当前时间") if setting[:end_time].to_time <= Time.now
tip_exception("截止时间不能早于发布时间") if setting[:publish_time].to_time > setting[:end_time].to_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].to_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].to_time > course.end_date.end_of_day
homework.end_time = params[:end_time]
elsif !homework.unified_setting
homework.create_homework_group_settings
tip_exception("分班发布设置不能为空") if params[:group_settings].reject(&:blank?).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].to_time <= Time.now && group_settings.group_published.count == 0
tip_exception("截止时间不能早于等于当前时间") if setting[:end_time].to_time <= Time.now && group_settings.none_end.count > 0
tip_exception("截止时间不能早于发布时间") if setting[:publish_time].to_time > setting[:end_time].to_time
tip_exception("截止时间不能晚于课堂结束时间(#{course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")}") if
course.end_date.present? && setting[:end_time].to_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
homework.save!
HomeworkCommonPushNotifyJob.perform_later(homework.id, publish_group_ids) if send_tiding
end
private
def tip_exception(status = -1, message)
raise Educoder::TipException.new(status, message)
end
end

@ -1,12 +1,14 @@
class Users::ShixunService
attr_reader :user, :params
attr_reader :user, :params, :laboratory
def initialize(user, params)
def initialize(user, params, laboratory)
@user = user
@params = params
@laboratory = laboratory
end
def call
shixuns = category_scope_shixuns
shixuns = user_policy_filter(shixuns)
@ -19,12 +21,12 @@ class Users::ShixunService
def category_scope_shixuns
case params[:category]
when 'study' then
user.study_shixuns
user.study_shixuns.where(shixuns: {id: laboratory.shixuns})
when 'manage' then
user.shixuns
laboratory.shixuns.where(id: user.shixuns)
else
ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id)
Shixun.where(id: ids)
laboratory.shixuns.where(id: ids)
end
end

@ -24,33 +24,7 @@
<% if courses.present? %>
<% courses.each do |course| %>
<tr class="course-item-<%= course.id %>">
<td><%= course.id %></td>
<td class="text-left">
<%= link_to(course.name, "/courses/#{course.id}", target: '_blank') %>
</td>
<td><%= course.course_members_count %></td>
<td><%= get_attachment_count(course, 0) %></td>
<td><%= course.course_homework_count(1) %></td>
<td><%= course.course_homework_count(3) %></td>
<td><%= course.course_homework_count(4) %></td>
<td><%= course.exercises_count %></td>
<td><%= course.evaluate_count %></td>
<td><%= course.is_public == 1 ? "--" : "√" %></td>
<td><%= course.is_end ? "已结束" : "正在进行" %></td>
<td><%= course.school&.name %></td>
<td><%= course.teacher&.real_name %></td>
<td><%= course.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<%= check_box_tag :homepage_show,!course.homepage_show,course.homepage_show,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td>
<%= check_box_tag :email_notify,!course.email_notify,course.email_notify,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td class="action-container">
<% if course.is_delete == 0 %>
<%= delete_link '删除', admins_course_path(course, element: ".course-item-#{course.id}"), class: 'delete-course-action' %>
<% end %>
</td>
<%= render 'admins/courses/shared/td', course: course %>
</tr>
<% end %>
<% else %>

@ -0,0 +1,27 @@
<td><%= course.id %></td>
<td class="text-left">
<%= link_to(course.name, "/courses/#{course.id}", target: '_blank') %>
</td>
<td><%= course.course_members_count %></td>
<td><%= get_attachment_count(course, 0) %></td>
<td><%= course.course_homework_count(1) %></td>
<td><%= course.course_homework_count(3) %></td>
<td><%= course.course_homework_count(4) %></td>
<td><%= course.exercises_count %></td>
<td><%= course.evaluate_count %></td>
<td><%= course.is_public == 1 ? "--" : "√" %></td>
<td><%= course.is_end ? "已结束" : "正在进行" %></td>
<td><%= course.school&.name %></td>
<td><%= course.teacher&.real_name %></td>
<td><%= course.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<%= check_box_tag :homepage_show,!course.homepage_show,course.homepage_show,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td>
<%= check_box_tag :email_notify,!course.email_notify,course.email_notify,remote:true,data:{id:course.id},class:"course-setting-form" %>
</td>
<td class="action-container">
<% if course.is_delete == 0 %>
<%= delete_link '删除', admins_course_path(course, element: ".course-item-#{course.id}"), class: 'delete-course-action' %>
<% end %>
</td>

@ -0,0 +1 @@
$("#course-item-<%= @course.id %>").html("<%= j render partial: "admins/courses/shared/td",locals: {course: @course} %>")

@ -31,7 +31,17 @@
<td><%= laboratory.created_at.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<% if school.present? && laboratory.id != 1 %>
<%= check_box_tag :sync_course,!laboratory.sync_course,laboratory.sync_course,remote:true,data:{id:laboratory.id},class:"laboratory-sync-course" %>
<%= check_box_tag :sync_course,!laboratory.sync_course,laboratory.sync_course,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
<% end %>
</td>
<td>
<% if school.present? && laboratory.id != 1 %>
<%= check_box_tag :sync_subject,!laboratory.sync_subject,laboratory.sync_subject,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
<% end %>
</td>
<td>
<% if school.present? && laboratory.id != 1 %>
<%= check_box_tag :sync_shixun,!laboratory.sync_shixun,laboratory.sync_shixun,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
<% end %>
</td>
<td class="action-container">

@ -3,10 +3,12 @@
<tr>
<th width="14%" class="text-left">单位名称</th>
<th width="16%" class="text-left">域名</th>
<th width="10%">统计链接</th>
<th width="6%">统计链接</th>
<th width="22%">管理员</th>
<th width="14%"><%= sort_tag('创建时间', name: 'id', path: admins_laboratories_path) %></th>
<th width="6%" title="同步显示显示主站下该单位的课堂">同步课堂</th>
<th width="10%"><%= sort_tag('创建时间', name: 'id', path: admins_laboratories_path) %></th>
<th width="4%" title="同步显示主站下该单位的课堂">同步课堂</th>
<th width="4%" title="同步显示主站下该单位用户创建的实践课程">同步实践课程</th>
<th width="4%" title="同步显示主站下该单位用户创建的实训">同步实训</th>
<th width="20%">操作</th>
</tr>
</thead>

@ -0,0 +1 @@
$(".laboratory-item-<%= @laboratory.id %>").html("<%= j render partial: "admins/laboratories/shared/laboratory_item",locals: {laboratory: @laboratory} %>")

@ -129,6 +129,16 @@
<label for="moop_cases_banner" class="banner-item-upload" data-toggle="tooltip" data-title="选择图片"></label>
</div>
</div>
<div class="col-12 col-md-4 banner-item">
<%- oj_banner = setting.oj_banner_url -%>
<div class="banner-item-top">开发者社区</div>
<div class="banner-item-bottom <%= oj_banner ? 'has-img' : '' %>">
<img class="banner-item-img oj-banner-img" src="<%= oj_banner %>" style="<%= oj_banner.present? ? '' : 'display: none' %>"/>
<%= file_field_tag(:oj_banner, accept: 'image/*', style: 'display: none', value: params[:oj_banner]) %>
<label for="oj_banner" class="banner-item-upload" data-toggle="tooltip" data-title="选择图片"></label>
</div>
</div>
</div>
</div>

@ -27,7 +27,8 @@
<li><%= sidebar_item(admins_shixun_settings_path, '实训配置', icon: 'cog', controller: 'admins-shixun_settings') %></li>
<li><%= sidebar_item(admins_mirror_repositories_path, '镜像管理', icon: 'cubes', controller: 'admins-mirror_repositories') %></li>
<li><%= sidebar_item(admins_myshixuns_path, '学员实训列表', icon: 'server', controller: 'admins-myshixuns') %></li>
<li><%= sidebar_item(admins_shixun_recycles_path, '实训回收站', icon: 'recycle', controller: 'admins-myshixuns') %></li>
<li><%= sidebar_item(admins_shixun_modify_records_path, '实训修改记录', icon: 'eraser', controller: 'admins-shixun_modify_records') %></li>
<li><%= sidebar_item(admins_shixun_recycles_path, '实训回收站', icon: 'recycle', controller: 'admins-shixun_recycles') %></li>
<% end %>
</li>

@ -15,7 +15,7 @@
<td><%= (@params_page.to_i - 1) * 20 + index + 1 %></td>
<% identifier = Game.find_by(challenge_id: discuss.challenge_id, user_id: discuss.user_id)&.identifier %>
<td class="text-left"><%= link_to discuss.dis.name, "/tasks/#{identifier}", target: '_blank'%></td>
<td class="text-left"><%= content_safe discuss.content %></td>
<td class="text-left content-img"><%= content_safe discuss.content %></td>
<td><%= discuss.user.show_real_name %></td>
<td><%= format_time discuss.created_at %></td>
</tr>

@ -0,0 +1,25 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('实训修改记录') %>
<% end %>
<div class="box search-form-container shixun-modify-record-list-form">
<%= form_tag(admins_shixun_modify_records_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group col-12 col-md-4">
<label for="user_name">用户名:</label>
<%= text_field_tag :user_name, params[:user_name], class: 'form-control flex-1', placeholder: '真实姓名搜索' %>
</div>
<div class="form-group col-12 col-md-auto">
<label for="status">时间范围:</label>
<% data_arrs = [['最近一周', 'weekly'], ['最近一个月', 'monthly']] %>
<%= select_tag(:date, options_for_select(data_arrs, params[:date]), class: 'form-control') %>
</div>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
</div>
<div class="box admin-list-container shixun-modify-record-list-container">
<%= render partial: 'admins/shixun_modify_records/shared/list', locals: { records: @records } %>
</div>

@ -0,0 +1 @@
$('.shixun-modify-record-list-container').html("<%= j( render partial: 'admins/shixun_modify_records/shared/list', locals: { records: @records } ) %>");

@ -0,0 +1,36 @@
<% if records.present? %>
<% records.each do |record| %>
<div class="card mb-5">
<div class="card-header font-16">
<span><%= record.user.real_name %></span>
<span class="ml-3"><%= format_time record.created_at %></span>
</div>
<div class="mt-2 mb-3 ml-3 font-14">
<span>实训名称:<%= record.container&.shixun&.name %></span>
<% if record.container_type == "Challenge" %>
<span class="ml-3">/</span>
<span class="ml-3">关卡名:<%= record.container&.subject %></span>
<% end %>
</div>
<div class="diff font-12">
<ul>
<% record.diff_record_content&.content&.split("\n").each do |line| %>
<% if line =~ /^[\+]/ %>
<li class="ins"><ins><%= line %></ins></li>
<% elsif line =~ /^[\-]/ %>
<li class="del"><del><%= line %></del></li>
<% else %>
<li class="unchanged"><span><%= line %></span></li>
<% end %>
<% end %>
</ul>
</div>
</div>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
<%= render partial: 'admins/shared/paginate', locals: { objects: records } %>

@ -1,3 +1,4 @@
json.(@hack_user, :id, :status, :error_line, :error_msg, :expected_output,
:input, :output, :execute_time, :execute_memory)
:input, :output, :execute_time, :execute_memory, :created_at, :code)
json.language @hack_user.hack.language
json.name @hack_user.hack.name

@ -1,12 +1,19 @@
json.hack do
json.(@hack, :difficult, :time_limit, :description, :score, :identifier)
json.(@hack, :name, :difficult, :time_limit, :description, :score, :identifier)
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
end
json.test_case do
json.input @hack.input_test_case
end
json.user do
json.partial! 'users/user', user: current_user
json.hack_manager @hack.manager?(current_user)
end

@ -1,4 +1,4 @@
json.array! @my_hack.hack_user_codes do |hack_user|
json.array! @records do |hack_user|
json.(hack_user, :id, :created_at, :status, :execute_time, :execute_memory)
json.language hack_user.hack.language
end

@ -1,5 +1,5 @@
# 编程内容
json.(@hack, :name, :description, :language, :difficult, :category, :time_limit, :open_or_not)
json.(@hack, :name, :description, :language, :difficult, :category, :time_limit, :open_or_not, :status)
# 代码
json.language @hack.language
@ -11,3 +11,6 @@ json.hack_sets do
json.(set, :id, :input, :output, :position)
end
end
json.user do
json.partial! 'users/user', user: current_user
end

@ -0,0 +1,3 @@
json.user do
json.partial! 'users/user', user: current_user
end

@ -22,6 +22,6 @@ json.question do
end
end
if question_votes.find_vote_text.present?
json.vote_text question_votes.pluck(:vote_text).reject(&:blank?) #问题的回答是否有用户手动输入的内容
json.vote_text question_votes.pluck(:vote_text) #问题的回答是否有用户手动输入的内容
end
end

@ -10,6 +10,7 @@ json.setting do
json.course_banner_url (setting.course_banner_url || default_setting.course_banner_url)&.[](1..-1)
json.competition_banner_url (setting.competition_banner_url || default_setting.competition_banner_url)&.[](1..-1)
json.moop_cases_banner_url (setting.moop_cases_banner_url || default_setting.moop_cases_banner_url)&.[](1..-1)
json.oj_banner_url (setting.oj_banner_url || default_setting.oj_banner_url)&.[](1..-1)
json.navbar setting.navbar || default_setting.navbar

@ -18,6 +18,7 @@ json.shixun_list do
json.title highlights.delete(:name)&.join('...') || obj.searchable_title
json.description highlights[:description]&.join('...') || Util.extract_content(obj.description)[0..300]&.gsub(atta_reg, '')
json.pic url_to_avatar(obj)
json.content highlights
json.level level_to_s(obj.trainee)
json.subjects obj.subjects.uniq do |subject|

@ -15,6 +15,7 @@ json.shixuns_list do
json.shixun_name shixun.name
json.shixun_hidden shixun.hidden
json.identifier shixun.identifier
json.challenges_count shixun.challenges_count
json.complete_status stage_myshixun_status(myshixuns.select{|ms| ms.shixun_id == shixun.id}.first)
json.shixun_status stage_shixun_status(subject.status, shixun.status, shixun.hidden)
end

@ -11,7 +11,7 @@ json.update_user_name @is_evaluation ? "匿名" : @work.update_user.try(:real_na
json.update_atta @homework.late_duration && @is_author
json.attachments @attachments do |atta|
json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: false}
json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: false, }
end
unless @is_evaluation

@ -6,6 +6,7 @@ json.members_count course.course_members_count
json.homework_commons_count get_tasks_count course
json.attachments_count course.attachments.count
json.visits course.visits
json.school course.school&.name
json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course)

@ -59,6 +59,7 @@ Rails.application.routes.draw do
get :result
get :submit_records
post :restore_initial_code
post :sync_code
end
collection do
@ -926,6 +927,10 @@ Rails.application.routes.draw do
delete :delete_course_students
end
end
resources :homework_commons do
post :update_settings, on: :member
end
end
resources :users_for_partners, only: [:index]
@ -1052,6 +1057,7 @@ Rails.application.routes.draw do
resources :shixun_recycles, only: [:index, :destroy] do
post :resume, on: :member
end
resources :shixun_modify_records, only: [:index]
resources :department_applies,only: [:index,:destroy] do
collection do
post :merge
@ -1090,7 +1096,7 @@ Rails.application.routes.draw do
post :drag, on: :collection
post :replace_image_url, on: :member
end
resources :laboratories, only: [:index, :create, :destroy] do
resources :laboratories, only: [:index, :create, :destroy, :update] do
member do
get :shixuns_for_select
get :subjects_for_select

@ -0,0 +1,6 @@
class AddSyncShixunSubjectToLaboratory < ActiveRecord::Migration[5.2]
def change
add_column :laboratories, :sync_subject, :boolean, default: 0
add_column :laboratories, :sync_shixun, :boolean, default: 0
end
end

@ -0,0 +1,17 @@
class AddUniqIndexToExerciseAnswer < ActiveRecord::Migration[5.2]
def change
# remove_index :exercise_answers, column: [:exercise_question_id, :user_id]
#
# change_column_default :exercise_answers, :exercise_choice_id, from: nil, to: -1
# ExerciseAnswer.where(exercise_choice_id: nil).update_all(exercise_choice_id: -1)
# sql = %Q(delete from exercise_answers where (exercise_question_id, user_id, exercise_choice_id) in
# (select * from (select exercise_question_id, user_id, exercise_choice_id from exercise_answers group by exercise_question_id, user_id, exercise_choice_id having count(*) > 1) a)
# and id not in (select * from (select min(id) from exercise_answers group by exercise_question_id, user_id, exercise_choice_id having count(*) > 1 order by id) b))
# ActiveRecord::Base.connection.execute sql
#
# add_index :exercise_answers, [:exercise_question_id, :user_id, :exercise_choice_id], name: 'exercise_choice_index', unique: true
end
end

@ -0,0 +1,16 @@
class AddUniqIndexToPollVotes < ActiveRecord::Migration[5.2]
def change
# remove_index :poll_votes, column: [:poll_question_id, :user_id]
#
# change_column_default :poll_votes, :poll_question_id, from: nil, to: -1
# PollVote.where(poll_answer_id: nil).update_all(poll_answer_id: -1)
#
# sql = %Q(delete from poll_votes where (poll_question_id, user_id, poll_answer_id) in
# (select * from (select poll_question_id, user_id, poll_answer_id from poll_votes group by poll_question_id, user_id, poll_answer_id having count(*) > 1) a)
# and id not in (select * from (select min(id) from poll_votes group by poll_question_id, user_id, poll_answer_id having count(*) > 1 order by id) b))
# ActiveRecord::Base.connection.execute sql
#
# add_index :poll_votes, [:poll_question_id, :user_id, :poll_answer_id], name: 'poll_answer_index', unique: true
end
end

@ -0,0 +1,5 @@
class AddIndexToExerciseAnswers < ActiveRecord::Migration[5.2]
def change
add_index :exercise_answers, [:exercise_question_id, :user_id], name: "index_on_question_id_user_id"
end
end

@ -0,0 +1,16 @@
class AddIndexToExerciseChoice < ActiveRecord::Migration[5.2]
def change
change_column_default :exercise_answers, :exercise_choice_id, from: nil, to: -1
ExerciseAnswer.where(exercise_choice_id: nil).update_all(exercise_choice_id: -1)
sql = %Q(delete from exercise_answers where (exercise_question_id, user_id, exercise_choice_id) in
(select * from (select exercise_question_id, user_id, exercise_choice_id from exercise_answers group by exercise_question_id, user_id, exercise_choice_id having count(*) > 1) a)
and id not in (select * from (select min(id) from exercise_answers group by exercise_question_id, user_id, exercise_choice_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :exercise_answers, [:exercise_question_id, :user_id, :exercise_choice_id], name: 'exercise_choice_index', unique: true
remove_index :exercise_answers, name: :index_on_question_id_user_id
end
end

@ -0,0 +1,15 @@
class AddIndexToPollAnswer < ActiveRecord::Migration[5.2]
def change
remove_index :poll_votes, column: [:poll_question_id, :user_id]
change_column_default :poll_votes, :poll_question_id, from: nil, to: -1
PollVote.where(poll_answer_id: nil).update_all(poll_answer_id: -1)
sql = %Q(delete from poll_votes where (poll_question_id, user_id, poll_answer_id) in
(select * from (select poll_question_id, user_id, poll_answer_id from poll_votes group by poll_question_id, user_id, poll_answer_id having count(*) > 1) a)
and id not in (select * from (select min(id) from poll_votes group by poll_question_id, user_id, poll_answer_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :poll_votes, [:poll_question_id, :user_id, :poll_answer_id], name: 'poll_answer_index', unique: true
end
end

@ -0,0 +1,27 @@
class MigrateExerciseSingleQuestionScore < ActiveRecord::Migration[5.2]
def change
# # 删除判断、单选题中生成多条记录但exercise_choice_id不同的数据
# sql = %Q(delete from exercise_answers where (exercise_question_id, user_id) in
# (select * from (select exercise_question_id, user_id from exercise_answers join exercise_questions eq on exercise_question_id = eq.id where eq.question_type in (0, 2) group by exercise_question_id, user_id having count(*) > 1) a)
# and id not in (select * from (select min(exercise_answers.id) from exercise_answers join exercise_questions eq on exercise_question_id = eq.id where eq.question_type in (0, 2) group by exercise_question_id, user_id having count(*) > 1 order by exercise_answers.id) b))
# ActiveRecord::Base.connection.execute sql
#
# # 更新成绩
# exercise_answers = ExerciseAnswer.joins(:exercise_question).where(score: -1, exercise_questions: {question_type: [0, 2]})
# exercise_answers.includes(:exercise_choice, exercise_question: :exercise_standard_answers).find_each do |answer|
#
# question = answer.exercise_question
# exercise_user = ExerciseUser.find_by(exercise_id: question.exercise_id, user_id: answer.user_id)
#
# if exercise_user && exercise_user.commit_status == 1
# user_choice_position = answer.exercise_choice&.choice_position
# if user_choice_position && (user_choice_position.to_i == question.exercise_standard_answers.take&.exercise_choice_id.to_i)
# answer.update!(score: question.question_score)
# score = exercise_user.score.to_f + question.question_score
# objective_score = exercise_user.objective_score + question.question_score
# exercise_user.update!(score: score, objective_score: objective_score)
# end
# end
# end
end
end

@ -0,0 +1,6 @@
class AddModifyTimeForHackCodes < ActiveRecord::Migration[5.2]
def change
add_column :hack_codes, :modify_time, :timestamp
add_column :hack_user_lastest_codes, :modify_time, :timestamp
end
end

@ -0,0 +1,6 @@
class AddIndexForHackCodes < ActiveRecord::Migration[5.2]
def change
HackCode.destroy_all
add_index :hack_codes, [:hack_id, :language], unique: true
end
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save